OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 //------------------------------------------------------------------------------ | 5 //------------------------------------------------------------------------------ |
6 // Description of the life cycle of a instance of MetricsService. | 6 // Description of the life cycle of a instance of MetricsService. |
7 // | 7 // |
8 // OVERVIEW | 8 // OVERVIEW |
9 // | 9 // |
10 // A MetricsService instance is typically created at application startup. It is | 10 // A MetricsService instance is typically created at application startup. It is |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 #include "base/values.h" | 184 #include "base/values.h" |
185 #include "components/metrics/metrics_log.h" | 185 #include "components/metrics/metrics_log.h" |
186 #include "components/metrics/metrics_log_manager.h" | 186 #include "components/metrics/metrics_log_manager.h" |
187 #include "components/metrics/metrics_log_uploader.h" | 187 #include "components/metrics/metrics_log_uploader.h" |
188 #include "components/metrics/metrics_pref_names.h" | 188 #include "components/metrics/metrics_pref_names.h" |
189 #include "components/metrics/metrics_reporting_scheduler.h" | 189 #include "components/metrics/metrics_reporting_scheduler.h" |
190 #include "components/metrics/metrics_service_client.h" | 190 #include "components/metrics/metrics_service_client.h" |
191 #include "components/metrics/metrics_state_manager.h" | 191 #include "components/metrics/metrics_state_manager.h" |
192 #include "components/variations/entropy_provider.h" | 192 #include "components/variations/entropy_provider.h" |
193 | 193 |
194 using base::Time; | 194 namespace metrics { |
195 using metrics::MetricsLogManager; | |
196 | 195 |
197 namespace { | 196 namespace { |
198 | 197 |
199 // Check to see that we're being called on only one thread. | 198 // Check to see that we're being called on only one thread. |
200 bool IsSingleThreaded() { | 199 bool IsSingleThreaded() { |
201 static base::PlatformThreadId thread_id = 0; | 200 static base::PlatformThreadId thread_id = 0; |
202 if (!thread_id) | 201 if (!thread_id) |
203 thread_id = base::PlatformThread::CurrentId(); | 202 thread_id = base::PlatformThread::CurrentId(); |
204 return base::PlatformThread::CurrentId() == thread_id; | 203 return base::PlatformThread::CurrentId() == thread_id; |
205 } | 204 } |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 // Call GetUptimes() for the first time, thus allowing all later calls | 605 // Call GetUptimes() for the first time, thus allowing all later calls |
607 // to record incremental uptimes accurately. | 606 // to record incremental uptimes accurately. |
608 base::TimeDelta ignored_uptime_parameter; | 607 base::TimeDelta ignored_uptime_parameter; |
609 base::TimeDelta startup_uptime; | 608 base::TimeDelta startup_uptime; |
610 GetUptimes(local_state_, &startup_uptime, &ignored_uptime_parameter); | 609 GetUptimes(local_state_, &startup_uptime, &ignored_uptime_parameter); |
611 DCHECK_EQ(0, startup_uptime.InMicroseconds()); | 610 DCHECK_EQ(0, startup_uptime.InMicroseconds()); |
612 // For backwards compatibility, leave this intact in case Omaha is checking | 611 // For backwards compatibility, leave this intact in case Omaha is checking |
613 // them. metrics::prefs::kStabilityLastTimestampSec may also be useless now. | 612 // them. metrics::prefs::kStabilityLastTimestampSec may also be useless now. |
614 // TODO(jar): Delete these if they have no uses. | 613 // TODO(jar): Delete these if they have no uses. |
615 local_state_->SetInt64(metrics::prefs::kStabilityLaunchTimeSec, | 614 local_state_->SetInt64(metrics::prefs::kStabilityLaunchTimeSec, |
616 Time::Now().ToTimeT()); | 615 base::Time::Now().ToTimeT()); |
617 | 616 |
618 // Bookkeeping for the uninstall metrics. | 617 // Bookkeeping for the uninstall metrics. |
619 IncrementLongPrefsValue(metrics::prefs::kUninstallLaunchCount); | 618 IncrementLongPrefsValue(metrics::prefs::kUninstallLaunchCount); |
620 | 619 |
621 // Kick off the process of saving the state (so the uptime numbers keep | 620 // Kick off the process of saving the state (so the uptime numbers keep |
622 // getting updated) every n minutes. | 621 // getting updated) every n minutes. |
623 ScheduleNextStateSave(); | 622 ScheduleNextStateSave(); |
624 } | 623 } |
625 | 624 |
626 void MetricsService::OnUserAction(const std::string& action) { | 625 void MetricsService::OnUserAction(const std::string& action) { |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1183 } | 1182 } |
1184 | 1183 |
1185 void MetricsService::RecordBooleanPrefValue(const char* path, bool value) { | 1184 void MetricsService::RecordBooleanPrefValue(const char* path, bool value) { |
1186 DCHECK(IsSingleThreaded()); | 1185 DCHECK(IsSingleThreaded()); |
1187 local_state_->SetBoolean(path, value); | 1186 local_state_->SetBoolean(path, value); |
1188 RecordCurrentState(local_state_); | 1187 RecordCurrentState(local_state_); |
1189 } | 1188 } |
1190 | 1189 |
1191 void MetricsService::RecordCurrentState(PrefService* pref) { | 1190 void MetricsService::RecordCurrentState(PrefService* pref) { |
1192 pref->SetInt64(metrics::prefs::kStabilityLastTimestampSec, | 1191 pref->SetInt64(metrics::prefs::kStabilityLastTimestampSec, |
1193 Time::Now().ToTimeT()); | 1192 base::Time::Now().ToTimeT()); |
1194 } | 1193 } |
| 1194 |
| 1195 } // namespace metrics |
OLD | NEW |