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

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

Issue 1548113002: Switch to standard integer types in components/, part 2 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: gn Created 4 years, 12 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // saved for re-transmission. These duplicates could be filtered out server 119 // saved for re-transmission. These duplicates could be filtered out server
120 // side, but are not expected to be a significant problem. 120 // side, but are not expected to be a significant problem.
121 // 121 //
122 // 122 //
123 //------------------------------------------------------------------------------ 123 //------------------------------------------------------------------------------
124 124
125 #include "components/metrics/metrics_service.h" 125 #include "components/metrics/metrics_service.h"
126 126
127 #include <algorithm> 127 #include <algorithm>
128 128
129 #include <stddef.h>
130
129 #include "base/bind.h" 131 #include "base/bind.h"
130 #include "base/callback.h" 132 #include "base/callback.h"
131 #include "base/location.h" 133 #include "base/location.h"
132 #include "base/metrics/histogram_base.h" 134 #include "base/metrics/histogram_base.h"
133 #include "base/metrics/histogram_macros.h" 135 #include "base/metrics/histogram_macros.h"
134 #include "base/metrics/histogram_samples.h" 136 #include "base/metrics/histogram_samples.h"
135 #include "base/metrics/sparse_histogram.h" 137 #include "base/metrics/sparse_histogram.h"
136 #include "base/metrics/statistics_recorder.h" 138 #include "base/metrics/statistics_recorder.h"
137 #include "base/prefs/pref_registry_simple.h" 139 #include "base/prefs/pref_registry_simple.h"
138 #include "base/prefs/pref_service.h" 140 #include "base/prefs/pref_service.h"
139 #include "base/rand_util.h" 141 #include "base/rand_util.h"
140 #include "base/single_thread_task_runner.h" 142 #include "base/single_thread_task_runner.h"
141 #include "base/strings/string_number_conversions.h" 143 #include "base/strings/string_number_conversions.h"
142 #include "base/strings/utf_string_conversions.h" 144 #include "base/strings/utf_string_conversions.h"
143 #include "base/thread_task_runner_handle.h" 145 #include "base/thread_task_runner_handle.h"
144 #include "base/threading/platform_thread.h" 146 #include "base/threading/platform_thread.h"
145 #include "base/threading/thread.h" 147 #include "base/threading/thread.h"
146 #include "base/threading/thread_restrictions.h" 148 #include "base/threading/thread_restrictions.h"
147 #include "base/time/time.h" 149 #include "base/time/time.h"
148 #include "base/tracked_objects.h" 150 #include "base/tracked_objects.h"
149 #include "base/values.h" 151 #include "base/values.h"
152 #include "build/build_config.h"
150 #include "components/metrics/metrics_log.h" 153 #include "components/metrics/metrics_log.h"
151 #include "components/metrics/metrics_log_manager.h" 154 #include "components/metrics/metrics_log_manager.h"
152 #include "components/metrics/metrics_log_uploader.h" 155 #include "components/metrics/metrics_log_uploader.h"
153 #include "components/metrics/metrics_pref_names.h" 156 #include "components/metrics/metrics_pref_names.h"
154 #include "components/metrics/metrics_reporting_scheduler.h" 157 #include "components/metrics/metrics_reporting_scheduler.h"
155 #include "components/metrics/metrics_service_client.h" 158 #include "components/metrics/metrics_service_client.h"
156 #include "components/metrics/metrics_state_manager.h" 159 #include "components/metrics/metrics_state_manager.h"
157 #include "components/variations/entropy_provider.h" 160 #include "components/variations/entropy_provider.h"
158 #include "components/variations/variations_associated_data.h" 161 #include "components/variations/variations_associated_data.h"
159 162
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 idle_since_last_transmission_(false), 294 idle_since_last_transmission_(false),
292 session_id_(-1), 295 session_id_(-1),
293 self_ptr_factory_(this), 296 self_ptr_factory_(this),
294 state_saver_factory_(this) { 297 state_saver_factory_(this) {
295 DCHECK(IsSingleThreaded()); 298 DCHECK(IsSingleThreaded());
296 DCHECK(state_manager_); 299 DCHECK(state_manager_);
297 DCHECK(client_); 300 DCHECK(client_);
298 DCHECK(local_state_); 301 DCHECK(local_state_);
299 302
300 // Set the install date if this is our first run. 303 // Set the install date if this is our first run.
301 int64 install_date = local_state_->GetInt64(prefs::kInstallDate); 304 int64_t install_date = local_state_->GetInt64(prefs::kInstallDate);
302 if (install_date == 0) 305 if (install_date == 0)
303 local_state_->SetInt64(prefs::kInstallDate, base::Time::Now().ToTimeT()); 306 local_state_->SetInt64(prefs::kInstallDate, base::Time::Now().ToTimeT());
304 } 307 }
305 308
306 MetricsService::~MetricsService() { 309 MetricsService::~MetricsService() {
307 DisableRecording(); 310 DisableRecording();
308 } 311 }
309 312
310 void MetricsService::InitializeMetricsRecordingState() { 313 void MetricsService::InitializeMetricsRecordingState() {
311 InitializeMetricsState(); 314 InitializeMetricsState();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 } 351 }
349 352
350 void MetricsService::DisableReporting() { 353 void MetricsService::DisableReporting() {
351 reporting_active_ = false; 354 reporting_active_ = false;
352 } 355 }
353 356
354 std::string MetricsService::GetClientId() { 357 std::string MetricsService::GetClientId() {
355 return state_manager_->client_id(); 358 return state_manager_->client_id();
356 } 359 }
357 360
358 int64 MetricsService::GetInstallDate() { 361 int64_t MetricsService::GetInstallDate() {
359 return local_state_->GetInt64(prefs::kInstallDate); 362 return local_state_->GetInt64(prefs::kInstallDate);
360 } 363 }
361 364
362 int64 MetricsService::GetMetricsReportingEnabledDate() { 365 int64_t MetricsService::GetMetricsReportingEnabledDate() {
363 return local_state_->GetInt64(prefs::kMetricsReportingEnabledTimestamp); 366 return local_state_->GetInt64(prefs::kMetricsReportingEnabledTimestamp);
364 } 367 }
365 368
366 bool MetricsService::WasLastShutdownClean() const { 369 bool MetricsService::WasLastShutdownClean() const {
367 return clean_exit_beacon_.exited_cleanly(); 370 return clean_exit_beacon_.exited_cleanly();
368 } 371 }
369 372
370 scoped_ptr<const base::FieldTrial::EntropyProvider> 373 scoped_ptr<const base::FieldTrial::EntropyProvider>
371 MetricsService::CreateEntropyProvider() { 374 MetricsService::CreateEntropyProvider() {
372 // TODO(asvitkine): Refactor the code so that MetricsService does not expose 375 // TODO(asvitkine): Refactor the code so that MetricsService does not expose
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 543
541 //------------------------------------------------------------------------------ 544 //------------------------------------------------------------------------------
542 // private methods 545 // private methods
543 //------------------------------------------------------------------------------ 546 //------------------------------------------------------------------------------
544 547
545 548
546 //------------------------------------------------------------------------------ 549 //------------------------------------------------------------------------------
547 // Initialization methods 550 // Initialization methods
548 551
549 void MetricsService::InitializeMetricsState() { 552 void MetricsService::InitializeMetricsState() {
550 const int64 buildtime = MetricsLog::GetBuildTime(); 553 const int64_t buildtime = MetricsLog::GetBuildTime();
551 const std::string version = client_->GetVersionString(); 554 const std::string version = client_->GetVersionString();
552 bool version_changed = false; 555 bool version_changed = false;
553 if (local_state_->GetInt64(prefs::kStabilityStatsBuildTime) != buildtime || 556 if (local_state_->GetInt64(prefs::kStabilityStatsBuildTime) != buildtime ||
554 local_state_->GetString(prefs::kStabilityStatsVersion) != version) { 557 local_state_->GetString(prefs::kStabilityStatsVersion) != version) {
555 local_state_->SetString(prefs::kStabilityStatsVersion, version); 558 local_state_->SetString(prefs::kStabilityStatsVersion, version);
556 local_state_->SetInt64(prefs::kStabilityStatsBuildTime, buildtime); 559 local_state_->SetInt64(prefs::kStabilityStatsBuildTime, buildtime);
557 version_changed = true; 560 version_changed = true;
558 } 561 }
559 562
560 log_manager_.LoadPersistedUnsentLogs(); 563 log_manager_.LoadPersistedUnsentLogs();
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 // If this is the first call, init |first_updated_time_| and 661 // If this is the first call, init |first_updated_time_| and
659 // |last_updated_time_|. 662 // |last_updated_time_|.
660 if (last_updated_time_.is_null()) { 663 if (last_updated_time_.is_null()) {
661 first_updated_time_ = now; 664 first_updated_time_ = now;
662 last_updated_time_ = now; 665 last_updated_time_ = now;
663 } 666 }
664 *incremental_uptime = now - last_updated_time_; 667 *incremental_uptime = now - last_updated_time_;
665 *uptime = now - first_updated_time_; 668 *uptime = now - first_updated_time_;
666 last_updated_time_ = now; 669 last_updated_time_ = now;
667 670
668 const int64 incremental_time_secs = incremental_uptime->InSeconds(); 671 const int64_t incremental_time_secs = incremental_uptime->InSeconds();
669 if (incremental_time_secs > 0) { 672 if (incremental_time_secs > 0) {
670 int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec); 673 int64_t metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec);
671 metrics_uptime += incremental_time_secs; 674 metrics_uptime += incremental_time_secs;
672 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime); 675 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime);
673 } 676 }
674 } 677 }
675 678
676 void MetricsService::NotifyOnDidCreateMetricsLog() { 679 void MetricsService::NotifyOnDidCreateMetricsLog() {
677 DCHECK(IsSingleThreaded()); 680 DCHECK(IsSingleThreaded());
678 for (size_t i = 0; i < metrics_providers_.size(); ++i) 681 for (size_t i = 0; i < metrics_providers_.size(); ++i)
679 metrics_providers_[i]->OnDidCreateMetricsLog(); 682 metrics_providers_[i]->OnDidCreateMetricsLog();
680 } 683 }
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 if (server_is_healthy) 1001 if (server_is_healthy)
999 client_->OnLogUploadComplete(); 1002 client_->OnLogUploadComplete();
1000 } 1003 }
1001 1004
1002 void MetricsService::IncrementPrefValue(const char* path) { 1005 void MetricsService::IncrementPrefValue(const char* path) {
1003 int value = local_state_->GetInteger(path); 1006 int value = local_state_->GetInteger(path);
1004 local_state_->SetInteger(path, value + 1); 1007 local_state_->SetInteger(path, value + 1);
1005 } 1008 }
1006 1009
1007 void MetricsService::IncrementLongPrefsValue(const char* path) { 1010 void MetricsService::IncrementLongPrefsValue(const char* path) {
1008 int64 value = local_state_->GetInt64(path); 1011 int64_t value = local_state_->GetInt64(path);
1009 local_state_->SetInt64(path, value + 1); 1012 local_state_->SetInt64(path, value + 1);
1010 } 1013 }
1011 1014
1012 bool MetricsService::UmaMetricsProperlyShutdown() { 1015 bool MetricsService::UmaMetricsProperlyShutdown() {
1013 CHECK(clean_shutdown_status_ == CLEANLY_SHUTDOWN || 1016 CHECK(clean_shutdown_status_ == CLEANLY_SHUTDOWN ||
1014 clean_shutdown_status_ == NEED_TO_SHUTDOWN); 1017 clean_shutdown_status_ == NEED_TO_SHUTDOWN);
1015 return clean_shutdown_status_ == CLEANLY_SHUTDOWN; 1018 return clean_shutdown_status_ == CLEANLY_SHUTDOWN;
1016 } 1019 }
1017 1020
1018 void MetricsService::AddSyntheticTrialObserver( 1021 void MetricsService::AddSyntheticTrialObserver(
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 base::Time::Now().ToTimeT()); 1138 base::Time::Now().ToTimeT());
1136 } 1139 }
1137 1140
1138 void MetricsService::SkipAndDiscardUpload() { 1141 void MetricsService::SkipAndDiscardUpload() {
1139 log_manager_.DiscardStagedLog(); 1142 log_manager_.DiscardStagedLog();
1140 scheduler_->UploadCancelled(); 1143 scheduler_->UploadCancelled();
1141 log_upload_in_progress_ = false; 1144 log_upload_in_progress_ = false;
1142 } 1145 }
1143 1146
1144 } // namespace metrics 1147 } // 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