Loading metrics/include/metrics/metrics_library.h +0 −7 Original line number Original line Diff line number Diff line Loading @@ -14,8 +14,6 @@ #include <base/memory/scoped_ptr.h> #include <base/memory/scoped_ptr.h> #include <gtest/gtest_prod.h> // for FRIEND_TEST #include <gtest/gtest_prod.h> // for FRIEND_TEST #include "policy/libpolicy.h" class MetricsLibraryInterface { class MetricsLibraryInterface { public: public: virtual void Init() = 0; virtual void Init() = 0; Loading Loading @@ -130,9 +128,6 @@ class MetricsLibrary : public MetricsLibraryInterface { char* buffer, int buffer_size, char* buffer, int buffer_size, bool* result); 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. // Time at which we last checked if metrics were enabled. static time_t cached_enabled_time_; static time_t cached_enabled_time_; Loading @@ -142,8 +137,6 @@ class MetricsLibrary : public MetricsLibraryInterface { std::string uma_events_file_; std::string uma_events_file_; std::string consent_file_; std::string consent_file_; scoped_ptr<policy::PolicyProvider> policy_provider_; DISALLOW_COPY_AND_ASSIGN(MetricsLibrary); DISALLOW_COPY_AND_ASSIGN(MetricsLibrary); }; }; Loading metrics/metrics_library.cc +1 −29 Original line number Original line Diff line number Diff line Loading @@ -16,8 +16,6 @@ #include "serialization/metric_sample.h" #include "serialization/metric_sample.h" #include "serialization/serialization_utils.h" #include "serialization/serialization_utils.h" #include "policy/device_policy.h" static const char kAutotestPath[] = "/var/log/metrics/autotest-events"; static const char kAutotestPath[] = "/var/log/metrics/autotest-events"; static const char kUMAEventsPath[] = "/var/lib/metrics/uma-events"; static const char kUMAEventsPath[] = "/var/lib/metrics/uma-events"; static const char kConsentFile[] = "/home/chronos/Consent To Send Stats"; static const char kConsentFile[] = "/home/chronos/Consent To Send Stats"; Loading Loading @@ -123,29 +121,7 @@ bool MetricsLibrary::AreMetricsEnabled() { time_t this_check_time = time(nullptr); time_t this_check_time = time(nullptr); if (this_check_time != cached_enabled_time_) { if (this_check_time != cached_enabled_time_) { cached_enabled_time_ = this_check_time; cached_enabled_time_ = this_check_time; cached_enabled_ = stat(consent_file_.c_str(), &stat_buffer) >= 0; 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; } } return cached_enabled_; return cached_enabled_; } } Loading Loading @@ -200,10 +176,6 @@ bool MetricsLibrary::SendCrashToUMA(const char *crash_kind) { *metrics::MetricSample::CrashSample(crash_kind).get(), kUMAEventsPath); *metrics::MetricSample::CrashSample(crash_kind).get(), kUMAEventsPath); } } void MetricsLibrary::SetPolicyProvider(policy::PolicyProvider* provider) { policy_provider_.reset(provider); } bool MetricsLibrary::SendCrosEventToUMA(const std::string& event) { bool MetricsLibrary::SendCrosEventToUMA(const std::string& event) { for (size_t i = 0; i < arraysize(kCrosEventNames); i++) { for (size_t i = 0; i < arraysize(kCrosEventNames); i++) { if (strcmp(event.c_str(), kCrosEventNames[i]) == 0) { if (strcmp(event.c_str(), kCrosEventNames[i]) == 0) { Loading Loading
metrics/include/metrics/metrics_library.h +0 −7 Original line number Original line Diff line number Diff line Loading @@ -14,8 +14,6 @@ #include <base/memory/scoped_ptr.h> #include <base/memory/scoped_ptr.h> #include <gtest/gtest_prod.h> // for FRIEND_TEST #include <gtest/gtest_prod.h> // for FRIEND_TEST #include "policy/libpolicy.h" class MetricsLibraryInterface { class MetricsLibraryInterface { public: public: virtual void Init() = 0; virtual void Init() = 0; Loading Loading @@ -130,9 +128,6 @@ class MetricsLibrary : public MetricsLibraryInterface { char* buffer, int buffer_size, char* buffer, int buffer_size, bool* result); 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. // Time at which we last checked if metrics were enabled. static time_t cached_enabled_time_; static time_t cached_enabled_time_; Loading @@ -142,8 +137,6 @@ class MetricsLibrary : public MetricsLibraryInterface { std::string uma_events_file_; std::string uma_events_file_; std::string consent_file_; std::string consent_file_; scoped_ptr<policy::PolicyProvider> policy_provider_; DISALLOW_COPY_AND_ASSIGN(MetricsLibrary); DISALLOW_COPY_AND_ASSIGN(MetricsLibrary); }; }; Loading
metrics/metrics_library.cc +1 −29 Original line number Original line Diff line number Diff line Loading @@ -16,8 +16,6 @@ #include "serialization/metric_sample.h" #include "serialization/metric_sample.h" #include "serialization/serialization_utils.h" #include "serialization/serialization_utils.h" #include "policy/device_policy.h" static const char kAutotestPath[] = "/var/log/metrics/autotest-events"; static const char kAutotestPath[] = "/var/log/metrics/autotest-events"; static const char kUMAEventsPath[] = "/var/lib/metrics/uma-events"; static const char kUMAEventsPath[] = "/var/lib/metrics/uma-events"; static const char kConsentFile[] = "/home/chronos/Consent To Send Stats"; static const char kConsentFile[] = "/home/chronos/Consent To Send Stats"; Loading Loading @@ -123,29 +121,7 @@ bool MetricsLibrary::AreMetricsEnabled() { time_t this_check_time = time(nullptr); time_t this_check_time = time(nullptr); if (this_check_time != cached_enabled_time_) { if (this_check_time != cached_enabled_time_) { cached_enabled_time_ = this_check_time; cached_enabled_time_ = this_check_time; cached_enabled_ = stat(consent_file_.c_str(), &stat_buffer) >= 0; 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; } } return cached_enabled_; return cached_enabled_; } } Loading Loading @@ -200,10 +176,6 @@ bool MetricsLibrary::SendCrashToUMA(const char *crash_kind) { *metrics::MetricSample::CrashSample(crash_kind).get(), kUMAEventsPath); *metrics::MetricSample::CrashSample(crash_kind).get(), kUMAEventsPath); } } void MetricsLibrary::SetPolicyProvider(policy::PolicyProvider* provider) { policy_provider_.reset(provider); } bool MetricsLibrary::SendCrosEventToUMA(const std::string& event) { bool MetricsLibrary::SendCrosEventToUMA(const std::string& event) { for (size_t i = 0; i < arraysize(kCrosEventNames); i++) { for (size_t i = 0; i < arraysize(kCrosEventNames); i++) { if (strcmp(event.c_str(), kCrosEventNames[i]) == 0) { if (strcmp(event.c_str(), kCrosEventNames[i]) == 0) { Loading