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

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

Issue 377713002: POSIX impl of https://codereview.chromium.org/372473004/ Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: mergeish/upload to switch platforms 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 e6dad5efe6a502859af30257cdb3095b5b3946ce..65a369f1883be66fe8418b93fd1454482fd8ce57 100644
--- a/chrome/browser/google/google_update_settings_posix.cc
+++ b/chrome/browser/google/google_update_settings_posix.cc
@@ -7,6 +7,8 @@
#include "base/file_util.h"
#include "base/lazy_instance.h"
#include "base/path_service.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/synchronization/lock.h"
@@ -14,18 +16,44 @@
namespace {
-base::LazyInstance<std::string>::Leaky g_posix_client_id =
+struct ClientInfo {
+ enum ConsentState {
+ CONSENT_ACCEPTED,
+ CONSENT_DENIED,
+ CONSENT_UNKNOWN
+ }
+
+ ClientInfo() : consent_state(CONSENT_UNKNOWN) {}
+
+ ConsentState consent_state;
+ std::string client_id;
+ int64 installation_date;
+};
+
+// Contains the ClientInfo for this user. If consent wasn't checked yet,
+// |consent_state| is set to CONSENT_UNKNOWN. Once consent is verified it is set
+// to CONSENT_ACCEPTED or CONSENT_DENIED accordingly. If CONSENT_ACCEPTED,
+// |client_id| and |installation_date| will also be set as retrieved from the
+// consent file.
+base::LazyInstance<ClientInfo>::Leaky g_posix_client_info =
LAZY_INSTANCE_INITIALIZER;
-base::LazyInstance<base::Lock>::Leaky g_posix_client_id_lock =
+base::LazyInstance<base::Lock>::Leaky g_posix_client_info_lock =
LAZY_INSTANCE_INITIALIZER;
// File name used in the user data dir to indicate consent.
const char kConsentToSendStats[] = "Consent To Send Stats";
+const char kConsentInfoPartsDelimiter = '/';
+
} // namespace
// static
bool GoogleUpdateSettings::GetCollectStatsConsent() {
+ base::AutoLock lock(g_posix_client_info_lock.Get());
+ ClientInfo* client_info = g_posix_client_info.Pointer();
+ if (client_info->consent_state != ClientInfo::CONSENT_UNKNOWN)
+ return client_info->consent_state;
+
base::FilePath consent_file;
PathService::Get(chrome::DIR_USER_DATA, &consent_file);
consent_file = consent_file.Append(kConsentToSendStats);
@@ -33,11 +61,18 @@ bool GoogleUpdateSettings::GetCollectStatsConsent() {
if (!base::DirectoryExists(consent_file.DirName()))
return false;
- std::string tmp_guid;
- bool consented = base::ReadFileToString(consent_file, &tmp_guid);
+ std::string client_info_str;
+ bool consented = base::ReadFileToString(consent_file, &client_info_str);
if (consented) {
- base::AutoLock lock(g_posix_client_id_lock.Get());
- g_posix_client_id.Get().assign(tmp_guid);
+ client_info->consent_state = CONSENT_ACCEPTED;
+
+ std::vector<std::string> client_info_parts;
+ base::SplitString(
+ client_info_str, kConsentInfoPartsDelimiter, &client_info_parts);
+ client_info->client_id.assign(client_info_parts[0]);
+ client_info->installation_date = base::StringToInt64(client_info_parts[1]);
+ } else {
+ client_info->consent_state = CONSENT_DENIED;
}
return consented;
}
@@ -49,18 +84,31 @@ bool GoogleUpdateSettings::SetCollectStatsConsent(bool consented) {
if (!base::DirectoryExists(consent_dir))
return false;
- base::AutoLock lock(g_posix_client_id_lock.Get());
+ base::AutoLock lock(g_posix_client_info_lock.Get());
+ ClientInfo* client_info = g_posix_client_info.Pointer();
base::FilePath consent_file = consent_dir.AppendASCII(kConsentToSendStats);
if (consented) {
- if ((!base::PathExists(consent_file)) ||
- (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;
+ client_info->consent_state = CONSENT_ACCEPTED;
+ // Write consent to disk if it wasn't previously accepted or if the client
+ // ID was just set.
+ if (!base::PathExists(consent_file) || !client_info->client_id.empty()) {
+ std::vector<std::string> client_info_parts;
+ client_info_parts.push_back(client_info->cliend_id);
+ client_info_parts.push_back(
+ base::Int64ToString(client_info->installation_date));
+
+ const std::string client_info_str =
+ base::JoinString(client_info_parts, kConsentInfoPartsDelimiter);
+ return base::WriteFile(
+ consent_file,
+ client_info_str.c_str(),
+ client_info_str.length()) == client_info_str.length();
}
} else {
- g_posix_client_id.Get().clear();
+ client_info->consent_state = CONSENT_DENIED;
+ client_info->client_id.clear();
+ client_info->installation_date = 0L;
return base::DeleteFile(consent_file, false);
}
return true;
@@ -77,6 +125,28 @@ scoped_ptr<metrics::ClientInfo> GoogleUpdateSettings::LoadMetricsClientInfo() {
client_info->client_id = g_posix_client_id.Get();
return client_info.Pass();
+
+
+ /*
+ base::AutoLock lock(g_posix_client_info_lock.Get());
+
+ // Read the ClientInfo if it hasn't been read into the global instance yet.
+ if (g_posix_client_info.Get().client_id.empty()) {
+ base::AutoUnlock unlock(g_posix_client_info_lock.Get());
+ if (!GetCollectStatsConsent())
+ return false;
+ }
+ const ClientInfo* client_info = g_posix_client_info.Pointer();
+
+ DCHECK(!client_info->client_id.empty());
+ DCHECK_EQ(client_info, CONSENT_ACCEPTED);
+
+ if (metrics_id)
+ *metrics_id = client_info->client_id;
+ if (installation_date)
+ *installation_date = client_info->installation_date;
+ return true;
+ */
}
// static
@@ -91,6 +161,15 @@ void GoogleUpdateSettings::StoreMetricsClientInfo(
// Since user has consented, write the metrics id to the file.
base::AutoLock lock(g_posix_client_id_lock.Get());
g_posix_client_id.Get() = client_info.client_id;
+
+
+/*
+ // Since user has consented, write the metrics info to the consent file.
+ base::AutoLock lock(g_posix_client_info_lock.Get());
+ ClientInfo* client_info = g_posix_client_info.Pointer();
+ client_info->client_id = client_id;
+ client_info->installation_date = installation_date;
+*/
}
GoogleUpdateSettings::SetCollectStatsConsent(true);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698