Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: chrome/browser/google/google_update_settings_posix.cc

Issue 8568039: Revert 110235 - chrome: Remove 14 exit time destructors and 2 static initializers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 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 13 std::string posix_guid;
14 static std::string& posix_guid() {
15 CR_DEFINE_STATIC_LOCAL(std::string, guid, ());
16 return guid;
17 } 14 }
18 15
19 } // namespace google_update
20
21 // File name used in the user data dir to indicate consent. 16 // File name used in the user data dir to indicate consent.
22 static const char kConsentToSendStats[] = "Consent To Send Stats"; 17 static const char kConsentToSendStats[] = "Consent To Send Stats";
23 18
24 // static 19 // static
25 bool GoogleUpdateSettings::GetCollectStatsConsent() { 20 bool GoogleUpdateSettings::GetCollectStatsConsent() {
26 FilePath consent_file; 21 FilePath consent_file;
27 PathService::Get(chrome::DIR_USER_DATA, &consent_file); 22 PathService::Get(chrome::DIR_USER_DATA, &consent_file);
28 consent_file = consent_file.Append(kConsentToSendStats); 23 consent_file = consent_file.Append(kConsentToSendStats);
29 std::string tmp_guid; 24 std::string tmp_guid;
30 bool consented = file_util::ReadFileToString(consent_file, &tmp_guid); 25 bool consented = file_util::ReadFileToString(consent_file, &tmp_guid);
31 if (consented) 26 if (consented)
32 google_update::posix_guid().assign(tmp_guid); 27 google_update::posix_guid.assign(tmp_guid);
33 return consented; 28 return consented;
34 } 29 }
35 30
36 // static 31 // static
37 bool GoogleUpdateSettings::SetCollectStatsConsent(bool consented) { 32 bool GoogleUpdateSettings::SetCollectStatsConsent(bool consented) {
38 FilePath consent_dir; 33 FilePath consent_dir;
39 PathService::Get(chrome::DIR_USER_DATA, &consent_dir); 34 PathService::Get(chrome::DIR_USER_DATA, &consent_dir);
40 if (!file_util::DirectoryExists(consent_dir)) 35 if (!file_util::DirectoryExists(consent_dir))
41 return false; 36 return false;
42 37
43 FilePath consent_file = consent_dir.AppendASCII(kConsentToSendStats); 38 FilePath consent_file = consent_dir.AppendASCII(kConsentToSendStats);
44 if (consented) { 39 if (consented) {
45 if ((!file_util::PathExists(consent_file)) || 40 if ((!file_util::PathExists(consent_file)) ||
46 (file_util::PathExists(consent_file) && 41 (file_util::PathExists(consent_file) &&
47 !google_update::posix_guid().empty())) { 42 !google_update::posix_guid.empty())) {
48 const char* c_str = google_update::posix_guid().c_str(); 43 const char* c_str = google_update::posix_guid.c_str();
49 int size = google_update::posix_guid().size(); 44 int size = google_update::posix_guid.size();
50 return file_util::WriteFile(consent_file, c_str, size) == size; 45 return file_util::WriteFile(consent_file, c_str, size) == size;
51 } 46 }
52 } else { 47 } else {
53 google_update::posix_guid().clear(); 48 google_update::posix_guid.clear();
54 return file_util::Delete(consent_file, false); 49 return file_util::Delete(consent_file, false);
55 } 50 }
56 return true; 51 return true;
57 } 52 }
58 53
59 bool GoogleUpdateSettings::SetMetricsId(const std::wstring& client_id) { 54 bool GoogleUpdateSettings::SetMetricsId(const std::wstring& client_id) {
60 // Make sure that user has consented to send crashes. 55 // Make sure that user has consented to send crashes.
61 FilePath consent_dir; 56 FilePath consent_dir;
62 PathService::Get(chrome::DIR_USER_DATA, &consent_dir); 57 PathService::Get(chrome::DIR_USER_DATA, &consent_dir);
63 if (!file_util::DirectoryExists(consent_dir) || 58 if (!file_util::DirectoryExists(consent_dir) ||
64 !GoogleUpdateSettings::GetCollectStatsConsent()) 59 !GoogleUpdateSettings::GetCollectStatsConsent())
65 return false; 60 return false;
66 61
67 // Since user has consented, write the metrics id to the file. 62 // Since user has consented, write the metrics id to the file.
68 google_update::posix_guid() = WideToASCII(client_id); 63 google_update::posix_guid = WideToASCII(client_id);
69 return GoogleUpdateSettings::SetCollectStatsConsent(true); 64 return GoogleUpdateSettings::SetCollectStatsConsent(true);
70 } 65 }
71 66
72 // GetLastRunTime and SetLastRunTime are not implemented for posix. Their 67 // GetLastRunTime and SetLastRunTime are not implemented for posix. Their
73 // current return values signal failure which the caller is designed to 68 // current return values signal failure which the caller is designed to
74 // handle. 69 // handle.
75 70
76 // static 71 // static
77 int GoogleUpdateSettings::GetLastRunTime() { 72 int GoogleUpdateSettings::GetLastRunTime() {
78 return -1; 73 return -1;
79 } 74 }
80 75
81 // static 76 // static
82 bool GoogleUpdateSettings::SetLastRunTime() { 77 bool GoogleUpdateSettings::SetLastRunTime() {
83 return false; 78 return false;
84 } 79 }
OLDNEW
« no previous file with comments | « chrome/browser/content_settings/tab_specific_content_settings.cc ('k') | chrome/browser/metrics/thread_watcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698