OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/install_static/install_util.h" | 5 #include "chrome/install_static/install_util.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <assert.h> | 8 #include <assert.h> |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <iostream> | 10 #include <iostream> |
11 #include <iterator> | 11 #include <iterator> |
12 #include <memory> | 12 #include <memory> |
13 #include <sstream> | 13 #include <sstream> |
14 | 14 |
15 #include "base/macros.h" | 15 #include "chrome_elf/nt_registry/nt_registry.h" |
16 #include "build/build_config.h" | |
17 | 16 |
18 namespace install_static { | 17 namespace install_static { |
19 | 18 |
20 ProcessType g_process_type = ProcessType::UNINITIALIZED; | 19 ProcessType g_process_type = ProcessType::UNINITIALIZED; |
21 | 20 |
22 // TODO(ananta) | 21 // TODO(ananta) |
23 // http://crbug.com/604923 | 22 // http://crbug.com/604923 |
24 // The constants defined in this file are also defined in chrome/installer and | 23 // The constants defined in this file are also defined in chrome/installer and |
25 // other places. we need to unify them. | 24 // other places. we need to unify them. |
26 | 25 |
27 // Chrome channel display names. | 26 // Chrome channel display names. |
28 const wchar_t kChromeChannelUnknown[] = L"unknown"; | 27 const wchar_t kChromeChannelUnknown[] = L"unknown"; |
29 const wchar_t kChromeChannelCanary[] = L"canary"; | 28 const wchar_t kChromeChannelCanary[] = L"canary"; |
30 const wchar_t kChromeChannelDev[] = L"dev"; | 29 const wchar_t kChromeChannelDev[] = L"dev"; |
31 const wchar_t kChromeChannelBeta[] = L"beta"; | 30 const wchar_t kChromeChannelBeta[] = L"beta"; |
32 const wchar_t kChromeChannelStable[] = L""; | 31 const wchar_t kChromeChannelStable[] = L""; |
33 const wchar_t kChromeChannelStableExplicit[] = L"stable"; | 32 const wchar_t kChromeChannelStableExplicit[] = L"stable"; |
34 const wchar_t kRegApField[] = L"ap"; | 33 const wchar_t kRegApField[] = L"ap"; |
35 | 34 |
36 #if defined(GOOGLE_CHROME_BUILD) | 35 #if defined(GOOGLE_CHROME_BUILD) |
37 const wchar_t kRegPathClientState[] = L"Software\\Google\\Update\\ClientState"; | 36 const wchar_t kRegPathClientState[] = L"Software\\Google\\Update\\ClientState"; |
38 const wchar_t kRegPathClientStateMedium[] = | 37 const wchar_t kRegPathClientStateMedium[] = |
39 L"Software\\Google\\Update\\ClientStateMedium"; | 38 L"Software\\Google\\Update\\ClientStateMedium"; |
40 const wchar_t kRegPathChromePolicy[] = L"SOFTWARE\\Policies\\Google\\Chrome"; | 39 const wchar_t kRegPathChromePolicy[] = L"SOFTWARE\\Policies\\Google\\Chrome"; |
41 #else | 40 #else |
42 const wchar_t kRegPathClientState[] = | 41 const wchar_t kRegPathClientState[] = |
43 L"Software\\Chromium\\Update\\ClientState"; | 42 L"Software\\Chromium\\Update\\ClientState"; |
44 const wchar_t kRegPathClientStateMedium[] = | 43 const wchar_t kRegPathClientStateMedium[] = |
45 L"Software\\Chromium\\Update\\ClientStateMedium"; | 44 L"Software\\Chromium\\Update\\ClientStateMedium"; |
46 const wchar_t kRegPathChromePolicy[] = L"SOFTWARE\\Policies\\Chromium"; | 45 const wchar_t kRegPathChromePolicy[] = L"SOFTWARE\\Policies\\Chromium"; |
47 #endif | 46 #endif |
48 | 47 |
49 const wchar_t kRegValueUsageStats[] = L"usagestats"; | 48 const wchar_t kRegValueUsageStats[] = L"usagestats"; |
50 const wchar_t kUninstallArgumentsField[] = L"UninstallArguments"; | 49 const wchar_t kUninstallArgumentsField[] = L"UninstallArguments"; |
51 const wchar_t kMetricsReportingEnabled[] = L"MetricsReportingEnabled"; | 50 const wchar_t kMetricsReportingEnabled[] = L"MetricsReportingEnabled"; |
52 | 51 |
53 const wchar_t kAppGuidCanary[] = | 52 const wchar_t kAppGuidCanary[] = L"{4ea16ac7-fd5a-47c3-875b-dbf4a2008c20}"; |
54 L"{4ea16ac7-fd5a-47c3-875b-dbf4a2008c20}"; | |
55 const wchar_t kAppGuidGoogleChrome[] = | 53 const wchar_t kAppGuidGoogleChrome[] = |
56 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; | 54 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; |
57 const wchar_t kAppGuidGoogleBinaries[] = | 55 const wchar_t kAppGuidGoogleBinaries[] = |
58 L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}"; | 56 L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}"; |
59 | 57 |
60 const wchar_t kHeadless[] = L"CHROME_HEADLESS"; | 58 const wchar_t kHeadless[] = L"CHROME_HEADLESS"; |
61 const wchar_t kShowRestart[] = L"CHROME_CRASHED"; | 59 const wchar_t kShowRestart[] = L"CHROME_CRASHED"; |
62 const wchar_t kRestartInfo[] = L"CHROME_RESTART"; | 60 const wchar_t kRestartInfo[] = L"CHROME_RESTART"; |
63 const wchar_t kRtlLocale[] = L"RIGHT_TO_LEFT"; | 61 const wchar_t kRtlLocale[] = L"RIGHT_TO_LEFT"; |
64 | 62 |
(...skipping 24 matching lines...) Expand all Loading... |
89 const wchar_t kRegPathGoogleUpdate[] = L"Software\\Google\\Update"; | 87 const wchar_t kRegPathGoogleUpdate[] = L"Software\\Google\\Update"; |
90 const wchar_t kRegGoogleUpdateVersion[] = L"version"; | 88 const wchar_t kRegGoogleUpdateVersion[] = L"version"; |
91 | 89 |
92 void Trace(const wchar_t* format_string, ...) { | 90 void Trace(const wchar_t* format_string, ...) { |
93 static const int kMaxLogBufferSize = 1024; | 91 static const int kMaxLogBufferSize = 1024; |
94 static wchar_t buffer[kMaxLogBufferSize] = {}; | 92 static wchar_t buffer[kMaxLogBufferSize] = {}; |
95 | 93 |
96 va_list args = {}; | 94 va_list args = {}; |
97 | 95 |
98 va_start(args, format_string); | 96 va_start(args, format_string); |
99 vswprintf(buffer, arraysize(buffer), format_string, args); | 97 vswprintf(buffer, kMaxLogBufferSize, format_string, args); |
100 OutputDebugString(buffer); | 98 OutputDebugStringW(buffer); |
101 va_end(args); | 99 va_end(args); |
102 } | 100 } |
103 | 101 |
104 // Reads a string value identified by |value_to_read| from the registry path | |
105 // under |key_path|. We look in HKLM or HKCU depending on whether the | |
106 // |system_install| parameter is true. | |
107 // Please note that this function only looks in the 32bit view of the registry. | |
108 bool ReadKeyValueString(bool system_install, const wchar_t* key_path, | |
109 const wchar_t* guid, const wchar_t* value_to_read, | |
110 base::string16* value_out) { | |
111 HKEY key = nullptr; | |
112 value_out->clear(); | |
113 | |
114 base::string16 full_key_path(key_path); | |
115 if (guid && *guid) { | |
116 full_key_path.append(1, L'\\'); | |
117 full_key_path.append(guid); | |
118 } | |
119 | |
120 if (::RegOpenKeyEx(system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, | |
121 full_key_path.c_str(), 0, | |
122 KEY_QUERY_VALUE | KEY_WOW64_32KEY, &key) != | |
123 ERROR_SUCCESS) { | |
124 return false; | |
125 } | |
126 | |
127 const size_t kMaxStringLength = 1024; | |
128 wchar_t raw_value[kMaxStringLength] = {}; | |
129 DWORD size = sizeof(raw_value); | |
130 DWORD type = REG_SZ; | |
131 LONG result = ::RegQueryValueEx(key, value_to_read, 0, &type, | |
132 reinterpret_cast<LPBYTE>(raw_value), &size); | |
133 | |
134 if (result == ERROR_SUCCESS) { | |
135 if (type != REG_SZ || (size & 1) != 0) { | |
136 result = ERROR_NOT_SUPPORTED; | |
137 } else if (size == 0) { | |
138 *raw_value = L'\0'; | |
139 } else if (raw_value[size / sizeof(wchar_t) - 1] != L'\0') { | |
140 if ((size / sizeof(wchar_t)) < kMaxStringLength) | |
141 raw_value[size / sizeof(wchar_t)] = L'\0'; | |
142 else | |
143 result = ERROR_MORE_DATA; | |
144 } | |
145 } | |
146 | |
147 if (result == ERROR_SUCCESS) | |
148 *value_out = raw_value; | |
149 | |
150 ::RegCloseKey(key); | |
151 | |
152 return result == ERROR_SUCCESS; | |
153 } | |
154 | |
155 // Reads a DWORD value identified by |value_to_read| from the registry path | |
156 // under |key_path|. We look in HKLM or HKCU depending on whether the | |
157 // |system_install| parameter is true. | |
158 // Please note that this function only looks in the 32bit view of the registry. | |
159 bool ReadKeyValueDW(bool system_install, const wchar_t* key_path, | |
160 base::string16 guid, const wchar_t* value_to_read, | |
161 DWORD* value_out) { | |
162 HKEY key = nullptr; | |
163 *value_out = 0; | |
164 | |
165 base::string16 full_key_path(key_path); | |
166 full_key_path.append(1, L'\\'); | |
167 full_key_path.append(guid); | |
168 | |
169 if (::RegOpenKeyEx(system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, | |
170 full_key_path.c_str(), 0, | |
171 KEY_QUERY_VALUE | KEY_WOW64_32KEY, &key) != | |
172 ERROR_SUCCESS) { | |
173 return false; | |
174 } | |
175 | |
176 DWORD size = sizeof(*value_out); | |
177 DWORD type = REG_DWORD; | |
178 LONG result = ::RegQueryValueEx(key, value_to_read, 0, &type, | |
179 reinterpret_cast<BYTE*>(value_out), &size); | |
180 | |
181 ::RegCloseKey(key); | |
182 | |
183 return result == ERROR_SUCCESS && size == sizeof(*value_out); | |
184 } | |
185 | |
186 bool GetLanguageAndCodePageFromVersionResource(const char* version_resource, | 102 bool GetLanguageAndCodePageFromVersionResource(const char* version_resource, |
187 WORD* language, | 103 WORD* language, |
188 WORD* code_page) { | 104 WORD* code_page) { |
189 if (!version_resource) | 105 if (!version_resource) |
190 return false; | 106 return false; |
191 | 107 |
192 struct LanguageAndCodePage { | 108 struct LanguageAndCodePage { |
193 WORD language; | 109 WORD language; |
194 WORD code_page; | 110 WORD code_page; |
195 }; | 111 }; |
196 | 112 |
197 LanguageAndCodePage* translation_info = nullptr; | 113 LanguageAndCodePage* translation_info = nullptr; |
198 uint32_t data_size_in_bytes = 0; | 114 uint32_t data_size_in_bytes = 0; |
199 BOOL query_result = VerQueryValue(version_resource, | 115 BOOL query_result = VerQueryValueW( |
200 L"\\VarFileInfo\\Translation", | 116 version_resource, L"\\VarFileInfo\\Translation", |
201 reinterpret_cast<void**>(&translation_info), | 117 reinterpret_cast<void**>(&translation_info), &data_size_in_bytes); |
202 &data_size_in_bytes); | |
203 if (!query_result) | 118 if (!query_result) |
204 return false; | 119 return false; |
205 | 120 |
206 *language = translation_info->language; | 121 *language = translation_info->language; |
207 *code_page = translation_info->code_page; | 122 *code_page = translation_info->code_page; |
208 return true; | 123 return true; |
209 } | 124 } |
210 | 125 |
211 bool GetValueFromVersionResource(const char* version_resource, | 126 bool GetValueFromVersionResource(const char* version_resource, |
212 const base::string16& name, | 127 const std::wstring& name, |
213 base::string16* value_str) { | 128 std::wstring* value_str) { |
214 assert(value_str); | 129 assert(value_str); |
215 value_str->clear(); | 130 value_str->clear(); |
216 | 131 |
217 // TODO(ananta) | 132 // TODO(ananta) |
218 // It may be better in the long run to enumerate the languages and code pages | 133 // It may be better in the long run to enumerate the languages and code pages |
219 // in the version resource and return the value from the first match. | 134 // in the version resource and return the value from the first match. |
220 WORD language = 0; | 135 WORD language = 0; |
221 WORD code_page = 0; | 136 WORD code_page = 0; |
222 if (!GetLanguageAndCodePageFromVersionResource(version_resource, | 137 if (!GetLanguageAndCodePageFromVersionResource(version_resource, &language, |
223 &language, | |
224 &code_page)) { | 138 &code_page)) { |
225 return false; | 139 return false; |
226 } | 140 } |
227 | 141 |
228 WORD lang_codepage[8] = {}; | 142 const size_t array_size = 8; |
| 143 WORD lang_codepage[array_size] = {}; |
229 size_t i = 0; | 144 size_t i = 0; |
230 // Use the language and codepage | 145 // Use the language and codepage |
231 lang_codepage[i++] = language; | 146 lang_codepage[i++] = language; |
232 lang_codepage[i++] = code_page; | 147 lang_codepage[i++] = code_page; |
233 // Use the default language and codepage from the resource. | 148 // Use the default language and codepage from the resource. |
234 lang_codepage[i++] = ::GetUserDefaultLangID(); | 149 lang_codepage[i++] = ::GetUserDefaultLangID(); |
235 lang_codepage[i++] = code_page; | 150 lang_codepage[i++] = code_page; |
236 // Use the language from the resource and Latin codepage (most common). | 151 // Use the language from the resource and Latin codepage (most common). |
237 lang_codepage[i++] = language; | 152 lang_codepage[i++] = language; |
238 lang_codepage[i++] = 1252; | 153 lang_codepage[i++] = 1252; |
239 // Use the default language and Latin codepage (most common). | 154 // Use the default language and Latin codepage (most common). |
240 lang_codepage[i++] = ::GetUserDefaultLangID(); | 155 lang_codepage[i++] = ::GetUserDefaultLangID(); |
241 lang_codepage[i++] = 1252; | 156 lang_codepage[i++] = 1252; |
242 | 157 |
243 static_assert((arraysize(lang_codepage) % 2) == 0, | 158 static_assert((array_size % 2) == 0, |
244 "Language code page size should be a multiple of 2"); | 159 "Language code page size should be a multiple of 2"); |
245 assert(arraysize(lang_codepage) == i); | 160 assert(array_size == i); |
246 | 161 |
247 for (i = 0; i < arraysize(lang_codepage);) { | 162 for (i = 0; i < array_size;) { |
248 wchar_t sub_block[MAX_PATH]; | 163 wchar_t sub_block[MAX_PATH]; |
249 WORD language = lang_codepage[i++]; | 164 WORD language = lang_codepage[i++]; |
250 WORD code_page = lang_codepage[i++]; | 165 WORD code_page = lang_codepage[i++]; |
251 _snwprintf_s(sub_block, MAX_PATH, MAX_PATH, | 166 _snwprintf_s(sub_block, MAX_PATH, MAX_PATH, |
252 L"\\StringFileInfo\\%04hx%04hx\\%ls", language, code_page, | 167 L"\\StringFileInfo\\%04hx%04hx\\%ls", language, code_page, |
253 name.c_str()); | 168 name.c_str()); |
254 void* value = nullptr; | 169 void* value = nullptr; |
255 uint32_t size = 0; | 170 uint32_t size = 0; |
256 BOOL r = ::VerQueryValue(version_resource, sub_block, &value, &size); | 171 BOOL r = ::VerQueryValueW(version_resource, sub_block, &value, &size); |
257 if (r && value) { | 172 if (r && value) { |
258 value_str->assign(static_cast<wchar_t*>(value)); | 173 value_str->assign(static_cast<wchar_t*>(value)); |
259 return true; | 174 return true; |
260 } | 175 } |
261 } | 176 } |
262 return false; | 177 return false; |
263 } | 178 } |
264 | 179 |
265 // Returns the executable path for the current process. | 180 // Returns the executable path for the current process. |
266 base::string16 GetCurrentProcessExePath() { | 181 std::wstring GetCurrentProcessExePath() { |
267 wchar_t exe_path[MAX_PATH]; | 182 wchar_t exe_path[MAX_PATH]; |
268 if (GetModuleFileName(nullptr, exe_path, arraysize(exe_path)) == 0) | 183 if (::GetModuleFileName(nullptr, exe_path, MAX_PATH) == 0) |
269 return base::string16(); | 184 return std::wstring(); |
270 return exe_path; | 185 return exe_path; |
271 } | 186 } |
272 | 187 |
273 bool RecursiveDirectoryCreate(const base::string16& full_path) { | 188 bool RecursiveDirectoryCreate(const std::wstring& full_path) { |
274 // If the path exists, we've succeeded if it's a directory, failed otherwise. | 189 // If the path exists, we've succeeded if it's a directory, failed otherwise. |
275 const wchar_t* full_path_str = full_path.c_str(); | 190 const wchar_t* full_path_str = full_path.c_str(); |
276 DWORD file_attributes = ::GetFileAttributes(full_path_str); | 191 DWORD file_attributes = ::GetFileAttributes(full_path_str); |
277 if (file_attributes != INVALID_FILE_ATTRIBUTES) { | 192 if (file_attributes != INVALID_FILE_ATTRIBUTES) { |
278 if ((file_attributes & FILE_ATTRIBUTE_DIRECTORY) != 0) { | 193 if ((file_attributes & FILE_ATTRIBUTE_DIRECTORY) != 0) { |
279 Trace(L"%hs( %ls directory exists )\n", __FUNCTION__, full_path_str); | 194 Trace(L"%hs( %ls directory exists )\n", __FUNCTION__, full_path_str); |
280 return true; | 195 return true; |
281 } | 196 } |
282 Trace(L"%hs( %ls directory conflicts with an existing file. )\n", | 197 Trace(L"%hs( %ls directory conflicts with an existing file. )\n", |
283 __FUNCTION__, full_path_str); | 198 __FUNCTION__, full_path_str); |
284 return false; | 199 return false; |
285 } | 200 } |
286 | 201 |
287 // Invariant: Path does not exist as file or directory. | 202 // Invariant: Path does not exist as file or directory. |
288 | 203 |
289 // Attempt to create the parent recursively. This will immediately return | 204 // Attempt to create the parent recursively. This will immediately return |
290 // true if it already exists, otherwise will create all required parent | 205 // true if it already exists, otherwise will create all required parent |
291 // directories starting with the highest-level missing parent. | 206 // directories starting with the highest-level missing parent. |
292 base::string16 parent_path; | 207 std::wstring parent_path; |
293 std::size_t pos = full_path.find_last_of(L"/\\"); | 208 std::size_t pos = full_path.find_last_of(L"/\\"); |
294 if (pos != base::string16::npos) { | 209 if (pos != std::wstring::npos) { |
295 parent_path = full_path.substr(0, pos); | 210 parent_path = full_path.substr(0, pos); |
296 if (!RecursiveDirectoryCreate(parent_path)) { | 211 if (!RecursiveDirectoryCreate(parent_path)) { |
297 Trace(L"Failed to create one of the parent directories"); | 212 Trace(L"Failed to create one of the parent directories"); |
298 return false; | 213 return false; |
299 } | 214 } |
300 } | 215 } |
301 if (!::CreateDirectory(full_path_str, nullptr)) { | 216 if (!::CreateDirectory(full_path_str, nullptr)) { |
302 DWORD error_code = ::GetLastError(); | 217 DWORD error_code = ::GetLastError(); |
303 if (error_code == ERROR_ALREADY_EXISTS) { | 218 if (error_code == ERROR_ALREADY_EXISTS) { |
304 DWORD file_attributes = ::GetFileAttributes(full_path_str); | 219 DWORD file_attributes = ::GetFileAttributes(full_path_str); |
305 if ((file_attributes != INVALID_FILE_ATTRIBUTES) && | 220 if ((file_attributes != INVALID_FILE_ATTRIBUTES) && |
306 ((file_attributes & FILE_ATTRIBUTE_DIRECTORY) != 0)) { | 221 ((file_attributes & FILE_ATTRIBUTE_DIRECTORY) != 0)) { |
307 // This error code ERROR_ALREADY_EXISTS doesn't indicate whether we | 222 // This error code ERROR_ALREADY_EXISTS doesn't indicate whether we |
308 // were racing with someone creating the same directory, or a file | 223 // were racing with someone creating the same directory, or a file |
309 // with the same path. If the directory exists, we lost the | 224 // with the same path. If the directory exists, we lost the |
310 // race to create the same directory. | 225 // race to create the same directory. |
311 return true; | 226 return true; |
312 } else { | 227 } else { |
313 Trace(L"Failed to create directory %ls, last error is %d\n", | 228 Trace(L"Failed to create directory %ls, last error is %d\n", |
314 full_path_str, error_code); | 229 full_path_str, error_code); |
315 return false; | 230 return false; |
316 } | 231 } |
317 } | 232 } |
318 } | 233 } |
319 return true; | 234 return true; |
320 } | 235 } |
321 | 236 |
322 bool GetCollectStatsConsentImpl(const base::string16& exe_path) { | 237 bool GetCollectStatsConsentImpl(const std::wstring& exe_path) { |
323 bool enabled = true; | 238 bool enabled = true; |
324 if (ReportingIsEnforcedByPolicy(&enabled)) | 239 bool controlled_by_policy = ReportingIsEnforcedByPolicy(&enabled); |
325 return enabled; | 240 |
| 241 if (controlled_by_policy && !enabled) |
| 242 return false; |
326 | 243 |
327 bool system_install = IsSystemInstall(exe_path.c_str()); | 244 bool system_install = IsSystemInstall(exe_path.c_str()); |
328 base::string16 app_guid; | 245 std::wstring app_guid; |
329 | 246 |
330 if (IsSxSChrome(exe_path.c_str())) { | 247 if (IsSxSChrome(exe_path.c_str())) { |
331 app_guid = kAppGuidCanary; | 248 app_guid = kAppGuidCanary; |
332 } else { | 249 } else { |
333 app_guid = IsMultiInstall(system_install) ? kAppGuidGoogleBinaries : | 250 app_guid = IsMultiInstall(system_install) ? kAppGuidGoogleBinaries |
334 kAppGuidGoogleChrome; | 251 : kAppGuidGoogleChrome; |
335 } | 252 } |
336 | 253 |
337 DWORD out_value = 0; | 254 DWORD out_value = 0; |
338 if (system_install && | |
339 ReadKeyValueDW(system_install, kRegPathClientStateMedium, app_guid, | |
340 kRegValueUsageStats, &out_value)) { | |
341 return out_value == 1; | |
342 } | |
343 | 255 |
344 return ReadKeyValueDW(system_install, kRegPathClientState, app_guid, | 256 // If system_install, first try kRegPathClientStateMedium. |
345 kRegValueUsageStats, &out_value) && out_value == 1; | 257 std::wstring full_key_path(kRegPathClientStateMedium); |
| 258 full_key_path.append(1, L'\\'); |
| 259 full_key_path.append(app_guid); |
| 260 if (system_install && nt::QueryRegValueDWORD(nt::HKLM, full_key_path.c_str(), |
| 261 kRegValueUsageStats, &out_value)) |
| 262 return (out_value == 1); |
| 263 |
| 264 // Second, try kRegPathClientState. |
| 265 full_key_path = kRegPathClientState; |
| 266 full_key_path.append(1, L'\\'); |
| 267 full_key_path.append(app_guid); |
| 268 return (nt::QueryRegValueDWORD((system_install ? nt::HKLM : nt::HKCU), |
| 269 full_key_path.c_str(), kRegValueUsageStats, |
| 270 &out_value) && |
| 271 out_value == 1); |
346 } | 272 } |
347 | 273 |
348 // Returns true if the |source| string matches the |pattern|. The pattern | 274 // Returns true if the |source| string matches the |pattern|. The pattern |
349 // may contain wildcards like '?' which matches one character or a '*' | 275 // may contain wildcards like '?' which matches one character or a '*' |
350 // which matches 0 or more characters. | 276 // which matches 0 or more characters. |
351 // Please note that pattern matches the whole string. If you want to find | 277 // Please note that pattern matches the whole string. If you want to find |
352 // something in the middle of the string then you need to specify the pattern | 278 // something in the middle of the string then you need to specify the pattern |
353 // as '*xyz*'. | 279 // as '*xyz*'. |
354 // |source_index| is the index of the current character being matched in | 280 // |source_index| is the index of the current character being matched in |
355 // |source|. | 281 // |source|. |
356 // |pattern_index| is the index of the current pattern character in |pattern| | 282 // |pattern_index| is the index of the current pattern character in |pattern| |
357 // which is matched with source. | 283 // which is matched with source. |
358 bool MatchPatternImpl(const base::string16& source, | 284 bool MatchPatternImpl(const std::wstring& source, |
359 const base::string16& pattern, | 285 const std::wstring& pattern, |
360 size_t source_index, | 286 size_t source_index, |
361 size_t pattern_index) { | 287 size_t pattern_index) { |
362 if (source.empty() && pattern.empty()) | 288 if (source.empty() && pattern.empty()) |
363 return true; | 289 return true; |
364 | 290 |
365 if (source_index > source.length() || pattern_index > pattern.length()) | 291 if (source_index > source.length() || pattern_index > pattern.length()) |
366 return false; | 292 return false; |
367 | 293 |
368 // If we reached the end of both strings, then we are done. | 294 // If we reached the end of both strings, then we are done. |
369 if ((source_index == source.length()) && | 295 if ((source_index == source.length()) && |
(...skipping 15 matching lines...) Expand all Loading... |
385 if ((pattern[pattern_index] == L'?') || | 311 if ((pattern[pattern_index] == L'?') || |
386 (pattern[pattern_index] == source[source_index])) { | 312 (pattern[pattern_index] == source[source_index])) { |
387 return MatchPatternImpl(source, pattern, source_index + 1, | 313 return MatchPatternImpl(source, pattern, source_index + 1, |
388 pattern_index + 1); | 314 pattern_index + 1); |
389 } | 315 } |
390 | 316 |
391 // If we have a '*' then there are two possibilities | 317 // If we have a '*' then there are two possibilities |
392 // 1. We consider current character of source. | 318 // 1. We consider current character of source. |
393 // 2. We ignore current character of source. | 319 // 2. We ignore current character of source. |
394 if (pattern[pattern_index] == L'*') { | 320 if (pattern[pattern_index] == L'*') { |
395 return MatchPatternImpl(source, pattern, source_index + 1, | 321 return MatchPatternImpl(source, pattern, source_index + 1, pattern_index) || |
396 pattern_index) || | |
397 MatchPatternImpl(source, pattern, source_index, pattern_index + 1); | 322 MatchPatternImpl(source, pattern, source_index, pattern_index + 1); |
398 } | 323 } |
399 return false; | 324 return false; |
400 } | 325 } |
401 | 326 |
402 // Defines the type of whitespace characters typically found in strings. | 327 // Defines the type of whitespace characters typically found in strings. |
403 constexpr char kWhiteSpaces[] = " \t\n\r\f\v"; | 328 constexpr char kWhiteSpaces[] = " \t\n\r\f\v"; |
404 constexpr base::char16 kWhiteSpaces16[] = L" \t\n\r\f\v"; | 329 constexpr wchar_t kWhiteSpaces16[] = L" \t\n\r\f\v"; |
405 | 330 |
406 // Define specializations for white spaces based on the type of the string. | 331 // Define specializations for white spaces based on the type of the string. |
407 template<class StringType> StringType GetWhiteSpacesForType(); | 332 template <class StringType> |
408 template<> | 333 StringType GetWhiteSpacesForType(); |
409 base::string16 GetWhiteSpacesForType() { | 334 template <> |
| 335 std::wstring GetWhiteSpacesForType() { |
410 return kWhiteSpaces16; | 336 return kWhiteSpaces16; |
411 } | 337 } |
412 template<> | 338 template <> |
413 std::string GetWhiteSpacesForType() { | 339 std::string GetWhiteSpacesForType() { |
414 return kWhiteSpaces; | 340 return kWhiteSpaces; |
415 } | 341 } |
416 | 342 |
417 // Trim whitespaces from left & right | 343 // Trim whitespaces from left & right |
418 template<class StringType> | 344 template <class StringType> |
419 void TrimT(StringType* str) { | 345 void TrimT(StringType* str) { |
420 str->erase(str->find_last_not_of(GetWhiteSpacesForType<StringType>()) + 1); | 346 str->erase(str->find_last_not_of(GetWhiteSpacesForType<StringType>()) + 1); |
421 str->erase(0, str->find_first_not_of(GetWhiteSpacesForType<StringType>())); | 347 str->erase(0, str->find_first_not_of(GetWhiteSpacesForType<StringType>())); |
422 } | 348 } |
423 | 349 |
424 bool IsValidNumber(const std::string& str) { | 350 bool IsValidNumber(const std::string& str) { |
425 if (str.empty()) | 351 if (str.empty()) |
426 return false; | 352 return false; |
427 return std::all_of(str.begin(), str.end(), ::isdigit); | 353 return std::all_of(str.begin(), str.end(), ::isdigit); |
428 } | 354 } |
429 | 355 |
430 // Tokenizes a string based on a single character delimiter. | 356 // Tokenizes a string based on a single character delimiter. |
431 template<class StringType> | 357 template <class StringType> |
432 std::vector<StringType> TokenizeStringT( | 358 std::vector<StringType> TokenizeStringT( |
433 const StringType& str, | 359 const StringType& str, |
434 typename StringType::value_type delimiter, | 360 typename StringType::value_type delimiter, |
435 bool trim_spaces) { | 361 bool trim_spaces) { |
436 std::vector<StringType> tokens; | 362 std::vector<StringType> tokens; |
437 std::basic_istringstream<typename StringType::value_type> buffer(str); | 363 std::basic_istringstream<typename StringType::value_type> buffer(str); |
438 for (StringType token; std::getline(buffer, token, delimiter);) { | 364 for (StringType token; std::getline(buffer, token, delimiter);) { |
439 if (trim_spaces) | 365 if (trim_spaces) |
440 TrimT<StringType>(&token); | 366 TrimT<StringType>(&token); |
441 tokens.push_back(token); | 367 tokens.push_back(token); |
442 } | 368 } |
443 return tokens; | 369 return tokens; |
444 } | 370 } |
445 | 371 |
446 } // namespace | 372 } // namespace |
447 | 373 |
448 bool IsSxSChrome(const wchar_t* exe_path) { | 374 bool IsSxSChrome(const wchar_t* exe_path) { |
449 return wcsstr(exe_path, L"Chrome SxS\\Application") != nullptr; | 375 return ::wcsstr(exe_path, L"Chrome SxS\\Application") != nullptr; |
450 } | 376 } |
451 | 377 |
452 bool IsSystemInstall(const wchar_t* exe_path) { | 378 bool IsSystemInstall(const wchar_t* exe_path) { |
453 wchar_t program_dir[MAX_PATH] = {}; | 379 wchar_t program_dir[MAX_PATH] = {}; |
454 DWORD ret = ::GetEnvironmentVariable(L"PROGRAMFILES", program_dir, | 380 DWORD ret = ::GetEnvironmentVariable(L"PROGRAMFILES", program_dir, MAX_PATH); |
455 arraysize(program_dir)); | 381 if (ret && ret < MAX_PATH && !::wcsnicmp(exe_path, program_dir, ret)) { |
456 if (ret && ret < arraysize(program_dir) && | |
457 !wcsnicmp(exe_path, program_dir, ret)) { | |
458 return true; | 382 return true; |
459 } | 383 } |
460 | 384 |
461 ret = ::GetEnvironmentVariable(L"PROGRAMFILES(X86)", program_dir, | 385 ret = ::GetEnvironmentVariable(L"PROGRAMFILES(X86)", program_dir, MAX_PATH); |
462 arraysize(program_dir)); | 386 if (ret && ret < MAX_PATH && !::wcsnicmp(exe_path, program_dir, ret)) { |
463 if (ret && ret < arraysize(program_dir) && | |
464 !wcsnicmp(exe_path, program_dir, ret)) { | |
465 return true; | 387 return true; |
466 } | 388 } |
467 | 389 |
468 return false; | 390 return false; |
469 } | 391 } |
470 | 392 |
471 bool IsMultiInstall(bool is_system_install) { | 393 bool IsMultiInstall(bool is_system_install) { |
472 base::string16 args; | 394 std::wstring args; |
473 if (!ReadKeyValueString(is_system_install, kRegPathClientState, | 395 |
474 kAppGuidGoogleChrome, kUninstallArgumentsField, | 396 std::wstring full_key_path(kRegPathClientState); |
475 &args)) { | 397 full_key_path.append(1, L'\\'); |
| 398 full_key_path.append(kAppGuidGoogleChrome); |
| 399 if (!nt::QueryRegValueSZ((is_system_install ? nt::HKLM : nt::HKCU), |
| 400 full_key_path.c_str(), kUninstallArgumentsField, |
| 401 &args)) |
476 return false; | 402 return false; |
477 } | 403 |
478 return args.find(L"--multi-install") != base::string16::npos; | 404 return (args.find(L"--multi-install") != std::wstring::npos); |
479 } | 405 } |
480 | 406 |
481 bool GetCollectStatsConsent() { | 407 bool GetCollectStatsConsent() { |
482 return GetCollectStatsConsentImpl(GetCurrentProcessExePath()); | 408 return GetCollectStatsConsentImpl(GetCurrentProcessExePath()); |
483 } | 409 } |
484 | 410 |
485 bool GetCollectStatsConsentForTesting(const base::string16& exe_path) { | 411 bool GetCollectStatsConsentForTesting(const std::wstring& exe_path) { |
486 return GetCollectStatsConsentImpl(exe_path); | 412 return GetCollectStatsConsentImpl(exe_path); |
487 } | 413 } |
488 | 414 |
489 bool ReportingIsEnforcedByPolicy(bool* metrics_is_enforced_by_policy) { | 415 bool ReportingIsEnforcedByPolicy(bool* metrics_is_enforced_by_policy) { |
490 HKEY key = nullptr; | |
491 DWORD value = 0; | 416 DWORD value = 0; |
492 BYTE* value_bytes = reinterpret_cast<BYTE*>(&value); | |
493 DWORD size = sizeof(value); | |
494 DWORD type = REG_DWORD; | |
495 | 417 |
496 if (::RegOpenKeyEx(HKEY_LOCAL_MACHINE, kRegPathChromePolicy, 0, | 418 // First, try HKLM. |
497 KEY_QUERY_VALUE, &key) == ERROR_SUCCESS) { | 419 if (nt::QueryRegValueDWORD(nt::HKLM, kRegPathChromePolicy, |
498 if (::RegQueryValueEx(key, kMetricsReportingEnabled, 0, &type, | 420 kMetricsReportingEnabled, &value)) { |
499 value_bytes, &size) == ERROR_SUCCESS) { | 421 *metrics_is_enforced_by_policy = (value != 0); |
500 *metrics_is_enforced_by_policy = value != 0; | 422 return true; |
501 } | |
502 ::RegCloseKey(key); | |
503 return size == sizeof(value); | |
504 } | 423 } |
505 | 424 |
506 if (::RegOpenKeyEx(HKEY_CURRENT_USER, kRegPathChromePolicy, 0, | 425 // Second, try HKCU. |
507 KEY_QUERY_VALUE, &key) == ERROR_SUCCESS) { | 426 if (nt::QueryRegValueDWORD(nt::HKCU, kRegPathChromePolicy, |
508 if (::RegQueryValueEx(key, kMetricsReportingEnabled, 0, &type, | 427 kMetricsReportingEnabled, &value)) { |
509 value_bytes, &size) == ERROR_SUCCESS) { | 428 *metrics_is_enforced_by_policy = (value != 0); |
510 *metrics_is_enforced_by_policy = value != 0; | 429 return true; |
511 } | |
512 ::RegCloseKey(key); | |
513 return size == sizeof(value); | |
514 } | 430 } |
515 | 431 |
516 return false; | 432 return false; |
517 } | 433 } |
518 | 434 |
519 void InitializeProcessType() { | 435 void InitializeProcessType() { |
520 assert(g_process_type == ProcessType::UNINITIALIZED); | 436 assert(g_process_type == ProcessType::UNINITIALIZED); |
521 typedef bool (*IsSandboxedProcessFunc)(); | 437 typedef bool (*IsSandboxedProcessFunc)(); |
522 IsSandboxedProcessFunc is_sandboxed_process_func = | 438 IsSandboxedProcessFunc is_sandboxed_process_func = |
523 reinterpret_cast<IsSandboxedProcessFunc>( | 439 reinterpret_cast<IsSandboxedProcessFunc>( |
524 GetProcAddress(GetModuleHandle(nullptr), "IsSandboxedProcess")); | 440 ::GetProcAddress(::GetModuleHandle(nullptr), "IsSandboxedProcess")); |
525 if (is_sandboxed_process_func && is_sandboxed_process_func()) { | 441 if (is_sandboxed_process_func && is_sandboxed_process_func()) { |
526 g_process_type = ProcessType::NON_BROWSER_PROCESS; | 442 g_process_type = ProcessType::NON_BROWSER_PROCESS; |
527 return; | 443 return; |
528 } | 444 } |
529 | 445 |
530 // TODO(robertshield): Drop the command line check when we drop support for | 446 // TODO(robertshield): Drop the command line check when we drop support for |
531 // enabling chrome_elf in unsandboxed processes. | 447 // enabling chrome_elf in unsandboxed processes. |
532 const wchar_t* command_line = GetCommandLine(); | 448 const wchar_t* command_line = GetCommandLine(); |
533 if (command_line && wcsstr(command_line, L"--type")) { | 449 if (command_line && ::wcsstr(command_line, L"--type")) { |
534 g_process_type = ProcessType::NON_BROWSER_PROCESS; | 450 g_process_type = ProcessType::NON_BROWSER_PROCESS; |
535 return; | 451 return; |
536 } | 452 } |
537 | 453 |
538 g_process_type = ProcessType::BROWSER_PROCESS; | 454 g_process_type = ProcessType::BROWSER_PROCESS; |
539 } | 455 } |
540 | 456 |
541 bool IsNonBrowserProcess() { | 457 bool IsNonBrowserProcess() { |
542 assert(g_process_type != ProcessType::UNINITIALIZED); | 458 assert(g_process_type != ProcessType::UNINITIALIZED); |
543 return g_process_type == ProcessType::NON_BROWSER_PROCESS; | 459 return g_process_type == ProcessType::NON_BROWSER_PROCESS; |
544 } | 460 } |
545 | 461 |
546 bool GetDefaultUserDataDirectory(base::string16* result) { | 462 bool GetDefaultUserDataDirectory(std::wstring* result) { |
547 static const wchar_t kLocalAppData[] = L"%LOCALAPPDATA%"; | 463 static const wchar_t kLocalAppData[] = L"%LOCALAPPDATA%"; |
548 | 464 |
549 std::unique_ptr<wchar_t> user_data_dir_path; | 465 std::unique_ptr<wchar_t> user_data_dir_path; |
550 | 466 |
551 // This environment variable should be set on Windows 7 and up. | 467 // This environment variable should be set on Windows 7 and up. |
552 // If we fail to find this variable then we default to the temporary files | 468 // If we fail to find this variable then we default to the temporary files |
553 // path. | 469 // path. |
554 DWORD size = ::ExpandEnvironmentStrings(kLocalAppData, nullptr, 0); | 470 DWORD size = ::ExpandEnvironmentStrings(kLocalAppData, nullptr, 0); |
555 if (size) { | 471 if (size) { |
556 user_data_dir_path.reset(new wchar_t[size]); | 472 user_data_dir_path.reset(new wchar_t[size]); |
557 if (::ExpandEnvironmentStrings(kLocalAppData, | 473 if (::ExpandEnvironmentStrings(kLocalAppData, user_data_dir_path.get(), |
558 user_data_dir_path.get(), | |
559 size) != size) { | 474 size) != size) { |
560 user_data_dir_path.reset(); | 475 user_data_dir_path.reset(); |
561 } | 476 } |
562 } | 477 } |
563 // We failed to find the %LOCALAPPDATA% folder. Fallback to the temporary | 478 // We failed to find the %LOCALAPPDATA% folder. Fallback to the temporary |
564 // files path. If we fail to find this we bail. | 479 // files path. If we fail to find this we bail. |
565 if (!user_data_dir_path.get()) { | 480 if (!user_data_dir_path.get()) { |
566 size = ::GetTempPath(0, nullptr); | 481 size = ::GetTempPath(0, nullptr); |
567 if (!size) | 482 if (!size) |
568 return false; | 483 return false; |
569 user_data_dir_path.reset(new wchar_t[size + 1]); | 484 user_data_dir_path.reset(new wchar_t[size + 1]); |
570 if (::GetTempPath(size + 1, user_data_dir_path.get()) != size) | 485 if (::GetTempPath(size + 1, user_data_dir_path.get()) != size) |
571 return false; | 486 return false; |
572 } | 487 } |
573 | 488 |
574 base::string16 install_sub_directory = GetChromeInstallSubDirectory(); | 489 std::wstring install_sub_directory = GetChromeInstallSubDirectory(); |
575 | 490 |
576 *result = user_data_dir_path.get(); | 491 *result = user_data_dir_path.get(); |
577 if ((*result)[result->length() - 1] != L'\\') | 492 if ((*result)[result->length() - 1] != L'\\') |
578 result->append(L"\\"); | 493 result->append(L"\\"); |
579 result->append(install_sub_directory); | 494 result->append(install_sub_directory); |
580 result->append(L"\\"); | 495 result->append(L"\\"); |
581 result->append(kUserDataDirname); | 496 result->append(kUserDataDirname); |
582 return true; | 497 return true; |
583 } | 498 } |
584 | 499 |
585 bool GetDefaultCrashDumpLocation(base::string16* crash_dir) { | 500 bool GetDefaultCrashDumpLocation(std::wstring* crash_dir) { |
586 // In order to be able to start crash handling very early, we do not rely on | 501 // In order to be able to start crash handling very early, we do not rely on |
587 // chrome's PathService entries (for DIR_CRASH_DUMPS) being available on | 502 // chrome's PathService entries (for DIR_CRASH_DUMPS) being available on |
588 // Windows. See https://crbug.com/564398. | 503 // Windows. See https://crbug.com/564398. |
589 if (!GetDefaultUserDataDirectory(crash_dir)) | 504 if (!GetDefaultUserDataDirectory(crash_dir)) |
590 return false; | 505 return false; |
591 | 506 |
592 // We have to make sure the user data dir exists on first run. See | 507 // We have to make sure the user data dir exists on first run. See |
593 // http://crbug.com/591504. | 508 // http://crbug.com/591504. |
594 if (!RecursiveDirectoryCreate(crash_dir->c_str())) | 509 if (!RecursiveDirectoryCreate(crash_dir->c_str())) |
595 return false; | 510 return false; |
596 crash_dir->append(L"\\Crashpad"); | 511 crash_dir->append(L"\\Crashpad"); |
597 return true; | 512 return true; |
598 } | 513 } |
599 | 514 |
600 | |
601 std::string GetEnvironmentString(const std::string& variable_name) { | 515 std::string GetEnvironmentString(const std::string& variable_name) { |
602 return UTF16ToUTF8(GetEnvironmentString16(UTF8ToUTF16(variable_name))); | 516 return UTF16ToUTF8(GetEnvironmentString16(UTF8ToUTF16(variable_name))); |
603 } | 517 } |
604 | 518 |
605 base::string16 GetEnvironmentString16(const base::string16& variable_name) { | 519 std::wstring GetEnvironmentString16(const std::wstring& variable_name) { |
606 DWORD value_length = | 520 DWORD value_length = |
607 ::GetEnvironmentVariable(variable_name.c_str(), nullptr, 0); | 521 ::GetEnvironmentVariable(variable_name.c_str(), nullptr, 0); |
608 if (value_length == 0) | 522 if (value_length == 0) |
609 return base::string16(); | 523 return std::wstring(); |
610 std::unique_ptr<wchar_t[]> value(new wchar_t[value_length]); | 524 std::unique_ptr<wchar_t[]> value(new wchar_t[value_length]); |
611 ::GetEnvironmentVariable(variable_name.c_str(), value.get(), value_length); | 525 ::GetEnvironmentVariable(variable_name.c_str(), value.get(), value_length); |
612 return value.get(); | 526 return value.get(); |
613 } | 527 } |
614 | 528 |
615 bool SetEnvironmentString(const std::string& variable_name, | 529 bool SetEnvironmentString(const std::string& variable_name, |
616 const std::string& new_value) { | 530 const std::string& new_value) { |
617 return SetEnvironmentString16(UTF8ToUTF16(variable_name), | 531 return SetEnvironmentString16(UTF8ToUTF16(variable_name), |
618 UTF8ToUTF16(new_value)); | 532 UTF8ToUTF16(new_value)); |
619 } | 533 } |
620 | 534 |
621 bool SetEnvironmentString16(const base::string16& variable_name, | 535 bool SetEnvironmentString16(const std::wstring& variable_name, |
622 const base::string16& new_value) { | 536 const std::wstring& new_value) { |
623 return !!SetEnvironmentVariable(variable_name.c_str(), new_value.c_str()); | 537 return !!SetEnvironmentVariable(variable_name.c_str(), new_value.c_str()); |
624 } | 538 } |
625 | 539 |
626 bool HasEnvironmentVariable(const std::string& variable_name) { | 540 bool HasEnvironmentVariable(const std::string& variable_name) { |
627 return HasEnvironmentVariable16(UTF8ToUTF16(variable_name)); | 541 return HasEnvironmentVariable16(UTF8ToUTF16(variable_name)); |
628 } | 542 } |
629 | 543 |
630 bool HasEnvironmentVariable16(const base::string16& variable_name) { | 544 bool HasEnvironmentVariable16(const std::wstring& variable_name) { |
631 return !!::GetEnvironmentVariable(variable_name.c_str(), nullptr, 0); | 545 return !!::GetEnvironmentVariable(variable_name.c_str(), nullptr, 0); |
632 } | 546 } |
633 | 547 |
634 bool GetExecutableVersionDetails(const base::string16& exe_path, | 548 bool GetExecutableVersionDetails(const std::wstring& exe_path, |
635 base::string16* product_name, | 549 std::wstring* product_name, |
636 base::string16* version, | 550 std::wstring* version, |
637 base::string16* special_build, | 551 std::wstring* special_build, |
638 base::string16* channel_name) { | 552 std::wstring* channel_name) { |
639 assert(product_name); | 553 assert(product_name); |
640 assert(version); | 554 assert(version); |
641 assert(special_build); | 555 assert(special_build); |
642 assert(channel_name); | 556 assert(channel_name); |
643 | 557 |
644 // Default values in case we don't find a version resource. | 558 // Default values in case we don't find a version resource. |
645 *product_name = L"Chrome"; | 559 *product_name = L"Chrome"; |
646 *version = L"0.0.0.0-devel"; | 560 *version = L"0.0.0.0-devel"; |
647 *channel_name = kChromeChannelUnknown; | 561 *channel_name = kChromeChannelUnknown; |
648 special_build->clear(); | 562 special_build->clear(); |
649 | 563 |
650 DWORD dummy = 0; | 564 DWORD dummy = 0; |
651 DWORD length = ::GetFileVersionInfoSize(exe_path.c_str(), &dummy); | 565 DWORD length = ::GetFileVersionInfoSize(exe_path.c_str(), &dummy); |
652 if (length) { | 566 if (length) { |
653 std::unique_ptr<char> data(new char[length]); | 567 std::unique_ptr<char> data(new char[length]); |
654 if (::GetFileVersionInfo(exe_path.c_str(), dummy, length, | 568 if (::GetFileVersionInfo(exe_path.c_str(), dummy, length, data.get())) { |
655 data.get())) { | |
656 GetValueFromVersionResource(data.get(), L"ProductVersion", version); | 569 GetValueFromVersionResource(data.get(), L"ProductVersion", version); |
657 | 570 |
658 base::string16 official_build; | 571 std::wstring official_build; |
659 GetValueFromVersionResource(data.get(), L"Official Build", | 572 GetValueFromVersionResource(data.get(), L"Official Build", |
660 &official_build); | 573 &official_build); |
661 if (official_build != L"1") | 574 if (official_build != L"1") |
662 version->append(L"-devel"); | 575 version->append(L"-devel"); |
663 GetValueFromVersionResource(data.get(), L"ProductShortName", | 576 GetValueFromVersionResource(data.get(), L"ProductShortName", |
664 product_name); | 577 product_name); |
665 GetValueFromVersionResource(data.get(), L"SpecialBuild", special_build); | 578 GetValueFromVersionResource(data.get(), L"SpecialBuild", special_build); |
666 } | 579 } |
667 } | 580 } |
668 GetChromeChannelName(!IsSystemInstall(exe_path.c_str()), true, channel_name); | 581 GetChromeChannelName(!IsSystemInstall(exe_path.c_str()), true, channel_name); |
669 return true; | 582 return true; |
670 } | 583 } |
671 | 584 |
672 void GetChromeChannelName(bool is_per_user_install, | 585 void GetChromeChannelName(bool is_per_user_install, |
673 bool add_modifier, | 586 bool add_modifier, |
674 base::string16* channel_name) { | 587 std::wstring* channel_name) { |
675 channel_name->clear(); | 588 channel_name->clear(); |
676 // TODO(ananta) | 589 // TODO(ananta) |
677 // http://crbug.com/604923 | 590 // http://crbug.com/604923 |
678 // Unify this with the chrome/installer/util/channel_info.h/.cc. | 591 // Unify this with the chrome/installer/util/channel_info.h/.cc. |
679 if (IsSxSChrome(GetCurrentProcessExePath().c_str())) { | 592 if (IsSxSChrome(GetCurrentProcessExePath().c_str())) { |
680 *channel_name = L"canary"; | 593 *channel_name = L"canary"; |
681 } else { | 594 } else { |
682 base::string16 value; | 595 std::wstring value; |
683 bool channel_available = false; | 596 bool channel_available = false; |
684 bool is_multi_install = IsMultiInstall(!is_per_user_install); | 597 bool is_multi_install = IsMultiInstall(!is_per_user_install); |
685 if (is_multi_install) { | 598 if (is_multi_install) { |
686 channel_available = ReadKeyValueString(!is_per_user_install, | 599 std::wstring full_key_path(kRegPathClientState); |
687 kRegPathClientState, | 600 full_key_path.append(1, L'\\'); |
688 kAppGuidGoogleBinaries, | 601 full_key_path.append(kAppGuidGoogleBinaries); |
689 kRegApField, | 602 channel_available = |
690 &value); | 603 nt::QueryRegValueSZ(is_per_user_install ? nt::HKCU : nt::HKLM, |
| 604 full_key_path.c_str(), kRegApField, &value); |
691 } else { | 605 } else { |
692 channel_available = ReadKeyValueString(!is_per_user_install, | 606 std::wstring full_key_path(kRegPathClientState); |
693 kRegPathClientState, | 607 full_key_path.append(1, L'\\'); |
694 kAppGuidGoogleChrome, | 608 full_key_path.append(kAppGuidGoogleChrome); |
695 kRegApField, | 609 channel_available = |
696 &value); | 610 nt::QueryRegValueSZ(is_per_user_install ? nt::HKCU : nt::HKLM, |
| 611 full_key_path.c_str(), kRegApField, &value); |
697 } | 612 } |
698 if (channel_available) { | 613 if (channel_available) { |
699 static const wchar_t kChromeChannelBetaPattern[] = L"1?1-*"; | 614 static const wchar_t kChromeChannelBetaPattern[] = L"1?1-*"; |
700 static const wchar_t kChromeChannelBetaX64Pattern[] = L"*x64-beta*"; | 615 static const wchar_t kChromeChannelBetaX64Pattern[] = L"*x64-beta*"; |
701 static const wchar_t kChromeChannelDevPattern[] = L"2?0-d*"; | 616 static const wchar_t kChromeChannelDevPattern[] = L"2?0-d*"; |
702 static const wchar_t kChromeChannelDevX64Pattern[] = L"*x64-dev*"; | 617 static const wchar_t kChromeChannelDevX64Pattern[] = L"*x64-dev*"; |
703 | 618 |
704 std::transform(value.begin(), value.end(), value.begin(), ::tolower); | 619 std::transform(value.begin(), value.end(), value.begin(), ::tolower); |
705 | 620 |
706 // Empty channel names or those containing "stable" should be reported as | 621 // Empty channel names or those containing "stable" should be reported as |
707 // an empty string. Exceptions being if |add_modifier| is true and this | 622 // an empty string. Exceptions being if |add_modifier| is true and this |
708 // is a multi install. In that case we report the channel name as "-m". | 623 // is a multi install. In that case we report the channel name as "-m". |
709 if (value.empty() || (value.find(kChromeChannelStableExplicit) | 624 if (value.empty() || |
710 != base::string16::npos)) { | 625 (value.find(kChromeChannelStableExplicit) != std::wstring::npos)) { |
711 if (add_modifier && is_multi_install) | 626 if (add_modifier && is_multi_install) |
712 channel_name->append(L"-m"); | 627 channel_name->append(L"-m"); |
713 return; | 628 return; |
714 } | 629 } |
715 | 630 |
716 if (MatchPattern(value, kChromeChannelDevPattern) || | 631 if (MatchPattern(value, kChromeChannelDevPattern) || |
717 MatchPattern(value, kChromeChannelDevX64Pattern)) { | 632 MatchPattern(value, kChromeChannelDevX64Pattern)) { |
718 channel_name->assign(kChromeChannelDev); | 633 channel_name->assign(kChromeChannelDev); |
719 } | 634 } |
720 | 635 |
(...skipping 13 matching lines...) Expand all Loading... |
734 } else { | 649 } else { |
735 *channel_name = kChromeChannelUnknown; | 650 *channel_name = kChromeChannelUnknown; |
736 } | 651 } |
737 } | 652 } |
738 } | 653 } |
739 | 654 |
740 std::string GetGoogleUpdateVersion() { | 655 std::string GetGoogleUpdateVersion() { |
741 // TODO(ananta) | 656 // TODO(ananta) |
742 // Consider whether Chromium should connect to Google update to manage | 657 // Consider whether Chromium should connect to Google update to manage |
743 // updates. Should this be returning an empty string for Chromium builds?. | 658 // updates. Should this be returning an empty string for Chromium builds?. |
744 base::string16 update_version; | 659 std::wstring update_version; |
745 if (ReadKeyValueString(IsSystemInstall(GetCurrentProcessExePath().c_str()), | 660 if (nt::QueryRegValueSZ(nt::AUTO, kRegPathGoogleUpdate, |
746 kRegPathGoogleUpdate, | 661 kRegGoogleUpdateVersion, &update_version)) |
747 nullptr, | |
748 kRegGoogleUpdateVersion, | |
749 &update_version)) { | |
750 return UTF16ToUTF8(update_version); | 662 return UTF16ToUTF8(update_version); |
751 } | 663 |
752 return std::string(); | 664 return std::string(); |
753 } | 665 } |
754 | 666 |
755 base::string16 GetChromeInstallSubDirectory() { | 667 std::wstring GetChromeInstallSubDirectory() { |
756 #if defined(GOOGLE_CHROME_BUILD) | 668 #if defined(GOOGLE_CHROME_BUILD) |
757 base::string16 result = kGoogleChromeInstallSubDir1; | 669 std::wstring result = kGoogleChromeInstallSubDir1; |
758 result += L"\\"; | 670 result += L"\\"; |
759 result += kGoogleChromeInstallSubDir2; | 671 result += kGoogleChromeInstallSubDir2; |
760 if (IsSxSChrome(GetCurrentProcessExePath().c_str())) | 672 if (IsSxSChrome(GetCurrentProcessExePath().c_str())) |
761 result += kSxSSuffix; | 673 result += kSxSSuffix; |
762 return result; | 674 return result; |
763 #else | 675 #else |
764 return base::string16(kChromiumInstallSubDir); | 676 return std::wstring(kChromiumInstallSubDir); |
765 #endif | 677 #endif |
766 } | 678 } |
767 | 679 |
768 base::string16 GetBrowserCrashDumpAttemptsRegistryPath() { | 680 std::wstring GetBrowserCrashDumpAttemptsRegistryPath() { |
769 base::string16 registry_path = L"Software\\"; | 681 std::wstring registry_path = L"Software\\"; |
770 registry_path += GetChromeInstallSubDirectory(); | 682 registry_path += GetChromeInstallSubDirectory(); |
771 registry_path += kBrowserCrashDumpMetricsSubKey; | 683 registry_path += kBrowserCrashDumpMetricsSubKey; |
772 return registry_path; | 684 return registry_path; |
773 } | 685 } |
774 | 686 |
775 bool MatchPattern(const base::string16& source, | 687 bool MatchPattern(const std::wstring& source, const std::wstring& pattern) { |
776 const base::string16& pattern) { | 688 assert(pattern.find(L"**") == std::wstring::npos); |
777 assert(pattern.find(L"**") == base::string16::npos); | |
778 return MatchPatternImpl(source, pattern, 0, 0); | 689 return MatchPatternImpl(source, pattern, 0, 0); |
779 } | 690 } |
780 | 691 |
781 std::string UTF16ToUTF8(const base::string16& source) { | 692 std::string UTF16ToUTF8(const std::wstring& source) { |
782 if (source.empty() || | 693 if (source.empty() || |
783 static_cast<int>(source.size()) > std::numeric_limits<int>::max()) { | 694 static_cast<int>(source.size()) > std::numeric_limits<int>::max()) { |
784 return std::string(); | 695 return std::string(); |
785 } | 696 } |
786 int size = ::WideCharToMultiByte(CP_UTF8, 0, &source[0], | 697 int size = ::WideCharToMultiByte(CP_UTF8, 0, &source[0], |
787 static_cast<int>(source.size()), nullptr, 0, | 698 static_cast<int>(source.size()), nullptr, 0, |
788 nullptr, nullptr); | 699 nullptr, nullptr); |
789 std::string result(size, '\0'); | 700 std::string result(size, '\0'); |
790 if (::WideCharToMultiByte(CP_UTF8, 0, &source[0], | 701 if (::WideCharToMultiByte(CP_UTF8, 0, &source[0], |
791 static_cast<int>(source.size()), &result[0], size, | 702 static_cast<int>(source.size()), &result[0], size, |
792 nullptr, nullptr) != size) { | 703 nullptr, nullptr) != size) { |
793 assert(false); | 704 assert(false); |
794 return std::string(); | 705 return std::string(); |
795 } | 706 } |
796 return result; | 707 return result; |
797 } | 708 } |
798 | 709 |
799 base::string16 UTF8ToUTF16(const std::string& source) { | 710 std::wstring UTF8ToUTF16(const std::string& source) { |
800 if (source.empty() || | 711 if (source.empty() || |
801 static_cast<int>(source.size()) > std::numeric_limits<int>::max()) { | 712 static_cast<int>(source.size()) > std::numeric_limits<int>::max()) { |
802 return base::string16(); | 713 return std::wstring(); |
803 } | 714 } |
804 int size = ::MultiByteToWideChar(CP_UTF8, 0, &source[0], | 715 int size = ::MultiByteToWideChar(CP_UTF8, 0, &source[0], |
805 static_cast<int>(source.size()), nullptr, 0); | 716 static_cast<int>(source.size()), nullptr, 0); |
806 base::string16 result(size, L'\0'); | 717 std::wstring result(size, L'\0'); |
807 if (::MultiByteToWideChar(CP_UTF8, 0, &source[0], | 718 if (::MultiByteToWideChar(CP_UTF8, 0, &source[0], |
808 static_cast<int>(source.size()), &result[0], | 719 static_cast<int>(source.size()), &result[0], |
809 size) != size) { | 720 size) != size) { |
810 assert(false); | 721 assert(false); |
811 return base::string16(); | 722 return std::wstring(); |
812 } | 723 } |
813 return result; | 724 return result; |
814 } | 725 } |
815 | 726 |
816 std::vector<std::string> TokenizeString(const std::string& str, | 727 std::vector<std::string> TokenizeString(const std::string& str, |
817 char delimiter, | 728 char delimiter, |
818 bool trim_spaces) { | 729 bool trim_spaces) { |
819 return TokenizeStringT<std::string>(str, delimiter, trim_spaces); | 730 return TokenizeStringT<std::string>(str, delimiter, trim_spaces); |
820 } | 731 } |
821 | 732 |
822 std::vector<base::string16> TokenizeString16(const base::string16& str, | 733 std::vector<std::wstring> TokenizeString16(const std::wstring& str, |
823 base::char16 delimiter, | 734 wchar_t delimiter, |
824 bool trim_spaces) { | 735 bool trim_spaces) { |
825 return TokenizeStringT<base::string16>(str, delimiter, trim_spaces); | 736 return TokenizeStringT<std::wstring>(str, delimiter, trim_spaces); |
826 } | 737 } |
827 | 738 |
828 bool CompareVersionStrings(const std::string& version1, | 739 bool CompareVersionStrings(const std::string& version1, |
829 const std::string& version2, | 740 const std::string& version2, |
830 int* result) { | 741 int* result) { |
831 if (version1.empty() || version2.empty()) | 742 if (version1.empty() || version2.empty()) |
832 return false; | 743 return false; |
833 | 744 |
834 // Tokenize both version strings with "." as the separator. If either of | 745 // Tokenize both version strings with "." as the separator. If either of |
835 // the returned token lists are empty then bail. | 746 // the returned token lists are empty then bail. |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
945 switch_value_end_offset = command_line_copy.length(); | 856 switch_value_end_offset = command_line_copy.length(); |
946 | 857 |
947 std::string switch_value = command_line_copy.substr( | 858 std::string switch_value = command_line_copy.substr( |
948 switch_value_start_offset, | 859 switch_value_start_offset, |
949 switch_value_end_offset - (switch_offset + switch_token.length())); | 860 switch_value_end_offset - (switch_offset + switch_token.length())); |
950 TrimT<std::string>(&switch_value); | 861 TrimT<std::string>(&switch_value); |
951 return switch_value; | 862 return switch_value; |
952 } | 863 } |
953 | 864 |
954 } // namespace install_static | 865 } // namespace install_static |
OLD | NEW |