Chromium Code Reviews| Index: chrome/browser/metrics/metrics_services_manager.cc |
| diff --git a/chrome/browser/metrics/metrics_services_manager.cc b/chrome/browser/metrics/metrics_services_manager.cc |
| index 8278913da7da438199e2c1b3f363649bc54148d3..360a4d88b9b2d47ce3610635b1223405184e7ca4 100644 |
| --- a/chrome/browser/metrics/metrics_services_manager.cc |
| +++ b/chrome/browser/metrics/metrics_services_manager.cc |
| @@ -4,12 +4,17 @@ |
| #include "chrome/browser/metrics/metrics_services_manager.h" |
| +#include <string> |
| + |
| #include "base/command_line.h" |
| +#include "base/guid.h" |
| +#include "base/logging.h" |
| #include "base/prefs/pref_service.h" |
| #include "chrome/browser/metrics/chrome_metrics_service_client.h" |
| #include "chrome/browser/metrics/variations/variations_service.h" |
| #include "chrome/common/chrome_switches.h" |
| #include "chrome/common/pref_names.h" |
| +#include "chrome/installer/util/google_update_settings.h" |
| #include "components/metrics/metrics_service.h" |
| #include "components/metrics/metrics_state_manager.h" |
| #include "components/rappor/rappor_service.h" |
| @@ -18,6 +23,47 @@ |
| #include "chrome/browser/chromeos/settings/cros_settings.h" |
| #endif |
| +namespace { |
| + |
| +// Attempts to retrieve |client_id| and |installation_date| backed up in |
| +// GoogleUpdateSettings. Returns true on success retrieving at least the |
| +// |client_id|. |
| +bool RetrieveClientInfo(std::string* client_id, int64* installation_date) { |
| + DCHECK(client_id); |
| + DCHECK(installation_date); |
| + bool result = |
| + GoogleUpdateSettings::RetrieveMetricsInfo(client_id, installation_date); |
| + |
| + // Prior to 2014-07, the client ID was stripped of its dashes before being |
| + // saved, migrate back to a proper GUID if this is the case. This migration |
|
Ilya Sherman
2014/07/08 01:10:21
nit: "saved, migrate" -> "saved. Migrate"
gab
2014/07/09 19:16:59
Done.
|
| + // code below can be removed in M41+. |
| + const size_t kGUIDLengthWithoutDashes = 32U; |
| + if (result && client_id->length() == kGUIDLengthWithoutDashes) { |
| + DCHECK(client_id->find('-') == std::string::npos); |
| + |
| + std::string client_id_with_dashes; |
| + client_id_with_dashes.reserve(kGUIDLengthWithoutDashes + 4U); |
| + std::string::const_iterator client_id_it = client_id->begin(); |
| + for (size_t i = 0; i < kGUIDLengthWithoutDashes + 4U; ++i) { |
| + if (i == 8U || i == 13U || i == 18U || i == 23U) { |
| + client_id_with_dashes.push_back('-'); |
| + } else { |
| + client_id_with_dashes.push_back(*(client_id_it++)); |
|
Ilya Sherman
2014/07/08 01:10:21
nit: I'd prefer that you separate out reading from
gab
2014/07/09 19:16:59
Done.
|
| + } |
| + } |
| + DCHECK(client_id_it == client_id->end()); |
| + client_id->assign(client_id_with_dashes); |
| + } |
| + |
| + // The GUID retrieved (and possibly fixed above) should be valid unless |
| + // retrieval failed. |
| + DCHECK(base::IsValidGUID(*client_id) || !result); |
| + |
| + return result; |
| +} |
| + |
| +} // namespace |
| + |
| MetricsServicesManager::MetricsServicesManager(PrefService* local_state) |
| : local_state_(local_state) { |
| DCHECK(local_state); |
| @@ -70,7 +116,9 @@ metrics::MetricsStateManager* MetricsServicesManager::GetMetricsStateManager() { |
| metrics_state_manager_ = metrics::MetricsStateManager::Create( |
| local_state_, |
| base::Bind(&MetricsServicesManager::IsMetricsReportingEnabled, |
| - base::Unretained(this))); |
| + base::Unretained(this)), |
| + base::Bind(&GoogleUpdateSettings::SaveMetricsInfo), |
| + base::Bind(&RetrieveClientInfo)); |
| } |
| return metrics_state_manager_.get(); |
| } |