Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: components/metrics/metrics_service.cc

Issue 1818613002: Implement UMA log throttling for cellular connections (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/metrics/metrics_service.h ('k') | components/metrics/metrics_service_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 16 matching lines...) Expand all
287 client_(client), 289 client_(client),
288 local_state_(local_state), 290 local_state_(local_state),
289 clean_exit_beacon_(client->GetRegistryBackupKey(), local_state), 291 clean_exit_beacon_(client->GetRegistryBackupKey(), local_state),
290 recording_state_(UNSET), 292 recording_state_(UNSET),
291 reporting_active_(false), 293 reporting_active_(false),
292 test_mode_active_(false), 294 test_mode_active_(false),
293 state_(INITIALIZED), 295 state_(INITIALIZED),
294 log_upload_in_progress_(false), 296 log_upload_in_progress_(false),
295 idle_since_last_transmission_(false), 297 idle_since_last_transmission_(false),
296 session_id_(-1), 298 session_id_(-1),
299 data_use_tracker_(DataUseTracker::Create(local_state_)),
297 self_ptr_factory_(this), 300 self_ptr_factory_(this),
298 state_saver_factory_(this) { 301 state_saver_factory_(this) {
299 DCHECK(IsSingleThreaded()); 302 DCHECK(IsSingleThreaded());
300 DCHECK(state_manager_); 303 DCHECK(state_manager_);
301 DCHECK(client_); 304 DCHECK(client_);
302 DCHECK(local_state_); 305 DCHECK(local_state_);
303 306
304 // Set the install date if this is our first run. 307 // Set the install date if this is our first run.
305 int64_t install_date = local_state_->GetInt64(prefs::kInstallDate); 308 int64_t install_date = local_state_->GetInt64(prefs::kInstallDate);
306 if (install_date == 0) 309 if (install_date == 0)
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
554 if (data_use_tracker_) {
555 return data_use_tracker_->GetDataUseForwardingCallback(
556 base::ThreadTaskRunnerHandle::Get());
557 }
558 return UpdateUsagePrefCallbackType();
559 }
560
548 //------------------------------------------------------------------------------ 561 //------------------------------------------------------------------------------
549 // private methods 562 // private methods
550 //------------------------------------------------------------------------------ 563 //------------------------------------------------------------------------------
551 564
552 565
553 //------------------------------------------------------------------------------ 566 //------------------------------------------------------------------------------
554 // Initialization methods 567 // Initialization methods
555 568
556 void MetricsService::InitializeMetricsState() { 569 void MetricsService::InitializeMetricsState() {
557 const int64_t buildtime = MetricsLog::GetBuildTime(); 570 const int64_t buildtime = MetricsLog::GetBuildTime();
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 } 872 }
860 if (!log_manager_.has_unsent_logs()) { 873 if (!log_manager_.has_unsent_logs()) {
861 // Should only get here if serializing the log failed somehow. 874 // Should only get here if serializing the log failed somehow.
862 // Just tell the scheduler it was uploaded and wait for the next log 875 // Just tell the scheduler it was uploaded and wait for the next log
863 // interval. 876 // interval.
864 scheduler_->UploadFinished(true, log_manager_.has_unsent_logs()); 877 scheduler_->UploadFinished(true, log_manager_.has_unsent_logs());
865 return; 878 return;
866 } 879 }
867 if (!log_manager_.has_staged_log()) 880 if (!log_manager_.has_staged_log())
868 log_manager_.StageNextLogForUpload(); 881 log_manager_.StageNextLogForUpload();
869 SendStagedLog(); 882
883 // Proceed to stage the log for upload if log size satisfies cellular log
884 // upload constrains.
885 if (client_->IsUMACellularUploadLogicEnabled() &&
886 !data_use_tracker_->ShouldUploadLogOnCellular(
887 log_manager_.staged_log_hash().size())) {
888 scheduler_->UploadCancelled();
889 } else {
890 SendStagedLog();
891 }
870 } 892 }
871 893
872 bool MetricsService::ProvidersHaveInitialStabilityMetrics() { 894 bool MetricsService::ProvidersHaveInitialStabilityMetrics() {
873 // Check whether any metrics provider has initial stability metrics. 895 // Check whether any metrics provider has initial stability metrics.
874 for (MetricsProvider* provider : metrics_providers_) { 896 for (MetricsProvider* provider : metrics_providers_) {
875 if (provider->HasInitialStabilityMetrics()) 897 if (provider->HasInitialStabilityMetrics())
876 return true; 898 return true;
877 } 899 }
878 900
879 return false; 901 return false;
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
1161 base::Time::Now().ToTimeT()); 1183 base::Time::Now().ToTimeT());
1162 } 1184 }
1163 1185
1164 void MetricsService::SkipAndDiscardUpload() { 1186 void MetricsService::SkipAndDiscardUpload() {
1165 log_manager_.DiscardStagedLog(); 1187 log_manager_.DiscardStagedLog();
1166 scheduler_->UploadCancelled(); 1188 scheduler_->UploadCancelled();
1167 log_upload_in_progress_ = false; 1189 log_upload_in_progress_ = false;
1168 } 1190 }
1169 1191
1170 } // namespace metrics 1192 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/metrics_service.h ('k') | components/metrics/metrics_service_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698