Respect the metrics file if no policy value is set (for legacy migration).
BUG=chromium-os:18430
TEST=Update chromeos and check whether the consent for stats is preserved.
Change-Id: I86d4710ef9f381abd9f1eac728040878e6fc5b71
Reviewed-on: http://gerrit.chromium.org/gerrit/5139
Reviewed-by: Ken Mixter <kmixter@chromium.org>
Tested-by: Julian Pastarmov <pastarmovj@chromium.org>
diff --git a/metrics/metrics_library.cc b/metrics/metrics_library.cc
index ae6c8e0..707ea68 100644
--- a/metrics/metrics_library.cc
+++ b/metrics/metrics_library.cc
@@ -132,20 +132,30 @@
}
bool MetricsLibrary::AreMetricsEnabled() {
+ static struct stat stat_buffer;
time_t this_check_time = time(NULL);
- if (!policy_provider_.get())
- policy_provider_.reset(new policy::PolicyProvider());
- else
- 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;
- if (policy_provider_->device_policy_is_loaded())
- policy_provider_->GetDevicePolicy().GetMetricsEnabled(&enabled);
-
if (this_check_time != cached_enabled_time_) {
cached_enabled_time_ = this_check_time;
+
+ if (!policy_provider_.get())
+ policy_provider_.reset(new policy::PolicyProvider());
+ else
+ 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_, &stat_buffer) >= 0;
+ }
+
if (enabled && !IsGuestMode())
cached_enabled_ = true;
else