OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "chrome/common/chrome_paths.h" | 10 #include "chrome/common/chrome_paths.h" |
11 | 11 |
12 namespace google_update { | 12 namespace google_update { |
13 std::string posix_guid; | 13 |
14 static std::string& posix_guid() { | |
joth
2011/11/18 01:16:37
nit: non-const reference not allowed in style guid
| |
15 CR_DEFINE_STATIC_LOCAL(std::string, guid, ()); | |
16 return guid; | |
14 } | 17 } |
15 | 18 |
19 } // namespace google_update | |
20 | |
16 // File name used in the user data dir to indicate consent. | 21 // File name used in the user data dir to indicate consent. |
17 static const char kConsentToSendStats[] = "Consent To Send Stats"; | 22 static const char kConsentToSendStats[] = "Consent To Send Stats"; |
18 | 23 |
19 // static | 24 // static |
20 bool GoogleUpdateSettings::GetCollectStatsConsent() { | 25 bool GoogleUpdateSettings::GetCollectStatsConsent() { |
21 FilePath consent_file; | 26 FilePath consent_file; |
22 PathService::Get(chrome::DIR_USER_DATA, &consent_file); | 27 PathService::Get(chrome::DIR_USER_DATA, &consent_file); |
23 consent_file = consent_file.Append(kConsentToSendStats); | 28 consent_file = consent_file.Append(kConsentToSendStats); |
24 std::string tmp_guid; | 29 std::string tmp_guid; |
25 bool consented = file_util::ReadFileToString(consent_file, &tmp_guid); | 30 bool consented = file_util::ReadFileToString(consent_file, &tmp_guid); |
26 if (consented) | 31 if (consented) |
27 google_update::posix_guid.assign(tmp_guid); | 32 google_update::posix_guid().assign(tmp_guid); |
28 return consented; | 33 return consented; |
29 } | 34 } |
30 | 35 |
31 // static | 36 // static |
32 bool GoogleUpdateSettings::SetCollectStatsConsent(bool consented) { | 37 bool GoogleUpdateSettings::SetCollectStatsConsent(bool consented) { |
33 FilePath consent_dir; | 38 FilePath consent_dir; |
34 PathService::Get(chrome::DIR_USER_DATA, &consent_dir); | 39 PathService::Get(chrome::DIR_USER_DATA, &consent_dir); |
35 if (!file_util::DirectoryExists(consent_dir)) | 40 if (!file_util::DirectoryExists(consent_dir)) |
36 return false; | 41 return false; |
37 | 42 |
38 FilePath consent_file = consent_dir.AppendASCII(kConsentToSendStats); | 43 FilePath consent_file = consent_dir.AppendASCII(kConsentToSendStats); |
39 if (consented) { | 44 if (consented) { |
40 if ((!file_util::PathExists(consent_file)) || | 45 if ((!file_util::PathExists(consent_file)) || |
41 (file_util::PathExists(consent_file) && | 46 (file_util::PathExists(consent_file) && |
42 !google_update::posix_guid.empty())) { | 47 !google_update::posix_guid().empty())) { |
43 const char* c_str = google_update::posix_guid.c_str(); | 48 const char* c_str = google_update::posix_guid().c_str(); |
44 int size = google_update::posix_guid.size(); | 49 int size = google_update::posix_guid().size(); |
45 return file_util::WriteFile(consent_file, c_str, size) == size; | 50 return file_util::WriteFile(consent_file, c_str, size) == size; |
46 } | 51 } |
47 } else { | 52 } else { |
48 google_update::posix_guid.clear(); | 53 google_update::posix_guid().clear(); |
49 return file_util::Delete(consent_file, false); | 54 return file_util::Delete(consent_file, false); |
50 } | 55 } |
51 return true; | 56 return true; |
52 } | 57 } |
53 | 58 |
54 bool GoogleUpdateSettings::SetMetricsId(const std::wstring& client_id) { | 59 bool GoogleUpdateSettings::SetMetricsId(const std::wstring& client_id) { |
55 // Make sure that user has consented to send crashes. | 60 // Make sure that user has consented to send crashes. |
56 FilePath consent_dir; | 61 FilePath consent_dir; |
57 PathService::Get(chrome::DIR_USER_DATA, &consent_dir); | 62 PathService::Get(chrome::DIR_USER_DATA, &consent_dir); |
58 if (!file_util::DirectoryExists(consent_dir) || | 63 if (!file_util::DirectoryExists(consent_dir) || |
59 !GoogleUpdateSettings::GetCollectStatsConsent()) | 64 !GoogleUpdateSettings::GetCollectStatsConsent()) |
60 return false; | 65 return false; |
61 | 66 |
62 // Since user has consented, write the metrics id to the file. | 67 // Since user has consented, write the metrics id to the file. |
63 google_update::posix_guid = WideToASCII(client_id); | 68 google_update::posix_guid() = WideToASCII(client_id); |
64 return GoogleUpdateSettings::SetCollectStatsConsent(true); | 69 return GoogleUpdateSettings::SetCollectStatsConsent(true); |
65 } | 70 } |
66 | 71 |
67 // GetLastRunTime and SetLastRunTime are not implemented for posix. Their | 72 // GetLastRunTime and SetLastRunTime are not implemented for posix. Their |
68 // current return values signal failure which the caller is designed to | 73 // current return values signal failure which the caller is designed to |
69 // handle. | 74 // handle. |
70 | 75 |
71 // static | 76 // static |
72 int GoogleUpdateSettings::GetLastRunTime() { | 77 int GoogleUpdateSettings::GetLastRunTime() { |
73 return -1; | 78 return -1; |
74 } | 79 } |
75 | 80 |
76 // static | 81 // static |
77 bool GoogleUpdateSettings::SetLastRunTime() { | 82 bool GoogleUpdateSettings::SetLastRunTime() { |
78 return false; | 83 return false; |
79 } | 84 } |
OLD | NEW |