Merge "metricsd: Fix race condition in the tests."
diff --git a/metricsd/include/metrics/metrics_library.h b/metricsd/include/metrics/metrics_library.h
index 26df2f4..5556e57 100644
--- a/metricsd/include/metrics/metrics_library.h
+++ b/metricsd/include/metrics/metrics_library.h
@@ -142,10 +142,10 @@
bool* result);
// Time at which we last checked if metrics were enabled.
- static time_t cached_enabled_time_;
+ time_t cached_enabled_time_;
// Cached state of whether or not metrics were enabled.
- static bool cached_enabled_;
+ bool cached_enabled_;
base::FilePath uma_events_file_;
base::FilePath consent_file_;
diff --git a/metricsd/metrics_library.cc b/metricsd/metrics_library.cc
index 6449a24..3109704 100644
--- a/metricsd/metrics_library.cc
+++ b/metricsd/metrics_library.cc
@@ -53,9 +53,6 @@
"TPM.EarlyResetDuringCommand", // 12
};
-time_t MetricsLibrary::cached_enabled_time_ = 0;
-bool MetricsLibrary::cached_enabled_ = false;
-
MetricsLibrary::MetricsLibrary() {}
MetricsLibrary::~MetricsLibrary() {}
@@ -140,11 +137,15 @@
base::FilePath dir = base::FilePath(metrics::kMetricsDirectory);
uma_events_file_ = dir.Append(metrics::kMetricsEventsFileName);
consent_file_ = dir.Append(metrics::kConsentFileName);
+ cached_enabled_ = false;
+ cached_enabled_time_ = 0;
}
void MetricsLibrary::InitForTest(const base::FilePath& metrics_directory) {
uma_events_file_ = metrics_directory.Append(metrics::kMetricsEventsFileName);
consent_file_ = metrics_directory.Append(metrics::kConsentFileName);
+ cached_enabled_ = false;
+ cached_enabled_time_ = 0;
}
bool MetricsLibrary::SendToUMA(const std::string& name,
diff --git a/metricsd/uploader/upload_service_test.cc b/metricsd/uploader/upload_service_test.cc
index 0dd7db6..305fd0c 100644
--- a/metricsd/uploader/upload_service_test.cc
+++ b/metricsd/uploader/upload_service_test.cc
@@ -42,6 +42,8 @@
chromeos_metrics::PersistentInteger::SetMetricsDirectory(
dir_.path().value());
metrics_lib_.InitForTest(dir_.path());
+ ASSERT_EQ(0, base::WriteFile(
+ dir_.path().Append(metrics::kConsentFileName), "", 0));
upload_service_.reset(new UploadService(new MockSystemProfileSetter(),
&metrics_lib_, "", true));