summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorgab@chromium.org <gab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-09 05:42:41 +0000
committergab@chromium.org <gab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-09 05:42:41 +0000
commit6580145cd456bbb934a5a8eaaa7e839626b3753a (patch)
tree10cd1739dc52ddd09ae98b8c1406478f50b8f6b8 /components
parentb00022a5d40a013cd618c31181fef9e5f7cc1aae (diff)
downloadchromium_src-6580145cd456bbb934a5a8eaaa7e839626b3753a.zip
chromium_src-6580145cd456bbb934a5a8eaaa7e839626b3753a.tar.gz
chromium_src-6580145cd456bbb934a5a8eaaa7e839626b3753a.tar.bz2
Move kInstallDate from chrome/common/pref_names.h to components/metrics/metrics_pref_names.h
This is a precursor CL to having MetricsStateManager be able to recover missing client_ids and restore old installation dates. BUG=391338 TBR=sky@chromium.org Review URL: https://codereview.chromium.org/370813003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@281960 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components')
-rw-r--r--components/metrics/metrics_log.cc5
-rw-r--r--components/metrics/metrics_log.h3
-rw-r--r--components/metrics/metrics_log_unittest.cc17
-rw-r--r--components/metrics/metrics_pref_names.cc4
-rw-r--r--components/metrics/metrics_pref_names.h1
-rw-r--r--components/metrics/metrics_service.cc12
-rw-r--r--components/metrics/metrics_service.h3
-rw-r--r--components/metrics/metrics_service_client.h3
-rw-r--r--components/metrics/metrics_service_unittest.cc3
-rw-r--r--components/metrics/test_metrics_service_client.cc7
-rw-r--r--components/metrics/test_metrics_service_client.h3
11 files changed, 35 insertions, 26 deletions
diff --git a/components/metrics/metrics_log.cc b/components/metrics/metrics_log.cc
index c5f63be..6076f88 100644
--- a/components/metrics/metrics_log.cc
+++ b/components/metrics/metrics_log.cc
@@ -330,7 +330,8 @@ void MetricsLog::WriteRealtimeStabilityAttributes(
void MetricsLog::RecordEnvironment(
const std::vector<metrics::MetricsProvider*>& metrics_providers,
- const std::vector<variations::ActiveGroupId>& synthetic_trials) {
+ const std::vector<variations::ActiveGroupId>& synthetic_trials,
+ int64 install_date) {
DCHECK(!HasEnvironment());
SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
@@ -347,8 +348,6 @@ void MetricsLog::RecordEnvironment(
// Reduce granularity of the enabled_date field to nearest hour.
system_profile->set_uma_enabled_date(RoundSecondsToHour(enabled_date));
- int64 install_date = client_->GetInstallDate();
-
// Reduce granularity of the install_date field to nearest hour.
system_profile->set_install_date(RoundSecondsToHour(install_date));
diff --git a/components/metrics/metrics_log.h b/components/metrics/metrics_log.h
index 8da3078..2d0519e 100644
--- a/components/metrics/metrics_log.h
+++ b/components/metrics/metrics_log.h
@@ -96,7 +96,8 @@ class MetricsLog {
// is determined by the pref value.
void RecordEnvironment(
const std::vector<metrics::MetricsProvider*>& metrics_providers,
- const std::vector<variations::ActiveGroupId>& synthetic_trials);
+ const std::vector<variations::ActiveGroupId>& synthetic_trials,
+ int64 install_date);
// Loads the environment proto that was saved by the last RecordEnvironment()
// call from prefs and clears the pref value. Returns true on success or false
diff --git a/components/metrics/metrics_log_unittest.cc b/components/metrics/metrics_log_unittest.cc
index 38102eb..5c309bd 100644
--- a/components/metrics/metrics_log_unittest.cc
+++ b/components/metrics/metrics_log_unittest.cc
@@ -241,7 +241,6 @@ TEST_F(MetricsLogTest, HistogramBucketFields) {
TEST_F(MetricsLogTest, RecordEnvironment) {
TestMetricsServiceClient client;
- client.set_install_date(kInstallDate);
TestMetricsLog log(
kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_);
@@ -251,7 +250,8 @@ TEST_F(MetricsLogTest, RecordEnvironment) {
synthetic_trials.push_back(kSyntheticTrials[1]);
log.RecordEnvironment(std::vector<MetricsProvider*>(),
- synthetic_trials);
+ synthetic_trials,
+ kInstallDate);
// Check that the system profile on the log has the correct values set.
CheckSystemProfile(log.system_profile());
@@ -273,7 +273,6 @@ TEST_F(MetricsLogTest, LoadSavedEnvironmentFromPrefs) {
prefs::kStabilitySavedSystemProfileHash;
TestMetricsServiceClient client;
- client.set_install_date(kInstallDate);
// The pref value is empty, so loading it from prefs should fail.
{
@@ -287,7 +286,8 @@ TEST_F(MetricsLogTest, LoadSavedEnvironmentFromPrefs) {
TestMetricsLog log(
kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_);
log.RecordEnvironment(std::vector<MetricsProvider*>(),
- std::vector<variations::ActiveGroupId>());
+ std::vector<variations::ActiveGroupId>(),
+ kInstallDate);
EXPECT_FALSE(prefs_.GetString(kSystemProfilePref).empty());
EXPECT_FALSE(prefs_.GetString(kSystemProfileHashPref).empty());
}
@@ -310,7 +310,8 @@ TEST_F(MetricsLogTest, LoadSavedEnvironmentFromPrefs) {
kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_);
// Call RecordEnvironment() to record the pref again.
log.RecordEnvironment(std::vector<MetricsProvider*>(),
- std::vector<variations::ActiveGroupId>());
+ std::vector<variations::ActiveGroupId>(),
+ kInstallDate);
}
{
@@ -334,7 +335,8 @@ TEST_F(MetricsLogTest, InitialLogStabilityMetrics) {
&prefs_);
std::vector<MetricsProvider*> metrics_providers;
log.RecordEnvironment(metrics_providers,
- std::vector<variations::ActiveGroupId>());
+ std::vector<variations::ActiveGroupId>(),
+ kInstallDate);
log.RecordStabilityMetrics(metrics_providers, base::TimeDelta(),
base::TimeDelta());
const SystemProfileProto_Stability& stability =
@@ -356,7 +358,8 @@ TEST_F(MetricsLogTest, OngoingLogStabilityMetrics) {
kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_);
std::vector<MetricsProvider*> metrics_providers;
log.RecordEnvironment(metrics_providers,
- std::vector<variations::ActiveGroupId>());
+ std::vector<variations::ActiveGroupId>(),
+ kInstallDate);
log.RecordStabilityMetrics(metrics_providers, base::TimeDelta(),
base::TimeDelta());
const SystemProfileProto_Stability& stability =
diff --git a/components/metrics/metrics_pref_names.cc b/components/metrics/metrics_pref_names.cc
index 8b96e1a..17b6c01 100644
--- a/components/metrics/metrics_pref_names.cc
+++ b/components/metrics/metrics_pref_names.cc
@@ -7,6 +7,10 @@
namespace metrics {
namespace prefs {
+// Set once, to the current epoch time, on the first run of chrome on this
+// machine. Attached to metrics reports forever thereafter.
+const char kInstallDate[] = "uninstall_metrics.installation_date2";
+
// The metrics client GUID.
// Note: The name client_id2 is a result of creating
// new prefs to do a one-time reset of the previous values.
diff --git a/components/metrics/metrics_pref_names.h b/components/metrics/metrics_pref_names.h
index 26352a8..659228a 100644
--- a/components/metrics/metrics_pref_names.h
+++ b/components/metrics/metrics_pref_names.h
@@ -10,6 +10,7 @@ namespace prefs {
// Alphabetical list of preference names specific to the metrics
// component. Document each in the .cc file.
+extern const char kInstallDate[];
extern const char kMetricsClientID[];
extern const char kMetricsInitialLogs[];
extern const char kMetricsInitialLogsOld[];
diff --git a/components/metrics/metrics_service.cc b/components/metrics/metrics_service.cc
index 66ee1ce..b9d8dbb 100644
--- a/components/metrics/metrics_service.cc
+++ b/components/metrics/metrics_service.cc
@@ -286,6 +286,8 @@ void MetricsService::RegisterPrefs(PrefRegistrySimple* registry) {
metrics::MetricsStateManager::RegisterPrefs(registry);
MetricsLog::RegisterPrefs(registry);
+ registry->RegisterInt64Pref(metrics::prefs::kInstallDate, 0);
+
registry->RegisterInt64Pref(metrics::prefs::kStabilityLaunchTimeSec, 0);
registry->RegisterInt64Pref(metrics::prefs::kStabilityLastTimestampSec, 0);
registry->RegisterStringPref(metrics::prefs::kStabilityStatsVersion,
@@ -383,6 +385,10 @@ std::string MetricsService::GetClientId() {
return state_manager_->client_id();
}
+int64 MetricsService::GetInstallDate() {
+ return local_state_->GetInt64(metrics::prefs::kInstallDate);
+}
+
scoped_ptr<const base::FieldTrial::EntropyProvider>
MetricsService::CreateEntropyProvider() {
// TODO(asvitkine): Refactor the code so that MetricsService does not expose
@@ -740,7 +746,8 @@ void MetricsService::CloseCurrentLog() {
DCHECK(current_log);
std::vector<variations::ActiveGroupId> synthetic_trials;
GetCurrentSyntheticFieldTrials(&synthetic_trials);
- current_log->RecordEnvironment(metrics_providers_.get(), synthetic_trials);
+ current_log->RecordEnvironment(
+ metrics_providers_.get(), synthetic_trials, GetInstallDate());
base::TimeDelta incremental_uptime;
base::TimeDelta uptime;
GetUptimes(local_state_, &incremental_uptime, &uptime);
@@ -953,7 +960,8 @@ void MetricsService::PrepareInitialMetricsLog() {
std::vector<variations::ActiveGroupId> synthetic_trials;
GetCurrentSyntheticFieldTrials(&synthetic_trials);
initial_metrics_log_->RecordEnvironment(metrics_providers_.get(),
- synthetic_trials);
+ synthetic_trials,
+ GetInstallDate());
base::TimeDelta incremental_uptime;
base::TimeDelta uptime;
GetUptimes(local_state_, &incremental_uptime, &uptime);
diff --git a/components/metrics/metrics_service.h b/components/metrics/metrics_service.h
index b586263..b0dcb82 100644
--- a/components/metrics/metrics_service.h
+++ b/components/metrics/metrics_service.h
@@ -134,6 +134,9 @@ class MetricsService : public base::HistogramFlattener {
// recording is not currently running.
std::string GetClientId();
+ // Returns the install date of the application, in seconds since the epoch.
+ int64 GetInstallDate();
+
// Returns the preferred entropy provider used to seed persistent activities
// based on whether or not metrics reporting will be permitted on this client.
//
diff --git a/components/metrics/metrics_service_client.h b/components/metrics/metrics_service_client.h
index 1ef3188..1fcfb6e 100644
--- a/components/metrics/metrics_service_client.h
+++ b/components/metrics/metrics_service_client.h
@@ -42,9 +42,6 @@ class MetricsServiceClient {
// Returns the version of the application as a string.
virtual std::string GetVersionString() = 0;
- // Returns the install date of the application, in seconds since the epoch.
- virtual int64 GetInstallDate() = 0;
-
// Called by the metrics service when a log has been uploaded.
virtual void OnLogUploadComplete() = 0;
diff --git a/components/metrics/metrics_service_unittest.cc b/components/metrics/metrics_service_unittest.cc
index 947fb4e..694c45a 100644
--- a/components/metrics/metrics_service_unittest.cc
+++ b/components/metrics/metrics_service_unittest.cc
@@ -161,7 +161,8 @@ TEST_F(MetricsServiceTest, InitialStabilityLogAfterCrash) {
metrics::TestMetricsServiceClient client;
TestMetricsLog log("client", 1, &client, GetLocalState());
log.RecordEnvironment(std::vector<metrics::MetricsProvider*>(),
- std::vector<variations::ActiveGroupId>());
+ std::vector<variations::ActiveGroupId>(),
+ 0);
// Record stability build time and version from previous session, so that
// stability metrics (including exited cleanly flag) won't be cleared.
diff --git a/components/metrics/test_metrics_service_client.cc b/components/metrics/test_metrics_service_client.cc
index cab333b..4e1a3c3 100644
--- a/components/metrics/test_metrics_service_client.cc
+++ b/components/metrics/test_metrics_service_client.cc
@@ -13,8 +13,7 @@ namespace metrics {
const char TestMetricsServiceClient::kBrandForTesting[] = "brand_for_testing";
TestMetricsServiceClient::TestMetricsServiceClient()
- : install_date_(0),
- version_string_("5.0.322.0-64-devel") {
+ : version_string_("5.0.322.0-64-devel") {
}
TestMetricsServiceClient::~TestMetricsServiceClient() {
@@ -45,10 +44,6 @@ std::string TestMetricsServiceClient::GetVersionString() {
return version_string_;
}
-int64 TestMetricsServiceClient::GetInstallDate() {
- return install_date_;
-}
-
void TestMetricsServiceClient::OnLogUploadComplete() {
}
diff --git a/components/metrics/test_metrics_service_client.h b/components/metrics/test_metrics_service_client.h
index e0aa35b..0b7bdef 100644
--- a/components/metrics/test_metrics_service_client.h
+++ b/components/metrics/test_metrics_service_client.h
@@ -27,7 +27,6 @@ class TestMetricsServiceClient : public MetricsServiceClient {
virtual bool GetBrand(std::string* brand_code) OVERRIDE;
virtual SystemProfileProto::Channel GetChannel() OVERRIDE;
virtual std::string GetVersionString() OVERRIDE;
- virtual int64 GetInstallDate() OVERRIDE;
virtual void OnLogUploadComplete() OVERRIDE;
virtual void StartGatheringMetrics(
const base::Closure& done_callback) OVERRIDE;
@@ -39,12 +38,10 @@ class TestMetricsServiceClient : public MetricsServiceClient {
const base::Callback<void(int)>& on_upload_complete) OVERRIDE;
const std::string& get_client_id() const { return client_id_; }
- void set_install_date(int64 install_date) { install_date_ = install_date; }
void set_version_string(const std::string& str) { version_string_ = str; }
private:
std::string client_id_;
- int64 install_date_;
std::string version_string_;
DISALLOW_COPY_AND_ASSIGN(TestMetricsServiceClient);