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

Side by Side Diff: chrome/install_static/install_util.cc

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

Powered by Google App Engine
This is Rietveld 408576698