Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d16e9c25 authored by Bertrand Simonnet's avatar Bertrand Simonnet Committed by Gerrit Code Review
Browse files

Merge "metrics: Don't use the policy file."

parents 932d61d9 5db66c38
Loading
Loading
Loading
Loading
+0 −7
Original line number Diff line number Diff line
@@ -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);
};

+1 −29
Original line number Diff line number Diff line
@@ -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) {