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

Side by Side Diff: chrome_elf/chrome_elf_util.cc

Issue 154653002: Breakpad coverage for chrome_elf start up (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Missed some nits Created 6 years, 10 months 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
(Empty)
1 // Copyright 2014 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_elf/chrome_elf_util.h"
6
7 #include "base/strings/string16.h"
8
9 namespace {
10
11 const wchar_t kRegPathClientState[] = L"Software\\Google\\Update\\ClientState";
12 const wchar_t kRegPathClientStateMedium[] =
13 L"Software\\Google\\Update\\ClientStateMedium";
14 const wchar_t kRegValueUsageStats[] = L"usagestats";
15 const wchar_t kUninstallArgumentsField[] = L"UninstallArguments";
16
17
18 const wchar_t kAppGuidCanary[] =
19 L"{4ea16ac7-fd5a-47c3-875b-dbf4a2008c20}";
20 const wchar_t kAppGuidGoogleChrome[] =
21 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}";
22 const wchar_t kAppGuidGoogleBinaries[] =
23 L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}";
24
25 LONG ReadValue(HKEY key, const wchar_t* name, void* data, DWORD* data_size,
robertshield 2014/02/12 21:12:37 This function really just directly wraps ::RegQuer
Cait (Slow) 2014/02/13 00:03:20 Done.
26 DWORD* data_type) {
27 LONG result = ::RegQueryValueEx(key, name, 0, data_type,
28 reinterpret_cast<LPBYTE>(data), data_size);
robertshield 2014/02/12 21:12:37 LPBYTE -> BYTE*
Cait (Slow) 2014/02/13 00:03:20 Done.
29 return result;
30 }
31
32 bool ReadKeyValueString(bool system_install, const wchar_t* key_path,
33 const wchar_t* guid, const wchar_t* value_to_read,
robertshield 2014/02/12 21:12:37 nit: line up the indent
Cait (Slow) 2014/02/13 00:03:20 Done.
34 wchar_t* value_out) {
35 HKEY h_key;
robertshield 2014/02/12 21:12:37 = NULL;
Cait (Slow) 2014/02/13 00:03:20 Done.
36 value_out = L"";
37
38 base::string16 full_key_path(key_path);
39 full_key_path.append(1, L'\\');
40 full_key_path.append(guid);
41
42 if (::RegOpenKeyEx(system_install? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
43 full_key_path.c_str(), 0, KEY_QUERY_VALUE, &h_key) != ERROR_SUCCESS) {
44 return false;
45 }
46
47 const size_t kMaxStringLength = 1024;
48 wchar_t raw_value[kMaxStringLength];
robertshield 2014/02/12 21:12:37 = {}
Cait (Slow) 2014/02/13 00:03:20 Done.
49 DWORD type = REG_SZ;
50 DWORD size = sizeof(raw_value);
51 LONG result = ReadValue(h_key, value_to_read, raw_value, &size, &type);
52
53 value_out = raw_value;
robertshield 2014/02/12 21:12:37 Can't return a buffer allocated on the stack in an
Cait (Slow) 2014/02/13 00:03:20 Done.
54
55 ::RegCloseKey(h_key);
56
57 return ERROR_SUCCESS == result;
58 }
59
60 bool ReadKeyValueDW(bool system_install, const wchar_t* key_path,
61 base::string16 guid, const wchar_t* value_to_read,
62 DWORD* value_out) {
63 HKEY h_key;
robertshield 2014/02/12 21:12:37 = NULL;
Cait (Slow) 2014/02/13 00:03:20 Done.
64 *value_out = 0;
65
66 base::string16 full_key_path(key_path);
67 full_key_path.append(1, L'\\');
68 full_key_path.append(guid.c_str());
69
70 if (::RegOpenKeyEx(system_install? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
71 full_key_path.c_str(), 0, KEY_QUERY_VALUE, &h_key) != ERROR_SUCCESS) {
72 return false;
73 }
74
75 DWORD type = REG_DWORD;
76 DWORD size = sizeof(DWORD);
77 LONG result = ReadValue(h_key, value_to_read, value_out, &size, &type);
78
79 DWORD buffer_size = sizeof(DWORD);
robertshield 2014/02/12 21:12:37 unused?
Cait (Slow) 2014/02/13 00:03:20 Done.
80
81 ::RegCloseKey(h_key);
82
83 return ERROR_SUCCESS == result;
84 }
85
86 } // namespace
87
88 bool IsCanary(wchar_t* exe_path) {
89 wchar_t* found = wcsstr(exe_path, L"Google\\Chrome SxS");
robertshield 2014/02/12 21:12:37 return wcsstr(exe_path, L"Google\\Chrome SxS") !=
Cait (Slow) 2014/02/13 00:03:20 Done.
90 return !!found;
91 }
92
93 bool IsSystemInstall(wchar_t* exe_path) {
94 bool found = wcsncmp(exe_path, L"C:\\Program Files", 15) == 0;
robertshield 2014/02/12 21:12:37 this can be shortened too, though I still think we
Cait (Slow) 2014/02/13 00:03:20 Done.
95 return found;
96 }
97
98 bool IsMultiInstall(wchar_t* exe_path) {
99 wchar_t* args = L"";
robertshield 2014/02/12 21:12:37 this is setting args to a static string, which isn
Cait (Slow) 2014/02/13 00:03:20 Done.
100 if (ERROR_SUCCESS != ReadKeyValueString(IsSystemInstall(exe_path),
101 kRegPathClientState, kAppGuidGoogleChrome, kUninstallArgumentsField,
102 args)) {
103 return false;
104 }
105 wchar_t* found = wcsstr(args, L"--multi-install");
106 return !!found;
robertshield 2014/02/12 21:12:37 return wcsstr(args, L"--multi-install") != NULL;
Cait (Slow) 2014/02/13 00:03:20 Done.
107 }
108
109 bool AreUsageStatsEnabled() {
110 #if !defined(GOOGLE_CHROME_BUILD)
111 return false;
112 #else
113 wchar_t exe_path[MAX_PATH] = {};
114 if (!GetModuleFileNameW(NULL, exe_path, MAX_PATH))
115 return false;
116
117 bool system_install = IsSystemInstall(exe_path);
118 base::string16 app_guid;
119
120 if (IsCanary(exe_path)) {
121 app_guid = kAppGuidCanary;
122 } else {
123 app_guid = IsMultiInstall(exe_path)? kAppGuidGoogleBinaries :
124 kAppGuidGoogleChrome;
125 }
126
127 DWORD out_value = 0;
128
robertshield 2014/02/12 21:12:37 nit: drop this blank line
Cait (Slow) 2014/02/13 00:03:20 Done.
129 if (system_install && ReadKeyValueDW(system_install,
130 kRegPathClientStateMedium, app_guid, kRegValueUsageStats,
131 &out_value)) {
132 return out_value == 1;
robertshield 2014/02/12 21:12:37 indent is off here.
Cait (Slow) 2014/02/13 00:03:20 Done.
133 }
134
135 return ReadKeyValueDW(system_install, kRegPathClientState,
136 app_guid, kRegValueUsageStats, &out_value) && out_value == 1;
137 #endif // defined(GOOGLE_CHROME_BUILD)
138 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698