blob: fe5348940b60d0be62aeb8088a6542d5fe6cdbdb [file] [log] [blame]
[email protected]d6147bd2014-06-11 01:58:191// Copyright 2014 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
initial.commit09911bf2008-07-26 23:55:295//------------------------------------------------------------------------------
6// Description of the life cycle of a instance of MetricsService.
7//
8// OVERVIEW
9//
[email protected]e3eb0c42013-04-18 06:18:5810// A MetricsService instance is typically created at application startup. It is
11// the central controller for the acquisition of log data, and the automatic
initial.commit09911bf2008-07-26 23:55:2912// 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,
[email protected]e3eb0c42013-04-18 06:18:5816// closing the logs, translating to protocol buffer format, and compressing the
17// results for transmission. Transmission includes submitting a compressed log
18// as data in a URL-post, and retransmitting (or retaining at process
19// termination) if the attempted transmission failed. Retention across process
20// terminations is done using the the PrefServices facilities. The retained logs
21// (the ones that never got transmitted) are compressed and base64-encoded
22// before being persisted.
initial.commit09911bf2008-07-26 23:55:2923//
[email protected]281d2882009-01-20 20:32:4224// Logs fall into one of two categories: "initial logs," and "ongoing logs."
[email protected]80a8f312013-12-16 18:00:3025// There is at most one initial log sent for each complete run of Chrome (from
26// startup, to browser shutdown). An initial log is generally transmitted some
27// short time (1 minute?) after startup, and includes stats such as recent crash
28// info, the number and types of plugins, etc. The external server's response
29// to the initial log conceptually tells this MS if it should continue
30// transmitting logs (during this session). The server response can actually be
31// much more detailed, and always includes (at a minimum) how often additional
32// ongoing logs should be sent.
initial.commit09911bf2008-07-26 23:55:2933//
34// After the above initial log, a series of ongoing logs will be transmitted.
35// The first ongoing log actually begins to accumulate information stating when
36// the MS was first constructed. Note that even though the initial log is
37// commonly sent a full minute after startup, the initial log does not include
38// much in the way of user stats. The most common interlog period (delay)
[email protected]3a668152013-06-21 23:56:4239// is 30 minutes. That time period starts when the first user action causes a
initial.commit09911bf2008-07-26 23:55:2940// logging event. This means that if there is no user action, there may be long
[email protected]281d2882009-01-20 20:32:4241// periods without any (ongoing) log transmissions. Ongoing logs typically
initial.commit09911bf2008-07-26 23:55:2942// contain very detailed records of user activities (ex: opened tab, closed
43// tab, fetched URL, maximized window, etc.) In addition, just before an
44// ongoing log is closed out, a call is made to gather memory statistics. Those
45// memory statistics are deposited into a histogram, and the log finalization
46// code is then called. In the finalization, a call to a Histogram server
47// acquires a list of all local histograms that have been flagged for upload
[email protected]80a8f312013-12-16 18:00:3048// to the UMA server. The finalization also acquires the most recent number
[email protected]281d2882009-01-20 20:32:4249// of page loads, along with any counts of renderer or plugin crashes.
initial.commit09911bf2008-07-26 23:55:2950//
51// When the browser shuts down, there will typically be a fragment of an ongoing
[email protected]80a8f312013-12-16 18:00:3052// log that has not yet been transmitted. At shutdown time, that fragment is
53// closed (including snapshotting histograms), and persisted, for potential
54// transmission during a future run of the product.
initial.commit09911bf2008-07-26 23:55:2955//
56// There are two slightly abnormal shutdown conditions. There is a
57// "disconnected scenario," and a "really fast startup and shutdown" scenario.
58// In the "never connected" situation, the user has (during the running of the
59// process) never established an internet connection. As a result, attempts to
60// transmit the initial log have failed, and a lot(?) of data has accumulated in
61// the ongoing log (which didn't yet get closed, because there was never even a
62// contemplation of sending it). There is also a kindred "lost connection"
63// situation, where a loss of connection prevented an ongoing log from being
64// transmitted, and a (still open) log was stuck accumulating a lot(?) of data,
65// while the earlier log retried its transmission. In both of these
66// disconnected situations, two logs need to be, and are, persistently stored
67// for future transmission.
68//
69// The other unusual shutdown condition, termed "really fast startup and
70// shutdown," involves the deliberate user termination of the process before
71// the initial log is even formed or transmitted. In that situation, no logging
72// is done, but the historical crash statistics remain (unlogged) for inclusion
73// in a future run's initial log. (i.e., we don't lose crash stats).
74//
75// With the above overview, we can now describe the state machine's various
[email protected]80a8f312013-12-16 18:00:3076// states, based on the State enum specified in the state_ member. Those states
initial.commit09911bf2008-07-26 23:55:2977// are:
78//
Steven Holte2c294a32015-03-12 21:45:0379// INITIALIZED, // Constructor was called.
80// INIT_TASK_SCHEDULED, // Waiting for deferred init tasks to finish.
81// INIT_TASK_DONE, // Waiting for timer to send initial log.
82// SENDING_LOGS, // Sending logs and creating new ones when we run out.
initial.commit09911bf2008-07-26 23:55:2983//
84// In more detail, we have:
85//
86// INITIALIZED, // Constructor was called.
87// The MS has been constructed, but has taken no actions to compose the
88// initial log.
89//
[email protected]80a8f312013-12-16 18:00:3090// INIT_TASK_SCHEDULED, // Waiting for deferred init tasks to finish.
initial.commit09911bf2008-07-26 23:55:2991// Typically about 30 seconds after startup, a task is sent to a second thread
[email protected]85ed9d42010-06-08 22:37:4492// (the file thread) to perform deferred (lower priority and slower)
93// initialization steps such as getting the list of plugins. That task will
94// (when complete) make an async callback (via a Task) to indicate the
95// completion.
initial.commit09911bf2008-07-26 23:55:2996//
[email protected]85ed9d42010-06-08 22:37:4497// INIT_TASK_DONE, // Waiting for timer to send initial log.
initial.commit09911bf2008-07-26 23:55:2998// The callback has arrived, and it is now possible for an initial log to be
99// created. This callback typically arrives back less than one second after
[email protected]85ed9d42010-06-08 22:37:44100// the deferred init task is dispatched.
initial.commit09911bf2008-07-26 23:55:29101//
Steven Holte2c294a32015-03-12 21:45:03102// SENDING_LOGS, // Sending logs an creating new ones when we run out.
103// Logs from previous sessions have been loaded, and initial logs have been
104// created (an optional stability log and the first metrics log). We will
105// send all of these logs, and when run out, we will start cutting new logs
106// to send. We will also cut a new log if we expect a shutdown.
[email protected]80a8f312013-12-16 18:00:30107//
Steven Holte2c294a32015-03-12 21:45:03108// The progression through the above states is simple, and sequential.
109// States proceed from INITIAL to SENDING_LOGS, and remain in the latter until
110// shutdown.
initial.commit09911bf2008-07-26 23:55:29111//
Steven Holte2c294a32015-03-12 21:45:03112// Also note that whenever we successfully send a log, we mirror the list
[email protected]cac267c2011-09-29 15:18:10113// of logs into the PrefService. This ensures that IF we crash, we won't start
114// up and retransmit our old logs again.
initial.commit09911bf2008-07-26 23:55:29115//
116// Due to race conditions, it is always possible that a log file could be sent
117// twice. For example, if a log file is sent, but not yet acknowledged by
118// the external server, and the user shuts down, then a copy of the log may be
119// saved for re-transmission. These duplicates could be filtered out server
[email protected]281d2882009-01-20 20:32:42120// side, but are not expected to be a significant problem.
initial.commit09911bf2008-07-26 23:55:29121//
122//
123//------------------------------------------------------------------------------
124
[email protected]d6147bd2014-06-11 01:58:19125#include "components/metrics/metrics_service.h"
[email protected]40bcc302009-03-02 20:50:39126
[email protected]d7c1fa62012-06-15 23:35:30127#include <algorithm>
128
[email protected]7f7f1962011-04-20 15:58:16129#include "base/bind.h"
130#include "base/callback.h"
[email protected]835d7c82010-10-14 04:38:38131#include "base/metrics/histogram.h"
[email protected]acc2ce5512014-05-22 18:29:13132#include "base/metrics/histogram_base.h"
133#include "base/metrics/histogram_samples.h"
[email protected]1026afd2013-03-20 14:28:54134#include "base/metrics/sparse_histogram.h"
[email protected]567d30e2012-07-13 21:48:29135#include "base/metrics/statistics_recorder.h"
[email protected]3853a4c2013-02-11 17:15:57136#include "base/prefs/pref_registry_simple.h"
137#include "base/prefs/pref_service.h"
[email protected]3ea1b182013-02-08 22:38:41138#include "base/strings/string_number_conversions.h"
[email protected]112158af2013-06-07 23:46:18139#include "base/strings/utf_string_conversions.h"
[email protected]ce072a72010-12-31 20:02:16140#include "base/threading/platform_thread.h"
[email protected]b3841c502011-03-09 01:21:31141#include "base/threading/thread.h"
[email protected]3a7b66d2012-04-26 16:34:16142#include "base/threading/thread_restrictions.h"
[email protected]64b8652c2014-07-16 19:14:28143#include "base/time/time.h"
[email protected]ed0fd002012-04-25 23:10:34144#include "base/tracked_objects.h"
[email protected]679082052010-07-21 21:30:13145#include "base/values.h"
[email protected]91b1d912014-06-05 10:52:08146#include "components/metrics/metrics_log.h"
[email protected]064107e2014-05-02 00:59:06147#include "components/metrics/metrics_log_manager.h"
[email protected]0d5a61a82014-05-31 22:28:34148#include "components/metrics/metrics_log_uploader.h"
[email protected]7f07db62014-05-15 01:12:45149#include "components/metrics/metrics_pref_names.h"
[email protected]14bb46692014-05-20 17:16:45150#include "components/metrics/metrics_reporting_scheduler.h"
[email protected]73929422014-05-22 08:19:05151#include "components/metrics/metrics_service_client.h"
[email protected]16a30912014-06-04 00:20:04152#include "components/metrics/metrics_state_manager.h"
[email protected]50ae9f12013-08-29 18:03:22153#include "components/variations/entropy_provider.h"
initial.commit09911bf2008-07-26 23:55:29154
asvitkinecbd420732014-08-26 22:15:40155namespace metrics {
[email protected]e1acf6f2008-10-27 20:43:33156
[email protected]fe58acc22012-02-29 01:29:58157namespace {
[email protected]b2a4812d2012-02-28 05:31:31158
[email protected]fe58acc22012-02-29 01:29:58159// Check to see that we're being called on only one thread.
160bool IsSingleThreaded() {
161 static base::PlatformThreadId thread_id = 0;
162 if (!thread_id)
163 thread_id = base::PlatformThread::CurrentId();
164 return base::PlatformThread::CurrentId() == thread_id;
165}
166
[email protected]7f7f1962011-04-20 15:58:16167// The delay, in seconds, after starting recording before doing expensive
168// initialization work.
[email protected]12180f82012-10-10 21:13:30169#if defined(OS_ANDROID) || defined(OS_IOS)
170// On mobile devices, a significant portion of sessions last less than a minute.
171// Use a shorter timer on these platforms to avoid losing data.
172// TODO(dfalcantara): To avoid delaying startup, tighten up initialization so
173// that it occurs after the user gets their initial page.
174const int kInitializationDelaySeconds = 5;
175#else
[email protected]fe58acc22012-02-29 01:29:58176const int kInitializationDelaySeconds = 30;
[email protected]12180f82012-10-10 21:13:30177#endif
[email protected]252873ef2008-08-04 21:59:45178
[email protected]54702c92011-04-15 15:06:43179// The maximum number of events in a log uploaded to the UMA server.
[email protected]fe58acc22012-02-29 01:29:58180const int kEventLimit = 2400;
[email protected]68475e602008-08-22 03:21:15181
182// If an upload fails, and the transmission was over this byte count, then we
183// will discard the log, and not try to retransmit it. We also don't persist
184// the log to the prefs for transmission during the next chrome session if this
185// limit is exceeded.
[email protected]a63006e2014-06-20 05:22:32186const size_t kUploadLogAvoidRetransmitSize = 100 * 1024;
initial.commit09911bf2008-07-26 23:55:29187
[email protected]fc4252a72012-01-12 21:58:47188// Interval, in minutes, between state saves.
[email protected]fe58acc22012-02-29 01:29:58189const int kSaveStateIntervalMinutes = 5;
190
[email protected]4266def22012-05-17 01:02:40191enum ResponseStatus {
192 UNKNOWN_FAILURE,
193 SUCCESS,
194 BAD_REQUEST, // Invalid syntax or log too large.
[email protected]9f5c1ce82012-05-23 23:11:28195 NO_RESPONSE,
[email protected]4266def22012-05-17 01:02:40196 NUM_RESPONSE_STATUSES
197};
198
199ResponseStatus ResponseCodeToStatus(int response_code) {
200 switch (response_code) {
[email protected]0d5a61a82014-05-31 22:28:34201 case -1:
202 return NO_RESPONSE;
[email protected]4266def22012-05-17 01:02:40203 case 200:
204 return SUCCESS;
205 case 400:
206 return BAD_REQUEST;
207 default:
208 return UNKNOWN_FAILURE;
209 }
210}
211
hashimotoa5c00e28d2015-03-27 06:28:37212#if defined(OS_ANDROID) || defined(OS_IOS)
erikwright65b58df2014-09-12 00:05:28213void MarkAppCleanShutdownAndCommit(CleanExitBeacon* clean_exit_beacon,
214 PrefService* local_state) {
215 clean_exit_beacon->WriteBeaconValue(true);
asvitkinea63d19e2014-10-24 16:19:39216 local_state->SetInteger(prefs::kStabilityExecutionPhase,
[email protected]24f81ca2014-05-26 15:59:34217 MetricsService::SHUTDOWN_COMPLETE);
[email protected]84c384e2013-03-01 23:20:19218 // Start writing right away (write happens on a different thread).
[email protected]24f81ca2014-05-26 15:59:34219 local_state->CommitPendingWrite();
[email protected]84c384e2013-03-01 23:20:19220}
hashimotoa5c00e28d2015-03-27 06:28:37221#endif // defined(OS_ANDROID) || defined(OS_IOS)
[email protected]84c384e2013-03-01 23:20:19222
[email protected]20f999b52012-08-24 22:32:59223} // namespace
initial.commit09911bf2008-07-26 23:55:29224
[email protected]60677562013-11-17 15:52:55225
[email protected]7a5c07812014-02-26 11:45:41226SyntheticTrialGroup::SyntheticTrialGroup(uint32 trial, uint32 group) {
[email protected]60677562013-11-17 15:52:55227 id.name = trial;
228 id.group = group;
229}
230
231SyntheticTrialGroup::~SyntheticTrialGroup() {
232}
233
[email protected]c0c55e92011-09-10 18:47:30234// static
235MetricsService::ShutdownCleanliness MetricsService::clean_shutdown_status_ =
236 MetricsService::CLEANLY_SHUTDOWN;
237
[email protected]6a6d0d12013-10-28 15:58:19238MetricsService::ExecutionPhase MetricsService::execution_phase_ =
[email protected]6d67ea0d2013-11-14 11:02:21239 MetricsService::UNINITIALIZED_PHASE;
[email protected]6a6d0d12013-10-28 15:58:19240
initial.commit09911bf2008-07-26 23:55:29241// static
[email protected]b1de2c72013-02-06 02:45:47242void MetricsService::RegisterPrefs(PrefRegistrySimple* registry) {
initial.commit09911bf2008-07-26 23:55:29243 DCHECK(IsSingleThreaded());
asvitkinea63d19e2014-10-24 16:19:39244 MetricsStateManager::RegisterPrefs(registry);
[email protected]91b1d912014-06-05 10:52:08245 MetricsLog::RegisterPrefs(registry);
[email protected]39076642014-05-05 20:32:55246
asvitkinea63d19e2014-10-24 16:19:39247 registry->RegisterInt64Pref(prefs::kInstallDate, 0);
[email protected]65801452014-07-09 05:42:41248
asvitkinea63d19e2014-10-24 16:19:39249 registry->RegisterInt64Pref(prefs::kStabilityLaunchTimeSec, 0);
250 registry->RegisterInt64Pref(prefs::kStabilityLastTimestampSec, 0);
251 registry->RegisterStringPref(prefs::kStabilityStatsVersion, std::string());
252 registry->RegisterInt64Pref(prefs::kStabilityStatsBuildTime, 0);
253 registry->RegisterBooleanPref(prefs::kStabilityExitedCleanly, true);
254 registry->RegisterIntegerPref(prefs::kStabilityExecutionPhase,
[email protected]6d67ea0d2013-11-14 11:02:21255 UNINITIALIZED_PHASE);
asvitkinea63d19e2014-10-24 16:19:39256 registry->RegisterBooleanPref(prefs::kStabilitySessionEndCompleted, true);
257 registry->RegisterIntegerPref(prefs::kMetricsSessionID, -1);
[email protected]0f2f7792013-11-28 16:09:14258
asvitkinea63d19e2014-10-24 16:19:39259 registry->RegisterListPref(prefs::kMetricsInitialLogs);
260 registry->RegisterListPref(prefs::kMetricsOngoingLogs);
[email protected]0bb1a622009-03-04 03:22:32261
asvitkinea63d19e2014-10-24 16:19:39262 registry->RegisterInt64Pref(prefs::kUninstallLaunchCount, 0);
263 registry->RegisterInt64Pref(prefs::kUninstallMetricsUptimeSec, 0);
initial.commit09911bf2008-07-26 23:55:29264}
265
asvitkinea63d19e2014-10-24 16:19:39266MetricsService::MetricsService(MetricsStateManager* state_manager,
267 MetricsServiceClient* client,
[email protected]24f81ca2014-05-26 15:59:34268 PrefService* local_state)
269 : log_manager_(local_state, kUploadLogAvoidRetransmitSize),
[email protected]acc2ce5512014-05-22 18:29:13270 histogram_snapshot_manager_(this),
[email protected]7f07db62014-05-15 01:12:45271 state_manager_(state_manager),
[email protected]728de072014-05-21 09:20:32272 client_(client),
[email protected]24f81ca2014-05-26 15:59:34273 local_state_(local_state),
erikwright65b58df2014-09-12 00:05:28274 clean_exit_beacon_(client->GetRegistryBackupKey(), local_state),
[email protected]37d4709a2014-03-29 03:07:40275 recording_active_(false),
[email protected]d01b8732008-10-16 02:18:07276 reporting_active_(false),
[email protected]410938e02012-10-24 16:33:59277 test_mode_active_(false),
[email protected]d01b8732008-10-16 02:18:07278 state_(INITIALIZED),
[email protected]0d5a61a82014-05-31 22:28:34279 log_upload_in_progress_(false),
[email protected]d01b8732008-10-16 02:18:07280 idle_since_last_transmission_(false),
[email protected]80a8f312013-12-16 18:00:30281 session_id_(-1),
[email protected]9c009092013-05-01 03:14:09282 self_ptr_factory_(this),
[email protected]0d5a61a82014-05-31 22:28:34283 state_saver_factory_(this) {
initial.commit09911bf2008-07-26 23:55:29284 DCHECK(IsSingleThreaded());
[email protected]39076642014-05-05 20:32:55285 DCHECK(state_manager_);
[email protected]728de072014-05-21 09:20:32286 DCHECK(client_);
[email protected]24f81ca2014-05-26 15:59:34287 DCHECK(local_state_);
[email protected]64b8652c2014-07-16 19:14:28288
289 // Set the install date if this is our first run.
asvitkinea63d19e2014-10-24 16:19:39290 int64 install_date = local_state_->GetInt64(prefs::kInstallDate);
291 if (install_date == 0)
292 local_state_->SetInt64(prefs::kInstallDate, base::Time::Now().ToTimeT());
initial.commit09911bf2008-07-26 23:55:29293}
294
295MetricsService::~MetricsService() {
[email protected]410938e02012-10-24 16:33:59296 DisableRecording();
initial.commit09911bf2008-07-26 23:55:29297}
298
[email protected]39076642014-05-05 20:32:55299void MetricsService::InitializeMetricsRecordingState() {
300 InitializeMetricsState();
[email protected]80a8f312013-12-16 18:00:30301
gayaned52ca402015-02-23 21:23:06302 base::Closure upload_callback =
303 base::Bind(&MetricsService::StartScheduledUpload,
304 self_ptr_factory_.GetWeakPtr());
305 scheduler_.reset(
gunsch7cbdcb22015-03-13 17:02:05306 new MetricsReportingScheduler(
307 upload_callback,
308 // MetricsServiceClient outlives MetricsService, and
309 // MetricsReportingScheduler is tied to the lifetime of |this|.
310 base::Bind(&MetricsServiceClient::GetStandardUploadInterval,
311 base::Unretained(client_))));
[email protected]80a8f312013-12-16 18:00:30312}
313
[email protected]d01b8732008-10-16 02:18:07314void MetricsService::Start() {
[email protected]b1c8dc02011-04-13 18:32:04315 HandleIdleSinceLastTransmission(false);
[email protected]410938e02012-10-24 16:33:59316 EnableRecording();
317 EnableReporting();
[email protected]d01b8732008-10-16 02:18:07318}
319
[email protected]39076642014-05-05 20:32:55320bool MetricsService::StartIfMetricsReportingEnabled() {
321 const bool enabled = state_manager_->IsMetricsReportingEnabled();
322 if (enabled)
323 Start();
324 return enabled;
325}
326
[email protected]410938e02012-10-24 16:33:59327void MetricsService::StartRecordingForTests() {
328 test_mode_active_ = true;
329 EnableRecording();
330 DisableReporting();
[email protected]d01b8732008-10-16 02:18:07331}
332
333void MetricsService::Stop() {
[email protected]b1c8dc02011-04-13 18:32:04334 HandleIdleSinceLastTransmission(false);
[email protected]410938e02012-10-24 16:33:59335 DisableReporting();
336 DisableRecording();
337}
338
339void MetricsService::EnableReporting() {
340 if (reporting_active_)
341 return;
342 reporting_active_ = true;
343 StartSchedulerIfNecessary();
344}
345
346void MetricsService::DisableReporting() {
347 reporting_active_ = false;
[email protected]d01b8732008-10-16 02:18:07348}
349
[email protected]edafd4c2011-05-10 17:18:53350std::string MetricsService::GetClientId() {
[email protected]39076642014-05-05 20:32:55351 return state_manager_->client_id();
[email protected]edafd4c2011-05-10 17:18:53352}
353
[email protected]65801452014-07-09 05:42:41354int64 MetricsService::GetInstallDate() {
asvitkinea63d19e2014-10-24 16:19:39355 return local_state_->GetInt64(prefs::kInstallDate);
[email protected]65801452014-07-09 05:42:41356}
357
olivierrobinc3dfc5b2015-04-07 19:12:00358int64 MetricsService::GetMetricsReportingEnabledDate() {
359 return local_state_->GetInt64(prefs::kMetricsReportingEnabledTimestamp);
360}
361
[email protected]20f999b52012-08-24 22:32:59362scoped_ptr<const base::FieldTrial::EntropyProvider>
[email protected]39076642014-05-05 20:32:55363MetricsService::CreateEntropyProvider() {
364 // TODO(asvitkine): Refactor the code so that MetricsService does not expose
365 // this method.
366 return state_manager_->CreateEntropyProvider();
[email protected]5cbeeef72012-02-08 02:05:18367}
368
[email protected]410938e02012-10-24 16:33:59369void MetricsService::EnableRecording() {
initial.commit09911bf2008-07-26 23:55:29370 DCHECK(IsSingleThreaded());
371
[email protected]410938e02012-10-24 16:33:59372 if (recording_active_)
initial.commit09911bf2008-07-26 23:55:29373 return;
[email protected]410938e02012-10-24 16:33:59374 recording_active_ = true;
initial.commit09911bf2008-07-26 23:55:29375
[email protected]39076642014-05-05 20:32:55376 state_manager_->ForceClientIdCreation();
[email protected]9d1b0152014-07-09 18:53:22377 client_->SetMetricsClientId(state_manager_->client_id());
[email protected]410938e02012-10-24 16:33:59378 if (!log_manager_.current_log())
379 OpenNewLog();
[email protected]005ef3e2009-05-22 20:55:46380
[email protected]85791b0b2014-05-20 15:18:58381 for (size_t i = 0; i < metrics_providers_.size(); ++i)
382 metrics_providers_[i]->OnRecordingEnabled();
383
[email protected]e6e30ac2014-01-13 21:24:39384 base::RemoveActionCallback(action_callback_);
[email protected]dd98f392013-02-04 13:03:22385 action_callback_ = base::Bind(&MetricsService::OnUserAction,
386 base::Unretained(this));
[email protected]e6e30ac2014-01-13 21:24:39387 base::AddActionCallback(action_callback_);
[email protected]410938e02012-10-24 16:33:59388}
389
390void MetricsService::DisableRecording() {
391 DCHECK(IsSingleThreaded());
392
393 if (!recording_active_)
394 return;
395 recording_active_ = false;
396
Mark Mentovaic67fa64f2015-03-24 14:00:06397 client_->OnRecordingDisabled();
398
[email protected]e6e30ac2014-01-13 21:24:39399 base::RemoveActionCallback(action_callback_);
[email protected]85791b0b2014-05-20 15:18:58400
401 for (size_t i = 0; i < metrics_providers_.size(); ++i)
402 metrics_providers_[i]->OnRecordingDisabled();
403
[email protected]410938e02012-10-24 16:33:59404 PushPendingLogsToPersistentStorage();
initial.commit09911bf2008-07-26 23:55:29405}
406
[email protected]d01b8732008-10-16 02:18:07407bool MetricsService::recording_active() const {
initial.commit09911bf2008-07-26 23:55:29408 DCHECK(IsSingleThreaded());
[email protected]d01b8732008-10-16 02:18:07409 return recording_active_;
initial.commit09911bf2008-07-26 23:55:29410}
411
[email protected]d01b8732008-10-16 02:18:07412bool MetricsService::reporting_active() const {
413 DCHECK(IsSingleThreaded());
414 return reporting_active_;
initial.commit09911bf2008-07-26 23:55:29415}
416
[email protected]acc2ce5512014-05-22 18:29:13417void MetricsService::RecordDelta(const base::HistogramBase& histogram,
418 const base::HistogramSamples& snapshot) {
419 log_manager_.current_log()->RecordHistogramDelta(histogram.histogram_name(),
420 snapshot);
421}
422
423void MetricsService::InconsistencyDetected(
424 base::HistogramBase::Inconsistency problem) {
425 UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesBrowser",
426 problem, base::HistogramBase::NEVER_EXCEEDED_VALUE);
427}
428
429void MetricsService::UniqueInconsistencyDetected(
430 base::HistogramBase::Inconsistency problem) {
431 UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesBrowserUnique",
432 problem, base::HistogramBase::NEVER_EXCEEDED_VALUE);
433}
434
435void MetricsService::InconsistencyDetectedInLoggedCount(int amount) {
436 UMA_HISTOGRAM_COUNTS("Histogram.InconsistentSnapshotBrowser",
437 std::abs(amount));
438}
439
[email protected]d01b8732008-10-16 02:18:07440void MetricsService::HandleIdleSinceLastTransmission(bool in_idle) {
441 // If there wasn't a lot of action, maybe the computer was asleep, in which
442 // case, the log transmissions should have stopped. Here we start them up
443 // again.
[email protected]cac78842008-11-27 01:02:20444 if (!in_idle && idle_since_last_transmission_)
[email protected]7f7f1962011-04-20 15:58:16445 StartSchedulerIfNecessary();
[email protected]cac78842008-11-27 01:02:20446 idle_since_last_transmission_ = in_idle;
initial.commit09911bf2008-07-26 23:55:29447}
448
[email protected]d7ea39e2014-05-22 03:59:18449void MetricsService::OnApplicationNotIdle() {
450 if (recording_active_)
451 HandleIdleSinceLastTransmission(false);
452}
453
initial.commit09911bf2008-07-26 23:55:29454void MetricsService::RecordStartOfSessionEnd() {
[email protected]466f3c12011-03-23 21:20:38455 LogCleanShutdown();
asvitkinea63d19e2014-10-24 16:19:39456 RecordBooleanPrefValue(prefs::kStabilitySessionEndCompleted, false);
initial.commit09911bf2008-07-26 23:55:29457}
458
459void MetricsService::RecordCompletedSessionEnd() {
[email protected]466f3c12011-03-23 21:20:38460 LogCleanShutdown();
asvitkinea63d19e2014-10-24 16:19:39461 RecordBooleanPrefValue(prefs::kStabilitySessionEndCompleted, true);
initial.commit09911bf2008-07-26 23:55:29462}
463
[email protected]410938e02012-10-24 16:33:59464#if defined(OS_ANDROID) || defined(OS_IOS)
[email protected]117fbdf22012-06-26 18:36:39465void MetricsService::OnAppEnterBackground() {
466 scheduler_->Stop();
467
erikwright65b58df2014-09-12 00:05:28468 MarkAppCleanShutdownAndCommit(&clean_exit_beacon_, local_state_);
[email protected]117fbdf22012-06-26 18:36:39469
470 // At this point, there's no way of knowing when the process will be
471 // killed, so this has to be treated similar to a shutdown, closing and
472 // persisting all logs. Unlinke a shutdown, the state is primed to be ready
473 // to continue logging and uploading if the process does return.
Steven Holte2c294a32015-03-12 21:45:03474 if (recording_active() && state_ >= SENDING_LOGS) {
[email protected]117fbdf22012-06-26 18:36:39475 PushPendingLogsToPersistentStorage();
[email protected]410938e02012-10-24 16:33:59476 // Persisting logs closes the current log, so start recording a new log
477 // immediately to capture any background work that might be done before the
478 // process is killed.
479 OpenNewLog();
[email protected]117fbdf22012-06-26 18:36:39480 }
[email protected]117fbdf22012-06-26 18:36:39481}
482
483void MetricsService::OnAppEnterForeground() {
erikwright65b58df2014-09-12 00:05:28484 clean_exit_beacon_.WriteBeaconValue(false);
[email protected]117fbdf22012-06-26 18:36:39485 StartSchedulerIfNecessary();
486}
[email protected]84c384e2013-03-01 23:20:19487#else
erikwrightcc98a7e02014-09-09 22:05:12488void MetricsService::LogNeedForCleanShutdown() {
erikwright65b58df2014-09-12 00:05:28489 clean_exit_beacon_.WriteBeaconValue(false);
[email protected]84c384e2013-03-01 23:20:19490 // Redundant setting to be sure we call for a clean shutdown.
491 clean_shutdown_status_ = NEED_TO_SHUTDOWN;
492}
493#endif // defined(OS_ANDROID) || defined(OS_IOS)
[email protected]117fbdf22012-06-26 18:36:39494
[email protected]6d67ea0d2013-11-14 11:02:21495// static
[email protected]24f81ca2014-05-26 15:59:34496void MetricsService::SetExecutionPhase(ExecutionPhase execution_phase,
497 PrefService* local_state) {
[email protected]6d67ea0d2013-11-14 11:02:21498 execution_phase_ = execution_phase;
asvitkinea63d19e2014-10-24 16:19:39499 local_state->SetInteger(prefs::kStabilityExecutionPhase, execution_phase_);
[email protected]6d67ea0d2013-11-14 11:02:21500}
501
[email protected]7f7f1962011-04-20 15:58:16502void MetricsService::RecordBreakpadRegistration(bool success) {
[email protected]68475e602008-08-22 03:21:15503 if (!success)
asvitkinea63d19e2014-10-24 16:19:39504 IncrementPrefValue(prefs::kStabilityBreakpadRegistrationFail);
[email protected]e73c01972008-08-13 00:18:24505 else
asvitkinea63d19e2014-10-24 16:19:39506 IncrementPrefValue(prefs::kStabilityBreakpadRegistrationSuccess);
[email protected]e73c01972008-08-13 00:18:24507}
508
509void MetricsService::RecordBreakpadHasDebugger(bool has_debugger) {
510 if (!has_debugger)
asvitkinea63d19e2014-10-24 16:19:39511 IncrementPrefValue(prefs::kStabilityDebuggerNotPresent);
[email protected]e73c01972008-08-13 00:18:24512 else
asvitkinea63d19e2014-10-24 16:19:39513 IncrementPrefValue(prefs::kStabilityDebuggerPresent);
[email protected]e73c01972008-08-13 00:18:24514}
515
yiyaoliu14ef3ead2014-11-19 02:36:50516void MetricsService::ClearSavedStabilityMetrics() {
517 for (size_t i = 0; i < metrics_providers_.size(); ++i)
518 metrics_providers_[i]->ClearSavedStabilityMetrics();
519
520 // Reset the prefs that are managed by MetricsService/MetricsLog directly.
521 local_state_->SetInteger(prefs::kStabilityCrashCount, 0);
522 local_state_->SetInteger(prefs::kStabilityExecutionPhase,
523 UNINITIALIZED_PHASE);
524 local_state_->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
525 local_state_->SetInteger(prefs::kStabilityLaunchCount, 0);
526 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, true);
527}
528
olivierrobinc3dfc5b2015-04-07 19:12:00529void MetricsService::PushExternalLog(const std::string& log) {
530 log_manager_.StoreLog(log, MetricsLog::ONGOING_LOG);
531}
532
initial.commit09911bf2008-07-26 23:55:29533//------------------------------------------------------------------------------
534// private methods
535//------------------------------------------------------------------------------
536
537
538//------------------------------------------------------------------------------
539// Initialization methods
540
[email protected]39076642014-05-05 20:32:55541void MetricsService::InitializeMetricsState() {
asvitkineff3e2a62014-09-18 22:01:49542 const int64 buildtime = MetricsLog::GetBuildTime();
543 const std::string version = client_->GetVersionString();
544 bool version_changed = false;
545 if (local_state_->GetInt64(prefs::kStabilityStatsBuildTime) != buildtime ||
546 local_state_->GetString(prefs::kStabilityStatsVersion) != version) {
asvitkinea63d19e2014-10-24 16:19:39547 local_state_->SetString(prefs::kStabilityStatsVersion, version);
548 local_state_->SetInt64(prefs::kStabilityStatsBuildTime, buildtime);
asvitkineff3e2a62014-09-18 22:01:49549 version_changed = true;
550 }
initial.commit09911bf2008-07-26 23:55:29551
[email protected]94dce122014-07-16 04:20:12552 log_manager_.LoadPersistedUnsentLogs();
553
asvitkinea63d19e2014-10-24 16:19:39554 session_id_ = local_state_->GetInteger(prefs::kMetricsSessionID);
erikwright65b58df2014-09-12 00:05:28555
556 if (!clean_exit_beacon_.exited_cleanly()) {
asvitkinea63d19e2014-10-24 16:19:39557 IncrementPrefValue(prefs::kStabilityCrashCount);
[email protected]c0c55e92011-09-10 18:47:30558 // Reset flag, and wait until we call LogNeedForCleanShutdown() before
559 // monitoring.
erikwright65b58df2014-09-12 00:05:28560 clean_exit_beacon_.WriteBeaconValue(true);
siggic179dd062014-09-10 17:02:31561 }
[email protected]6a6d0d12013-10-28 15:58:19562
Steven Holte2c294a32015-03-12 21:45:03563 bool has_initial_stability_log = false;
lpromeroca8cb6f2015-04-30 18:16:53564 if (!clean_exit_beacon_.exited_cleanly() ||
565 ProvidersHaveInitialStabilityMetrics()) {
[email protected]6a6d0d12013-10-28 15:58:19566 // TODO(rtenneti): On windows, consider saving/getting execution_phase from
567 // the registry.
[email protected]24f81ca2014-05-26 15:59:34568 int execution_phase =
asvitkinea63d19e2014-10-24 16:19:39569 local_state_->GetInteger(prefs::kStabilityExecutionPhase);
[email protected]6d67ea0d2013-11-14 11:02:21570 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Browser.CrashedExecutionPhase",
[email protected]6a6d0d12013-10-28 15:58:19571 execution_phase);
[email protected]80a8f312013-12-16 18:00:30572
siggic179dd062014-09-10 17:02:31573 // If the previous session didn't exit cleanly, or if any provider
574 // explicitly requests it, prepare an initial stability log -
575 // provided UMA is enabled.
[email protected]39076642014-05-05 20:32:55576 if (state_manager_->IsMetricsReportingEnabled())
Steven Holte2c294a32015-03-12 21:45:03577 has_initial_stability_log = PrepareInitialStabilityLog();
initial.commit09911bf2008-07-26 23:55:29578 }
[email protected]80a8f312013-12-16 18:00:30579
asvitkineff3e2a62014-09-18 22:01:49580 // If no initial stability log was generated and there was a version upgrade,
581 // clear the stability stats from the previous version (so that they don't get
582 // attributed to the current version). This could otherwise happen due to a
583 // number of different edge cases, such as if the last version crashed before
584 // it could save off a system profile or if UMA reporting is disabled (which
585 // normally results in stats being accumulated).
Steven Holte2c294a32015-03-12 21:45:03586 if (!has_initial_stability_log && version_changed)
yiyaoliu14ef3ead2014-11-19 02:36:50587 ClearSavedStabilityMetrics();
asvitkineff3e2a62014-09-18 22:01:49588
[email protected]80a8f312013-12-16 18:00:30589 // Update session ID.
590 ++session_id_;
asvitkinea63d19e2014-10-24 16:19:39591 local_state_->SetInteger(prefs::kMetricsSessionID, session_id_);
[email protected]80a8f312013-12-16 18:00:30592
593 // Stability bookkeeping
asvitkinea63d19e2014-10-24 16:19:39594 IncrementPrefValue(prefs::kStabilityLaunchCount);
[email protected]80a8f312013-12-16 18:00:30595
[email protected]6d67ea0d2013-11-14 11:02:21596 DCHECK_EQ(UNINITIALIZED_PHASE, execution_phase_);
[email protected]24f81ca2014-05-26 15:59:34597 SetExecutionPhase(START_METRICS_RECORDING, local_state_);
[email protected]e73c01972008-08-13 00:18:24598
asvitkinea63d19e2014-10-24 16:19:39599 if (!local_state_->GetBoolean(prefs::kStabilitySessionEndCompleted)) {
600 IncrementPrefValue(prefs::kStabilityIncompleteSessionEndCount);
[email protected]c9abf242009-07-18 06:00:38601 // This is marked false when we get a WM_ENDSESSION.
asvitkinea63d19e2014-10-24 16:19:39602 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, true);
initial.commit09911bf2008-07-26 23:55:29603 }
initial.commit09911bf2008-07-26 23:55:29604
[email protected]076961c2014-03-12 22:23:56605 // Call GetUptimes() for the first time, thus allowing all later calls
606 // to record incremental uptimes accurately.
607 base::TimeDelta ignored_uptime_parameter;
608 base::TimeDelta startup_uptime;
[email protected]24f81ca2014-05-26 15:59:34609 GetUptimes(local_state_, &startup_uptime, &ignored_uptime_parameter);
[email protected]c68a2b9b2013-10-09 18:16:36610 DCHECK_EQ(0, startup_uptime.InMicroseconds());
[email protected]9165f742010-03-10 22:55:01611 // For backwards compatibility, leave this intact in case Omaha is checking
asvitkinea63d19e2014-10-24 16:19:39612 // them. prefs::kStabilityLastTimestampSec may also be useless now.
[email protected]9165f742010-03-10 22:55:01613 // TODO(jar): Delete these if they have no uses.
asvitkinea63d19e2014-10-24 16:19:39614 local_state_->SetInt64(prefs::kStabilityLaunchTimeSec,
asvitkinecbd420732014-08-26 22:15:40615 base::Time::Now().ToTimeT());
[email protected]0bb1a622009-03-04 03:22:32616
617 // Bookkeeping for the uninstall metrics.
asvitkinea63d19e2014-10-24 16:19:39618 IncrementLongPrefsValue(prefs::kUninstallLaunchCount);
initial.commit09911bf2008-07-26 23:55:29619
initial.commit09911bf2008-07-26 23:55:29620 // Kick off the process of saving the state (so the uptime numbers keep
621 // getting updated) every n minutes.
622 ScheduleNextStateSave();
623}
624
[email protected]dd98f392013-02-04 13:03:22625void MetricsService::OnUserAction(const std::string& action) {
[email protected]e5ad60a2014-03-11 03:54:04626 if (!ShouldLogEvents())
[email protected]dd98f392013-02-04 13:03:22627 return;
628
[email protected]4426d2d2014-04-09 12:33:00629 log_manager_.current_log()->RecordUserAction(action);
[email protected]dd98f392013-02-04 13:03:22630 HandleIdleSinceLastTransmission(false);
631}
632
[email protected]4a55a712014-06-08 16:50:34633void MetricsService::FinishedGatheringInitialMetrics() {
[email protected]ed0fd002012-04-25 23:10:34634 DCHECK_EQ(INIT_TASK_SCHEDULED, state_);
[email protected]c68a2b9b2013-10-09 18:16:36635 state_ = INIT_TASK_DONE;
[email protected]83d09f92014-06-03 14:58:26636
637 // Create the initial log.
638 if (!initial_metrics_log_.get()) {
639 initial_metrics_log_ = CreateLog(MetricsLog::ONGOING_LOG);
640 NotifyOnDidCreateMetricsLog();
641 }
642
[email protected]70886cd2013-12-04 05:53:42643 scheduler_->InitTaskComplete();
[email protected]c68a2b9b2013-10-09 18:16:36644}
645
[email protected]076961c2014-03-12 22:23:56646void MetricsService::GetUptimes(PrefService* pref,
647 base::TimeDelta* incremental_uptime,
648 base::TimeDelta* uptime) {
[email protected]c68a2b9b2013-10-09 18:16:36649 base::TimeTicks now = base::TimeTicks::Now();
[email protected]076961c2014-03-12 22:23:56650 // If this is the first call, init |first_updated_time_| and
651 // |last_updated_time_|.
652 if (last_updated_time_.is_null()) {
653 first_updated_time_ = now;
[email protected]c68a2b9b2013-10-09 18:16:36654 last_updated_time_ = now;
[email protected]076961c2014-03-12 22:23:56655 }
656 *incremental_uptime = now - last_updated_time_;
657 *uptime = now - first_updated_time_;
[email protected]c68a2b9b2013-10-09 18:16:36658 last_updated_time_ = now;
659
[email protected]076961c2014-03-12 22:23:56660 const int64 incremental_time_secs = incremental_uptime->InSeconds();
[email protected]c68a2b9b2013-10-09 18:16:36661 if (incremental_time_secs > 0) {
asvitkinea63d19e2014-10-24 16:19:39662 int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec);
[email protected]c68a2b9b2013-10-09 18:16:36663 metrics_uptime += incremental_time_secs;
asvitkinea63d19e2014-10-24 16:19:39664 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime);
[email protected]c68a2b9b2013-10-09 18:16:36665 }
initial.commit09911bf2008-07-26 23:55:29666}
667
[email protected]2a321de32014-05-10 19:59:06668void MetricsService::NotifyOnDidCreateMetricsLog() {
asvitkinebbde62b2014-09-03 16:33:21669 DCHECK(IsSingleThreaded());
[email protected]8304f61a2014-05-24 12:17:33670 for (size_t i = 0; i < metrics_providers_.size(); ++i)
671 metrics_providers_[i]->OnDidCreateMetricsLog();
[email protected]2a321de32014-05-10 19:59:06672}
673
initial.commit09911bf2008-07-26 23:55:29674//------------------------------------------------------------------------------
675// State save methods
676
677void MetricsService::ScheduleNextStateSave() {
[email protected]8454aeb2011-11-19 23:38:20678 state_saver_factory_.InvalidateWeakPtrs();
initial.commit09911bf2008-07-26 23:55:29679
[email protected]b3a25092013-05-28 22:08:16680 base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
[email protected]8454aeb2011-11-19 23:38:20681 base::Bind(&MetricsService::SaveLocalState,
682 state_saver_factory_.GetWeakPtr()),
[email protected]fc4252a72012-01-12 21:58:47683 base::TimeDelta::FromMinutes(kSaveStateIntervalMinutes));
initial.commit09911bf2008-07-26 23:55:29684}
685
686void MetricsService::SaveLocalState() {
[email protected]24f81ca2014-05-26 15:59:34687 RecordCurrentState(local_state_);
initial.commit09911bf2008-07-26 23:55:29688
[email protected]fc4252a72012-01-12 21:58:47689 // TODO(jar):110021 Does this run down the batteries????
initial.commit09911bf2008-07-26 23:55:29690 ScheduleNextStateSave();
691}
692
693
694//------------------------------------------------------------------------------
695// Recording control methods
696
[email protected]410938e02012-10-24 16:33:59697void MetricsService::OpenNewLog() {
698 DCHECK(!log_manager_.current_log());
initial.commit09911bf2008-07-26 23:55:29699
[email protected]bfb77b52014-06-07 01:54:01700 log_manager_.BeginLoggingWithLog(CreateLog(MetricsLog::ONGOING_LOG));
[email protected]2a321de32014-05-10 19:59:06701 NotifyOnDidCreateMetricsLog();
initial.commit09911bf2008-07-26 23:55:29702 if (state_ == INITIALIZED) {
703 // We only need to schedule that run once.
[email protected]85ed9d42010-06-08 22:37:44704 state_ = INIT_TASK_SCHEDULED;
initial.commit09911bf2008-07-26 23:55:29705
[email protected]d6147bd2014-06-11 01:58:19706 base::MessageLoop::current()->PostDelayedTask(
[email protected]ed10dd12011-12-07 12:03:42707 FROM_HERE,
[email protected]51994b22014-05-30 13:24:21708 base::Bind(&MetricsService::StartGatheringMetrics,
709 self_ptr_factory_.GetWeakPtr()),
[email protected]7e560102012-03-08 20:58:42710 base::TimeDelta::FromSeconds(kInitializationDelaySeconds));
initial.commit09911bf2008-07-26 23:55:29711 }
712}
713
[email protected]51994b22014-05-30 13:24:21714void MetricsService::StartGatheringMetrics() {
[email protected]51994b22014-05-30 13:24:21715 client_->StartGatheringMetrics(
[email protected]4a55a712014-06-08 16:50:34716 base::Bind(&MetricsService::FinishedGatheringInitialMetrics,
[email protected]51994b22014-05-30 13:24:21717 self_ptr_factory_.GetWeakPtr()));
718}
719
[email protected]410938e02012-10-24 16:33:59720void MetricsService::CloseCurrentLog() {
[email protected]cac267c2011-09-29 15:18:10721 if (!log_manager_.current_log())
initial.commit09911bf2008-07-26 23:55:29722 return;
723
[email protected]68475e602008-08-22 03:21:15724 // TODO(jar): Integrate bounds on log recording more consistently, so that we
725 // can stop recording logs that are too big much sooner.
[email protected]cac267c2011-09-29 15:18:10726 if (log_manager_.current_log()->num_events() > kEventLimit) {
[email protected]553dba62009-02-24 19:08:23727 UMA_HISTOGRAM_COUNTS("UMA.Discarded Log Events",
[email protected]cac267c2011-09-29 15:18:10728 log_manager_.current_log()->num_events());
729 log_manager_.DiscardCurrentLog();
[email protected]410938e02012-10-24 16:33:59730 OpenNewLog(); // Start trivial log to hold our histograms.
[email protected]68475e602008-08-22 03:21:15731 }
732
[email protected]0b33f80b2008-12-17 21:34:36733 // Put incremental data (histogram deltas, and realtime stats deltas) at the
[email protected]147bbc0b2009-01-06 19:37:40734 // end of all log transmissions (initial log handles this separately).
[email protected]024b5cd2011-05-27 03:29:38735 // RecordIncrementalStabilityElements only exists on the derived
736 // MetricsLog class.
[email protected]94dce122014-07-16 04:20:12737 MetricsLog* current_log = log_manager_.current_log();
[email protected]024b5cd2011-05-27 03:29:38738 DCHECK(current_log);
asvitkine88aa9332014-09-29 23:29:17739 RecordCurrentEnvironment(current_log);
[email protected]076961c2014-03-12 22:23:56740 base::TimeDelta incremental_uptime;
741 base::TimeDelta uptime;
[email protected]24f81ca2014-05-26 15:59:34742 GetUptimes(local_state_, &incremental_uptime, &uptime);
[email protected]85791b0b2014-05-20 15:18:58743 current_log->RecordStabilityMetrics(metrics_providers_.get(),
744 incremental_uptime, uptime);
[email protected]60677562013-11-17 15:52:55745
[email protected]85791b0b2014-05-20 15:18:58746 current_log->RecordGeneralMetrics(metrics_providers_.get());
mariakhomenko191028982014-10-20 23:22:56747 RecordCurrentHistograms();
initial.commit09911bf2008-07-26 23:55:29748
[email protected]29948262012-03-01 12:15:08749 log_manager_.FinishCurrentLog();
initial.commit09911bf2008-07-26 23:55:29750}
751
[email protected]cac267c2011-09-29 15:18:10752void MetricsService::PushPendingLogsToPersistentStorage() {
Steven Holte2c294a32015-03-12 21:45:03753 if (state_ < SENDING_LOGS)
[email protected]28ab7f92009-01-06 21:39:04754 return; // We didn't and still don't have time to get plugin list etc.
initial.commit09911bf2008-07-26 23:55:29755
[email protected]410938e02012-10-24 16:33:59756 CloseCurrentLog();
[email protected]80a8f312013-12-16 18:00:30757 log_manager_.PersistUnsentLogs();
initial.commit09911bf2008-07-26 23:55:29758}
759
760//------------------------------------------------------------------------------
761// Transmission of logs methods
762
[email protected]7f7f1962011-04-20 15:58:16763void MetricsService::StartSchedulerIfNecessary() {
[email protected]410938e02012-10-24 16:33:59764 // Never schedule cutting or uploading of logs in test mode.
765 if (test_mode_active_)
766 return;
767
768 // Even if reporting is disabled, the scheduler is needed to trigger the
769 // creation of the initial log, which must be done in order for any logs to be
770 // persisted on shutdown or backgrounding.
[email protected]80a8f312013-12-16 18:00:30771 if (recording_active() &&
Steven Holte2c294a32015-03-12 21:45:03772 (reporting_active() || state_ < SENDING_LOGS)) {
[email protected]7f7f1962011-04-20 15:58:16773 scheduler_->Start();
[email protected]80a8f312013-12-16 18:00:30774 }
initial.commit09911bf2008-07-26 23:55:29775}
776
[email protected]7f7f1962011-04-20 15:58:16777void MetricsService::StartScheduledUpload() {
holtea6a39172015-03-25 19:57:20778 DCHECK(state_ >= INIT_TASK_DONE);
[email protected]cd1ac712012-06-26 08:26:47779 // If we're getting no notifications, then the log won't have much in it, and
780 // it's possible the computer is about to go to sleep, so don't upload and
781 // stop the scheduler.
[email protected]410938e02012-10-24 16:33:59782 // If recording has been turned off, the scheduler doesn't need to run.
783 // If reporting is off, proceed if the initial log hasn't been created, since
784 // that has to happen in order for logs to be cut and stored when persisting.
[email protected]d7ea39e2014-05-22 03:59:18785 // TODO(stuartmorgan): Call Stop() on the scheduler when reporting and/or
[email protected]cd1ac712012-06-26 08:26:47786 // recording are turned off instead of letting it fire and then aborting.
787 if (idle_since_last_transmission_ ||
[email protected]410938e02012-10-24 16:33:59788 !recording_active() ||
Steven Holte2c294a32015-03-12 21:45:03789 (!reporting_active() && state_ >= SENDING_LOGS)) {
[email protected]7f7f1962011-04-20 15:58:16790 scheduler_->Stop();
791 scheduler_->UploadCancelled();
792 return;
793 }
794
[email protected]cd1ac712012-06-26 08:26:47795 // If there are unsent logs, send the next one. If not, start the asynchronous
796 // process of finalizing the current log for upload.
Steven Holte2c294a32015-03-12 21:45:03797 if (state_ == SENDING_LOGS && log_manager_.has_unsent_logs()) {
holtea6a39172015-03-25 19:57:20798 SendNextLog();
[email protected]cd1ac712012-06-26 08:26:47799 } else {
holtea6a39172015-03-25 19:57:20800 // There are no logs left to send, so start creating a new one.
[email protected]4b4892b2014-05-22 15:06:15801 client_->CollectFinalMetrics(
802 base::Bind(&MetricsService::OnFinalLogInfoCollectionDone,
803 self_ptr_factory_.GetWeakPtr()));
[email protected]cd1ac712012-06-26 08:26:47804 }
[email protected]29948262012-03-01 12:15:08805}
806
[email protected]29948262012-03-01 12:15:08807void MetricsService::OnFinalLogInfoCollectionDone() {
[email protected]0d5a61a82014-05-31 22:28:34808 // If somehow there is a log upload in progress, we return and hope things
809 // work out. The scheduler isn't informed since if this happens, the scheduler
[email protected]7f7f1962011-04-20 15:58:16810 // will get a response from the upload.
[email protected]0d5a61a82014-05-31 22:28:34811 DCHECK(!log_upload_in_progress_);
812 if (log_upload_in_progress_)
[email protected]7f7f1962011-04-20 15:58:16813 return;
814
[email protected]cd1ac712012-06-26 08:26:47815 // Abort if metrics were turned off during the final info gathering.
[email protected]410938e02012-10-24 16:33:59816 if (!recording_active()) {
[email protected]7f7f1962011-04-20 15:58:16817 scheduler_->Stop();
818 scheduler_->UploadCancelled();
[email protected]d01b8732008-10-16 02:18:07819 return;
820 }
821
holtea6a39172015-03-25 19:57:20822 if (state_ == INIT_TASK_DONE) {
823 PrepareInitialMetricsLog();
824 } else {
825 DCHECK_EQ(SENDING_LOGS, state_);
826 CloseCurrentLog();
827 OpenNewLog();
828 }
829 SendNextLog();
830}
[email protected]410938e02012-10-24 16:33:59831
holtea6a39172015-03-25 19:57:20832void MetricsService::SendNextLog() {
833 DCHECK_EQ(SENDING_LOGS, state_);
[email protected]410938e02012-10-24 16:33:59834 if (!reporting_active()) {
835 scheduler_->Stop();
836 scheduler_->UploadCancelled();
837 return;
838 }
holtea6a39172015-03-25 19:57:20839 if (!log_manager_.has_unsent_logs()) {
840 // Should only get here if serializing the log failed somehow.
841 // Just tell the scheduler it was uploaded and wait for the next log
842 // interval.
843 scheduler_->UploadFinished(true, log_manager_.has_unsent_logs());
[email protected]29948262012-03-01 12:15:08844 return;
[email protected]29948262012-03-01 12:15:08845 }
holtea6a39172015-03-25 19:57:20846 if (!log_manager_.has_staged_log())
847 log_manager_.StageNextLogForUpload();
848 SendStagedLog();
[email protected]29948262012-03-01 12:15:08849}
850
lpromeroca8cb6f2015-04-30 18:16:53851bool MetricsService::ProvidersHaveInitialStabilityMetrics() {
852 // Check whether any metrics provider has initial stability metrics.
siggic179dd062014-09-10 17:02:31853 for (size_t i = 0; i < metrics_providers_.size(); ++i) {
lpromeroca8cb6f2015-04-30 18:16:53854 if (metrics_providers_[i]->HasInitialStabilityMetrics())
siggic179dd062014-09-10 17:02:31855 return true;
856 }
857
858 return false;
859}
860
Steven Holte2c294a32015-03-12 21:45:03861bool MetricsService::PrepareInitialStabilityLog() {
[email protected]80a8f312013-12-16 18:00:30862 DCHECK_EQ(INITIALIZED, state_);
[email protected]29948262012-03-01 12:15:08863
[email protected]80a8f312013-12-16 18:00:30864 scoped_ptr<MetricsLog> initial_stability_log(
[email protected]09dee82d2014-05-22 14:00:53865 CreateLog(MetricsLog::INITIAL_STABILITY_LOG));
[email protected]2a321de32014-05-10 19:59:06866
867 // Do not call NotifyOnDidCreateMetricsLog here because the stability
868 // log describes stats from the _previous_ session.
869
[email protected]80a8f312013-12-16 18:00:30870 if (!initial_stability_log->LoadSavedEnvironmentFromPrefs())
Steven Holte2c294a32015-03-12 21:45:03871 return false;
[email protected]85791b0b2014-05-20 15:18:58872
[email protected]80a8f312013-12-16 18:00:30873 log_manager_.PauseCurrentLog();
[email protected]bfb77b52014-06-07 01:54:01874 log_manager_.BeginLoggingWithLog(initial_stability_log.Pass());
[email protected]85791b0b2014-05-20 15:18:58875
876 // Note: Some stability providers may record stability stats via histograms,
877 // so this call has to be after BeginLoggingWithLog().
[email protected]bfb77b52014-06-07 01:54:01878 log_manager_.current_log()->RecordStabilityMetrics(
879 metrics_providers_.get(), base::TimeDelta(), base::TimeDelta());
[email protected]c778687a2014-02-11 14:46:45880 RecordCurrentStabilityHistograms();
[email protected]85791b0b2014-05-20 15:18:58881
882 // Note: RecordGeneralMetrics() intentionally not called since this log is for
883 // stability stats from a previous session only.
884
[email protected]80a8f312013-12-16 18:00:30885 log_manager_.FinishCurrentLog();
886 log_manager_.ResumePausedLog();
887
888 // Store unsent logs, including the stability log that was just saved, so
889 // that they're not lost in case of a crash before upload time.
890 log_manager_.PersistUnsentLogs();
891
Steven Holte2c294a32015-03-12 21:45:03892 return true;
[email protected]80a8f312013-12-16 18:00:30893}
894
[email protected]b58b8b22014-04-08 22:40:33895void MetricsService::PrepareInitialMetricsLog() {
Steven Holte2c294a32015-03-12 21:45:03896 DCHECK_EQ(INIT_TASK_DONE, state_);
[email protected]0edf8762013-11-21 18:33:30897
asvitkine88aa9332014-09-29 23:29:17898 RecordCurrentEnvironment(initial_metrics_log_.get());
[email protected]076961c2014-03-12 22:23:56899 base::TimeDelta incremental_uptime;
900 base::TimeDelta uptime;
[email protected]24f81ca2014-05-26 15:59:34901 GetUptimes(local_state_, &incremental_uptime, &uptime);
[email protected]29948262012-03-01 12:15:08902
903 // Histograms only get written to the current log, so make the new log current
904 // before writing them.
905 log_manager_.PauseCurrentLog();
[email protected]bfb77b52014-06-07 01:54:01906 log_manager_.BeginLoggingWithLog(initial_metrics_log_.Pass());
[email protected]85791b0b2014-05-20 15:18:58907
908 // Note: Some stability providers may record stability stats via histograms,
909 // so this call has to be after BeginLoggingWithLog().
[email protected]94dce122014-07-16 04:20:12910 MetricsLog* current_log = log_manager_.current_log();
[email protected]85791b0b2014-05-20 15:18:58911 current_log->RecordStabilityMetrics(metrics_providers_.get(),
912 base::TimeDelta(), base::TimeDelta());
[email protected]85791b0b2014-05-20 15:18:58913 current_log->RecordGeneralMetrics(metrics_providers_.get());
mariakhomenko191028982014-10-20 23:22:56914 RecordCurrentHistograms();
[email protected]85791b0b2014-05-20 15:18:58915
[email protected]29948262012-03-01 12:15:08916 log_manager_.FinishCurrentLog();
917 log_manager_.ResumePausedLog();
918
[email protected]94dce122014-07-16 04:20:12919 // Store unsent logs, including the initial log that was just saved, so
920 // that they're not lost in case of a crash before upload time.
921 log_manager_.PersistUnsentLogs();
holtea6a39172015-03-25 19:57:20922
923 state_ = SENDING_LOGS;
[email protected]29948262012-03-01 12:15:08924}
925
[email protected]29948262012-03-01 12:15:08926void MetricsService::SendStagedLog() {
927 DCHECK(log_manager_.has_staged_log());
[email protected]0d5a61a82014-05-31 22:28:34928 if (!log_manager_.has_staged_log())
929 return;
[email protected]29948262012-03-01 12:15:08930
[email protected]0d5a61a82014-05-31 22:28:34931 DCHECK(!log_upload_in_progress_);
932 log_upload_in_progress_ = true;
[email protected]d01b8732008-10-16 02:18:07933
[email protected]0d5a61a82014-05-31 22:28:34934 if (!log_uploader_) {
935 log_uploader_ = client_->CreateUploader(
[email protected]0d5a61a82014-05-31 22:28:34936 base::Bind(&MetricsService::OnLogUploadComplete,
937 self_ptr_factory_.GetWeakPtr()));
938 }
939
940 const std::string hash =
941 base::HexEncode(log_manager_.staged_log_hash().data(),
942 log_manager_.staged_log_hash().size());
943 bool success = log_uploader_->UploadLog(log_manager_.staged_log(), hash);
944 UMA_HISTOGRAM_BOOLEAN("UMA.UploadCreation", success);
945 if (!success) {
[email protected]dc61fe92012-06-12 00:13:50946 // Skip this upload and hope things work out next time.
[email protected]cac267c2011-09-29 15:18:10947 log_manager_.DiscardStagedLog();
[email protected]7f7f1962011-04-20 15:58:16948 scheduler_->UploadCancelled();
[email protected]0d5a61a82014-05-31 22:28:34949 log_upload_in_progress_ = false;
[email protected]d01b8732008-10-16 02:18:07950 return;
951 }
952
[email protected]d01b8732008-10-16 02:18:07953 HandleIdleSinceLastTransmission(true);
954}
955
[email protected]cac78842008-11-27 01:02:20956
[email protected]0d5a61a82014-05-31 22:28:34957void MetricsService::OnLogUploadComplete(int response_code) {
Steven Holte2c294a32015-03-12 21:45:03958 DCHECK_EQ(SENDING_LOGS, state_);
[email protected]0d5a61a82014-05-31 22:28:34959 DCHECK(log_upload_in_progress_);
960 log_upload_in_progress_ = false;
[email protected]fe58acc22012-02-29 01:29:58961
[email protected]dc61fe92012-06-12 00:13:50962 // Log a histogram to track response success vs. failure rates.
[email protected]e3eb0c42013-04-18 06:18:58963 UMA_HISTOGRAM_ENUMERATION("UMA.UploadResponseStatus.Protobuf",
964 ResponseCodeToStatus(response_code),
965 NUM_RESPONSE_STATUSES);
[email protected]fe58acc22012-02-29 01:29:58966
[email protected]dc61fe92012-06-12 00:13:50967 bool upload_succeeded = response_code == 200;
[email protected]7f7f1962011-04-20 15:58:16968
[email protected]0eb34fee2009-01-21 08:04:38969 // Provide boolean for error recovery (allow us to ignore response_code).
[email protected]dc6f4962009-02-13 01:25:50970 bool discard_log = false;
[email protected]7f07db62014-05-15 01:12:45971 const size_t log_size = log_manager_.staged_log().length();
asvitkined80ebf6c2014-09-02 22:29:11972 if (upload_succeeded) {
973 UMA_HISTOGRAM_COUNTS_10000("UMA.LogSize.OnSuccess", log_size / 1024);
974 } else if (log_size > kUploadLogAvoidRetransmitSize) {
[email protected]dc61fe92012-06-12 00:13:50975 UMA_HISTOGRAM_COUNTS("UMA.Large Rejected Log was Discarded",
976 static_cast<int>(log_size));
[email protected]0eb34fee2009-01-21 08:04:38977 discard_log = true;
[email protected]dc61fe92012-06-12 00:13:50978 } else if (response_code == 400) {
[email protected]0eb34fee2009-01-21 08:04:38979 // Bad syntax. Retransmission won't work.
[email protected]0eb34fee2009-01-21 08:04:38980 discard_log = true;
[email protected]68475e602008-08-22 03:21:15981 }
982
[email protected]94dce122014-07-16 04:20:12983 if (upload_succeeded || discard_log) {
[email protected]5f3e1642013-05-05 03:37:34984 log_manager_.DiscardStagedLog();
[email protected]94dce122014-07-16 04:20:12985 // Store the updated list to disk now that the removed log is uploaded.
986 log_manager_.PersistUnsentLogs();
987 }
[email protected]dc61fe92012-06-12 00:13:50988
[email protected]7f7f1962011-04-20 15:58:16989 // Error 400 indicates a problem with the log, not with the server, so
990 // don't consider that a sign that the server is in trouble.
[email protected]dc61fe92012-06-12 00:13:50991 bool server_is_healthy = upload_succeeded || response_code == 400;
holtea29872a2015-03-02 22:44:17992 scheduler_->UploadFinished(server_is_healthy, log_manager_.has_unsent_logs());
[email protected]d67d1052011-06-09 05:11:41993
[email protected]73929422014-05-22 08:19:05994 if (server_is_healthy)
995 client_->OnLogUploadComplete();
initial.commit09911bf2008-07-26 23:55:29996}
997
[email protected]57ecc4b2010-08-11 03:02:51998void MetricsService::IncrementPrefValue(const char* path) {
[email protected]24f81ca2014-05-26 15:59:34999 int value = local_state_->GetInteger(path);
1000 local_state_->SetInteger(path, value + 1);
[email protected]e73c01972008-08-13 00:18:241001}
1002
[email protected]57ecc4b2010-08-11 03:02:511003void MetricsService::IncrementLongPrefsValue(const char* path) {
[email protected]24f81ca2014-05-26 15:59:341004 int64 value = local_state_->GetInt64(path);
1005 local_state_->SetInt64(path, value + 1);
[email protected]0bb1a622009-03-04 03:22:321006}
1007
[email protected]c0c55e92011-09-10 18:47:301008bool MetricsService::UmaMetricsProperlyShutdown() {
1009 CHECK(clean_shutdown_status_ == CLEANLY_SHUTDOWN ||
1010 clean_shutdown_status_ == NEED_TO_SHUTDOWN);
1011 return clean_shutdown_status_ == CLEANLY_SHUTDOWN;
1012}
1013
asvitkinee0dbdbe2014-10-31 21:59:571014void MetricsService::AddSyntheticTrialObserver(
1015 SyntheticTrialObserver* observer) {
1016 synthetic_trial_observer_list_.AddObserver(observer);
1017 if (!synthetic_trial_groups_.empty())
1018 observer->OnSyntheticTrialsChanged(synthetic_trial_groups_);
1019}
1020
1021void MetricsService::RemoveSyntheticTrialObserver(
1022 SyntheticTrialObserver* observer) {
1023 synthetic_trial_observer_list_.RemoveObserver(observer);
1024}
1025
[email protected]60677562013-11-17 15:52:551026void MetricsService::RegisterSyntheticFieldTrial(
1027 const SyntheticTrialGroup& trial) {
1028 for (size_t i = 0; i < synthetic_trial_groups_.size(); ++i) {
1029 if (synthetic_trial_groups_[i].id.name == trial.id.name) {
1030 if (synthetic_trial_groups_[i].id.group != trial.id.group) {
1031 synthetic_trial_groups_[i].id.group = trial.id.group;
[email protected]7a5c07812014-02-26 11:45:411032 synthetic_trial_groups_[i].start_time = base::TimeTicks::Now();
asvitkinee0dbdbe2014-10-31 21:59:571033 NotifySyntheticTrialObservers();
[email protected]60677562013-11-17 15:52:551034 }
1035 return;
1036 }
1037 }
1038
[email protected]7a5c07812014-02-26 11:45:411039 SyntheticTrialGroup trial_group = trial;
1040 trial_group.start_time = base::TimeTicks::Now();
[email protected]60677562013-11-17 15:52:551041 synthetic_trial_groups_.push_back(trial_group);
asvitkinee0dbdbe2014-10-31 21:59:571042 NotifySyntheticTrialObservers();
[email protected]60677562013-11-17 15:52:551043}
1044
[email protected]85791b0b2014-05-20 15:18:581045void MetricsService::RegisterMetricsProvider(
asvitkinea63d19e2014-10-24 16:19:391046 scoped_ptr<MetricsProvider> provider) {
[email protected]85791b0b2014-05-20 15:18:581047 DCHECK_EQ(INITIALIZED, state_);
1048 metrics_providers_.push_back(provider.release());
1049}
1050
[email protected]61b0d482014-05-20 14:49:101051void MetricsService::CheckForClonedInstall(
1052 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
1053 state_manager_->CheckForClonedInstall(task_runner);
[email protected]99c892d2014-03-24 18:11:211054}
1055
asvitkinee0dbdbe2014-10-31 21:59:571056void MetricsService::NotifySyntheticTrialObservers() {
1057 FOR_EACH_OBSERVER(SyntheticTrialObserver, synthetic_trial_observer_list_,
1058 OnSyntheticTrialsChanged(synthetic_trial_groups_));
1059}
1060
[email protected]60677562013-11-17 15:52:551061void MetricsService::GetCurrentSyntheticFieldTrials(
[email protected]b3610d42014-05-19 18:07:231062 std::vector<variations::ActiveGroupId>* synthetic_trials) {
[email protected]60677562013-11-17 15:52:551063 DCHECK(synthetic_trials);
1064 synthetic_trials->clear();
[email protected]94dce122014-07-16 04:20:121065 const MetricsLog* current_log = log_manager_.current_log();
[email protected]60677562013-11-17 15:52:551066 for (size_t i = 0; i < synthetic_trial_groups_.size(); ++i) {
1067 if (synthetic_trial_groups_[i].start_time <= current_log->creation_time())
1068 synthetic_trials->push_back(synthetic_trial_groups_[i].id);
1069 }
1070}
1071
[email protected]09dee82d2014-05-22 14:00:531072scoped_ptr<MetricsLog> MetricsService::CreateLog(MetricsLog::LogType log_type) {
[email protected]24f81ca2014-05-26 15:59:341073 return make_scoped_ptr(new MetricsLog(state_manager_->client_id(),
1074 session_id_,
1075 log_type,
1076 client_,
1077 local_state_));
[email protected]09dee82d2014-05-22 14:00:531078}
1079
asvitkine88aa9332014-09-29 23:29:171080void MetricsService::RecordCurrentEnvironment(MetricsLog* log) {
1081 std::vector<variations::ActiveGroupId> synthetic_trials;
1082 GetCurrentSyntheticFieldTrials(&synthetic_trials);
1083 log->RecordEnvironment(metrics_providers_.get(), synthetic_trials,
olivierrobinc3dfc5b2015-04-07 19:12:001084 GetInstallDate(), GetMetricsReportingEnabledDate());
asvitkine88aa9332014-09-29 23:29:171085 UMA_HISTOGRAM_COUNTS_100("UMA.SyntheticTrials.Count",
1086 synthetic_trials.size());
1087}
1088
[email protected]acc2ce5512014-05-22 18:29:131089void MetricsService::RecordCurrentHistograms() {
1090 DCHECK(log_manager_.current_log());
1091 histogram_snapshot_manager_.PrepareDeltas(
1092 base::Histogram::kNoFlags, base::Histogram::kUmaTargetedHistogramFlag);
1093}
1094
1095void MetricsService::RecordCurrentStabilityHistograms() {
1096 DCHECK(log_manager_.current_log());
1097 histogram_snapshot_manager_.PrepareDeltas(
1098 base::Histogram::kNoFlags, base::Histogram::kUmaStabilityHistogramFlag);
1099}
1100
[email protected]466f3c12011-03-23 21:20:381101void MetricsService::LogCleanShutdown() {
[email protected]c0c55e92011-09-10 18:47:301102 // Redundant setting to assure that we always reset this value at shutdown
1103 // (and that we don't use some alternate path, and not call LogCleanShutdown).
1104 clean_shutdown_status_ = CLEANLY_SHUTDOWN;
[email protected]acd55b32011-09-05 17:35:311105
erikwright65b58df2014-09-12 00:05:281106 clean_exit_beacon_.WriteBeaconValue(true);
1107 RecordCurrentState(local_state_);
asvitkinea63d19e2014-10-24 16:19:391108 local_state_->SetInteger(prefs::kStabilityExecutionPhase,
[email protected]24f81ca2014-05-26 15:59:341109 MetricsService::SHUTDOWN_COMPLETE);
[email protected]466f3c12011-03-23 21:20:381110}
1111
[email protected]e5ad60a2014-03-11 03:54:041112bool MetricsService::ShouldLogEvents() {
1113 // We simply don't log events to UMA if there is a single incognito
initial.commit09911bf2008-07-26 23:55:291114 // session visible. The problem is that we always notify using the orginal
1115 // profile in order to simplify notification processing.
[email protected]7d000322014-05-23 07:16:021116 return !client_->IsOffTheRecordSessionActive();
initial.commit09911bf2008-07-26 23:55:291117}
1118
[email protected]57ecc4b2010-08-11 03:02:511119void MetricsService::RecordBooleanPrefValue(const char* path, bool value) {
initial.commit09911bf2008-07-26 23:55:291120 DCHECK(IsSingleThreaded());
[email protected]24f81ca2014-05-26 15:59:341121 local_state_->SetBoolean(path, value);
1122 RecordCurrentState(local_state_);
initial.commit09911bf2008-07-26 23:55:291123}
1124
1125void MetricsService::RecordCurrentState(PrefService* pref) {
asvitkinea63d19e2014-10-24 16:19:391126 pref->SetInt64(prefs::kStabilityLastTimestampSec,
asvitkinecbd420732014-08-26 22:15:401127 base::Time::Now().ToTimeT());
initial.commit09911bf2008-07-26 23:55:291128}
asvitkinecbd420732014-08-26 22:15:401129
1130} // namespace metrics