summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--chrome/browser/chrome_browser_field_trials.cc4
-rw-r--r--chrome/browser/chrome_browser_main.cc9
-rw-r--r--chrome/browser/metrics/chrome_metrics_service_client.cc5
-rw-r--r--chrome/browser/metrics/chrome_metrics_service_client.h1
-rw-r--r--chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc3
-rw-r--r--chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc4
-rw-r--r--chrome/common/pref_names.cc4
-rw-r--r--chrome/common/pref_names.h1
-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
19 files changed, 48 insertions, 44 deletions
diff --git a/chrome/browser/chrome_browser_field_trials.cc b/chrome/browser/chrome_browser_field_trials.cc
index 08e7a1c..655cf45 100644
--- a/chrome/browser/chrome_browser_field_trials.cc
+++ b/chrome/browser/chrome_browser_field_trials.cc
@@ -14,8 +14,8 @@
#include "chrome/browser/omnibox/omnibox_field_trial.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/chrome_version_info.h"
-#include "chrome/common/pref_names.h"
#include "chrome/common/variations/uniformity_field_trials.h"
+#include "components/metrics/metrics_pref_names.h"
#if defined(OS_ANDROID) || defined(OS_IOS)
#include "chrome/browser/chrome_browser_field_trials_mobile.h"
@@ -33,7 +33,7 @@ ChromeBrowserFieldTrials::~ChromeBrowserFieldTrials() {
void ChromeBrowserFieldTrials::SetupFieldTrials(PrefService* local_state) {
const base::Time install_time = base::Time::FromTimeT(
- local_state->GetInt64(prefs::kInstallDate));
+ local_state->GetInt64(metrics::prefs::kInstallDate));
DCHECK(!install_time.is_null());
// Field trials that are shared by all platforms.
diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc
index f8f8b99..7fa0378 100644
--- a/chrome/browser/chrome_browser_main.cc
+++ b/chrome/browser/chrome_browser_main.cc
@@ -105,6 +105,7 @@
#include "chrome/installer/util/google_update_settings.h"
#include "components/google/core/browser/google_util.h"
#include "components/language_usage_metrics/language_usage_metrics.h"
+#include "components/metrics/metrics_pref_names.h"
#include "components/metrics/metrics_service.h"
#include "components/nacl/browser/nacl_browser.h"
#include "components/nacl/browser/nacl_process_host.h"
@@ -939,9 +940,11 @@ int ChromeBrowserMainParts::PreCreateThreadsImpl() {
// Now that all preferences have been registered, set the install date
// for the uninstall metrics if this is our first run. This only actually
// gets used if the user has metrics reporting enabled at uninstall time.
- int64 install_date = local_state_->GetInt64(prefs::kInstallDate);
- if (install_date == 0)
- local_state_->SetInt64(prefs::kInstallDate, base::Time::Now().ToTimeT());
+ int64 install_date = local_state_->GetInt64(metrics::prefs::kInstallDate);
+ if (install_date == 0) {
+ local_state_->SetInt64(metrics::prefs::kInstallDate,
+ base::Time::Now().ToTimeT());
+ }
#if defined(OS_MACOSX)
// Get the Keychain API to register for distributed notifications on the main
diff --git a/chrome/browser/metrics/chrome_metrics_service_client.cc b/chrome/browser/metrics/chrome_metrics_service_client.cc
index 1a7af6bf..6a2c51b 100644
--- a/chrome/browser/metrics/chrome_metrics_service_client.cc
+++ b/chrome/browser/metrics/chrome_metrics_service_client.cc
@@ -146,7 +146,6 @@ scoped_ptr<ChromeMetricsServiceClient> ChromeMetricsServiceClient::Create(
// static
void ChromeMetricsServiceClient::RegisterPrefs(PrefRegistrySimple* registry) {
- registry->RegisterInt64Pref(prefs::kInstallDate, 0);
registry->RegisterInt64Pref(prefs::kUninstallLastLaunchTimeSec, 0);
registry->RegisterInt64Pref(prefs::kUninstallLastObservedRunTimeSec, 0);
@@ -198,10 +197,6 @@ std::string ChromeMetricsServiceClient::GetVersionString() {
return version;
}
-int64 ChromeMetricsServiceClient::GetInstallDate() {
- return g_browser_process->local_state()->GetInt64(prefs::kInstallDate);
-}
-
void ChromeMetricsServiceClient::OnLogUploadComplete() {
// Collect network stats after each UMA upload.
network_stats_uploader_.CollectAndReportNetworkStats();
diff --git a/chrome/browser/metrics/chrome_metrics_service_client.h b/chrome/browser/metrics/chrome_metrics_service_client.h
index c6d1166..03f9c83 100644
--- a/chrome/browser/metrics/chrome_metrics_service_client.h
+++ b/chrome/browser/metrics/chrome_metrics_service_client.h
@@ -58,7 +58,6 @@ class ChromeMetricsServiceClient
virtual bool GetBrand(std::string* brand_code) OVERRIDE;
virtual metrics::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;
diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
index 09831b1..5bb45d1 100644
--- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
+++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
@@ -64,6 +64,7 @@
#include "components/autofill/core/browser/validation.h"
#include "components/autofill/core/common/autofill_pref_names.h"
#include "components/autofill/core/common/form_data.h"
+#include "components/metrics/metrics_service.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/geolocation_provider.h"
@@ -2892,7 +2893,7 @@ void AutofillDialogControllerImpl::LoadRiskFingerprintData() {
std::string accept_languages =
user_prefs->GetString(::prefs::kAcceptLanguages);
base::Time install_time = base::Time::FromTimeT(
- g_browser_process->local_state()->GetInt64(::prefs::kInstallDate));
+ g_browser_process->metrics_service()->GetInstallDate());
risk::GetFingerprint(
obfuscated_gaia_id, window_bounds, web_contents(),
diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc
index 08fd025..4dca846 100644
--- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc
+++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc
@@ -50,6 +50,7 @@
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "components/bookmarks/browser/bookmark_model.h"
+#include "components/metrics/metrics_service.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/page_navigator.h"
@@ -1002,8 +1003,7 @@ void BookmarkBarView::BookmarkMenuControllerDeleted(
}
void BookmarkBarView::ShowImportDialog() {
- int64 install_time =
- g_browser_process->local_state()->GetInt64(prefs::kInstallDate);
+ int64 install_time = g_browser_process->metrics_service()->GetInstallDate();
int64 time_from_install = base::Time::Now().ToTimeT() - install_time;
if (bookmark_bar_state_ == BookmarkBar::SHOW) {
UMA_HISTOGRAM_COUNTS("Import.ShowDialog.FromBookmarkBarView",
diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc
index 18d3c94..c9248cd 100644
--- a/chrome/common/pref_names.cc
+++ b/chrome/common/pref_names.cc
@@ -1369,9 +1369,7 @@ const char kStabilityPluginLoadingErrors[] = "loading_errors";
// The keys below are strictly increasing counters over the lifetime of
// a chrome installation. They are (optionally) sent up to the uninstall
-// survey in the event of uninstallation. The installation date is used by some
-// opt-in services such as Wallet and UMA.
-const char kInstallDate[] = "uninstall_metrics.installation_date2";
+// survey in the event of uninstallation.
const char kUninstallMetricsPageLoadCount[] =
"uninstall_metrics.page_load_count";
const char kUninstallLastLaunchTimeSec[] =
diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h
index 0c18251..acaa19a 100644
--- a/chrome/common/pref_names.h
+++ b/chrome/common/pref_names.h
@@ -454,7 +454,6 @@ extern const char kStabilityPluginInstances[];
extern const char kStabilityPluginCrashes[];
extern const char kStabilityPluginLoadingErrors[];
-extern const char kInstallDate[];
extern const char kUninstallMetricsPageLoadCount[];
extern const char kUninstallLastLaunchTimeSec[];
extern const char kUninstallLastObservedRunTimeSec[];
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);