OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
13 #include "chrome/common/chrome_paths.h" | 13 #include "chrome/common/chrome_paths.h" |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 base::LazyInstance<std::string>::Leaky g_posix_guid = LAZY_INSTANCE_INITIALIZER; | 17 base::LazyInstance<std::string>::Leaky g_posix_client_id = |
18 base::LazyInstance<base::Lock>::Leaky g_posix_guid_lock = | 18 LAZY_INSTANCE_INITIALIZER; |
19 base::LazyInstance<base::Lock>::Leaky g_posix_client_id_lock = | |
19 LAZY_INSTANCE_INITIALIZER; | 20 LAZY_INSTANCE_INITIALIZER; |
20 | 21 |
21 // File name used in the user data dir to indicate consent. | 22 // File name used in the user data dir to indicate consent. |
22 const char kConsentToSendStats[] = "Consent To Send Stats"; | 23 const char kConsentToSendStats[] = "Consent To Send Stats"; |
23 | 24 |
24 } // namespace | 25 } // namespace |
25 | 26 |
26 // static | 27 // static |
27 bool GoogleUpdateSettings::GetCollectStatsConsent() { | 28 bool GoogleUpdateSettings::GetCollectStatsConsent() { |
28 base::FilePath consent_file; | 29 base::FilePath consent_file; |
29 PathService::Get(chrome::DIR_USER_DATA, &consent_file); | 30 PathService::Get(chrome::DIR_USER_DATA, &consent_file); |
30 consent_file = consent_file.Append(kConsentToSendStats); | 31 consent_file = consent_file.Append(kConsentToSendStats); |
32 | |
33 if (!base::DirectoryExists(consent_file.DirName())) | |
grt (UTC plus 2)
2014/07/09 12:59:59
i see that this was moved here from SetMetricsId,
gab
2014/07/09 14:42:38
I think it should (and the impl makes it look like
| |
34 return false; | |
35 | |
31 std::string tmp_guid; | 36 std::string tmp_guid; |
32 bool consented = base::ReadFileToString(consent_file, &tmp_guid); | 37 bool consented = base::ReadFileToString(consent_file, &tmp_guid); |
33 if (consented) { | 38 if (consented) { |
34 base::AutoLock lock(g_posix_guid_lock.Get()); | 39 base::AutoLock lock(g_posix_client_id_lock.Get()); |
35 g_posix_guid.Get().assign(tmp_guid); | 40 g_posix_client_id.Get().assign(tmp_guid); |
36 } | 41 } |
37 return consented; | 42 return consented; |
38 } | 43 } |
39 | 44 |
40 // static | 45 // static |
41 bool GoogleUpdateSettings::SetCollectStatsConsent(bool consented) { | 46 bool GoogleUpdateSettings::SetCollectStatsConsent(bool consented) { |
42 base::FilePath consent_dir; | 47 base::FilePath consent_dir; |
43 PathService::Get(chrome::DIR_USER_DATA, &consent_dir); | 48 PathService::Get(chrome::DIR_USER_DATA, &consent_dir); |
44 if (!base::DirectoryExists(consent_dir)) | 49 if (!base::DirectoryExists(consent_dir)) |
45 return false; | 50 return false; |
46 | 51 |
47 base::AutoLock lock(g_posix_guid_lock.Get()); | 52 base::AutoLock lock(g_posix_client_id_lock.Get()); |
48 | 53 |
49 base::FilePath consent_file = consent_dir.AppendASCII(kConsentToSendStats); | 54 base::FilePath consent_file = consent_dir.AppendASCII(kConsentToSendStats); |
50 if (consented) { | 55 if (consented) { |
51 if ((!base::PathExists(consent_file)) || | 56 if ((!base::PathExists(consent_file)) || |
52 (base::PathExists(consent_file) && !g_posix_guid.Get().empty())) { | 57 (base::PathExists(consent_file) && !g_posix_client_id.Get().empty())) { |
53 const char* c_str = g_posix_guid.Get().c_str(); | 58 const char* c_str = g_posix_client_id.Get().c_str(); |
54 int size = g_posix_guid.Get().size(); | 59 int size = g_posix_client_id.Get().size(); |
55 return base::WriteFile(consent_file, c_str, size) == size; | 60 return base::WriteFile(consent_file, c_str, size) == size; |
56 } | 61 } |
57 } else { | 62 } else { |
58 g_posix_guid.Get().clear(); | 63 g_posix_client_id.Get().clear(); |
59 return base::DeleteFile(consent_file, false); | 64 return base::DeleteFile(consent_file, false); |
60 } | 65 } |
61 return true; | 66 return true; |
62 } | 67 } |
63 | 68 |
64 // static | 69 // static |
65 bool GoogleUpdateSettings::GetMetricsId(std::string* metrics_id) { | 70 bool GoogleUpdateSettings::LoadMetricsClientId(std::string* metrics_id) { |
66 base::AutoLock lock(g_posix_guid_lock.Get()); | 71 base::AutoLock lock(g_posix_client_id_lock.Get()); |
67 *metrics_id = g_posix_guid.Get(); | 72 *metrics_id = g_posix_client_id.Get(); |
68 return true; | 73 return true; |
69 } | 74 } |
70 | 75 |
71 // static | 76 // static |
72 bool GoogleUpdateSettings::SetMetricsId(const std::string& client_id) { | 77 bool GoogleUpdateSettings::StoreMetricsClientId(const std::string& client_id) { |
73 // Make sure that user has consented to send crashes. | 78 // Make sure that user has consented to send crashes. |
74 base::FilePath consent_dir; | 79 if (!GoogleUpdateSettings::GetCollectStatsConsent()) |
75 PathService::Get(chrome::DIR_USER_DATA, &consent_dir); | |
76 if (!base::DirectoryExists(consent_dir) || | |
77 !GoogleUpdateSettings::GetCollectStatsConsent()) { | |
78 return false; | 80 return false; |
79 } | |
80 | 81 |
81 { | 82 { |
82 // Since user has consented, write the metrics id to the file. | 83 // Since user has consented, write the metrics id to the file. |
83 base::AutoLock lock(g_posix_guid_lock.Get()); | 84 base::AutoLock lock(g_posix_client_id_lock.Get()); |
84 g_posix_guid.Get() = client_id; | 85 g_posix_client_id.Get() = client_id; |
85 } | 86 } |
86 return GoogleUpdateSettings::SetCollectStatsConsent(true); | 87 return GoogleUpdateSettings::SetCollectStatsConsent(true); |
87 } | 88 } |
88 | 89 |
89 // GetLastRunTime and SetLastRunTime are not implemented for posix. Their | 90 // GetLastRunTime and SetLastRunTime are not implemented for posix. Their |
90 // current return values signal failure which the caller is designed to | 91 // current return values signal failure which the caller is designed to |
91 // handle. | 92 // handle. |
92 | 93 |
93 // static | 94 // static |
94 int GoogleUpdateSettings::GetLastRunTime() { | 95 int GoogleUpdateSettings::GetLastRunTime() { |
95 return -1; | 96 return -1; |
96 } | 97 } |
97 | 98 |
98 // static | 99 // static |
99 bool GoogleUpdateSettings::SetLastRunTime() { | 100 bool GoogleUpdateSettings::SetLastRunTime() { |
100 return false; | 101 return false; |
101 } | 102 } |
OLD | NEW |