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_)); | |
311 } | |
312 | |
313 MetricsService::MetricsService(MetricsStateManager* state_manager, | |
314 MetricsServiceClient* client, | |
315 PrefService* local_state, | |
316 base::Callback<void(bool*)> cellular_callback) | |
317 : MetricsService(state_manager, client, local_state) { | |
318 cellular_callback_ = cellular_callback; | |
308 } | 319 } |
309 | 320 |
310 MetricsService::~MetricsService() { | 321 MetricsService::~MetricsService() { |
311 DisableRecording(); | 322 DisableRecording(); |
312 } | 323 } |
313 | 324 |
314 void MetricsService::InitializeMetricsRecordingState() { | 325 void MetricsService::InitializeMetricsRecordingState() { |
315 InitializeMetricsState(); | 326 InitializeMetricsState(); |
316 | 327 |
317 base::Closure upload_callback = | 328 base::Closure upload_callback = |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
538 UNINITIALIZED_PHASE); | 549 UNINITIALIZED_PHASE); |
539 local_state_->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); | 550 local_state_->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); |
540 local_state_->SetInteger(prefs::kStabilityLaunchCount, 0); | 551 local_state_->SetInteger(prefs::kStabilityLaunchCount, 0); |
541 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, true); | 552 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, true); |
542 } | 553 } |
543 | 554 |
544 void MetricsService::PushExternalLog(const std::string& log) { | 555 void MetricsService::PushExternalLog(const std::string& log) { |
545 log_manager_.StoreLog(log, MetricsLog::ONGOING_LOG); | 556 log_manager_.StoreLog(log, MetricsLog::ONGOING_LOG); |
546 } | 557 } |
547 | 558 |
559 UpdateUsagePrefCallbackType MetricsService::GetDataUseForwardingCallback() { | |
560 DCHECK(IsSingleThreaded()); | |
561 return data_use_tracker_->GetDataUseForwardingCallback( | |
562 base::ThreadTaskRunnerHandle::Get()); | |
563 } | |
564 | |
548 //------------------------------------------------------------------------------ | 565 //------------------------------------------------------------------------------ |
549 // private methods | 566 // private methods |
550 //------------------------------------------------------------------------------ | 567 //------------------------------------------------------------------------------ |
551 | 568 |
552 | 569 |
553 //------------------------------------------------------------------------------ | 570 //------------------------------------------------------------------------------ |
554 // Initialization methods | 571 // Initialization methods |
555 | 572 |
556 void MetricsService::InitializeMetricsState() { | 573 void MetricsService::InitializeMetricsState() { |
557 const int64_t buildtime = MetricsLog::GetBuildTime(); | 574 const int64_t buildtime = MetricsLog::GetBuildTime(); |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
859 } | 876 } |
860 if (!log_manager_.has_unsent_logs()) { | 877 if (!log_manager_.has_unsent_logs()) { |
861 // Should only get here if serializing the log failed somehow. | 878 // Should only get here if serializing the log failed somehow. |
862 // Just tell the scheduler it was uploaded and wait for the next log | 879 // Just tell the scheduler it was uploaded and wait for the next log |
863 // interval. | 880 // interval. |
864 scheduler_->UploadFinished(true, log_manager_.has_unsent_logs()); | 881 scheduler_->UploadFinished(true, log_manager_.has_unsent_logs()); |
865 return; | 882 return; |
866 } | 883 } |
867 if (!log_manager_.has_staged_log()) | 884 if (!log_manager_.has_staged_log()) |
868 log_manager_.StageNextLogForUpload(); | 885 log_manager_.StageNextLogForUpload(); |
869 SendStagedLog(); | 886 |
887 // Proceed to stage the log for upload if log size satisfies cellular log | |
888 // upload constrains. | |
889 bool is_cellular = false; | |
890 if (!cellular_callback_.is_null()) | |
891 cellular_callback_.Run(&is_cellular); | |
892 | |
893 if (is_cellular && | |
894 !data_use_tracker_->CanUploadUMALog( | |
895 log_manager_.staged_log_hash().size())) | |
Alexei Svitkine (slow)
2016/03/31 22:18:03
Nit: Add {}'s
gayane -on leave until 09-2017
2016/04/01 19:49:31
Done.
| |
896 scheduler_->UploadCancelled(); | |
897 else | |
898 SendStagedLog(); | |
870 } | 899 } |
871 | 900 |
872 bool MetricsService::ProvidersHaveInitialStabilityMetrics() { | 901 bool MetricsService::ProvidersHaveInitialStabilityMetrics() { |
873 // Check whether any metrics provider has initial stability metrics. | 902 // Check whether any metrics provider has initial stability metrics. |
874 for (MetricsProvider* provider : metrics_providers_) { | 903 for (MetricsProvider* provider : metrics_providers_) { |
875 if (provider->HasInitialStabilityMetrics()) | 904 if (provider->HasInitialStabilityMetrics()) |
876 return true; | 905 return true; |
877 } | 906 } |
878 | 907 |
879 return false; | 908 return false; |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1161 base::Time::Now().ToTimeT()); | 1190 base::Time::Now().ToTimeT()); |
1162 } | 1191 } |
1163 | 1192 |
1164 void MetricsService::SkipAndDiscardUpload() { | 1193 void MetricsService::SkipAndDiscardUpload() { |
1165 log_manager_.DiscardStagedLog(); | 1194 log_manager_.DiscardStagedLog(); |
1166 scheduler_->UploadCancelled(); | 1195 scheduler_->UploadCancelled(); |
1167 log_upload_in_progress_ = false; | 1196 log_upload_in_progress_ = false; |
1168 } | 1197 } |
1169 | 1198 |
1170 } // namespace metrics | 1199 } // namespace metrics |
OLD | NEW |