OLD | NEW |
---|---|
(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 | |
grt (UTC plus 2)
2014/02/13 03:58:26
nit: remove extra newline
Cait (Slow)
2014/02/14 01:17:02
Done.
| |
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 bool ReadKeyValueString(bool system_install, const wchar_t* key_path, | |
26 const wchar_t* guid, const wchar_t* value_to_read, | |
27 base::string16* value_out) { | |
28 HKEY h_key = NULL; | |
29 *value_out = base::string16(); | |
grt (UTC plus 2)
2014/02/13 03:58:26
value_out->clear();
Cait (Slow)
2014/02/14 01:17:02
Done.
| |
30 | |
31 base::string16 full_key_path(key_path); | |
32 full_key_path.append(1, L'\\'); | |
33 full_key_path.append(guid); | |
34 | |
35 if (::RegOpenKeyEx(system_install? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, | |
grt (UTC plus 2)
2014/02/13 03:58:26
nit: space before ?
Cait (Slow)
2014/02/14 01:17:02
Done.
| |
36 full_key_path.c_str(), 0, KEY_QUERY_VALUE, &h_key) != ERROR_SUCCESS) { | |
grt (UTC plus 2)
2014/02/13 03:58:26
use the KEY_WOW64_32KEY flag here and on line 64 (
Cait (Slow)
2014/02/14 01:17:02
Done.
| |
37 return false; | |
38 } | |
39 | |
40 const size_t kMaxStringLength = 1024; | |
41 wchar_t raw_value[kMaxStringLength] = {}; | |
42 DWORD size = sizeof(raw_value); | |
43 DWORD type = REG_SZ; | |
44 LONG result = ::RegQueryValueEx(h_key, value_to_read, 0, &type, | |
grt (UTC plus 2)
2014/02/13 03:58:26
this isn't guaranteed to return a null-terminated
Cait (Slow)
2014/02/14 01:17:02
Done.
| |
45 reinterpret_cast<LPBYTE>(raw_value), &size); | |
46 *value_out = raw_value; | |
47 | |
48 ::RegCloseKey(h_key); | |
49 | |
50 return ERROR_SUCCESS == result; | |
grt (UTC plus 2)
2014/02/13 03:58:26
chromium style puts the constant after the variabl
Cait (Slow)
2014/02/14 01:17:02
Done.
grt (UTC plus 2)
2014/02/14 16:37:31
Really? ;-)
| |
51 } | |
52 | |
53 bool ReadKeyValueDW(bool system_install, const wchar_t* key_path, | |
54 base::string16 guid, const wchar_t* value_to_read, | |
55 DWORD* value_out) { | |
56 HKEY h_key = NULL;; | |
grt (UTC plus 2)
2014/02/13 03:58:26
nit: remove extra ;
Cait (Slow)
2014/02/14 01:17:02
Done.
| |
57 *value_out = 0; | |
58 | |
59 base::string16 full_key_path(key_path); | |
60 full_key_path.append(1, L'\\'); | |
61 full_key_path.append(guid.c_str()); | |
grt (UTC plus 2)
2014/02/13 03:58:26
remove .c_str()
Cait (Slow)
2014/02/14 01:17:02
Done.
| |
62 | |
63 if (::RegOpenKeyEx(system_install? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, | |
grt (UTC plus 2)
2014/02/13 03:58:26
nit: space before ?
Cait (Slow)
2014/02/14 01:17:02
Done.
| |
64 full_key_path.c_str(), 0, KEY_QUERY_VALUE, &h_key) != ERROR_SUCCESS) { | |
65 return false; | |
66 } | |
67 | |
68 DWORD size = sizeof(DWORD); | |
69 DWORD type = REG_DWORD; | |
70 LONG result = ::RegQueryValueEx(h_key, value_to_read, 0, &type, | |
71 reinterpret_cast<BYTE*>(value_out), &size); | |
72 | |
73 ::RegCloseKey(h_key); | |
74 | |
75 return ERROR_SUCCESS == result; | |
grt (UTC plus 2)
2014/02/13 03:58:26
see above
Cait (Slow)
2014/02/14 01:17:02
Done.
grt (UTC plus 2)
2014/02/14 16:37:31
More doing?
| |
76 } | |
77 | |
78 } // namespace | |
79 | |
80 bool IsCanary(wchar_t* exe_path) { | |
81 return wcsstr(exe_path, L"Google\\Chrome SxS") != NULL; | |
grt (UTC plus 2)
2014/02/13 03:58:26
i think chrome looks for "Chrome SxS\\Application"
Cait (Slow)
2014/02/14 01:17:02
Done.
| |
82 } | |
83 | |
84 bool IsSystemInstall(wchar_t* exe_path) { | |
85 wchar_t program_dir[MAX_PATH] = {}; | |
86 DWORD ret = ::GetEnvironmentVariable(L"PROGRAMFILES", program_dir, MAX_PATH); | |
grt (UTC plus 2)
2014/02/13 03:58:26
MAX_PATH -> arraysize(program_dir) here and below
Cait (Slow)
2014/02/14 01:17:02
Done.
| |
87 if (ret!=0 && ret<=MAX_PATH && wcsncmp(exe_path, program_dir, ret) == 0) | |
grt (UTC plus 2)
2014/02/13 03:58:26
whitespace around operators
simplify zero tests
re
Cait (Slow)
2014/02/14 01:17:02
Done.
| |
88 return true; | |
89 | |
90 ret = ::GetEnvironmentVariable(L"PROGRAMFILES(X86)", program_dir, MAX_PATH); | |
91 if (ret!=0 && ret<=MAX_PATH && wcsncmp(exe_path, program_dir, ret) == 0) | |
92 return true; | |
93 | |
94 return false; | |
95 } | |
96 | |
97 bool IsMultiInstall(wchar_t* exe_path) { | |
98 base::string16 args; | |
99 if (ERROR_SUCCESS != ReadKeyValueString(IsSystemInstall(exe_path), | |
grt (UTC plus 2)
2014/02/13 03:58:26
ReadKeyValueString returns bool:
if (!ReadKeyVal
Cait (Slow)
2014/02/14 01:17:02
Done.
| |
100 kRegPathClientState, kAppGuidGoogleChrome, kUninstallArgumentsField, | |
101 &args)) { | |
102 return false; | |
103 } | |
104 return wcsstr(args.c_str(), L"--multi-install") != NULL; | |
grt (UTC plus 2)
2014/02/13 03:58:26
return args.find(L"--multi-install") != base::stri
Cait (Slow)
2014/02/14 01:17:02
Done.
| |
105 } | |
106 | |
107 bool AreUsageStatsEnabled() { | |
108 #if !defined(GOOGLE_CHROME_BUILD) | |
109 return false; | |
110 #else | |
111 wchar_t exe_path[MAX_PATH] = {}; | |
112 if (!GetModuleFileNameW(NULL, exe_path, MAX_PATH)) | |
grt (UTC plus 2)
2014/02/13 03:58:26
MAX_PATH -> arraysize(exe_path)
Cait (Slow)
2014/02/14 01:17:02
Done.
| |
113 return false; | |
114 | |
115 bool system_install = IsSystemInstall(exe_path); | |
116 base::string16 app_guid; | |
117 | |
118 if (IsCanary(exe_path)) { | |
119 app_guid = kAppGuidCanary; | |
120 } else { | |
121 app_guid = IsMultiInstall(exe_path)? kAppGuidGoogleBinaries : | |
grt (UTC plus 2)
2014/02/13 03:58:26
nit: space before ?
Cait (Slow)
2014/02/14 01:17:02
Done.
| |
122 kAppGuidGoogleChrome; | |
123 } | |
124 | |
125 DWORD out_value = 0; | |
126 if (system_install && ReadKeyValueDW(system_install, | |
127 kRegPathClientStateMedium, app_guid, kRegValueUsageStats, | |
128 &out_value)) { | |
129 return out_value == 1; | |
130 } | |
131 | |
132 return ReadKeyValueDW(system_install, kRegPathClientState, | |
133 app_guid, kRegValueUsageStats, &out_value) && out_value == 1; | |
134 #endif // defined(GOOGLE_CHROME_BUILD) | |
135 } | |
OLD | NEW |