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
This commit is contained in:
Bertrand SIMONNET 2015-07-28 15:42:42 -07:00
parent 4b915ae1b2
commit 5db66c3859
2 changed files with 1 additions and 36 deletions

View File

@ -14,8 +14,6 @@
#include <base/memory/scoped_ptr.h>
#include <gtest/gtest_prod.h> // 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::PolicyProvider> policy_provider_;
DISALLOW_COPY_AND_ASSIGN(MetricsLibrary);
};

View File

@ -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) {