From 067ec8ba78287d2992331423d74d978cfa8669ff Mon Sep 17 00:00:00 2001 From: Ben Chan Date: Tue, 17 Feb 2015 13:54:04 -0800 Subject: [PATCH] metrics: Disable uploader on non-official build. The metrics uploader should only be enabled on an official build. BUG=chromium:459105 TEST=`FEATURES=test emerge-$BOARD metrics` TEST=Verified that metrics uploader is disabled on a developer build. Change-Id: I5cadb3afeb56c0adac971228aa48ad56ed913bbf Reviewed-on: https://chromium-review.googlesource.com/250542 Reviewed-by: Bertrand Simonnet Commit-Queue: Ben Chan Tested-by: Ben Chan --- metrics/metrics_daemon.cc | 22 +++++++++++++++++++--- metrics/metrics_daemon.h | 3 +++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/metrics/metrics_daemon.cc b/metrics/metrics_daemon.cc index a746e06a0..4a69d8b4c 100644 --- a/metrics/metrics_daemon.cc +++ b/metrics/metrics_daemon.cc @@ -48,6 +48,10 @@ const char kCrashReporterUserCrashSignal[] = "UserCrash"; const char kCrashReporterMatchRule[] = "type='signal',interface='%s',path='/',member='%s'"; +// Build type of an official build. +// See src/third_party/chromiumos-overlay/chromeos/scripts/cros_set_lsb_release. +const char kOfficialBuild[] = "Official Build"; + const int kSecondsPerMinute = 60; const int kMinutesPerHour = 60; const int kHoursPerDay = 24; @@ -209,6 +213,13 @@ uint32_t MetricsDaemon::GetOsVersionHash() { return cached_version_hash; } +bool MetricsDaemon::IsOnOfficialBuild() const { + std::string build_type; + return (base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_BUILD_TYPE", + &build_type) && + build_type == kOfficialBuild); +} + void MetricsDaemon::Init(bool testing, bool uploader_active, MetricsLibraryInterface* metrics_lib, @@ -327,9 +338,14 @@ int MetricsDaemon::OnInit() { base::TimeDelta::FromMilliseconds(kUpdateStatsIntervalMs)); if (uploader_active_) { - LOG(INFO) << "uploader enabled"; - upload_service_.reset(new UploadService(new SystemProfileCache(), server_)); - upload_service_->Init(upload_interval_, metrics_file_); + if (IsOnOfficialBuild()) { + LOG(INFO) << "uploader enabled"; + upload_service_.reset( + new UploadService(new SystemProfileCache(), server_)); + upload_service_->Init(upload_interval_, metrics_file_); + } else { + LOG(INFO) << "uploader disabled on non-official build"; + } } return EX_OK; diff --git a/metrics/metrics_daemon.h b/metrics/metrics_daemon.h index 397fd2109..d38dcd92d 100644 --- a/metrics/metrics_daemon.h +++ b/metrics/metrics_daemon.h @@ -273,6 +273,9 @@ class MetricsDaemon : public chromeos::DBusDaemon { // to a unsigned 32-bit int. uint32_t GetOsVersionHash(); + // Returns true if the system is using an official build. + bool IsOnOfficialBuild() const; + // Updates stats, additionally sending them to UMA if enough time has elapsed // since the last report. void UpdateStats(base::TimeTicks now_ticks, base::Time now_wall_time);