From 5db66c3859990b9ec9f5423c869c0f2a901412ed Mon Sep 17 00:00:00 2001 From: Bertrand SIMONNET Date: Tue, 28 Jul 2015 15:42:42 -0700 Subject: [PATCH] metrics: Don't use the policy file. Android does not have any policy file. Instead, rely only on the existence of the consent file to determine whether the metrics are enabled or not. BUG: 22879597 Change-Id: I7e628f09d623c97b9bab3a490a636db873230817 --- metrics/include/metrics/metrics_library.h | 7 ------ metrics/metrics_library.cc | 30 +---------------------- 2 files changed, 1 insertion(+), 36 deletions(-) diff --git a/metrics/include/metrics/metrics_library.h b/metrics/include/metrics/metrics_library.h index a90f3e61a..7508100f8 100644 --- a/metrics/include/metrics/metrics_library.h +++ b/metrics/include/metrics/metrics_library.h @@ -14,8 +14,6 @@ #include #include // for FRIEND_TEST -#include "policy/libpolicy.h" - class MetricsLibraryInterface { public: virtual void Init() = 0; @@ -130,9 +128,6 @@ class MetricsLibrary : public MetricsLibraryInterface { char* buffer, int buffer_size, bool* result); - // This function is used by tests only to mock the device policies. - void SetPolicyProvider(policy::PolicyProvider* provider); - // Time at which we last checked if metrics were enabled. static time_t cached_enabled_time_; @@ -142,8 +137,6 @@ class MetricsLibrary : public MetricsLibraryInterface { std::string uma_events_file_; std::string consent_file_; - scoped_ptr policy_provider_; - DISALLOW_COPY_AND_ASSIGN(MetricsLibrary); }; diff --git a/metrics/metrics_library.cc b/metrics/metrics_library.cc index 437787a89..fb80354c6 100644 --- a/metrics/metrics_library.cc +++ b/metrics/metrics_library.cc @@ -16,8 +16,6 @@ #include "serialization/metric_sample.h" #include "serialization/serialization_utils.h" -#include "policy/device_policy.h" - static const char kAutotestPath[] = "/var/log/metrics/autotest-events"; static const char kUMAEventsPath[] = "/var/lib/metrics/uma-events"; static const char kConsentFile[] = "/home/chronos/Consent To Send Stats"; @@ -123,29 +121,7 @@ bool MetricsLibrary::AreMetricsEnabled() { time_t this_check_time = time(nullptr); if (this_check_time != cached_enabled_time_) { cached_enabled_time_ = this_check_time; - - if (!policy_provider_.get()) - policy_provider_.reset(new policy::PolicyProvider()); - policy_provider_->Reload(); - // We initialize with the default value which is false and will be preserved - // if the policy is not set. - bool enabled = false; - bool has_policy = false; - if (policy_provider_->device_policy_is_loaded()) { - has_policy = - policy_provider_->GetDevicePolicy().GetMetricsEnabled(&enabled); - } - // If policy couldn't be loaded or the metrics policy is not set we should - // still respect the consent file if it is present for migration purposes. - // TODO(pastarmovj) - if (!has_policy) { - enabled = stat(consent_file_.c_str(), &stat_buffer) >= 0; - } - - if (enabled && !IsGuestMode()) - cached_enabled_ = true; - else - cached_enabled_ = false; + cached_enabled_ = stat(consent_file_.c_str(), &stat_buffer) >= 0; } return cached_enabled_; } @@ -200,10 +176,6 @@ bool MetricsLibrary::SendCrashToUMA(const char *crash_kind) { *metrics::MetricSample::CrashSample(crash_kind).get(), kUMAEventsPath); } -void MetricsLibrary::SetPolicyProvider(policy::PolicyProvider* provider) { - policy_provider_.reset(provider); -} - bool MetricsLibrary::SendCrosEventToUMA(const std::string& event) { for (size_t i = 0; i < arraysize(kCrosEventNames); i++) { if (strcmp(event.c_str(), kCrosEventNames[i]) == 0) {