Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(588)

Unified Diff: chrome/browser/google/google_update_settings_posix.cc

Issue 365133005: Refactor SetClientID such that metrics rather than crash backs up the client id in Google Update set (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits:grt Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/google/google_update_settings_posix.cc
diff --git a/chrome/browser/google/google_update_settings_posix.cc b/chrome/browser/google/google_update_settings_posix.cc
index 67e63cc8d18d24af216b7399f02a0781a67f133c..99dc0cc8e2f54c78bf4b3268447d91367f9282ea 100644
--- a/chrome/browser/google/google_update_settings_posix.cc
+++ b/chrome/browser/google/google_update_settings_posix.cc
@@ -14,8 +14,9 @@
namespace {
-base::LazyInstance<std::string>::Leaky g_posix_guid = LAZY_INSTANCE_INITIALIZER;
-base::LazyInstance<base::Lock>::Leaky g_posix_guid_lock =
+base::LazyInstance<std::string>::Leaky g_posix_client_id =
+ LAZY_INSTANCE_INITIALIZER;
+base::LazyInstance<base::Lock>::Leaky g_posix_client_id_lock =
LAZY_INSTANCE_INITIALIZER;
// File name used in the user data dir to indicate consent.
@@ -28,11 +29,15 @@ bool GoogleUpdateSettings::GetCollectStatsConsent() {
base::FilePath consent_file;
PathService::Get(chrome::DIR_USER_DATA, &consent_file);
consent_file = consent_file.Append(kConsentToSendStats);
+
+ if (!base::DirectoryExists(consent_file.DirName()))
+ return false;
+
std::string tmp_guid;
bool consented = base::ReadFileToString(consent_file, &tmp_guid);
if (consented) {
- base::AutoLock lock(g_posix_guid_lock.Get());
- g_posix_guid.Get().assign(tmp_guid);
+ base::AutoLock lock(g_posix_client_id_lock.Get());
+ g_posix_client_id.Get().assign(tmp_guid);
}
return consented;
}
@@ -44,44 +49,40 @@ bool GoogleUpdateSettings::SetCollectStatsConsent(bool consented) {
if (!base::DirectoryExists(consent_dir))
return false;
- base::AutoLock lock(g_posix_guid_lock.Get());
+ base::AutoLock lock(g_posix_client_id_lock.Get());
base::FilePath consent_file = consent_dir.AppendASCII(kConsentToSendStats);
if (consented) {
if ((!base::PathExists(consent_file)) ||
- (base::PathExists(consent_file) && !g_posix_guid.Get().empty())) {
- const char* c_str = g_posix_guid.Get().c_str();
- int size = g_posix_guid.Get().size();
+ (base::PathExists(consent_file) && !g_posix_client_id.Get().empty())) {
+ const char* c_str = g_posix_client_id.Get().c_str();
+ int size = g_posix_client_id.Get().size();
return base::WriteFile(consent_file, c_str, size) == size;
}
} else {
- g_posix_guid.Get().clear();
+ g_posix_client_id.Get().clear();
return base::DeleteFile(consent_file, false);
}
return true;
}
// static
-bool GoogleUpdateSettings::GetMetricsId(std::string* metrics_id) {
- base::AutoLock lock(g_posix_guid_lock.Get());
- *metrics_id = g_posix_guid.Get();
+bool GoogleUpdateSettings::LoadMetricsClientId(std::string* metrics_id) {
+ base::AutoLock lock(g_posix_client_id_lock.Get());
+ *metrics_id = g_posix_client_id.Get();
return true;
}
// static
-bool GoogleUpdateSettings::SetMetricsId(const std::string& client_id) {
+bool GoogleUpdateSettings::StoreMetricsClientId(const std::string& client_id) {
// Make sure that user has consented to send crashes.
- base::FilePath consent_dir;
- PathService::Get(chrome::DIR_USER_DATA, &consent_dir);
- if (!base::DirectoryExists(consent_dir) ||
- !GoogleUpdateSettings::GetCollectStatsConsent()) {
+ if (!GoogleUpdateSettings::GetCollectStatsConsent())
return false;
- }
{
// Since user has consented, write the metrics id to the file.
- base::AutoLock lock(g_posix_guid_lock.Get());
- g_posix_guid.Get() = client_id;
+ base::AutoLock lock(g_posix_client_id_lock.Get());
+ g_posix_client_id.Get() = client_id;
}
return GoogleUpdateSettings::SetCollectStatsConsent(true);
}
« no previous file with comments | « chrome/browser/chrome_content_browser_client.cc ('k') | chrome/browser/metrics/chrome_metrics_service_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698