| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/installer/util/google_update_settings.h" | |
| 6 | |
| 7 #include "base/file_util.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "base/path_service.h" | |
| 10 #include "base/rand_util.h" | |
| 11 #include "base/string_util.h" | |
| 12 #include "chrome/common/chrome_paths.h" | |
| 13 | |
| 14 namespace google_update { | |
| 15 std::string linux_guid; | |
| 16 } | |
| 17 | |
| 18 // File name used in the user data dir to indicate consent. | |
| 19 static const char kConsentToSendStats[] = "Consent To Send Stats"; | |
| 20 static const int kGuidLen = sizeof(uint64) * 4; // 128 bits -> 32 bytes hex. | |
| 21 | |
| 22 // static | |
| 23 bool GoogleUpdateSettings::GetCollectStatsConsent() { | |
| 24 FilePath consent_file; | |
| 25 PathService::Get(chrome::DIR_USER_DATA, &consent_file); | |
| 26 consent_file = consent_file.Append(kConsentToSendStats); | |
| 27 bool r = file_util::ReadFileToString(consent_file, | |
| 28 &google_update::linux_guid); | |
| 29 google_update::linux_guid.resize(kGuidLen, '0'); | |
| 30 return r; | |
| 31 } | |
| 32 | |
| 33 // static | |
| 34 bool GoogleUpdateSettings::SetCollectStatsConsent(bool consented) { | |
| 35 FilePath consent_dir; | |
| 36 PathService::Get(chrome::DIR_USER_DATA, &consent_dir); | |
| 37 if (!file_util::DirectoryExists(consent_dir)) | |
| 38 return false; | |
| 39 | |
| 40 FilePath consent_file = consent_dir.AppendASCII(kConsentToSendStats); | |
| 41 if (consented) { | |
| 42 uint64 random; | |
| 43 google_update::linux_guid.clear(); | |
| 44 for (int i = 0; i < 2; i++) { | |
| 45 random = base::RandUint64(); | |
| 46 google_update::linux_guid += HexEncode(&random, sizeof(uint64)); | |
| 47 } | |
| 48 const char* c_str = google_update::linux_guid.c_str(); | |
| 49 return file_util::WriteFile(consent_file, c_str, kGuidLen) == kGuidLen; | |
| 50 } | |
| 51 else { | |
| 52 google_update::linux_guid .clear(); | |
| 53 google_update::linux_guid.resize(kGuidLen, '0'); | |
| 54 return file_util::Delete(consent_file, false); | |
| 55 } | |
| 56 } | |
| 57 | |
| 58 // static | |
| 59 bool GoogleUpdateSettings::GetLanguage(std::wstring* language) { | |
| 60 NOTIMPLEMENTED(); | |
| 61 return false; | |
| 62 } | |
| OLD | NEW |