This source file includes following definitions.
- GetCollectStatsConsent
- SetCollectStatsConsent
- GetMetricsId
- SetMetricsId
- GetLastRunTime
- SetLastRunTime
#include "chrome/installer/util/google_update_settings.h"
#include "base/file_util.h"
#include "base/lazy_instance.h"
#include "base/path_service.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/synchronization/lock.h"
#include "chrome/common/chrome_paths.h"
namespace {
base::LazyInstance<std::string>::Leaky g_posix_guid = LAZY_INSTANCE_INITIALIZER;
base::LazyInstance<base::Lock>::Leaky g_posix_guid_lock =
LAZY_INSTANCE_INITIALIZER;
const char kConsentToSendStats[] = "Consent To Send Stats";
}
bool GoogleUpdateSettings::GetCollectStatsConsent() {
base::FilePath consent_file;
PathService::Get(chrome::DIR_USER_DATA, &consent_file);
consent_file = consent_file.Append(kConsentToSendStats);
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);
}
return consented;
}
bool GoogleUpdateSettings::SetCollectStatsConsent(bool consented) {
base::FilePath consent_dir;
PathService::Get(chrome::DIR_USER_DATA, &consent_dir);
if (!base::DirectoryExists(consent_dir))
return false;
base::AutoLock lock(g_posix_guid_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();
return base::WriteFile(consent_file, c_str, size) == size;
}
} else {
g_posix_guid.Get().clear();
return base::DeleteFile(consent_file, false);
}
return true;
}
bool GoogleUpdateSettings::GetMetricsId(std::string* metrics_id) {
base::AutoLock lock(g_posix_guid_lock.Get());
*metrics_id = g_posix_guid.Get();
return true;
}
bool GoogleUpdateSettings::SetMetricsId(const std::string& client_id) {
base::FilePath consent_dir;
PathService::Get(chrome::DIR_USER_DATA, &consent_dir);
if (!base::DirectoryExists(consent_dir) ||
!GoogleUpdateSettings::GetCollectStatsConsent()) {
return false;
}
{
base::AutoLock lock(g_posix_guid_lock.Get());
g_posix_guid.Get() = client_id;
}
return GoogleUpdateSettings::SetCollectStatsConsent(true);
}
int GoogleUpdateSettings::GetLastRunTime() {
return -1;
}
bool GoogleUpdateSettings::SetLastRunTime() {
return false;
}