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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 #include "base/strings/string_number_conversions.h" | 142 #include "base/strings/string_number_conversions.h" |
143 #include "base/strings/utf_string_conversions.h" | 143 #include "base/strings/utf_string_conversions.h" |
144 #include "base/thread_task_runner_handle.h" | 144 #include "base/thread_task_runner_handle.h" |
145 #include "base/threading/platform_thread.h" | 145 #include "base/threading/platform_thread.h" |
146 #include "base/threading/thread.h" | 146 #include "base/threading/thread.h" |
147 #include "base/threading/thread_restrictions.h" | 147 #include "base/threading/thread_restrictions.h" |
148 #include "base/time/time.h" | 148 #include "base/time/time.h" |
149 #include "base/tracked_objects.h" | 149 #include "base/tracked_objects.h" |
150 #include "base/values.h" | 150 #include "base/values.h" |
151 #include "build/build_config.h" | 151 #include "build/build_config.h" |
152 #include "components/metrics/data_use_tracker.h" | |
152 #include "components/metrics/metrics_log.h" | 153 #include "components/metrics/metrics_log.h" |
153 #include "components/metrics/metrics_log_manager.h" | 154 #include "components/metrics/metrics_log_manager.h" |
154 #include "components/metrics/metrics_log_uploader.h" | 155 #include "components/metrics/metrics_log_uploader.h" |
155 #include "components/metrics/metrics_pref_names.h" | 156 #include "components/metrics/metrics_pref_names.h" |
156 #include "components/metrics/metrics_reporting_scheduler.h" | 157 #include "components/metrics/metrics_reporting_scheduler.h" |
157 #include "components/metrics/metrics_service_client.h" | 158 #include "components/metrics/metrics_service_client.h" |
158 #include "components/metrics/metrics_state_manager.h" | 159 #include "components/metrics/metrics_state_manager.h" |
159 #include "components/prefs/pref_registry_simple.h" | 160 #include "components/prefs/pref_registry_simple.h" |
160 #include "components/prefs/pref_service.h" | 161 #include "components/prefs/pref_service.h" |
161 #include "components/variations/entropy_provider.h" | 162 #include "components/variations/entropy_provider.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
251 MetricsService::CLEANLY_SHUTDOWN; | 252 MetricsService::CLEANLY_SHUTDOWN; |
252 | 253 |
253 MetricsService::ExecutionPhase MetricsService::execution_phase_ = | 254 MetricsService::ExecutionPhase MetricsService::execution_phase_ = |
254 MetricsService::UNINITIALIZED_PHASE; | 255 MetricsService::UNINITIALIZED_PHASE; |
255 | 256 |
256 // static | 257 // static |
257 void MetricsService::RegisterPrefs(PrefRegistrySimple* registry) { | 258 void MetricsService::RegisterPrefs(PrefRegistrySimple* registry) { |
258 DCHECK(IsSingleThreaded()); | 259 DCHECK(IsSingleThreaded()); |
259 MetricsStateManager::RegisterPrefs(registry); | 260 MetricsStateManager::RegisterPrefs(registry); |
260 MetricsLog::RegisterPrefs(registry); | 261 MetricsLog::RegisterPrefs(registry); |
262 DataUseTracker::RegisterPrefs(registry); | |
261 | 263 |
262 registry->RegisterInt64Pref(prefs::kInstallDate, 0); | 264 registry->RegisterInt64Pref(prefs::kInstallDate, 0); |
263 | 265 |
264 registry->RegisterInt64Pref(prefs::kStabilityLaunchTimeSec, 0); | 266 registry->RegisterInt64Pref(prefs::kStabilityLaunchTimeSec, 0); |
265 registry->RegisterInt64Pref(prefs::kStabilityLastTimestampSec, 0); | 267 registry->RegisterInt64Pref(prefs::kStabilityLastTimestampSec, 0); |
266 registry->RegisterStringPref(prefs::kStabilityStatsVersion, std::string()); | 268 registry->RegisterStringPref(prefs::kStabilityStatsVersion, std::string()); |
267 registry->RegisterInt64Pref(prefs::kStabilityStatsBuildTime, 0); | 269 registry->RegisterInt64Pref(prefs::kStabilityStatsBuildTime, 0); |
268 registry->RegisterBooleanPref(prefs::kStabilityExitedCleanly, true); | 270 registry->RegisterBooleanPref(prefs::kStabilityExitedCleanly, true); |
269 registry->RegisterIntegerPref(prefs::kStabilityExecutionPhase, | 271 registry->RegisterIntegerPref(prefs::kStabilityExecutionPhase, |
270 UNINITIALIZED_PHASE); | 272 UNINITIALIZED_PHASE); |
(...skipping 27 matching lines...) Expand all Loading... | |
298 state_saver_factory_(this) { | 300 state_saver_factory_(this) { |
299 DCHECK(IsSingleThreaded()); | 301 DCHECK(IsSingleThreaded()); |
300 DCHECK(state_manager_); | 302 DCHECK(state_manager_); |
301 DCHECK(client_); | 303 DCHECK(client_); |
302 DCHECK(local_state_); | 304 DCHECK(local_state_); |
303 | 305 |
304 // Set the install date if this is our first run. | 306 // Set the install date if this is our first run. |
305 int64_t install_date = local_state_->GetInt64(prefs::kInstallDate); | 307 int64_t install_date = local_state_->GetInt64(prefs::kInstallDate); |
306 if (install_date == 0) | 308 if (install_date == 0) |
307 local_state_->SetInt64(prefs::kInstallDate, base::Time::Now().ToTimeT()); | 309 local_state_->SetInt64(prefs::kInstallDate, base::Time::Now().ToTimeT()); |
310 data_use_tracker_.reset(new DataUseTracker(local_state_)); | |
Alexei Svitkine (slow)
2016/04/06 18:37:43
We only want to do this logic if enabled via varia
gayane -on leave until 09-2017
2016/04/07 15:30:39
Done.
| |
308 } | 311 } |
309 | 312 |
310 MetricsService::~MetricsService() { | 313 MetricsService::~MetricsService() { |
311 DisableRecording(); | 314 DisableRecording(); |
312 } | 315 } |
313 | 316 |
314 void MetricsService::InitializeMetricsRecordingState() { | 317 void MetricsService::InitializeMetricsRecordingState() { |
315 InitializeMetricsState(); | 318 InitializeMetricsState(); |
316 | 319 |
317 base::Closure upload_callback = | 320 base::Closure upload_callback = |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
538 UNINITIALIZED_PHASE); | 541 UNINITIALIZED_PHASE); |
539 local_state_->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); | 542 local_state_->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); |
540 local_state_->SetInteger(prefs::kStabilityLaunchCount, 0); | 543 local_state_->SetInteger(prefs::kStabilityLaunchCount, 0); |
541 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, true); | 544 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, true); |
542 } | 545 } |
543 | 546 |
544 void MetricsService::PushExternalLog(const std::string& log) { | 547 void MetricsService::PushExternalLog(const std::string& log) { |
545 log_manager_.StoreLog(log, MetricsLog::ONGOING_LOG); | 548 log_manager_.StoreLog(log, MetricsLog::ONGOING_LOG); |
546 } | 549 } |
547 | 550 |
551 UpdateUsagePrefCallbackType MetricsService::GetDataUseForwardingCallback() { | |
552 DCHECK(IsSingleThreaded()); | |
553 return data_use_tracker_->GetDataUseForwardingCallback( | |
554 base::ThreadTaskRunnerHandle::Get()); | |
555 } | |
556 | |
548 //------------------------------------------------------------------------------ | 557 //------------------------------------------------------------------------------ |
549 // private methods | 558 // private methods |
550 //------------------------------------------------------------------------------ | 559 //------------------------------------------------------------------------------ |
551 | 560 |
552 | 561 |
553 //------------------------------------------------------------------------------ | 562 //------------------------------------------------------------------------------ |
554 // Initialization methods | 563 // Initialization methods |
555 | 564 |
556 void MetricsService::InitializeMetricsState() { | 565 void MetricsService::InitializeMetricsState() { |
557 const int64_t buildtime = MetricsLog::GetBuildTime(); | 566 const int64_t buildtime = MetricsLog::GetBuildTime(); |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
859 } | 868 } |
860 if (!log_manager_.has_unsent_logs()) { | 869 if (!log_manager_.has_unsent_logs()) { |
861 // Should only get here if serializing the log failed somehow. | 870 // Should only get here if serializing the log failed somehow. |
862 // Just tell the scheduler it was uploaded and wait for the next log | 871 // Just tell the scheduler it was uploaded and wait for the next log |
863 // interval. | 872 // interval. |
864 scheduler_->UploadFinished(true, log_manager_.has_unsent_logs()); | 873 scheduler_->UploadFinished(true, log_manager_.has_unsent_logs()); |
865 return; | 874 return; |
866 } | 875 } |
867 if (!log_manager_.has_staged_log()) | 876 if (!log_manager_.has_staged_log()) |
868 log_manager_.StageNextLogForUpload(); | 877 log_manager_.StageNextLogForUpload(); |
869 SendStagedLog(); | 878 |
879 // Proceed to stage the log for upload if log size satisfies cellular log | |
880 // upload constrains. | |
881 if (client_->IsUMACellularUploadLogicEnabled() && | |
882 !data_use_tracker_->ShouldUploadLogOnCellular( | |
883 log_manager_.staged_log_hash().size())) { | |
884 scheduler_->UploadCancelled(); | |
885 } else { | |
886 SendStagedLog(); | |
887 } | |
870 } | 888 } |
871 | 889 |
872 bool MetricsService::ProvidersHaveInitialStabilityMetrics() { | 890 bool MetricsService::ProvidersHaveInitialStabilityMetrics() { |
873 // Check whether any metrics provider has initial stability metrics. | 891 // Check whether any metrics provider has initial stability metrics. |
874 for (MetricsProvider* provider : metrics_providers_) { | 892 for (MetricsProvider* provider : metrics_providers_) { |
875 if (provider->HasInitialStabilityMetrics()) | 893 if (provider->HasInitialStabilityMetrics()) |
876 return true; | 894 return true; |
877 } | 895 } |
878 | 896 |
879 return false; | 897 return false; |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1161 base::Time::Now().ToTimeT()); | 1179 base::Time::Now().ToTimeT()); |
1162 } | 1180 } |
1163 | 1181 |
1164 void MetricsService::SkipAndDiscardUpload() { | 1182 void MetricsService::SkipAndDiscardUpload() { |
1165 log_manager_.DiscardStagedLog(); | 1183 log_manager_.DiscardStagedLog(); |
1166 scheduler_->UploadCancelled(); | 1184 scheduler_->UploadCancelled(); |
1167 log_upload_in_progress_ = false; | 1185 log_upload_in_progress_ = false; |
1168 } | 1186 } |
1169 | 1187 |
1170 } // namespace metrics | 1188 } // namespace metrics |
OLD | NEW |