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