[email protected] | f90bf0d9 | 2011-01-13 02:12:44 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5 | //------------------------------------------------------------------------------ |
| 6 | // Description of the life cycle of a instance of MetricsService. |
| 7 | // |
| 8 | // OVERVIEW |
| 9 | // |
| 10 | // A MetricsService instance is typically created at application startup. It |
| 11 | // is the central controller for the acquisition of log data, and the automatic |
| 12 | // transmission of that log data to an external server. Its major job is to |
| 13 | // manage logs, grouping them for transmission, and transmitting them. As part |
| 14 | // of its grouping, MS finalizes logs by including some just-in-time gathered |
| 15 | // memory statistics, snapshotting the current stats of numerous histograms, |
| 16 | // closing the logs, translating to XML text, and compressing the results for |
| 17 | // transmission. Transmission includes submitting a compressed log as data in a |
[email protected] | 281d288 | 2009-01-20 20:32:42 | [diff] [blame] | 18 | // URL-post, and retransmitting (or retaining at process termination) if the |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 19 | // attempted transmission failed. Retention across process terminations is done |
[email protected] | 46f89e14 | 2010-07-19 08:00:42 | [diff] [blame] | 20 | // using the the PrefServices facilities. The retained logs (the ones that never |
| 21 | // got transmitted) are compressed and base64-encoded before being persisted. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 22 | // |
[email protected] | 281d288 | 2009-01-20 20:32:42 | [diff] [blame] | 23 | // Logs fall into one of two categories: "initial logs," and "ongoing logs." |
| 24 | // There is at most one initial log sent for each complete run of the chromium |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 25 | // product (from startup, to browser shutdown). An initial log is generally |
| 26 | // transmitted some short time (1 minute?) after startup, and includes stats |
| 27 | // such as recent crash info, the number and types of plugins, etc. The |
[email protected] | 281d288 | 2009-01-20 20:32:42 | [diff] [blame] | 28 | // external server's response to the initial log conceptually tells this MS if |
| 29 | // it should continue transmitting logs (during this session). The server |
| 30 | // response can actually be much more detailed, and always includes (at a |
| 31 | // minimum) how often additional ongoing logs should be sent. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 32 | // |
| 33 | // After the above initial log, a series of ongoing logs will be transmitted. |
| 34 | // The first ongoing log actually begins to accumulate information stating when |
| 35 | // the MS was first constructed. Note that even though the initial log is |
| 36 | // commonly sent a full minute after startup, the initial log does not include |
| 37 | // much in the way of user stats. The most common interlog period (delay) |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 38 | // is 20 minutes. That time period starts when the first user action causes a |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 39 | // logging event. This means that if there is no user action, there may be long |
[email protected] | 281d288 | 2009-01-20 20:32:42 | [diff] [blame] | 40 | // periods without any (ongoing) log transmissions. Ongoing logs typically |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 41 | // contain very detailed records of user activities (ex: opened tab, closed |
| 42 | // tab, fetched URL, maximized window, etc.) In addition, just before an |
| 43 | // ongoing log is closed out, a call is made to gather memory statistics. Those |
| 44 | // memory statistics are deposited into a histogram, and the log finalization |
| 45 | // code is then called. In the finalization, a call to a Histogram server |
| 46 | // acquires a list of all local histograms that have been flagged for upload |
[email protected] | 281d288 | 2009-01-20 20:32:42 | [diff] [blame] | 47 | // to the UMA server. The finalization also acquires a the most recent number |
| 48 | // of page loads, along with any counts of renderer or plugin crashes. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 49 | // |
| 50 | // When the browser shuts down, there will typically be a fragment of an ongoing |
| 51 | // log that has not yet been transmitted. At shutdown time, that fragment |
| 52 | // is closed (including snapshotting histograms), and converted to text. Note |
| 53 | // that memory stats are not gathered during shutdown, as gathering *might* be |
| 54 | // too time consuming. The textual representation of the fragment of the |
| 55 | // ongoing log is then stored persistently as a string in the PrefServices, for |
| 56 | // potential transmission during a future run of the product. |
| 57 | // |
| 58 | // There are two slightly abnormal shutdown conditions. There is a |
| 59 | // "disconnected scenario," and a "really fast startup and shutdown" scenario. |
| 60 | // In the "never connected" situation, the user has (during the running of the |
| 61 | // process) never established an internet connection. As a result, attempts to |
| 62 | // transmit the initial log have failed, and a lot(?) of data has accumulated in |
| 63 | // the ongoing log (which didn't yet get closed, because there was never even a |
| 64 | // contemplation of sending it). There is also a kindred "lost connection" |
| 65 | // situation, where a loss of connection prevented an ongoing log from being |
| 66 | // transmitted, and a (still open) log was stuck accumulating a lot(?) of data, |
| 67 | // while the earlier log retried its transmission. In both of these |
| 68 | // disconnected situations, two logs need to be, and are, persistently stored |
| 69 | // for future transmission. |
| 70 | // |
| 71 | // The other unusual shutdown condition, termed "really fast startup and |
| 72 | // shutdown," involves the deliberate user termination of the process before |
| 73 | // the initial log is even formed or transmitted. In that situation, no logging |
| 74 | // is done, but the historical crash statistics remain (unlogged) for inclusion |
| 75 | // in a future run's initial log. (i.e., we don't lose crash stats). |
| 76 | // |
| 77 | // With the above overview, we can now describe the state machine's various |
| 78 | // stats, based on the State enum specified in the state_ member. Those states |
| 79 | // are: |
| 80 | // |
| 81 | // INITIALIZED, // Constructor was called. |
[email protected] | 85ed9d4 | 2010-06-08 22:37:44 | [diff] [blame] | 82 | // INIT_TASK_SCHEDULED, // Waiting for deferred init tasks to complete. |
| 83 | // INIT_TASK_DONE, // Waiting for timer to send initial log. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 84 | // INITIAL_LOG_READY, // Initial log generated, and waiting for reply. |
| 85 | // SEND_OLD_INITIAL_LOGS, // Sending unsent logs from previous session. |
| 86 | // SENDING_OLD_LOGS, // Sending unsent logs from previous session. |
| 87 | // SENDING_CURRENT_LOGS, // Sending standard current logs as they accrue. |
| 88 | // |
| 89 | // In more detail, we have: |
| 90 | // |
| 91 | // INITIALIZED, // Constructor was called. |
| 92 | // The MS has been constructed, but has taken no actions to compose the |
| 93 | // initial log. |
| 94 | // |
[email protected] | 85ed9d4 | 2010-06-08 22:37:44 | [diff] [blame] | 95 | // INIT_TASK_SCHEDULED, // Waiting for deferred init tasks to complete. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 96 | // Typically about 30 seconds after startup, a task is sent to a second thread |
[email protected] | 85ed9d4 | 2010-06-08 22:37:44 | [diff] [blame] | 97 | // (the file thread) to perform deferred (lower priority and slower) |
| 98 | // initialization steps such as getting the list of plugins. That task will |
| 99 | // (when complete) make an async callback (via a Task) to indicate the |
| 100 | // completion. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 101 | // |
[email protected] | 85ed9d4 | 2010-06-08 22:37:44 | [diff] [blame] | 102 | // INIT_TASK_DONE, // Waiting for timer to send initial log. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 103 | // The callback has arrived, and it is now possible for an initial log to be |
| 104 | // created. This callback typically arrives back less than one second after |
[email protected] | 85ed9d4 | 2010-06-08 22:37:44 | [diff] [blame] | 105 | // the deferred init task is dispatched. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 106 | // |
| 107 | // INITIAL_LOG_READY, // Initial log generated, and waiting for reply. |
| 108 | // This state is entered only after an initial log has been composed, and |
| 109 | // prepared for transmission. It is also the case that any previously unsent |
| 110 | // logs have been loaded into instance variables for possible transmission. |
| 111 | // |
| 112 | // SEND_OLD_INITIAL_LOGS, // Sending unsent logs from previous session. |
| 113 | // This state indicates that the initial log for this session has been |
| 114 | // successfully sent and it is now time to send any "initial logs" that were |
| 115 | // saved from previous sessions. Most commonly, there are none, but all old |
| 116 | // logs that were "initial logs" must be sent before this state is exited. |
| 117 | // |
| 118 | // SENDING_OLD_LOGS, // Sending unsent logs from previous session. |
| 119 | // This state indicates that there are no more unsent initial logs, and now any |
| 120 | // ongoing logs from previous sessions should be transmitted. All such logs |
| 121 | // will be transmitted before exiting this state, and proceeding with ongoing |
| 122 | // logs from the current session (see next state). |
| 123 | // |
| 124 | // SENDING_CURRENT_LOGS, // Sending standard current logs as they accrue. |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 125 | // Current logs are being accumulated. Typically every 20 minutes a log is |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 126 | // closed and finalized for transmission, at the same time as a new log is |
| 127 | // started. |
| 128 | // |
| 129 | // The progression through the above states is simple, and sequential, in the |
| 130 | // most common use cases. States proceed from INITIAL to SENDING_CURRENT_LOGS, |
| 131 | // and remain in the latter until shutdown. |
| 132 | // |
| 133 | // The one unusual case is when the user asks that we stop logging. When that |
| 134 | // happens, any pending (transmission in progress) log is pushed into the list |
| 135 | // of old unsent logs (the appropriate list, depending on whether it is an |
| 136 | // initial log, or an ongoing log). An addition, any log that is currently |
| 137 | // accumulating is also finalized, and pushed into the unsent log list. With |
[email protected] | 281d288 | 2009-01-20 20:32:42 | [diff] [blame] | 138 | // those pushes performed, we regress back to the SEND_OLD_INITIAL_LOGS state in |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 139 | // case the user enables log recording again during this session. This way |
| 140 | // anything we have "pushed back" will be sent automatically if/when we progress |
| 141 | // back to SENDING_CURRENT_LOG state. |
| 142 | // |
| 143 | // Also note that whenever the member variables containing unsent logs are |
| 144 | // modified (i.e., when we send an old log), we mirror the list of logs into |
| 145 | // the PrefServices. This ensures that IF we crash, we won't start up and |
| 146 | // retransmit our old logs again. |
| 147 | // |
| 148 | // Due to race conditions, it is always possible that a log file could be sent |
| 149 | // twice. For example, if a log file is sent, but not yet acknowledged by |
| 150 | // the external server, and the user shuts down, then a copy of the log may be |
| 151 | // saved for re-transmission. These duplicates could be filtered out server |
[email protected] | 281d288 | 2009-01-20 20:32:42 | [diff] [blame] | 152 | // side, but are not expected to be a significant problem. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 153 | // |
| 154 | // |
| 155 | //------------------------------------------------------------------------------ |
| 156 | |
[email protected] | 40bcc30 | 2009-03-02 20:50:39 | [diff] [blame] | 157 | #include "chrome/browser/metrics/metrics_service.h" |
| 158 | |
[email protected] | 46f89e14 | 2010-07-19 08:00:42 | [diff] [blame] | 159 | #include "base/base64.h" |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 160 | #include "base/bind.h" |
| 161 | #include "base/callback.h" |
[email protected] | 5d91c9e | 2010-07-28 17:25:28 | [diff] [blame] | 162 | #include "base/command_line.h" |
[email protected] | 46f89e14 | 2010-07-19 08:00:42 | [diff] [blame] | 163 | #include "base/md5.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 164 | #include "base/metrics/histogram.h" |
[email protected] | 528c56d | 2010-07-30 19:28:44 | [diff] [blame] | 165 | #include "base/string_number_conversions.h" |
[email protected] | e257d5b | 2011-05-25 14:10:16 | [diff] [blame] | 166 | #include "base/string_util.h" // For WriteInto(). |
[email protected] | ce072a7 | 2010-12-31 20:02:16 | [diff] [blame] | 167 | #include "base/threading/platform_thread.h" |
[email protected] | b3841c50 | 2011-03-09 01:21:31 | [diff] [blame] | 168 | #include "base/threading/thread.h" |
[email protected] | 440b37b2 | 2010-08-30 05:31:40 | [diff] [blame] | 169 | #include "base/utf_string_conversions.h" |
[email protected] | 67908205 | 2010-07-21 21:30:13 | [diff] [blame] | 170 | #include "base/values.h" |
[email protected] | d8e41ed | 2008-09-11 15:22:32 | [diff] [blame] | 171 | #include "chrome/browser/bookmarks/bookmark_model.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 172 | #include "chrome/browser/browser_process.h" |
[email protected] | 84c988a | 2011-04-19 17:56:33 | [diff] [blame] | 173 | #include "chrome/browser/memory_details.h" |
[email protected] | 7c927b6 | 2010-02-24 09:54:13 | [diff] [blame] | 174 | #include "chrome/browser/metrics/histogram_synchronizer.h" |
[email protected] | 67908205 | 2010-07-21 21:30:13 | [diff] [blame] | 175 | #include "chrome/browser/metrics/metrics_log.h" |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 176 | #include "chrome/browser/metrics/metrics_reporting_scheduler.h" |
[email protected] | d67d105 | 2011-06-09 05:11:41 | [diff] [blame] | 177 | #include "chrome/browser/net/network_stats.h" |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 178 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | f8628c2 | 2011-04-05 12:10:18 | [diff] [blame] | 179 | #include "chrome/browser/prefs/scoped_user_pref_update.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 180 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 8e5c89a | 2011-06-07 18:13:33 | [diff] [blame] | 181 | #include "chrome/browser/search_engines/template_url_service.h" |
[email protected] | 71b73f0 | 2011-04-06 15:57:29 | [diff] [blame] | 182 | #include "chrome/browser/ui/browser_list.h" |
[email protected] | 157d547 | 2009-11-05 22:31:03 | [diff] [blame] | 183 | #include "chrome/common/child_process_logging.h" |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 184 | #include "chrome/common/chrome_notification_types.h" |
[email protected] | 9274524 | 2009-06-12 16:52:21 | [diff] [blame] | 185 | #include "chrome/common/chrome_switches.h" |
[email protected] | 3eb0d8f7 | 2010-12-15 23:38:25 | [diff] [blame] | 186 | #include "chrome/common/guid.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 187 | #include "chrome/common/pref_names.h" |
[email protected] | e09ba55 | 2009-02-05 03:26:29 | [diff] [blame] | 188 | #include "chrome/common/render_messages.h" |
[email protected] | 35e251d | 2011-05-24 21:01:04 | [diff] [blame] | 189 | #include "content/browser/load_notification_details.h" |
[email protected] | 5de63471 | 2011-03-02 00:20:19 | [diff] [blame] | 190 | #include "content/browser/renderer_host/render_process_host.h" |
[email protected] | 6faf7b1 | 2011-03-09 19:24:14 | [diff] [blame] | 191 | #include "content/common/child_process_info.h" |
[email protected] | b3841c50 | 2011-03-09 01:21:31 | [diff] [blame] | 192 | #include "content/common/notification_service.h" |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 193 | #include "webkit/plugins/npapi/plugin_list.h" |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame^] | 194 | #include "webkit/plugins/webplugininfo.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 195 | |
[email protected] | e06131d | 2010-02-10 18:40:33 | [diff] [blame] | 196 | // TODO(port): port browser_distribution.h. |
| 197 | #if !defined(OS_POSIX) |
[email protected] | 79bf0b7 | 2009-04-27 21:30:55 | [diff] [blame] | 198 | #include "chrome/installer/util/browser_distribution.h" |
[email protected] | dc6f496 | 2009-02-13 01:25:50 | [diff] [blame] | 199 | #endif |
| 200 | |
[email protected] | 5ccaa41 | 2009-11-13 22:00:16 | [diff] [blame] | 201 | #if defined(OS_CHROMEOS) |
[email protected] | db342d5 | 2010-08-09 21:19:37 | [diff] [blame] | 202 | #include "chrome/browser/chromeos/cros/cros_library.h" |
[email protected] | 5ccaa41 | 2009-11-13 22:00:16 | [diff] [blame] | 203 | #include "chrome/browser/chromeos/external_metrics.h" |
[email protected] | d43970a7 | 2011-07-10 06:24:52 | [diff] [blame] | 204 | #include "chrome/browser/chromeos/system/statistics_provider.h" |
[email protected] | 5ccaa41 | 2009-11-13 22:00:16 | [diff] [blame] | 205 | #endif |
| 206 | |
[email protected] | 46f89e14 | 2010-07-19 08:00:42 | [diff] [blame] | 207 | namespace { |
| 208 | MetricsService::LogRecallStatus MakeRecallStatusHistogram( |
| 209 | MetricsService::LogRecallStatus status) { |
| 210 | UMA_HISTOGRAM_ENUMERATION("PrefService.PersistentLogRecall", status, |
| 211 | MetricsService::END_RECALL_STATUS); |
| 212 | return status; |
| 213 | } |
| 214 | |
| 215 | // TODO(ziadh): Remove this when done with experiment. |
| 216 | void MakeStoreStatusHistogram(MetricsService::LogStoreStatus status) { |
[email protected] | 4e95d20 | 2010-07-24 01:47:56 | [diff] [blame] | 217 | UMA_HISTOGRAM_ENUMERATION("PrefService.PersistentLogStore2", status, |
[email protected] | 46f89e14 | 2010-07-19 08:00:42 | [diff] [blame] | 218 | MetricsService::END_STORE_STATUS); |
| 219 | } |
| 220 | } // namespace |
| 221 | |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 222 | using base::Time; |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 223 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 224 | // Check to see that we're being called on only one thread. |
| 225 | static bool IsSingleThreaded(); |
| 226 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 227 | static const char kMetricsType[] = "application/vnd.mozilla.metrics.bz2"; |
| 228 | |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 229 | // The delay, in seconds, after starting recording before doing expensive |
| 230 | // initialization work. |
| 231 | static const int kInitializationDelaySeconds = 30; |
[email protected] | 252873ef | 2008-08-04 21:59:45 | [diff] [blame] | 232 | |
[email protected] | c9a3ef8 | 2009-05-28 22:02:46 | [diff] [blame] | 233 | // This specifies the amount of time to wait for all renderers to send their |
| 234 | // data. |
| 235 | static const int kMaxHistogramGatheringWaitDuration = 60000; // 60 seconds. |
| 236 | |
[email protected] | 54702c9 | 2011-04-15 15:06:43 | [diff] [blame] | 237 | // The maximum number of events in a log uploaded to the UMA server. |
| 238 | static const int kEventLimit = 2400; |
[email protected] | 68475e60 | 2008-08-22 03:21:15 | [diff] [blame] | 239 | |
| 240 | // If an upload fails, and the transmission was over this byte count, then we |
| 241 | // will discard the log, and not try to retransmit it. We also don't persist |
| 242 | // the log to the prefs for transmission during the next chrome session if this |
| 243 | // limit is exceeded. |
| 244 | static const int kUploadLogAvoidRetransmitSize = 50000; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 245 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 246 | // Interval, in seconds, between state saves. |
| 247 | static const int kSaveStateInterval = 5 * 60; // five minutes |
| 248 | |
| 249 | // The number of "initial" logs we're willing to save, and hope to send during |
| 250 | // a future Chrome session. Initial logs contain crash stats, and are pretty |
| 251 | // small. |
| 252 | static const size_t kMaxInitialLogsPersisted = 20; |
| 253 | |
| 254 | // The number of ongoing logs we're willing to save persistently, and hope to |
[email protected] | 281d288 | 2009-01-20 20:32:42 | [diff] [blame] | 255 | // send during a this or future sessions. Note that each log may be pretty |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 256 | // large, as presumably the related "initial" log wasn't sent (probably nothing |
| 257 | // was, as the user was probably off-line). As a result, the log probably kept |
| 258 | // accumulating while the "initial" log was stalled (pending_), and couldn't be |
| 259 | // sent. As a result, we don't want to save too many of these mega-logs. |
| 260 | // A "standard shutdown" will create a small log, including just the data that |
| 261 | // was not yet been transmitted, and that is normal (to have exactly one |
| 262 | // ongoing_log_ at startup). |
[email protected] | 281d288 | 2009-01-20 20:32:42 | [diff] [blame] | 263 | static const size_t kMaxOngoingLogsPersisted = 8; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 264 | |
[email protected] | 46f89e14 | 2010-07-19 08:00:42 | [diff] [blame] | 265 | // We append (2) more elements to persisted lists: the size of the list and a |
| 266 | // checksum of the elements. |
| 267 | static const size_t kChecksumEntryCount = 2; |
| 268 | |
[email protected] | 67908205 | 2010-07-21 21:30:13 | [diff] [blame] | 269 | // This is used to quickly log stats from child process related notifications in |
| 270 | // MetricsService::child_stats_buffer_. The buffer's contents are transferred |
| 271 | // out when Local State is periodically saved. The information is then |
| 272 | // reported to the UMA server on next launch. |
| 273 | struct MetricsService::ChildProcessStats { |
| 274 | public: |
| 275 | explicit ChildProcessStats(ChildProcessInfo::ProcessType type) |
| 276 | : process_launches(0), |
| 277 | process_crashes(0), |
| 278 | instances(0), |
| 279 | process_type(type) {} |
| 280 | |
| 281 | // This constructor is only used by the map to return some default value for |
| 282 | // an index for which no value has been assigned. |
| 283 | ChildProcessStats() |
| 284 | : process_launches(0), |
| 285 | process_crashes(0), |
| 286 | instances(0), |
| 287 | process_type(ChildProcessInfo::UNKNOWN_PROCESS) {} |
| 288 | |
| 289 | // The number of times that the given child process has been launched |
| 290 | int process_launches; |
| 291 | |
| 292 | // The number of times that the given child process has crashed |
| 293 | int process_crashes; |
| 294 | |
| 295 | // The number of instances of this child process that have been created. |
| 296 | // An instance is a DOM object rendered by this child process during a page |
| 297 | // load. |
| 298 | int instances; |
| 299 | |
| 300 | ChildProcessInfo::ProcessType process_type; |
| 301 | }; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 302 | |
[email protected] | 84c988a | 2011-04-19 17:56:33 | [diff] [blame] | 303 | // Handles asynchronous fetching of memory details. |
| 304 | // Will run the provided task after finished. |
| 305 | class MetricsMemoryDetails : public MemoryDetails { |
| 306 | public: |
| 307 | explicit MetricsMemoryDetails(Task* completion) : completion_(completion) {} |
| 308 | |
| 309 | virtual void OnDetailsAvailable() { |
| 310 | MessageLoop::current()->PostTask(FROM_HERE, completion_); |
| 311 | } |
| 312 | |
| 313 | private: |
| 314 | ~MetricsMemoryDetails() {} |
| 315 | |
| 316 | Task* completion_; |
| 317 | DISALLOW_COPY_AND_ASSIGN(MetricsMemoryDetails); |
| 318 | }; |
| 319 | |
[email protected] | 85ed9d4 | 2010-06-08 22:37:44 | [diff] [blame] | 320 | class MetricsService::InitTaskComplete : public Task { |
[email protected] | 35fa6a2 | 2009-08-15 00:04:01 | [diff] [blame] | 321 | public: |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 322 | explicit InitTaskComplete( |
| 323 | const std::string& hardware_class, |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame^] | 324 | const std::vector<webkit::WebPluginInfo>& plugins) |
[email protected] | 85ed9d4 | 2010-06-08 22:37:44 | [diff] [blame] | 325 | : hardware_class_(hardware_class), plugins_(plugins) {} |
| 326 | |
[email protected] | 7f2e792e | 2009-11-30 23:18:29 | [diff] [blame] | 327 | virtual void Run() { |
[email protected] | 85ed9d4 | 2010-06-08 22:37:44 | [diff] [blame] | 328 | g_browser_process->metrics_service()->OnInitTaskComplete( |
| 329 | hardware_class_, plugins_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 330 | } |
[email protected] | 35fa6a2 | 2009-08-15 00:04:01 | [diff] [blame] | 331 | |
[email protected] | 7f2e792e | 2009-11-30 23:18:29 | [diff] [blame] | 332 | private: |
[email protected] | 85ed9d4 | 2010-06-08 22:37:44 | [diff] [blame] | 333 | std::string hardware_class_; |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame^] | 334 | std::vector<webkit::WebPluginInfo> plugins_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 335 | }; |
| 336 | |
[email protected] | 85ed9d4 | 2010-06-08 22:37:44 | [diff] [blame] | 337 | class MetricsService::InitTask : public Task { |
[email protected] | 7f2e792e | 2009-11-30 23:18:29 | [diff] [blame] | 338 | public: |
[email protected] | 85ed9d4 | 2010-06-08 22:37:44 | [diff] [blame] | 339 | explicit InitTask(MessageLoop* callback_loop) |
[email protected] | 7f2e792e | 2009-11-30 23:18:29 | [diff] [blame] | 340 | : callback_loop_(callback_loop) {} |
| 341 | |
| 342 | virtual void Run() { |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame^] | 343 | std::vector<webkit::WebPluginInfo> plugins; |
[email protected] | 6859807 | 2011-07-29 08:21:28 | [diff] [blame] | 344 | webkit::npapi::PluginList::Singleton()->GetPlugins(&plugins); |
[email protected] | 85ed9d4 | 2010-06-08 22:37:44 | [diff] [blame] | 345 | std::string hardware_class; // Empty string by default. |
| 346 | #if defined(OS_CHROMEOS) |
[email protected] | d43970a7 | 2011-07-10 06:24:52 | [diff] [blame] | 347 | chromeos::system::StatisticsProvider::GetInstance()->GetMachineStatistic( |
[email protected] | 9b34516 | 2011-04-15 05:21:30 | [diff] [blame] | 348 | "hardware_class", &hardware_class); |
[email protected] | 85ed9d4 | 2010-06-08 22:37:44 | [diff] [blame] | 349 | #endif // OS_CHROMEOS |
| 350 | callback_loop_->PostTask(FROM_HERE, new InitTaskComplete( |
| 351 | hardware_class, plugins)); |
[email protected] | 7f2e792e | 2009-11-30 23:18:29 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | private: |
| 355 | MessageLoop* callback_loop_; |
| 356 | }; |
[email protected] | 90d4137 | 2009-11-30 21:52:32 | [diff] [blame] | 357 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 358 | // static |
| 359 | void MetricsService::RegisterPrefs(PrefService* local_state) { |
| 360 | DCHECK(IsSingleThreaded()); |
[email protected] | 20ce516d | 2010-06-18 02:20:04 | [diff] [blame] | 361 | local_state->RegisterStringPref(prefs::kMetricsClientID, ""); |
[email protected] | 0bb1a62 | 2009-03-04 03:22:32 | [diff] [blame] | 362 | local_state->RegisterInt64Pref(prefs::kMetricsClientIDTimestamp, 0); |
| 363 | local_state->RegisterInt64Pref(prefs::kStabilityLaunchTimeSec, 0); |
| 364 | local_state->RegisterInt64Pref(prefs::kStabilityLastTimestampSec, 0); |
[email protected] | 20ce516d | 2010-06-18 02:20:04 | [diff] [blame] | 365 | local_state->RegisterStringPref(prefs::kStabilityStatsVersion, ""); |
[email protected] | 225c5084 | 2010-01-19 21:19:13 | [diff] [blame] | 366 | local_state->RegisterInt64Pref(prefs::kStabilityStatsBuildTime, 0); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 367 | local_state->RegisterBooleanPref(prefs::kStabilityExitedCleanly, true); |
| 368 | local_state->RegisterBooleanPref(prefs::kStabilitySessionEndCompleted, true); |
| 369 | local_state->RegisterIntegerPref(prefs::kMetricsSessionID, -1); |
| 370 | local_state->RegisterIntegerPref(prefs::kStabilityLaunchCount, 0); |
| 371 | local_state->RegisterIntegerPref(prefs::kStabilityCrashCount, 0); |
| 372 | local_state->RegisterIntegerPref(prefs::kStabilityIncompleteSessionEndCount, |
| 373 | 0); |
| 374 | local_state->RegisterIntegerPref(prefs::kStabilityPageLoadCount, 0); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 375 | local_state->RegisterIntegerPref(prefs::kStabilityRendererCrashCount, 0); |
[email protected] | 1f08562 | 2009-12-04 05:33:45 | [diff] [blame] | 376 | local_state->RegisterIntegerPref(prefs::kStabilityExtensionRendererCrashCount, |
| 377 | 0); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 378 | local_state->RegisterIntegerPref(prefs::kStabilityRendererHangCount, 0); |
[email protected] | 1f08562 | 2009-12-04 05:33:45 | [diff] [blame] | 379 | local_state->RegisterIntegerPref(prefs::kStabilityChildProcessCrashCount, 0); |
[email protected] | e73c0197 | 2008-08-13 00:18:24 | [diff] [blame] | 380 | local_state->RegisterIntegerPref(prefs::kStabilityBreakpadRegistrationFail, |
| 381 | 0); |
| 382 | local_state->RegisterIntegerPref(prefs::kStabilityBreakpadRegistrationSuccess, |
| 383 | 0); |
| 384 | local_state->RegisterIntegerPref(prefs::kStabilityDebuggerPresent, 0); |
| 385 | local_state->RegisterIntegerPref(prefs::kStabilityDebuggerNotPresent, 0); |
[email protected] | c1834a9 | 2011-01-21 18:21:03 | [diff] [blame] | 386 | #if defined(OS_CHROMEOS) |
| 387 | local_state->RegisterIntegerPref(prefs::kStabilityOtherUserCrashCount, 0); |
| 388 | local_state->RegisterIntegerPref(prefs::kStabilityKernelCrashCount, 0); |
| 389 | local_state->RegisterIntegerPref(prefs::kStabilitySystemUncleanShutdownCount, |
| 390 | 0); |
| 391 | #endif // OS_CHROMEOS |
[email protected] | e73c0197 | 2008-08-13 00:18:24 | [diff] [blame] | 392 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 393 | local_state->RegisterDictionaryPref(prefs::kProfileMetrics); |
| 394 | local_state->RegisterIntegerPref(prefs::kNumBookmarksOnBookmarkBar, 0); |
| 395 | local_state->RegisterIntegerPref(prefs::kNumFoldersOnBookmarkBar, 0); |
| 396 | local_state->RegisterIntegerPref(prefs::kNumBookmarksInOtherBookmarkFolder, |
| 397 | 0); |
| 398 | local_state->RegisterIntegerPref(prefs::kNumFoldersInOtherBookmarkFolder, 0); |
| 399 | local_state->RegisterIntegerPref(prefs::kNumKeywords, 0); |
| 400 | local_state->RegisterListPref(prefs::kMetricsInitialLogs); |
| 401 | local_state->RegisterListPref(prefs::kMetricsOngoingLogs); |
[email protected] | 0bb1a62 | 2009-03-04 03:22:32 | [diff] [blame] | 402 | |
| 403 | local_state->RegisterInt64Pref(prefs::kUninstallMetricsPageLoadCount, 0); |
| 404 | local_state->RegisterInt64Pref(prefs::kUninstallLaunchCount, 0); |
[email protected] | 6b5f21d | 2009-04-13 17:01:35 | [diff] [blame] | 405 | local_state->RegisterInt64Pref(prefs::kUninstallMetricsInstallDate, 0); |
[email protected] | 0bb1a62 | 2009-03-04 03:22:32 | [diff] [blame] | 406 | local_state->RegisterInt64Pref(prefs::kUninstallMetricsUptimeSec, 0); |
| 407 | local_state->RegisterInt64Pref(prefs::kUninstallLastLaunchTimeSec, 0); |
| 408 | local_state->RegisterInt64Pref(prefs::kUninstallLastObservedRunTimeSec, 0); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 409 | } |
| 410 | |
[email protected] | 541f7792 | 2009-02-23 21:14:38 | [diff] [blame] | 411 | // static |
| 412 | void MetricsService::DiscardOldStabilityStats(PrefService* local_state) { |
| 413 | local_state->SetBoolean(prefs::kStabilityExitedCleanly, true); |
[email protected] | c9abf24 | 2009-07-18 06:00:38 | [diff] [blame] | 414 | local_state->SetBoolean(prefs::kStabilitySessionEndCompleted, true); |
[email protected] | 541f7792 | 2009-02-23 21:14:38 | [diff] [blame] | 415 | |
| 416 | local_state->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); |
| 417 | local_state->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0); |
| 418 | local_state->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0); |
| 419 | local_state->SetInteger(prefs::kStabilityDebuggerPresent, 0); |
| 420 | local_state->SetInteger(prefs::kStabilityDebuggerNotPresent, 0); |
| 421 | |
| 422 | local_state->SetInteger(prefs::kStabilityLaunchCount, 0); |
| 423 | local_state->SetInteger(prefs::kStabilityCrashCount, 0); |
| 424 | |
| 425 | local_state->SetInteger(prefs::kStabilityPageLoadCount, 0); |
| 426 | local_state->SetInteger(prefs::kStabilityRendererCrashCount, 0); |
| 427 | local_state->SetInteger(prefs::kStabilityRendererHangCount, 0); |
| 428 | |
[email protected] | 9165f74 | 2010-03-10 22:55:01 | [diff] [blame] | 429 | local_state->SetInt64(prefs::kStabilityLaunchTimeSec, 0); |
| 430 | local_state->SetInt64(prefs::kStabilityLastTimestampSec, 0); |
[email protected] | 541f7792 | 2009-02-23 21:14:38 | [diff] [blame] | 431 | |
| 432 | local_state->ClearPref(prefs::kStabilityPluginStats); |
[email protected] | ae155cb9 | 2009-06-19 06:10:37 | [diff] [blame] | 433 | |
[email protected] | f8628c2 | 2011-04-05 12:10:18 | [diff] [blame] | 434 | local_state->ClearPref(prefs::kMetricsInitialLogs); |
| 435 | local_state->ClearPref(prefs::kMetricsOngoingLogs); |
[email protected] | 541f7792 | 2009-02-23 21:14:38 | [diff] [blame] | 436 | } |
| 437 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 438 | MetricsService::MetricsService() |
[email protected] | d01b873 | 2008-10-16 02:18:07 | [diff] [blame] | 439 | : recording_active_(false), |
| 440 | reporting_active_(false), |
[email protected] | d01b873 | 2008-10-16 02:18:07 | [diff] [blame] | 441 | state_(INITIALIZED), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 442 | current_fetch_(NULL), |
[email protected] | d67d105 | 2011-06-09 05:11:41 | [diff] [blame] | 443 | io_thread_(NULL), |
[email protected] | d01b873 | 2008-10-16 02:18:07 | [diff] [blame] | 444 | idle_since_last_transmission_(false), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 445 | next_window_id_(0), |
[email protected] | 40bcc30 | 2009-03-02 20:50:39 | [diff] [blame] | 446 | ALLOW_THIS_IN_INITIALIZER_LIST(log_sender_factory_(this)), |
| 447 | ALLOW_THIS_IN_INITIALIZER_LIST(state_saver_factory_(this)), |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 448 | waiting_for_asynchronus_reporting_step_(false) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 449 | DCHECK(IsSingleThreaded()); |
| 450 | InitializeMetricsState(); |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 451 | |
| 452 | base::Closure callback = base::Bind(&MetricsService::StartScheduledUpload, |
| 453 | base::Unretained(this)); |
| 454 | scheduler_.reset(new MetricsReportingScheduler(callback)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | MetricsService::~MetricsService() { |
| 458 | SetRecording(false); |
| 459 | } |
| 460 | |
[email protected] | d01b873 | 2008-10-16 02:18:07 | [diff] [blame] | 461 | void MetricsService::Start() { |
[email protected] | b1c8dc0 | 2011-04-13 18:32:04 | [diff] [blame] | 462 | HandleIdleSinceLastTransmission(false); |
[email protected] | d01b873 | 2008-10-16 02:18:07 | [diff] [blame] | 463 | SetRecording(true); |
| 464 | SetReporting(true); |
| 465 | } |
| 466 | |
| 467 | void MetricsService::StartRecordingOnly() { |
| 468 | SetRecording(true); |
| 469 | SetReporting(false); |
| 470 | } |
| 471 | |
| 472 | void MetricsService::Stop() { |
[email protected] | b1c8dc0 | 2011-04-13 18:32:04 | [diff] [blame] | 473 | HandleIdleSinceLastTransmission(false); |
[email protected] | d01b873 | 2008-10-16 02:18:07 | [diff] [blame] | 474 | SetReporting(false); |
| 475 | SetRecording(false); |
| 476 | } |
| 477 | |
[email protected] | edafd4c | 2011-05-10 17:18:53 | [diff] [blame] | 478 | std::string MetricsService::GetClientId() { |
| 479 | return client_id_; |
| 480 | } |
| 481 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 482 | void MetricsService::SetRecording(bool enabled) { |
| 483 | DCHECK(IsSingleThreaded()); |
| 484 | |
[email protected] | d01b873 | 2008-10-16 02:18:07 | [diff] [blame] | 485 | if (enabled == recording_active_) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 486 | return; |
| 487 | |
| 488 | if (enabled) { |
[email protected] | b0c819f | 2009-03-08 04:52:15 | [diff] [blame] | 489 | if (client_id_.empty()) { |
| 490 | PrefService* pref = g_browser_process->local_state(); |
| 491 | DCHECK(pref); |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 492 | client_id_ = pref->GetString(prefs::kMetricsClientID); |
[email protected] | b0c819f | 2009-03-08 04:52:15 | [diff] [blame] | 493 | if (client_id_.empty()) { |
| 494 | client_id_ = GenerateClientID(); |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 495 | pref->SetString(prefs::kMetricsClientID, client_id_); |
[email protected] | b0c819f | 2009-03-08 04:52:15 | [diff] [blame] | 496 | |
| 497 | // Might as well make a note of how long this ID has existed |
| 498 | pref->SetString(prefs::kMetricsClientIDTimestamp, |
[email protected] | 528c56d | 2010-07-30 19:28:44 | [diff] [blame] | 499 | base::Int64ToString(Time::Now().ToTimeT())); |
[email protected] | b0c819f | 2009-03-08 04:52:15 | [diff] [blame] | 500 | } |
| 501 | } |
[email protected] | 157d547 | 2009-11-05 22:31:03 | [diff] [blame] | 502 | child_process_logging::SetClientId(client_id_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 503 | StartRecording(); |
[email protected] | 005ef3e | 2009-05-22 20:55:46 | [diff] [blame] | 504 | |
[email protected] | 3ffd3ae | 2011-03-17 22:17:52 | [diff] [blame] | 505 | SetUpNotifications(®istrar_, this); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 506 | } else { |
[email protected] | 005ef3e | 2009-05-22 20:55:46 | [diff] [blame] | 507 | registrar_.RemoveAll(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 508 | PushPendingLogsToUnsentLists(); |
| 509 | DCHECK(!pending_log()); |
| 510 | if (state_ > INITIAL_LOG_READY && unsent_logs()) |
| 511 | state_ = SEND_OLD_INITIAL_LOGS; |
| 512 | } |
[email protected] | d01b873 | 2008-10-16 02:18:07 | [diff] [blame] | 513 | recording_active_ = enabled; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 514 | } |
| 515 | |
[email protected] | d01b873 | 2008-10-16 02:18:07 | [diff] [blame] | 516 | bool MetricsService::recording_active() const { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 517 | DCHECK(IsSingleThreaded()); |
[email protected] | d01b873 | 2008-10-16 02:18:07 | [diff] [blame] | 518 | return recording_active_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 519 | } |
| 520 | |
[email protected] | d01b873 | 2008-10-16 02:18:07 | [diff] [blame] | 521 | void MetricsService::SetReporting(bool enable) { |
| 522 | if (reporting_active_ != enable) { |
| 523 | reporting_active_ = enable; |
| 524 | if (reporting_active_) |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 525 | StartSchedulerIfNecessary(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 526 | } |
[email protected] | d01b873 | 2008-10-16 02:18:07 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | bool MetricsService::reporting_active() const { |
| 530 | DCHECK(IsSingleThreaded()); |
| 531 | return reporting_active_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 532 | } |
| 533 | |
[email protected] | 87ef9ea | 2011-02-26 03:15:15 | [diff] [blame] | 534 | // static |
[email protected] | 3ffd3ae | 2011-03-17 22:17:52 | [diff] [blame] | 535 | void MetricsService::SetUpNotifications(NotificationRegistrar* registrar, |
[email protected] | 87ef9ea | 2011-02-26 03:15:15 | [diff] [blame] | 536 | NotificationObserver* observer) { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 537 | registrar->Add(observer, chrome::NOTIFICATION_BROWSER_OPENED, |
[email protected] | 04024e2c | 2011-08-12 19:32:10 | [diff] [blame] | 538 | NotificationService::AllBrowserContextsAndSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 539 | registrar->Add(observer, chrome::NOTIFICATION_BROWSER_CLOSED, |
[email protected] | 87ef9ea | 2011-02-26 03:15:15 | [diff] [blame] | 540 | NotificationService::AllSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 541 | registrar->Add(observer, content::NOTIFICATION_USER_ACTION, |
[email protected] | 87ef9ea | 2011-02-26 03:15:15 | [diff] [blame] | 542 | NotificationService::AllSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 543 | registrar->Add(observer, content::NOTIFICATION_TAB_PARENTED, |
[email protected] | 87ef9ea | 2011-02-26 03:15:15 | [diff] [blame] | 544 | NotificationService::AllSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 545 | registrar->Add(observer, content::NOTIFICATION_TAB_CLOSING, |
[email protected] | 87ef9ea | 2011-02-26 03:15:15 | [diff] [blame] | 546 | NotificationService::AllSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 547 | registrar->Add(observer, content::NOTIFICATION_LOAD_START, |
[email protected] | 87ef9ea | 2011-02-26 03:15:15 | [diff] [blame] | 548 | NotificationService::AllSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 549 | registrar->Add(observer, content::NOTIFICATION_LOAD_STOP, |
[email protected] | 87ef9ea | 2011-02-26 03:15:15 | [diff] [blame] | 550 | NotificationService::AllSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 551 | registrar->Add(observer, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
[email protected] | 87ef9ea | 2011-02-26 03:15:15 | [diff] [blame] | 552 | NotificationService::AllSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 553 | registrar->Add(observer, content::NOTIFICATION_RENDERER_PROCESS_HANG, |
[email protected] | 87ef9ea | 2011-02-26 03:15:15 | [diff] [blame] | 554 | NotificationService::AllSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 555 | registrar->Add(observer, content::NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED, |
[email protected] | 87ef9ea | 2011-02-26 03:15:15 | [diff] [blame] | 556 | NotificationService::AllSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 557 | registrar->Add(observer, content::NOTIFICATION_CHILD_INSTANCE_CREATED, |
[email protected] | 87ef9ea | 2011-02-26 03:15:15 | [diff] [blame] | 558 | NotificationService::AllSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 559 | registrar->Add(observer, content::NOTIFICATION_CHILD_PROCESS_CRASHED, |
[email protected] | 87ef9ea | 2011-02-26 03:15:15 | [diff] [blame] | 560 | NotificationService::AllSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 561 | registrar->Add(observer, chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, |
[email protected] | 87ef9ea | 2011-02-26 03:15:15 | [diff] [blame] | 562 | NotificationService::AllSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 563 | registrar->Add(observer, chrome::NOTIFICATION_OMNIBOX_OPENED_URL, |
[email protected] | 87ef9ea | 2011-02-26 03:15:15 | [diff] [blame] | 564 | NotificationService::AllSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 565 | registrar->Add(observer, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, |
[email protected] | 2f35a31 | 2011-08-09 20:21:29 | [diff] [blame] | 566 | NotificationService::AllBrowserContextsAndSources()); |
[email protected] | 87ef9ea | 2011-02-26 03:15:15 | [diff] [blame] | 567 | } |
| 568 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 569 | void MetricsService::Observe(int type, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 570 | const NotificationSource& source, |
| 571 | const NotificationDetails& details) { |
| 572 | DCHECK(current_log_); |
| 573 | DCHECK(IsSingleThreaded()); |
| 574 | |
| 575 | if (!CanLogNotification(type, source, details)) |
| 576 | return; |
| 577 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 578 | switch (type) { |
| 579 | case content::NOTIFICATION_USER_ACTION: |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 580 | current_log_->RecordUserAction(*Details<const char*>(details).ptr()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 581 | break; |
| 582 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 583 | case chrome::NOTIFICATION_BROWSER_OPENED: |
| 584 | case chrome::NOTIFICATION_BROWSER_CLOSED: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 585 | LogWindowChange(type, source, details); |
| 586 | break; |
| 587 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 588 | case content::NOTIFICATION_TAB_PARENTED: |
| 589 | case content::NOTIFICATION_TAB_CLOSING: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 590 | LogWindowChange(type, source, details); |
| 591 | break; |
| 592 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 593 | case content::NOTIFICATION_LOAD_STOP: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 594 | LogLoadComplete(type, source, details); |
| 595 | break; |
| 596 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 597 | case content::NOTIFICATION_LOAD_START: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 598 | LogLoadStarted(); |
| 599 | break; |
| 600 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 601 | case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { |
[email protected] | cd69619b | 2010-05-05 02:41:38 | [diff] [blame] | 602 | RenderProcessHost::RendererClosedDetails* process_details = |
| 603 | Details<RenderProcessHost::RendererClosedDetails>(details).ptr(); |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 604 | if (process_details->status == |
| 605 | base::TERMINATION_STATUS_PROCESS_CRASHED || |
| 606 | process_details->status == |
| 607 | base::TERMINATION_STATUS_ABNORMAL_TERMINATION) { |
[email protected] | cd69619b | 2010-05-05 02:41:38 | [diff] [blame] | 608 | if (process_details->was_extension_renderer) { |
| 609 | LogExtensionRendererCrash(); |
| 610 | } else { |
| 611 | LogRendererCrash(); |
| 612 | } |
| 613 | } |
[email protected] | 1f08562 | 2009-12-04 05:33:45 | [diff] [blame] | 614 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 615 | break; |
| 616 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 617 | case content::NOTIFICATION_RENDERER_PROCESS_HANG: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 618 | LogRendererHang(); |
| 619 | break; |
| 620 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 621 | case content::NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED: |
| 622 | case content::NOTIFICATION_CHILD_PROCESS_CRASHED: |
| 623 | case content::NOTIFICATION_CHILD_INSTANCE_CREATED: |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 624 | LogChildProcessChange(type, source, details); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 625 | break; |
| 626 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 627 | case chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED: |
[email protected] | 8e5c89a | 2011-06-07 18:13:33 | [diff] [blame] | 628 | LogKeywords(Source<TemplateURLService>(source).ptr()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 629 | break; |
| 630 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 631 | case chrome::NOTIFICATION_OMNIBOX_OPENED_URL: { |
[email protected] | 1226abb | 2010-06-10 18:01:28 | [diff] [blame] | 632 | MetricsLog* current_log = current_log_->AsMetricsLog(); |
| 633 | DCHECK(current_log); |
| 634 | current_log->RecordOmniboxOpenedURL( |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 635 | *Details<AutocompleteLog>(details).ptr()); |
| 636 | break; |
[email protected] | 1226abb | 2010-06-10 18:01:28 | [diff] [blame] | 637 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 638 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 639 | case chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED: { |
[email protected] | b61236c6 | 2009-04-09 22:43:55 | [diff] [blame] | 640 | Profile* p = Source<Profile>(source).ptr(); |
| 641 | if (p) |
| 642 | LogBookmarks(p->GetBookmarkModel()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 643 | break; |
[email protected] | b61236c6 | 2009-04-09 22:43:55 | [diff] [blame] | 644 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 645 | default: |
[email protected] | a063c10 | 2010-07-22 22:20:19 | [diff] [blame] | 646 | NOTREACHED(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 647 | break; |
| 648 | } |
[email protected] | d01b873 | 2008-10-16 02:18:07 | [diff] [blame] | 649 | |
| 650 | HandleIdleSinceLastTransmission(false); |
| 651 | |
| 652 | if (current_log_) |
[email protected] | 66620503 | 2010-10-21 20:56:58 | [diff] [blame] | 653 | DVLOG(1) << "METRICS: NUMBER OF EVENTS = " << current_log_->num_events(); |
[email protected] | d01b873 | 2008-10-16 02:18:07 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | void MetricsService::HandleIdleSinceLastTransmission(bool in_idle) { |
| 657 | // If there wasn't a lot of action, maybe the computer was asleep, in which |
| 658 | // case, the log transmissions should have stopped. Here we start them up |
| 659 | // again. |
[email protected] | cac7884 | 2008-11-27 01:02:20 | [diff] [blame] | 660 | if (!in_idle && idle_since_last_transmission_) |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 661 | StartSchedulerIfNecessary(); |
[email protected] | cac7884 | 2008-11-27 01:02:20 | [diff] [blame] | 662 | idle_since_last_transmission_ = in_idle; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 663 | } |
| 664 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 665 | void MetricsService::RecordStartOfSessionEnd() { |
[email protected] | 466f3c1 | 2011-03-23 21:20:38 | [diff] [blame] | 666 | LogCleanShutdown(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 667 | RecordBooleanPrefValue(prefs::kStabilitySessionEndCompleted, false); |
| 668 | } |
| 669 | |
| 670 | void MetricsService::RecordCompletedSessionEnd() { |
[email protected] | 466f3c1 | 2011-03-23 21:20:38 | [diff] [blame] | 671 | LogCleanShutdown(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 672 | RecordBooleanPrefValue(prefs::kStabilitySessionEndCompleted, true); |
| 673 | } |
| 674 | |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 675 | void MetricsService::RecordBreakpadRegistration(bool success) { |
[email protected] | 68475e60 | 2008-08-22 03:21:15 | [diff] [blame] | 676 | if (!success) |
[email protected] | e73c0197 | 2008-08-13 00:18:24 | [diff] [blame] | 677 | IncrementPrefValue(prefs::kStabilityBreakpadRegistrationFail); |
| 678 | else |
| 679 | IncrementPrefValue(prefs::kStabilityBreakpadRegistrationSuccess); |
| 680 | } |
| 681 | |
| 682 | void MetricsService::RecordBreakpadHasDebugger(bool has_debugger) { |
| 683 | if (!has_debugger) |
| 684 | IncrementPrefValue(prefs::kStabilityDebuggerNotPresent); |
| 685 | else |
[email protected] | 68475e60 | 2008-08-22 03:21:15 | [diff] [blame] | 686 | IncrementPrefValue(prefs::kStabilityDebuggerPresent); |
[email protected] | e73c0197 | 2008-08-13 00:18:24 | [diff] [blame] | 687 | } |
| 688 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 689 | //------------------------------------------------------------------------------ |
| 690 | // private methods |
| 691 | //------------------------------------------------------------------------------ |
| 692 | |
| 693 | |
| 694 | //------------------------------------------------------------------------------ |
| 695 | // Initialization methods |
| 696 | |
| 697 | void MetricsService::InitializeMetricsState() { |
[email protected] | 79bf0b7 | 2009-04-27 21:30:55 | [diff] [blame] | 698 | #if defined(OS_POSIX) |
| 699 | server_url_ = L"https://clients4.google.com/firefox/metrics/collect"; |
[email protected] | d67d105 | 2011-06-09 05:11:41 | [diff] [blame] | 700 | // TODO(rtenneti): Return the network stats server name. |
| 701 | network_stats_server_ = ""; |
[email protected] | 79bf0b7 | 2009-04-27 21:30:55 | [diff] [blame] | 702 | #else |
| 703 | BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 704 | server_url_ = dist->GetStatsServerURL(); |
[email protected] | d67d105 | 2011-06-09 05:11:41 | [diff] [blame] | 705 | network_stats_server_ = dist->GetNetworkStatsServer(); |
[email protected] | 79bf0b7 | 2009-04-27 21:30:55 | [diff] [blame] | 706 | #endif |
| 707 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 708 | PrefService* pref = g_browser_process->local_state(); |
| 709 | DCHECK(pref); |
| 710 | |
[email protected] | 225c5084 | 2010-01-19 21:19:13 | [diff] [blame] | 711 | if ((pref->GetInt64(prefs::kStabilityStatsBuildTime) |
| 712 | != MetricsLog::GetBuildTime()) || |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 713 | (pref->GetString(prefs::kStabilityStatsVersion) |
[email protected] | 225c5084 | 2010-01-19 21:19:13 | [diff] [blame] | 714 | != MetricsLog::GetVersionString())) { |
[email protected] | 541f7792 | 2009-02-23 21:14:38 | [diff] [blame] | 715 | // This is a new version, so we don't want to confuse the stats about the |
| 716 | // old version with info that we upload. |
| 717 | DiscardOldStabilityStats(pref); |
| 718 | pref->SetString(prefs::kStabilityStatsVersion, |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 719 | MetricsLog::GetVersionString()); |
[email protected] | 225c5084 | 2010-01-19 21:19:13 | [diff] [blame] | 720 | pref->SetInt64(prefs::kStabilityStatsBuildTime, |
| 721 | MetricsLog::GetBuildTime()); |
[email protected] | 541f7792 | 2009-02-23 21:14:38 | [diff] [blame] | 722 | } |
| 723 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 724 | // Update session ID |
| 725 | session_id_ = pref->GetInteger(prefs::kMetricsSessionID); |
| 726 | ++session_id_; |
| 727 | pref->SetInteger(prefs::kMetricsSessionID, session_id_); |
| 728 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 729 | // Stability bookkeeping |
[email protected] | e73c0197 | 2008-08-13 00:18:24 | [diff] [blame] | 730 | IncrementPrefValue(prefs::kStabilityLaunchCount); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 731 | |
[email protected] | e73c0197 | 2008-08-13 00:18:24 | [diff] [blame] | 732 | if (!pref->GetBoolean(prefs::kStabilityExitedCleanly)) { |
| 733 | IncrementPrefValue(prefs::kStabilityCrashCount); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 734 | } |
[email protected] | e73c0197 | 2008-08-13 00:18:24 | [diff] [blame] | 735 | |
| 736 | // This will be set to 'true' if we exit cleanly. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 737 | pref->SetBoolean(prefs::kStabilityExitedCleanly, false); |
| 738 | |
[email protected] | e73c0197 | 2008-08-13 00:18:24 | [diff] [blame] | 739 | if (!pref->GetBoolean(prefs::kStabilitySessionEndCompleted)) { |
| 740 | IncrementPrefValue(prefs::kStabilityIncompleteSessionEndCount); |
[email protected] | c9abf24 | 2009-07-18 06:00:38 | [diff] [blame] | 741 | // This is marked false when we get a WM_ENDSESSION. |
| 742 | pref->SetBoolean(prefs::kStabilitySessionEndCompleted, true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 743 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 744 | |
[email protected] | 9165f74 | 2010-03-10 22:55:01 | [diff] [blame] | 745 | // Initialize uptime counters. |
| 746 | int64 startup_uptime = MetricsLog::GetIncrementalUptime(pref); |
[email protected] | ae393ec70 | 2010-06-27 16:23:14 | [diff] [blame] | 747 | DCHECK_EQ(0, startup_uptime); |
[email protected] | 9165f74 | 2010-03-10 22:55:01 | [diff] [blame] | 748 | // For backwards compatibility, leave this intact in case Omaha is checking |
| 749 | // them. prefs::kStabilityLastTimestampSec may also be useless now. |
| 750 | // TODO(jar): Delete these if they have no uses. |
[email protected] | 0bb1a62 | 2009-03-04 03:22:32 | [diff] [blame] | 751 | pref->SetInt64(prefs::kStabilityLaunchTimeSec, Time::Now().ToTimeT()); |
| 752 | |
| 753 | // Bookkeeping for the uninstall metrics. |
| 754 | IncrementLongPrefsValue(prefs::kUninstallLaunchCount); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 755 | |
| 756 | // Save profile metrics. |
| 757 | PrefService* prefs = g_browser_process->local_state(); |
| 758 | if (prefs) { |
| 759 | // Remove the current dictionary and store it for use when sending data to |
| 760 | // server. By removing the value we prune potentially dead profiles |
| 761 | // (and keys). All valid values are added back once services startup. |
| 762 | const DictionaryValue* profile_dictionary = |
| 763 | prefs->GetDictionary(prefs::kProfileMetrics); |
| 764 | if (profile_dictionary) { |
| 765 | // Do a deep copy of profile_dictionary since ClearPref will delete it. |
| 766 | profile_dictionary_.reset(static_cast<DictionaryValue*>( |
| 767 | profile_dictionary->DeepCopy())); |
| 768 | prefs->ClearPref(prefs::kProfileMetrics); |
| 769 | } |
| 770 | } |
| 771 | |
[email protected] | 9274524 | 2009-06-12 16:52:21 | [diff] [blame] | 772 | // Get stats on use of command line. |
| 773 | const CommandLine* command_line(CommandLine::ForCurrentProcess()); |
| 774 | size_t common_commands = 0; |
| 775 | if (command_line->HasSwitch(switches::kUserDataDir)) { |
| 776 | ++common_commands; |
| 777 | UMA_HISTOGRAM_COUNTS_100("Chrome.CommandLineDatDirCount", 1); |
| 778 | } |
| 779 | |
| 780 | if (command_line->HasSwitch(switches::kApp)) { |
| 781 | ++common_commands; |
| 782 | UMA_HISTOGRAM_COUNTS_100("Chrome.CommandLineAppModeCount", 1); |
| 783 | } |
| 784 | |
[email protected] | 62b4e52 | 2011-07-13 21:46:32 | [diff] [blame] | 785 | size_t switch_count = command_line->GetSwitches().size(); |
| 786 | UMA_HISTOGRAM_COUNTS_100("Chrome.CommandLineFlagCount", switch_count); |
[email protected] | 9274524 | 2009-06-12 16:52:21 | [diff] [blame] | 787 | UMA_HISTOGRAM_COUNTS_100("Chrome.CommandLineUncommonFlagCount", |
[email protected] | 62b4e52 | 2011-07-13 21:46:32 | [diff] [blame] | 788 | switch_count - common_commands); |
[email protected] | 9274524 | 2009-06-12 16:52:21 | [diff] [blame] | 789 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 790 | // Kick off the process of saving the state (so the uptime numbers keep |
| 791 | // getting updated) every n minutes. |
| 792 | ScheduleNextStateSave(); |
| 793 | } |
| 794 | |
[email protected] | 85ed9d4 | 2010-06-08 22:37:44 | [diff] [blame] | 795 | void MetricsService::OnInitTaskComplete( |
| 796 | const std::string& hardware_class, |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame^] | 797 | const std::vector<webkit::WebPluginInfo>& plugins) { |
[email protected] | 85ed9d4 | 2010-06-08 22:37:44 | [diff] [blame] | 798 | DCHECK(state_ == INIT_TASK_SCHEDULED); |
| 799 | hardware_class_ = hardware_class; |
[email protected] | 35fa6a2 | 2009-08-15 00:04:01 | [diff] [blame] | 800 | plugins_ = plugins; |
[email protected] | d67d105 | 2011-06-09 05:11:41 | [diff] [blame] | 801 | io_thread_ = g_browser_process->io_thread(); |
[email protected] | 85ed9d4 | 2010-06-08 22:37:44 | [diff] [blame] | 802 | if (state_ == INIT_TASK_SCHEDULED) |
| 803 | state_ = INIT_TASK_DONE; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | std::string MetricsService::GenerateClientID() { |
[email protected] | 3469e7e | 2010-10-14 20:34:59 | [diff] [blame] | 807 | return guid::GenerateGUID(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 808 | } |
| 809 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 810 | //------------------------------------------------------------------------------ |
| 811 | // State save methods |
| 812 | |
| 813 | void MetricsService::ScheduleNextStateSave() { |
| 814 | state_saver_factory_.RevokeAll(); |
| 815 | |
| 816 | MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 817 | state_saver_factory_.NewRunnableMethod(&MetricsService::SaveLocalState), |
| 818 | kSaveStateInterval * 1000); |
| 819 | } |
| 820 | |
| 821 | void MetricsService::SaveLocalState() { |
| 822 | PrefService* pref = g_browser_process->local_state(); |
| 823 | if (!pref) { |
[email protected] | a063c10 | 2010-07-22 22:20:19 | [diff] [blame] | 824 | NOTREACHED(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 825 | return; |
| 826 | } |
| 827 | |
| 828 | RecordCurrentState(pref); |
[email protected] | 6faa0e0d | 2009-04-28 06:50:36 | [diff] [blame] | 829 | pref->ScheduleSavePersistentPrefs(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 830 | |
[email protected] | 281d288 | 2009-01-20 20:32:42 | [diff] [blame] | 831 | // TODO(jar): Does this run down the batteries???? |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 832 | ScheduleNextStateSave(); |
| 833 | } |
| 834 | |
| 835 | |
| 836 | //------------------------------------------------------------------------------ |
| 837 | // Recording control methods |
| 838 | |
| 839 | void MetricsService::StartRecording() { |
| 840 | if (current_log_) |
| 841 | return; |
| 842 | |
| 843 | current_log_ = new MetricsLog(client_id_, session_id_); |
| 844 | if (state_ == INITIALIZED) { |
| 845 | // We only need to schedule that run once. |
[email protected] | 85ed9d4 | 2010-06-08 22:37:44 | [diff] [blame] | 846 | state_ = INIT_TASK_SCHEDULED; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 847 | |
[email protected] | 85ed9d4 | 2010-06-08 22:37:44 | [diff] [blame] | 848 | // Schedules a task on the file thread for execution of slower |
| 849 | // initialization steps (such as plugin list generation) necessary |
| 850 | // for sending the initial log. This avoids blocking the main UI |
| 851 | // thread. |
[email protected] | 7f2e792e | 2009-11-30 23:18:29 | [diff] [blame] | 852 | g_browser_process->file_thread()->message_loop()->PostDelayedTask(FROM_HERE, |
[email protected] | 85ed9d4 | 2010-06-08 22:37:44 | [diff] [blame] | 853 | new InitTask(MessageLoop::current()), |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 854 | kInitializationDelaySeconds * 1000); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 855 | } |
| 856 | } |
| 857 | |
[email protected] | 024b5cd | 2011-05-27 03:29:38 | [diff] [blame] | 858 | void MetricsService::StopRecording() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 859 | if (!current_log_) |
| 860 | return; |
| 861 | |
[email protected] | 49cd7e88 | 2011-02-01 03:54:36 | [diff] [blame] | 862 | current_log_->set_hardware_class(hardware_class_); // Adds to ongoing logs. |
[email protected] | 85ed9d4 | 2010-06-08 22:37:44 | [diff] [blame] | 863 | |
[email protected] | 68475e60 | 2008-08-22 03:21:15 | [diff] [blame] | 864 | // TODO(jar): Integrate bounds on log recording more consistently, so that we |
| 865 | // can stop recording logs that are too big much sooner. |
[email protected] | 54702c9 | 2011-04-15 15:06:43 | [diff] [blame] | 866 | if (current_log_->num_events() > kEventLimit) { |
[email protected] | 553dba6 | 2009-02-24 19:08:23 | [diff] [blame] | 867 | UMA_HISTOGRAM_COUNTS("UMA.Discarded Log Events", |
[email protected] | 68475e60 | 2008-08-22 03:21:15 | [diff] [blame] | 868 | current_log_->num_events()); |
| 869 | current_log_->CloseLog(); |
| 870 | delete current_log_; |
[email protected] | 29463878 | 2008-09-24 00:22:41 | [diff] [blame] | 871 | current_log_ = NULL; |
[email protected] | 68475e60 | 2008-08-22 03:21:15 | [diff] [blame] | 872 | StartRecording(); // Start trivial log to hold our histograms. |
| 873 | } |
| 874 | |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 875 | // Put incremental data (histogram deltas, and realtime stats deltas) at the |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 876 | // end of all log transmissions (initial log handles this separately). |
[email protected] | 024b5cd | 2011-05-27 03:29:38 | [diff] [blame] | 877 | // RecordIncrementalStabilityElements only exists on the derived |
| 878 | // MetricsLog class. |
| 879 | MetricsLog* current_log = current_log_->AsMetricsLog(); |
| 880 | DCHECK(current_log); |
| 881 | current_log->RecordIncrementalStabilityElements(); |
| 882 | RecordCurrentHistograms(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 883 | |
| 884 | current_log_->CloseLog(); |
[email protected] | 024b5cd | 2011-05-27 03:29:38 | [diff] [blame] | 885 | pending_log_ = current_log_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 886 | current_log_ = NULL; |
| 887 | } |
| 888 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 889 | void MetricsService::PushPendingLogsToUnsentLists() { |
| 890 | if (state_ < INITIAL_LOG_READY) |
[email protected] | 28ab7f9 | 2009-01-06 21:39:04 | [diff] [blame] | 891 | return; // We didn't and still don't have time to get plugin list etc. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 892 | |
| 893 | if (pending_log()) { |
| 894 | PreparePendingLogText(); |
| 895 | if (state_ == INITIAL_LOG_READY) { |
| 896 | // We may race here, and send second copy of initial log later. |
[email protected] | 46f89e14 | 2010-07-19 08:00:42 | [diff] [blame] | 897 | unsent_initial_logs_.push_back(compressed_log_); |
[email protected] | d01b873 | 2008-10-16 02:18:07 | [diff] [blame] | 898 | state_ = SEND_OLD_INITIAL_LOGS; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 899 | } else { |
[email protected] | 281d288 | 2009-01-20 20:32:42 | [diff] [blame] | 900 | // TODO(jar): Verify correctness in other states, including sending unsent |
[email protected] | 541f7792 | 2009-02-23 21:14:38 | [diff] [blame] | 901 | // initial logs. |
[email protected] | 68475e60 | 2008-08-22 03:21:15 | [diff] [blame] | 902 | PushPendingLogTextToUnsentOngoingLogs(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 903 | } |
| 904 | DiscardPendingLog(); |
| 905 | } |
| 906 | DCHECK(!pending_log()); |
[email protected] | 024b5cd | 2011-05-27 03:29:38 | [diff] [blame] | 907 | StopRecording(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 908 | PreparePendingLogText(); |
[email protected] | 68475e60 | 2008-08-22 03:21:15 | [diff] [blame] | 909 | PushPendingLogTextToUnsentOngoingLogs(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 910 | DiscardPendingLog(); |
| 911 | StoreUnsentLogs(); |
| 912 | } |
| 913 | |
[email protected] | 68475e60 | 2008-08-22 03:21:15 | [diff] [blame] | 914 | void MetricsService::PushPendingLogTextToUnsentOngoingLogs() { |
[email protected] | 46f89e14 | 2010-07-19 08:00:42 | [diff] [blame] | 915 | if (compressed_log_.length() > |
[email protected] | dc6f496 | 2009-02-13 01:25:50 | [diff] [blame] | 916 | static_cast<size_t>(kUploadLogAvoidRetransmitSize)) { |
[email protected] | 553dba6 | 2009-02-24 19:08:23 | [diff] [blame] | 917 | UMA_HISTOGRAM_COUNTS("UMA.Large Accumulated Log Not Persisted", |
[email protected] | 46f89e14 | 2010-07-19 08:00:42 | [diff] [blame] | 918 | static_cast<int>(compressed_log_.length())); |
[email protected] | 68475e60 | 2008-08-22 03:21:15 | [diff] [blame] | 919 | return; |
| 920 | } |
[email protected] | 46f89e14 | 2010-07-19 08:00:42 | [diff] [blame] | 921 | unsent_ongoing_logs_.push_back(compressed_log_); |
[email protected] | 68475e60 | 2008-08-22 03:21:15 | [diff] [blame] | 922 | } |
| 923 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 924 | //------------------------------------------------------------------------------ |
| 925 | // Transmission of logs methods |
| 926 | |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 927 | void MetricsService::StartSchedulerIfNecessary() { |
| 928 | if (reporting_active() && recording_active()) |
| 929 | scheduler_->Start(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 930 | } |
| 931 | |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 932 | void MetricsService::StartScheduledUpload() { |
| 933 | // If reporting has been turned off, the scheduler doesn't need to run. |
| 934 | if (!reporting_active() || !recording_active()) { |
| 935 | scheduler_->Stop(); |
| 936 | scheduler_->UploadCancelled(); |
| 937 | return; |
| 938 | } |
| 939 | |
| 940 | DCHECK(!waiting_for_asynchronus_reporting_step_); |
| 941 | waiting_for_asynchronus_reporting_step_ = true; |
| 942 | |
[email protected] | 84c988a | 2011-04-19 17:56:33 | [diff] [blame] | 943 | Task* task = log_sender_factory_. |
| 944 | NewRunnableMethod(&MetricsService::OnMemoryDetailCollectionDone); |
| 945 | |
| 946 | scoped_refptr<MetricsMemoryDetails> details(new MetricsMemoryDetails(task)); |
| 947 | details->StartFetch(); |
| 948 | |
| 949 | // Collect WebCore cache information to put into a histogram. |
| 950 | for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); |
| 951 | !i.IsAtEnd(); i.Advance()) |
| 952 | i.GetCurrentValue()->Send(new ViewMsg_GetCacheResourceStats()); |
| 953 | } |
| 954 | |
| 955 | void MetricsService::OnMemoryDetailCollectionDone() { |
[email protected] | c9a3ef8 | 2009-05-28 22:02:46 | [diff] [blame] | 956 | DCHECK(IsSingleThreaded()); |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 957 | // This function should only be called as the callback from an ansynchronous |
| 958 | // step. |
| 959 | DCHECK(waiting_for_asynchronus_reporting_step_); |
[email protected] | c9a3ef8 | 2009-05-28 22:02:46 | [diff] [blame] | 960 | |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 961 | // Right before the UMA transmission gets started, there's one more thing we'd |
| 962 | // like to record: the histogram of memory usage, so we spawn a task to |
| 963 | // collect the memory details and when that task is finished, it will call |
| 964 | // OnMemoryDetailCollectionDone, which will call HistogramSynchronization to |
| 965 | // collect histograms from all renderers and then we will call |
| 966 | // OnHistogramSynchronizationDone to continue processing. |
[email protected] | c9a3ef8 | 2009-05-28 22:02:46 | [diff] [blame] | 967 | |
| 968 | // Create a callback_task for OnHistogramSynchronizationDone. |
| 969 | Task* callback_task = log_sender_factory_.NewRunnableMethod( |
| 970 | &MetricsService::OnHistogramSynchronizationDone); |
| 971 | |
| 972 | // Set up the callback to task to call after we receive histograms from all |
| 973 | // renderer processes. Wait time specifies how long to wait before absolutely |
| 974 | // calling us back on the task. |
| 975 | HistogramSynchronizer::FetchRendererHistogramsAsynchronously( |
| 976 | MessageLoop::current(), callback_task, |
| 977 | kMaxHistogramGatheringWaitDuration); |
| 978 | } |
| 979 | |
| 980 | void MetricsService::OnHistogramSynchronizationDone() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 981 | DCHECK(IsSingleThreaded()); |
| 982 | |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 983 | // If somehow there is a fetch in progress, we return and hope things work |
| 984 | // out. The scheduler isn't informed since if this happens, the scheduler |
| 985 | // will get a response from the upload. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 986 | DCHECK(!current_fetch_.get()); |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 987 | if (current_fetch_.get()) |
| 988 | return; |
| 989 | |
| 990 | // This function should only be called as the callback from an ansynchronous |
| 991 | // step. |
| 992 | DCHECK(waiting_for_asynchronus_reporting_step_); |
| 993 | waiting_for_asynchronus_reporting_step_ = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 994 | |
[email protected] | d01b873 | 2008-10-16 02:18:07 | [diff] [blame] | 995 | // If we're getting no notifications, then the log won't have much in it, and |
| 996 | // it's possible the computer is about to go to sleep, so don't upload and |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 997 | // stop the scheduler. |
| 998 | // Similarly, if logs should no longer be uploaded, stop here. |
| 999 | if (idle_since_last_transmission_ || |
| 1000 | !recording_active() || !reporting_active()) { |
| 1001 | scheduler_->Stop(); |
| 1002 | scheduler_->UploadCancelled(); |
[email protected] | d01b873 | 2008-10-16 02:18:07 | [diff] [blame] | 1003 | return; |
| 1004 | } |
| 1005 | |
[email protected] | d01b873 | 2008-10-16 02:18:07 | [diff] [blame] | 1006 | MakePendingLog(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1007 | |
[email protected] | d01b873 | 2008-10-16 02:18:07 | [diff] [blame] | 1008 | // MakePendingLog should have put something in the pending log, if it didn't, |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 1009 | // we skip this upload and hope things work out next time. |
[email protected] | d01b873 | 2008-10-16 02:18:07 | [diff] [blame] | 1010 | if (!pending_log()) { |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 1011 | scheduler_->UploadCancelled(); |
[email protected] | d01b873 | 2008-10-16 02:18:07 | [diff] [blame] | 1012 | return; |
| 1013 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1014 | |
[email protected] | d01b873 | 2008-10-16 02:18:07 | [diff] [blame] | 1015 | PrepareFetchWithPendingLog(); |
| 1016 | |
| 1017 | if (!current_fetch_.get()) { |
| 1018 | // Compression failed, and log discarded :-/. |
| 1019 | DiscardPendingLog(); |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 1020 | scheduler_->UploadCancelled(); |
[email protected] | d01b873 | 2008-10-16 02:18:07 | [diff] [blame] | 1021 | // TODO(jar): If compression failed, we should have created a tiny log and |
| 1022 | // compressed that, so that we can signal that we're losing logs. |
| 1023 | return; |
| 1024 | } |
| 1025 | |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 1026 | DCHECK(!waiting_for_asynchronus_reporting_step_); |
[email protected] | d01b873 | 2008-10-16 02:18:07 | [diff] [blame] | 1027 | |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 1028 | waiting_for_asynchronus_reporting_step_ = true; |
[email protected] | d01b873 | 2008-10-16 02:18:07 | [diff] [blame] | 1029 | current_fetch_->Start(); |
| 1030 | |
| 1031 | HandleIdleSinceLastTransmission(true); |
| 1032 | } |
| 1033 | |
| 1034 | |
| 1035 | void MetricsService::MakePendingLog() { |
| 1036 | if (pending_log()) |
| 1037 | return; |
| 1038 | |
| 1039 | switch (state_) { |
| 1040 | case INITIALIZED: |
[email protected] | 85ed9d4 | 2010-06-08 22:37:44 | [diff] [blame] | 1041 | case INIT_TASK_SCHEDULED: // We should be further along by now. |
[email protected] | d01b873 | 2008-10-16 02:18:07 | [diff] [blame] | 1042 | DCHECK(false); |
| 1043 | return; |
| 1044 | |
[email protected] | 85ed9d4 | 2010-06-08 22:37:44 | [diff] [blame] | 1045 | case INIT_TASK_DONE: |
[email protected] | d01b873 | 2008-10-16 02:18:07 | [diff] [blame] | 1046 | // We need to wait for the initial log to be ready before sending |
| 1047 | // anything, because the server will tell us whether it wants to hear |
| 1048 | // from us. |
| 1049 | PrepareInitialLog(); |
[email protected] | 85ed9d4 | 2010-06-08 22:37:44 | [diff] [blame] | 1050 | DCHECK(state_ == INIT_TASK_DONE); |
[email protected] | d01b873 | 2008-10-16 02:18:07 | [diff] [blame] | 1051 | RecallUnsentLogs(); |
| 1052 | state_ = INITIAL_LOG_READY; |
| 1053 | break; |
| 1054 | |
| 1055 | case SEND_OLD_INITIAL_LOGS: |
[email protected] | cac7884 | 2008-11-27 01:02:20 | [diff] [blame] | 1056 | if (!unsent_initial_logs_.empty()) { |
[email protected] | 46f89e14 | 2010-07-19 08:00:42 | [diff] [blame] | 1057 | compressed_log_ = unsent_initial_logs_.back(); |
[email protected] | d53e223 | 2011-06-30 15:54:57 | [diff] [blame] | 1058 | unsent_initial_logs_.pop_back(); |
[email protected] | cac7884 | 2008-11-27 01:02:20 | [diff] [blame] | 1059 | break; |
| 1060 | } |
[email protected] | d01b873 | 2008-10-16 02:18:07 | [diff] [blame] | 1061 | state_ = SENDING_OLD_LOGS; |
| 1062 | // Fall through. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1063 | |
[email protected] | d01b873 | 2008-10-16 02:18:07 | [diff] [blame] | 1064 | case SENDING_OLD_LOGS: |
| 1065 | if (!unsent_ongoing_logs_.empty()) { |
[email protected] | 46f89e14 | 2010-07-19 08:00:42 | [diff] [blame] | 1066 | compressed_log_ = unsent_ongoing_logs_.back(); |
[email protected] | d53e223 | 2011-06-30 15:54:57 | [diff] [blame] | 1067 | unsent_ongoing_logs_.pop_back(); |
[email protected] | d01b873 | 2008-10-16 02:18:07 | [diff] [blame] | 1068 | break; |
| 1069 | } |
| 1070 | state_ = SENDING_CURRENT_LOGS; |
| 1071 | // Fall through. |
| 1072 | |
| 1073 | case SENDING_CURRENT_LOGS: |
[email protected] | 024b5cd | 2011-05-27 03:29:38 | [diff] [blame] | 1074 | StopRecording(); |
[email protected] | d01b873 | 2008-10-16 02:18:07 | [diff] [blame] | 1075 | StartRecording(); |
| 1076 | break; |
| 1077 | |
| 1078 | default: |
[email protected] | a063c10 | 2010-07-22 22:20:19 | [diff] [blame] | 1079 | NOTREACHED(); |
[email protected] | d01b873 | 2008-10-16 02:18:07 | [diff] [blame] | 1080 | return; |
| 1081 | } |
| 1082 | |
| 1083 | DCHECK(pending_log()); |
| 1084 | } |
| 1085 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1086 | void MetricsService::PrepareInitialLog() { |
[email protected] | 85ed9d4 | 2010-06-08 22:37:44 | [diff] [blame] | 1087 | DCHECK(state_ == INIT_TASK_DONE); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1088 | |
| 1089 | MetricsLog* log = new MetricsLog(client_id_, session_id_); |
[email protected] | 85ed9d4 | 2010-06-08 22:37:44 | [diff] [blame] | 1090 | log->set_hardware_class(hardware_class_); // Adds to initial log. |
[email protected] | 35fa6a2 | 2009-08-15 00:04:01 | [diff] [blame] | 1091 | log->RecordEnvironment(plugins_, profile_dictionary_.get()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1092 | |
| 1093 | // Histograms only get written to current_log_, so setup for the write. |
[email protected] | 1226abb | 2010-06-10 18:01:28 | [diff] [blame] | 1094 | MetricsLogBase* save_log = current_log_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1095 | current_log_ = log; |
| 1096 | RecordCurrentHistograms(); // Into current_log_... which is really log. |
| 1097 | current_log_ = save_log; |
| 1098 | |
| 1099 | log->CloseLog(); |
| 1100 | DCHECK(!pending_log()); |
| 1101 | pending_log_ = log; |
| 1102 | } |
| 1103 | |
[email protected] | 46f89e14 | 2010-07-19 08:00:42 | [diff] [blame] | 1104 | // static |
| 1105 | MetricsService::LogRecallStatus MetricsService::RecallUnsentLogsHelper( |
| 1106 | const ListValue& list, |
| 1107 | std::vector<std::string>* local_list) { |
| 1108 | DCHECK(local_list->empty()); |
| 1109 | if (list.GetSize() == 0) |
| 1110 | return MakeRecallStatusHistogram(LIST_EMPTY); |
| 1111 | if (list.GetSize() < 3) |
| 1112 | return MakeRecallStatusHistogram(LIST_SIZE_TOO_SMALL); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1113 | |
[email protected] | 46f89e14 | 2010-07-19 08:00:42 | [diff] [blame] | 1114 | // The size is stored at the beginning of the list. |
| 1115 | int size; |
| 1116 | bool valid = (*list.begin())->GetAsInteger(&size); |
| 1117 | if (!valid) |
| 1118 | return MakeRecallStatusHistogram(LIST_SIZE_MISSING); |
| 1119 | |
| 1120 | // Account for checksum and size included in the list. |
| 1121 | if (static_cast<unsigned int>(size) != |
| 1122 | list.GetSize() - kChecksumEntryCount) |
| 1123 | return MakeRecallStatusHistogram(LIST_SIZE_CORRUPTION); |
| 1124 | |
[email protected] | 0ad1d2d6 | 2011-07-18 16:54:58 | [diff] [blame] | 1125 | base::MD5Context ctx; |
| 1126 | base::MD5Init(&ctx); |
[email protected] | 46f89e14 | 2010-07-19 08:00:42 | [diff] [blame] | 1127 | std::string encoded_log; |
| 1128 | std::string decoded_log; |
| 1129 | for (ListValue::const_iterator it = list.begin() + 1; |
| 1130 | it != list.end() - 1; ++it) { // Last element is the checksum. |
| 1131 | valid = (*it)->GetAsString(&encoded_log); |
| 1132 | if (!valid) { |
| 1133 | local_list->clear(); |
| 1134 | return MakeRecallStatusHistogram(LOG_STRING_CORRUPTION); |
| 1135 | } |
| 1136 | |
[email protected] | a3bcff6 | 2011-07-26 23:39:50 | [diff] [blame] | 1137 | base::MD5Update(&ctx, encoded_log); |
[email protected] | 46f89e14 | 2010-07-19 08:00:42 | [diff] [blame] | 1138 | |
| 1139 | if (!base::Base64Decode(encoded_log, &decoded_log)) { |
| 1140 | local_list->clear(); |
| 1141 | return MakeRecallStatusHistogram(DECODE_FAIL); |
| 1142 | } |
| 1143 | local_list->push_back(decoded_log); |
| 1144 | } |
| 1145 | |
| 1146 | // Verify checksum. |
[email protected] | 0ad1d2d6 | 2011-07-18 16:54:58 | [diff] [blame] | 1147 | base::MD5Digest digest; |
| 1148 | base::MD5Final(&digest, &ctx); |
[email protected] | 46f89e14 | 2010-07-19 08:00:42 | [diff] [blame] | 1149 | std::string recovered_md5; |
| 1150 | // We store the hash at the end of the list. |
| 1151 | valid = (*(list.end() - 1))->GetAsString(&recovered_md5); |
| 1152 | if (!valid) { |
| 1153 | local_list->clear(); |
| 1154 | return MakeRecallStatusHistogram(CHECKSUM_STRING_CORRUPTION); |
| 1155 | } |
[email protected] | 0ad1d2d6 | 2011-07-18 16:54:58 | [diff] [blame] | 1156 | if (recovered_md5 != base::MD5DigestToBase16(digest)) { |
[email protected] | 46f89e14 | 2010-07-19 08:00:42 | [diff] [blame] | 1157 | local_list->clear(); |
| 1158 | return MakeRecallStatusHistogram(CHECKSUM_CORRUPTION); |
| 1159 | } |
| 1160 | return MakeRecallStatusHistogram(RECALL_SUCCESS); |
| 1161 | } |
| 1162 | void MetricsService::RecallUnsentLogs() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1163 | PrefService* local_state = g_browser_process->local_state(); |
| 1164 | DCHECK(local_state); |
| 1165 | |
[email protected] | f8628c2 | 2011-04-05 12:10:18 | [diff] [blame] | 1166 | const ListValue* unsent_initial_logs = local_state->GetList( |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1167 | prefs::kMetricsInitialLogs); |
[email protected] | 46f89e14 | 2010-07-19 08:00:42 | [diff] [blame] | 1168 | RecallUnsentLogsHelper(*unsent_initial_logs, &unsent_initial_logs_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1169 | |
[email protected] | f8628c2 | 2011-04-05 12:10:18 | [diff] [blame] | 1170 | const ListValue* unsent_ongoing_logs = local_state->GetList( |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1171 | prefs::kMetricsOngoingLogs); |
[email protected] | 46f89e14 | 2010-07-19 08:00:42 | [diff] [blame] | 1172 | RecallUnsentLogsHelper(*unsent_ongoing_logs, &unsent_ongoing_logs_); |
| 1173 | } |
| 1174 | |
| 1175 | // static |
| 1176 | void MetricsService::StoreUnsentLogsHelper( |
| 1177 | const std::vector<std::string>& local_list, |
| 1178 | const size_t kMaxLocalListSize, |
| 1179 | ListValue* list) { |
| 1180 | list->Clear(); |
| 1181 | size_t start = 0; |
| 1182 | if (local_list.size() > kMaxLocalListSize) |
| 1183 | start = local_list.size() - kMaxLocalListSize; |
| 1184 | DCHECK(start <= local_list.size()); |
| 1185 | if (local_list.size() == start) |
| 1186 | return; |
| 1187 | |
| 1188 | // Store size at the beginning of the list. |
| 1189 | list->Append(Value::CreateIntegerValue(local_list.size() - start)); |
| 1190 | |
[email protected] | 0ad1d2d6 | 2011-07-18 16:54:58 | [diff] [blame] | 1191 | base::MD5Context ctx; |
| 1192 | base::MD5Init(&ctx); |
[email protected] | 46f89e14 | 2010-07-19 08:00:42 | [diff] [blame] | 1193 | std::string encoded_log; |
| 1194 | for (std::vector<std::string>::const_iterator it = local_list.begin() + start; |
| 1195 | it != local_list.end(); ++it) { |
| 1196 | // We encode the compressed log as Value::CreateStringValue() expects to |
| 1197 | // take a valid UTF8 string. |
| 1198 | if (!base::Base64Encode(*it, &encoded_log)) { |
| 1199 | MakeStoreStatusHistogram(ENCODE_FAIL); |
| 1200 | list->Clear(); |
| 1201 | return; |
| 1202 | } |
[email protected] | a3bcff6 | 2011-07-26 23:39:50 | [diff] [blame] | 1203 | base::MD5Update(&ctx, encoded_log); |
[email protected] | 46f89e14 | 2010-07-19 08:00:42 | [diff] [blame] | 1204 | list->Append(Value::CreateStringValue(encoded_log)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1205 | } |
[email protected] | 46f89e14 | 2010-07-19 08:00:42 | [diff] [blame] | 1206 | |
| 1207 | // Append hash to the end of the list. |
[email protected] | 0ad1d2d6 | 2011-07-18 16:54:58 | [diff] [blame] | 1208 | base::MD5Digest digest; |
| 1209 | base::MD5Final(&digest, &ctx); |
| 1210 | list->Append(Value::CreateStringValue(base::MD5DigestToBase16(digest))); |
[email protected] | 46f89e14 | 2010-07-19 08:00:42 | [diff] [blame] | 1211 | DCHECK(list->GetSize() >= 3); // Minimum of 3 elements (size, data, hash). |
[email protected] | 4e95d20 | 2010-07-24 01:47:56 | [diff] [blame] | 1212 | MakeStoreStatusHistogram(STORE_SUCCESS); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1213 | } |
| 1214 | |
| 1215 | void MetricsService::StoreUnsentLogs() { |
| 1216 | if (state_ < INITIAL_LOG_READY) |
| 1217 | return; // We never Recalled the prior unsent logs. |
| 1218 | |
| 1219 | PrefService* local_state = g_browser_process->local_state(); |
| 1220 | DCHECK(local_state); |
| 1221 | |
[email protected] | f8628c2 | 2011-04-05 12:10:18 | [diff] [blame] | 1222 | { |
| 1223 | ListPrefUpdate update(local_state, prefs::kMetricsInitialLogs); |
| 1224 | ListValue* unsent_initial_logs = update.Get(); |
| 1225 | StoreUnsentLogsHelper(unsent_initial_logs_, kMaxInitialLogsPersisted, |
| 1226 | unsent_initial_logs); |
| 1227 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1228 | |
[email protected] | f8628c2 | 2011-04-05 12:10:18 | [diff] [blame] | 1229 | { |
| 1230 | ListPrefUpdate update(local_state, prefs::kMetricsOngoingLogs); |
| 1231 | ListValue* unsent_ongoing_logs = update.Get(); |
| 1232 | StoreUnsentLogsHelper(unsent_ongoing_logs_, kMaxOngoingLogsPersisted, |
| 1233 | unsent_ongoing_logs); |
| 1234 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | void MetricsService::PreparePendingLogText() { |
| 1238 | DCHECK(pending_log()); |
[email protected] | 46f89e14 | 2010-07-19 08:00:42 | [diff] [blame] | 1239 | if (!compressed_log_.empty()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1240 | return; |
[email protected] | 9ffcccf4 | 2009-09-15 22:19:18 | [diff] [blame] | 1241 | int text_size = pending_log_->GetEncodedLogSize(); |
| 1242 | |
[email protected] | 46f89e14 | 2010-07-19 08:00:42 | [diff] [blame] | 1243 | std::string pending_log_text; |
| 1244 | // Leave room for the NULL terminator. |
| 1245 | pending_log_->GetEncodedLog(WriteInto(&pending_log_text, text_size + 1), |
[email protected] | 9ffcccf4 | 2009-09-15 22:19:18 | [diff] [blame] | 1246 | text_size); |
[email protected] | 46f89e14 | 2010-07-19 08:00:42 | [diff] [blame] | 1247 | |
| 1248 | if (Bzip2Compress(pending_log_text, &compressed_log_)) { |
| 1249 | // Allow security conscious users to see all metrics logs that we send. |
[email protected] | 66620503 | 2010-10-21 20:56:58 | [diff] [blame] | 1250 | VLOG(1) << "COMPRESSED FOLLOWING METRICS LOG: " << pending_log_text; |
[email protected] | 46f89e14 | 2010-07-19 08:00:42 | [diff] [blame] | 1251 | } else { |
| 1252 | LOG(DFATAL) << "Failed to compress log for transmission."; |
| 1253 | // We can't discard the logs as other caller functions expect that |
| 1254 | // |compressed_log_| not be empty. We can detect this failure at the server |
| 1255 | // after we transmit. |
| 1256 | compressed_log_ = "Unable to compress!"; |
| 1257 | MakeStoreStatusHistogram(COMPRESS_FAIL); |
| 1258 | return; |
| 1259 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1260 | } |
| 1261 | |
[email protected] | d01b873 | 2008-10-16 02:18:07 | [diff] [blame] | 1262 | void MetricsService::PrepareFetchWithPendingLog() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1263 | DCHECK(pending_log()); |
| 1264 | DCHECK(!current_fetch_.get()); |
| 1265 | PreparePendingLogText(); |
[email protected] | 46f89e14 | 2010-07-19 08:00:42 | [diff] [blame] | 1266 | DCHECK(!compressed_log_.empty()); |
[email protected] | cac7884 | 2008-11-27 01:02:20 | [diff] [blame] | 1267 | |
[email protected] | 79bf0b7 | 2009-04-27 21:30:55 | [diff] [blame] | 1268 | current_fetch_.reset(new URLFetcher(GURL(WideToUTF16(server_url_)), |
| 1269 | URLFetcher::POST, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1270 | this)); |
[email protected] | 9abfa19 | 2011-07-20 15:48:53 | [diff] [blame] | 1271 | current_fetch_->set_request_context( |
[email protected] | 8ef3d805 | 2011-07-22 09:03:00 | [diff] [blame] | 1272 | g_browser_process->system_request_context()); |
[email protected] | 46f89e14 | 2010-07-19 08:00:42 | [diff] [blame] | 1273 | current_fetch_->set_upload_data(kMetricsType, compressed_log_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1274 | } |
| 1275 | |
[email protected] | f90bf0d9 | 2011-01-13 02:12:44 | [diff] [blame] | 1276 | static const char* StatusToString(const net::URLRequestStatus& status) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1277 | switch (status.status()) { |
[email protected] | f90bf0d9 | 2011-01-13 02:12:44 | [diff] [blame] | 1278 | case net::URLRequestStatus::SUCCESS: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1279 | return "SUCCESS"; |
| 1280 | |
[email protected] | f90bf0d9 | 2011-01-13 02:12:44 | [diff] [blame] | 1281 | case net::URLRequestStatus::IO_PENDING: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1282 | return "IO_PENDING"; |
| 1283 | |
[email protected] | f90bf0d9 | 2011-01-13 02:12:44 | [diff] [blame] | 1284 | case net::URLRequestStatus::HANDLED_EXTERNALLY: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1285 | return "HANDLED_EXTERNALLY"; |
| 1286 | |
[email protected] | f90bf0d9 | 2011-01-13 02:12:44 | [diff] [blame] | 1287 | case net::URLRequestStatus::CANCELED: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1288 | return "CANCELED"; |
| 1289 | |
[email protected] | f90bf0d9 | 2011-01-13 02:12:44 | [diff] [blame] | 1290 | case net::URLRequestStatus::FAILED: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1291 | return "FAILED"; |
| 1292 | |
| 1293 | default: |
[email protected] | a063c10 | 2010-07-22 22:20:19 | [diff] [blame] | 1294 | NOTREACHED(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1295 | return "Unknown"; |
| 1296 | } |
| 1297 | } |
| 1298 | |
| 1299 | void MetricsService::OnURLFetchComplete(const URLFetcher* source, |
| 1300 | const GURL& url, |
[email protected] | f90bf0d9 | 2011-01-13 02:12:44 | [diff] [blame] | 1301 | const net::URLRequestStatus& status, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1302 | int response_code, |
[email protected] | cb04f5e | 2011-05-06 01:10:00 | [diff] [blame] | 1303 | const net::ResponseCookies& cookies, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1304 | const std::string& data) { |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 1305 | DCHECK(waiting_for_asynchronus_reporting_step_); |
| 1306 | waiting_for_asynchronus_reporting_step_ = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1307 | DCHECK(current_fetch_.get()); |
| 1308 | current_fetch_.reset(NULL); // We're not allowed to re-use it. |
| 1309 | |
| 1310 | // Confirm send so that we can move on. |
[email protected] | 66620503 | 2010-10-21 20:56:58 | [diff] [blame] | 1311 | VLOG(1) << "METRICS RESPONSE CODE: " << response_code |
| 1312 | << " status=" << StatusToString(status); |
[email protected] | 252873ef | 2008-08-04 21:59:45 | [diff] [blame] | 1313 | |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 1314 | bool upload_succeeded = response_code == 200; |
| 1315 | |
[email protected] | 0eb34fee | 2009-01-21 08:04:38 | [diff] [blame] | 1316 | // Provide boolean for error recovery (allow us to ignore response_code). |
[email protected] | dc6f496 | 2009-02-13 01:25:50 | [diff] [blame] | 1317 | bool discard_log = false; |
[email protected] | 0eb34fee | 2009-01-21 08:04:38 | [diff] [blame] | 1318 | |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 1319 | if (!upload_succeeded && |
[email protected] | 46f89e14 | 2010-07-19 08:00:42 | [diff] [blame] | 1320 | (compressed_log_.length() > |
| 1321 | static_cast<size_t>(kUploadLogAvoidRetransmitSize))) { |
[email protected] | 553dba6 | 2009-02-24 19:08:23 | [diff] [blame] | 1322 | UMA_HISTOGRAM_COUNTS("UMA.Large Rejected Log was Discarded", |
[email protected] | 46f89e14 | 2010-07-19 08:00:42 | [diff] [blame] | 1323 | static_cast<int>(compressed_log_.length())); |
[email protected] | 0eb34fee | 2009-01-21 08:04:38 | [diff] [blame] | 1324 | discard_log = true; |
| 1325 | } else if (response_code == 400) { |
| 1326 | // Bad syntax. Retransmission won't work. |
[email protected] | 553dba6 | 2009-02-24 19:08:23 | [diff] [blame] | 1327 | UMA_HISTOGRAM_COUNTS("UMA.Unacceptable_Log_Discarded", state_); |
[email protected] | 0eb34fee | 2009-01-21 08:04:38 | [diff] [blame] | 1328 | discard_log = true; |
[email protected] | 68475e60 | 2008-08-22 03:21:15 | [diff] [blame] | 1329 | } |
| 1330 | |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 1331 | if (!upload_succeeded && !discard_log) { |
[email protected] | 66620503 | 2010-10-21 20:56:58 | [diff] [blame] | 1332 | VLOG(1) << "METRICS: transmission attempt returned a failure code: " |
| 1333 | << response_code << ". Verify network connectivity"; |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 1334 | LogBadResponseCode(); |
[email protected] | 0eb34fee | 2009-01-21 08:04:38 | [diff] [blame] | 1335 | } else { // Successful receipt (or we are discarding log). |
[email protected] | 66620503 | 2010-10-21 20:56:58 | [diff] [blame] | 1336 | VLOG(1) << "METRICS RESPONSE DATA: " << data; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1337 | switch (state_) { |
| 1338 | case INITIAL_LOG_READY: |
| 1339 | state_ = SEND_OLD_INITIAL_LOGS; |
| 1340 | break; |
| 1341 | |
| 1342 | case SEND_OLD_INITIAL_LOGS: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1343 | case SENDING_OLD_LOGS: |
[email protected] | d53e223 | 2011-06-30 15:54:57 | [diff] [blame] | 1344 | // Store the updated list to disk now that the removed log is uploaded. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1345 | StoreUnsentLogs(); |
| 1346 | break; |
| 1347 | |
| 1348 | case SENDING_CURRENT_LOGS: |
| 1349 | break; |
| 1350 | |
| 1351 | default: |
[email protected] | a063c10 | 2010-07-22 22:20:19 | [diff] [blame] | 1352 | NOTREACHED(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1353 | break; |
| 1354 | } |
[email protected] | d01b873 | 2008-10-16 02:18:07 | [diff] [blame] | 1355 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1356 | DiscardPendingLog(); |
[email protected] | 29be9255 | 2008-08-07 22:49:27 | [diff] [blame] | 1357 | // Since we sent a log, make sure our in-memory state is recorded to disk. |
| 1358 | PrefService* local_state = g_browser_process->local_state(); |
| 1359 | DCHECK(local_state); |
| 1360 | if (local_state) |
[email protected] | 6faa0e0d | 2009-04-28 06:50:36 | [diff] [blame] | 1361 | local_state->ScheduleSavePersistentPrefs(); |
[email protected] | 252873ef | 2008-08-04 21:59:45 | [diff] [blame] | 1362 | |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 1363 | if (unsent_logs()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1364 | DCHECK(state_ < SENDING_CURRENT_LOGS); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1365 | } |
[email protected] | 252873ef | 2008-08-04 21:59:45 | [diff] [blame] | 1366 | |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 1367 | // Error 400 indicates a problem with the log, not with the server, so |
| 1368 | // don't consider that a sign that the server is in trouble. |
| 1369 | bool server_is_healthy = upload_succeeded || response_code == 400; |
| 1370 | |
| 1371 | scheduler_->UploadFinished(server_is_healthy, unsent_logs()); |
[email protected] | d67d105 | 2011-06-09 05:11:41 | [diff] [blame] | 1372 | |
| 1373 | // Collect network stats if UMA upload succeeded. |
| 1374 | if (server_is_healthy && io_thread_) |
| 1375 | chrome_browser_net::CollectNetworkStats(network_stats_server_, io_thread_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1376 | } |
| 1377 | |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 1378 | void MetricsService::LogBadResponseCode() { |
[email protected] | 66620503 | 2010-10-21 20:56:58 | [diff] [blame] | 1379 | VLOG(1) << "Verify your metrics logs are formatted correctly. Verify server " |
| 1380 | "is active at " << server_url_; |
[email protected] | 252873ef | 2008-08-04 21:59:45 | [diff] [blame] | 1381 | if (!pending_log()) { |
[email protected] | 66620503 | 2010-10-21 20:56:58 | [diff] [blame] | 1382 | VLOG(1) << "METRICS: Recorder shutdown during log transmission."; |
[email protected] | 252873ef | 2008-08-04 21:59:45 | [diff] [blame] | 1383 | } else { |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 1384 | VLOG(1) << "METRICS: transmission retry being scheduled for " |
[email protected] | 66620503 | 2010-10-21 20:56:58 | [diff] [blame] | 1385 | << compressed_log_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1386 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1387 | } |
| 1388 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1389 | void MetricsService::LogWindowChange(int type, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1390 | const NotificationSource& source, |
| 1391 | const NotificationDetails& details) { |
[email protected] | 534e54b | 2008-08-13 15:40:09 | [diff] [blame] | 1392 | int controller_id = -1; |
| 1393 | uintptr_t window_or_tab = source.map_key(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1394 | MetricsLog::WindowEventType window_type; |
| 1395 | |
| 1396 | // Note: since we stop all logging when a single OTR session is active, it is |
| 1397 | // possible that we start getting notifications about a window that we don't |
| 1398 | // know about. |
[email protected] | 534e54b | 2008-08-13 15:40:09 | [diff] [blame] | 1399 | if (window_map_.find(window_or_tab) == window_map_.end()) { |
| 1400 | controller_id = next_window_id_++; |
| 1401 | window_map_[window_or_tab] = controller_id; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1402 | } else { |
[email protected] | 534e54b | 2008-08-13 15:40:09 | [diff] [blame] | 1403 | controller_id = window_map_[window_or_tab]; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1404 | } |
[email protected] | 9274524 | 2009-06-12 16:52:21 | [diff] [blame] | 1405 | DCHECK_NE(controller_id, -1); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1406 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1407 | switch (type) { |
| 1408 | case content::NOTIFICATION_TAB_PARENTED: |
| 1409 | case chrome::NOTIFICATION_BROWSER_OPENED: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1410 | window_type = MetricsLog::WINDOW_CREATE; |
| 1411 | break; |
| 1412 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1413 | case content::NOTIFICATION_TAB_CLOSING: |
| 1414 | case chrome::NOTIFICATION_BROWSER_CLOSED: |
[email protected] | 534e54b | 2008-08-13 15:40:09 | [diff] [blame] | 1415 | window_map_.erase(window_map_.find(window_or_tab)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1416 | window_type = MetricsLog::WINDOW_DESTROY; |
| 1417 | break; |
| 1418 | |
| 1419 | default: |
[email protected] | a063c10 | 2010-07-22 22:20:19 | [diff] [blame] | 1420 | NOTREACHED(); |
[email protected] | 68d74f0 | 2009-02-13 01:36:50 | [diff] [blame] | 1421 | return; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1422 | } |
| 1423 | |
[email protected] | 534e54b | 2008-08-13 15:40:09 | [diff] [blame] | 1424 | // TODO(brettw) we should have some kind of ID for the parent. |
| 1425 | current_log_->RecordWindowEvent(window_type, controller_id, 0); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1426 | } |
| 1427 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1428 | void MetricsService::LogLoadComplete(int type, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1429 | const NotificationSource& source, |
| 1430 | const NotificationDetails& details) { |
| 1431 | if (details == NotificationService::NoDetails()) |
| 1432 | return; |
| 1433 | |
[email protected] | 68475e60 | 2008-08-22 03:21:15 | [diff] [blame] | 1434 | // TODO(jar): There is a bug causing this to be called too many times, and |
| 1435 | // the log overflows. For now, we won't record these events. |
[email protected] | 553dba6 | 2009-02-24 19:08:23 | [diff] [blame] | 1436 | UMA_HISTOGRAM_COUNTS("UMA.LogLoadComplete called", 1); |
[email protected] | 68475e60 | 2008-08-22 03:21:15 | [diff] [blame] | 1437 | return; |
| 1438 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1439 | const Details<LoadNotificationDetails> load_details(details); |
[email protected] | 534e54b | 2008-08-13 15:40:09 | [diff] [blame] | 1440 | int controller_id = window_map_[details.map_key()]; |
| 1441 | current_log_->RecordLoadEvent(controller_id, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1442 | load_details->url(), |
| 1443 | load_details->origin(), |
| 1444 | load_details->session_index(), |
| 1445 | load_details->load_time()); |
| 1446 | } |
| 1447 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 1448 | void MetricsService::IncrementPrefValue(const char* path) { |
[email protected] | e73c0197 | 2008-08-13 00:18:24 | [diff] [blame] | 1449 | PrefService* pref = g_browser_process->local_state(); |
| 1450 | DCHECK(pref); |
| 1451 | int value = pref->GetInteger(path); |
| 1452 | pref->SetInteger(path, value + 1); |
| 1453 | } |
| 1454 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 1455 | void MetricsService::IncrementLongPrefsValue(const char* path) { |
[email protected] | 0bb1a62 | 2009-03-04 03:22:32 | [diff] [blame] | 1456 | PrefService* pref = g_browser_process->local_state(); |
| 1457 | DCHECK(pref); |
| 1458 | int64 value = pref->GetInt64(path); |
[email protected] | b42c5e4 | 2010-06-03 20:43:25 | [diff] [blame] | 1459 | pref->SetInt64(path, value + 1); |
[email protected] | 0bb1a62 | 2009-03-04 03:22:32 | [diff] [blame] | 1460 | } |
| 1461 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1462 | void MetricsService::LogLoadStarted() { |
[email protected] | e73c0197 | 2008-08-13 00:18:24 | [diff] [blame] | 1463 | IncrementPrefValue(prefs::kStabilityPageLoadCount); |
[email protected] | 0bb1a62 | 2009-03-04 03:22:32 | [diff] [blame] | 1464 | IncrementLongPrefsValue(prefs::kUninstallMetricsPageLoadCount); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 1465 | // We need to save the prefs, as page load count is a critical stat, and it |
| 1466 | // might be lost due to a crash :-(. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1467 | } |
| 1468 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1469 | void MetricsService::LogRendererCrash() { |
[email protected] | e73c0197 | 2008-08-13 00:18:24 | [diff] [blame] | 1470 | IncrementPrefValue(prefs::kStabilityRendererCrashCount); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1471 | } |
| 1472 | |
[email protected] | 1f08562 | 2009-12-04 05:33:45 | [diff] [blame] | 1473 | void MetricsService::LogExtensionRendererCrash() { |
| 1474 | IncrementPrefValue(prefs::kStabilityExtensionRendererCrashCount); |
| 1475 | } |
| 1476 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1477 | void MetricsService::LogRendererHang() { |
[email protected] | e73c0197 | 2008-08-13 00:18:24 | [diff] [blame] | 1478 | IncrementPrefValue(prefs::kStabilityRendererHangCount); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1479 | } |
| 1480 | |
[email protected] | 466f3c1 | 2011-03-23 21:20:38 | [diff] [blame] | 1481 | void MetricsService::LogCleanShutdown() { |
| 1482 | RecordBooleanPrefValue(prefs::kStabilityExitedCleanly, true); |
| 1483 | } |
| 1484 | |
[email protected] | c1834a9 | 2011-01-21 18:21:03 | [diff] [blame] | 1485 | #if defined(OS_CHROMEOS) |
| 1486 | void MetricsService::LogChromeOSCrash(const std::string &crash_type) { |
| 1487 | if (crash_type == "user") |
| 1488 | IncrementPrefValue(prefs::kStabilityOtherUserCrashCount); |
| 1489 | else if (crash_type == "kernel") |
| 1490 | IncrementPrefValue(prefs::kStabilityKernelCrashCount); |
| 1491 | else if (crash_type == "uncleanshutdown") |
| 1492 | IncrementPrefValue(prefs::kStabilitySystemUncleanShutdownCount); |
| 1493 | else |
| 1494 | NOTREACHED() << "Unexpected Chrome OS crash type " << crash_type; |
| 1495 | // Wake up metrics logs sending if necessary now that new |
| 1496 | // log data is available. |
| 1497 | HandleIdleSinceLastTransmission(false); |
| 1498 | } |
| 1499 | #endif // OS_CHROMEOS |
| 1500 | |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 1501 | void MetricsService::LogChildProcessChange( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1502 | int type, |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 1503 | const NotificationSource& source, |
| 1504 | const NotificationDetails& details) { |
[email protected] | 0d84c5d | 2009-10-09 01:10:42 | [diff] [blame] | 1505 | Details<ChildProcessInfo> child_details(details); |
[email protected] | 68b9e72b | 2011-08-05 23:08:22 | [diff] [blame] | 1506 | const string16& child_name = child_details->name(); |
[email protected] | 0d84c5d | 2009-10-09 01:10:42 | [diff] [blame] | 1507 | |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 1508 | if (child_process_stats_buffer_.find(child_name) == |
| 1509 | child_process_stats_buffer_.end()) { |
[email protected] | 0d84c5d | 2009-10-09 01:10:42 | [diff] [blame] | 1510 | child_process_stats_buffer_[child_name] = |
| 1511 | ChildProcessStats(child_details->type()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1512 | } |
| 1513 | |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 1514 | ChildProcessStats& stats = child_process_stats_buffer_[child_name]; |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1515 | switch (type) { |
| 1516 | case content::NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1517 | stats.process_launches++; |
| 1518 | break; |
| 1519 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1520 | case content::NOTIFICATION_CHILD_INSTANCE_CREATED: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1521 | stats.instances++; |
| 1522 | break; |
| 1523 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1524 | case content::NOTIFICATION_CHILD_PROCESS_CRASHED: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1525 | stats.process_crashes++; |
[email protected] | 1f08562 | 2009-12-04 05:33:45 | [diff] [blame] | 1526 | // Exclude plugin crashes from the count below because we report them via |
| 1527 | // a separate UMA metric. |
| 1528 | if (child_details->type() != ChildProcessInfo::PLUGIN_PROCESS) { |
| 1529 | IncrementPrefValue(prefs::kStabilityChildProcessCrashCount); |
| 1530 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1531 | break; |
| 1532 | |
| 1533 | default: |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1534 | NOTREACHED() << "Unexpected notification type " << type; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1535 | return; |
| 1536 | } |
| 1537 | } |
| 1538 | |
| 1539 | // Recursively counts the number of bookmarks and folders in node. |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 1540 | static void CountBookmarks(const BookmarkNode* node, |
| 1541 | int* bookmarks, |
| 1542 | int* folders) { |
[email protected] | 0890e60e | 2011-06-27 14:55:21 | [diff] [blame] | 1543 | if (node->is_url()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1544 | (*bookmarks)++; |
| 1545 | else |
| 1546 | (*folders)++; |
[email protected] | 9c1a75a | 2011-03-10 02:38:12 | [diff] [blame] | 1547 | for (int i = 0; i < node->child_count(); ++i) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1548 | CountBookmarks(node->GetChild(i), bookmarks, folders); |
| 1549 | } |
| 1550 | |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 1551 | void MetricsService::LogBookmarks(const BookmarkNode* node, |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 1552 | const char* num_bookmarks_key, |
| 1553 | const char* num_folders_key) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1554 | DCHECK(node); |
| 1555 | int num_bookmarks = 0; |
| 1556 | int num_folders = 0; |
| 1557 | CountBookmarks(node, &num_bookmarks, &num_folders); |
| 1558 | num_folders--; // Don't include the root folder in the count. |
| 1559 | |
| 1560 | PrefService* pref = g_browser_process->local_state(); |
| 1561 | DCHECK(pref); |
| 1562 | pref->SetInteger(num_bookmarks_key, num_bookmarks); |
| 1563 | pref->SetInteger(num_folders_key, num_folders); |
| 1564 | } |
| 1565 | |
[email protected] | d8e41ed | 2008-09-11 15:22:32 | [diff] [blame] | 1566 | void MetricsService::LogBookmarks(BookmarkModel* model) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1567 | DCHECK(model); |
[email protected] | 72bdcfe | 2011-07-22 17:21:58 | [diff] [blame] | 1568 | LogBookmarks(model->bookmark_bar_node(), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1569 | prefs::kNumBookmarksOnBookmarkBar, |
| 1570 | prefs::kNumFoldersOnBookmarkBar); |
| 1571 | LogBookmarks(model->other_node(), |
| 1572 | prefs::kNumBookmarksInOtherBookmarkFolder, |
| 1573 | prefs::kNumFoldersInOtherBookmarkFolder); |
| 1574 | ScheduleNextStateSave(); |
| 1575 | } |
| 1576 | |
[email protected] | 8e5c89a | 2011-06-07 18:13:33 | [diff] [blame] | 1577 | void MetricsService::LogKeywords(const TemplateURLService* url_model) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1578 | DCHECK(url_model); |
| 1579 | |
| 1580 | PrefService* pref = g_browser_process->local_state(); |
| 1581 | DCHECK(pref); |
| 1582 | pref->SetInteger(prefs::kNumKeywords, |
| 1583 | static_cast<int>(url_model->GetTemplateURLs().size())); |
| 1584 | ScheduleNextStateSave(); |
| 1585 | } |
| 1586 | |
| 1587 | void MetricsService::RecordPluginChanges(PrefService* pref) { |
[email protected] | f8628c2 | 2011-04-05 12:10:18 | [diff] [blame] | 1588 | ListPrefUpdate update(pref, prefs::kStabilityPluginStats); |
| 1589 | ListValue* plugins = update.Get(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1590 | DCHECK(plugins); |
| 1591 | |
| 1592 | for (ListValue::iterator value_iter = plugins->begin(); |
| 1593 | value_iter != plugins->end(); ++value_iter) { |
| 1594 | if (!(*value_iter)->IsType(Value::TYPE_DICTIONARY)) { |
[email protected] | a063c10 | 2010-07-22 22:20:19 | [diff] [blame] | 1595 | NOTREACHED(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1596 | continue; |
| 1597 | } |
| 1598 | |
| 1599 | DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*value_iter); |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 1600 | std::string plugin_name; |
[email protected] | 8e50b60 | 2009-03-03 22:59:43 | [diff] [blame] | 1601 | plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name); |
[email protected] | 6470ee8f | 2009-03-03 20:46:40 | [diff] [blame] | 1602 | if (plugin_name.empty()) { |
[email protected] | a063c10 | 2010-07-22 22:20:19 | [diff] [blame] | 1603 | NOTREACHED(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1604 | continue; |
| 1605 | } |
| 1606 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 1607 | // TODO(viettrungluu): remove conversions |
[email protected] | 68b9e72b | 2011-08-05 23:08:22 | [diff] [blame] | 1608 | string16 name16 = UTF8ToUTF16(plugin_name); |
| 1609 | if (child_process_stats_buffer_.find(name16) == |
| 1610 | child_process_stats_buffer_.end()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1611 | continue; |
[email protected] | 68b9e72b | 2011-08-05 23:08:22 | [diff] [blame] | 1612 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1613 | |
[email protected] | 68b9e72b | 2011-08-05 23:08:22 | [diff] [blame] | 1614 | ChildProcessStats stats = child_process_stats_buffer_[name16]; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1615 | if (stats.process_launches) { |
| 1616 | int launches = 0; |
[email protected] | 8e50b60 | 2009-03-03 22:59:43 | [diff] [blame] | 1617 | plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1618 | launches += stats.process_launches; |
[email protected] | 8e50b60 | 2009-03-03 22:59:43 | [diff] [blame] | 1619 | plugin_dict->SetInteger(prefs::kStabilityPluginLaunches, launches); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1620 | } |
| 1621 | if (stats.process_crashes) { |
| 1622 | int crashes = 0; |
[email protected] | 8e50b60 | 2009-03-03 22:59:43 | [diff] [blame] | 1623 | plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1624 | crashes += stats.process_crashes; |
[email protected] | 8e50b60 | 2009-03-03 22:59:43 | [diff] [blame] | 1625 | plugin_dict->SetInteger(prefs::kStabilityPluginCrashes, crashes); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1626 | } |
| 1627 | if (stats.instances) { |
| 1628 | int instances = 0; |
[email protected] | 8e50b60 | 2009-03-03 22:59:43 | [diff] [blame] | 1629 | plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1630 | instances += stats.instances; |
[email protected] | 8e50b60 | 2009-03-03 22:59:43 | [diff] [blame] | 1631 | plugin_dict->SetInteger(prefs::kStabilityPluginInstances, instances); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1632 | } |
| 1633 | |
[email protected] | 68b9e72b | 2011-08-05 23:08:22 | [diff] [blame] | 1634 | child_process_stats_buffer_.erase(name16); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1635 | } |
| 1636 | |
| 1637 | // Now go through and add dictionaries for plugins that didn't already have |
| 1638 | // reports in Local State. |
[email protected] | 68b9e72b | 2011-08-05 23:08:22 | [diff] [blame] | 1639 | for (std::map<string16, ChildProcessStats>::iterator cache_iter = |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 1640 | child_process_stats_buffer_.begin(); |
| 1641 | cache_iter != child_process_stats_buffer_.end(); ++cache_iter) { |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 1642 | ChildProcessStats stats = cache_iter->second; |
[email protected] | 0d84c5d | 2009-10-09 01:10:42 | [diff] [blame] | 1643 | |
| 1644 | // Insert only plugins information into the plugins list. |
| 1645 | if (ChildProcessInfo::PLUGIN_PROCESS != stats.process_type) |
| 1646 | continue; |
| 1647 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 1648 | // TODO(viettrungluu): remove conversion |
[email protected] | 68b9e72b | 2011-08-05 23:08:22 | [diff] [blame] | 1649 | std::string plugin_name = UTF16ToUTF8(cache_iter->first); |
[email protected] | 0d84c5d | 2009-10-09 01:10:42 | [diff] [blame] | 1650 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1651 | DictionaryValue* plugin_dict = new DictionaryValue; |
| 1652 | |
[email protected] | 8e50b60 | 2009-03-03 22:59:43 | [diff] [blame] | 1653 | plugin_dict->SetString(prefs::kStabilityPluginName, plugin_name); |
| 1654 | plugin_dict->SetInteger(prefs::kStabilityPluginLaunches, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1655 | stats.process_launches); |
[email protected] | 8e50b60 | 2009-03-03 22:59:43 | [diff] [blame] | 1656 | plugin_dict->SetInteger(prefs::kStabilityPluginCrashes, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1657 | stats.process_crashes); |
[email protected] | 8e50b60 | 2009-03-03 22:59:43 | [diff] [blame] | 1658 | plugin_dict->SetInteger(prefs::kStabilityPluginInstances, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1659 | stats.instances); |
| 1660 | plugins->Append(plugin_dict); |
| 1661 | } |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 1662 | child_process_stats_buffer_.clear(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1663 | } |
| 1664 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1665 | bool MetricsService::CanLogNotification(int type, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1666 | const NotificationSource& source, |
| 1667 | const NotificationDetails& details) { |
[email protected] | 2c910b7 | 2011-03-08 21:16:32 | [diff] [blame] | 1668 | // We simply don't log anything to UMA if there is a single incognito |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1669 | // session visible. The problem is that we always notify using the orginal |
| 1670 | // profile in order to simplify notification processing. |
| 1671 | return !BrowserList::IsOffTheRecordSessionActive(); |
| 1672 | } |
| 1673 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 1674 | void MetricsService::RecordBooleanPrefValue(const char* path, bool value) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1675 | DCHECK(IsSingleThreaded()); |
| 1676 | |
| 1677 | PrefService* pref = g_browser_process->local_state(); |
| 1678 | DCHECK(pref); |
| 1679 | |
| 1680 | pref->SetBoolean(path, value); |
| 1681 | RecordCurrentState(pref); |
| 1682 | } |
| 1683 | |
| 1684 | void MetricsService::RecordCurrentState(PrefService* pref) { |
[email protected] | 0bb1a62 | 2009-03-04 03:22:32 | [diff] [blame] | 1685 | pref->SetInt64(prefs::kStabilityLastTimestampSec, Time::Now().ToTimeT()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1686 | |
| 1687 | RecordPluginChanges(pref); |
| 1688 | } |
| 1689 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1690 | static bool IsSingleThreaded() { |
[email protected] | ce072a7 | 2010-12-31 20:02:16 | [diff] [blame] | 1691 | static base::PlatformThreadId thread_id = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1692 | if (!thread_id) |
[email protected] | ce072a7 | 2010-12-31 20:02:16 | [diff] [blame] | 1693 | thread_id = base::PlatformThread::CurrentId(); |
| 1694 | return base::PlatformThread::CurrentId() == thread_id; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1695 | } |
[email protected] | 5ccaa41 | 2009-11-13 22:00:16 | [diff] [blame] | 1696 | |
| 1697 | #if defined(OS_CHROMEOS) |
[email protected] | 29cf1677 | 2010-04-21 15:13:47 | [diff] [blame] | 1698 | void MetricsService::StartExternalMetrics() { |
[email protected] | 5ccaa41 | 2009-11-13 22:00:16 | [diff] [blame] | 1699 | external_metrics_ = new chromeos::ExternalMetrics; |
[email protected] | 29cf1677 | 2010-04-21 15:13:47 | [diff] [blame] | 1700 | external_metrics_->Start(); |
[email protected] | 5ccaa41 | 2009-11-13 22:00:16 | [diff] [blame] | 1701 | } |
| 1702 | #endif |