Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome_elf/chrome_elf_util.h" | |
| 6 | |
| 7 #include "base/strings/string16.h" | |
| 8 #include "base/win/registry.h" | |
|
robertshield
2014/02/11 22:26:58
To double check: this doesn't add any new dependen
Cait (Slow)
2014/02/12 19:15:41
It does :( I've removed it, and reinvented a few w
| |
| 9 | |
| 10 namespace { | |
| 11 | |
| 12 const wchar_t kRegPathClients[] = L"Software\\Google\\Update\\Clients"; | |
| 13 const wchar_t kRegPathClientState[] = L"Software\\Google\\Update\\ClientState"; | |
| 14 const wchar_t kRegPathClientStateMedium[] = | |
| 15 L"Software\\Google\\Update\\ClientStateMedium"; | |
| 16 const wchar_t kRegValueUsageStats[] = L"usagestats"; | |
| 17 const wchar_t kRegValuePV[] = L"pv"; | |
| 18 | |
| 19 const wchar_t kCanaryGuid[] = | |
| 20 L"4EA16AC7-FD5A-47C3-875B-DBF4A2008C20"; | |
| 21 const wchar_t kChromeSingleInstallGuid[] = | |
| 22 L"8A69D345-D564-463c-AFF1-A69D9E530F96"; | |
| 23 const wchar_t kChromeMultiInstallGuid[] = | |
| 24 L"4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D"; | |
| 25 | |
| 26 bool ReadKeyValue(bool system_install, const wchar_t* key_path, | |
| 27 const wchar_t* guid, const wchar_t* value_to_read, | |
| 28 DWORD* value_out) { | |
| 29 base::win::RegKey key; | |
|
robertshield
2014/02/11 22:26:58
nit: declare |key| next to where it is used.
Cait (Slow)
2014/02/12 19:15:41
Done.
| |
| 30 *value_out = 0; | |
| 31 bool have_value = false; | |
| 32 | |
| 33 base::string16 full_key_path = base::string16(key_path).append(1, L'\\') | |
| 34 .append(guid); | |
|
robertshield
2014/02/11 22:26:58
This would be one less copy:
base::string16 full_
Cait (Slow)
2014/02/12 19:15:41
Done.
| |
| 35 | |
| 36 LONG result = key.Open(system_install? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, | |
| 37 full_key_path.c_str(), KEY_QUERY_VALUE); | |
|
robertshield
2014/02/11 22:26:58
could shorten the last few lines to:
return key.O
| |
| 38 | |
| 39 if (result != ERROR_SUCCESS) { | |
| 40 return false; | |
| 41 } | |
| 42 | |
| 43 return key.ReadValueDW(value_to_read, value_out) == ERROR_SUCCESS; | |
| 44 } | |
| 45 | |
| 46 } // namespace | |
| 47 | |
| 48 bool IsCanary(LPWSTR exe_path) { | |
| 49 wchar_t* found = wcsstr(exe_path, L"Google\\Chrome SxS"); | |
| 50 return !!found; | |
| 51 } | |
| 52 | |
| 53 bool IsSystemInstall(LPWSTR exe_path) { | |
| 54 bool found = wcsncmp(exe_path, L"C:\\Program Files", 15) == 0; | |
|
robertshield
2014/02/11 22:26:58
We can't use shell apis to get the thing the syste
Cait (Slow)
2014/02/12 19:15:41
Unfortunately this check will be one of the first
robertshield
2014/02/12 21:12:37
GetEnvironmentVariable is a kernel32 function.
| |
| 55 return found; | |
| 56 } | |
| 57 | |
| 58 bool IsMultiInstall(LPWSTR exe_path) { | |
| 59 DWORD value = 0; | |
| 60 return ReadKeyValue(IsSystemInstall(exe_path), kRegPathClients, | |
| 61 kChromeMultiInstallGuid, kRegValuePV, &value); | |
| 62 } | |
| 63 | |
| 64 bool AreUsageStatsEnabled() { | |
| 65 DWORD out_value = 0; | |
| 66 wchar_t exe_path[MAX_PATH] = {}; | |
| 67 if (!GetModuleFileNameW(NULL, exe_path, MAX_PATH)) | |
| 68 return false; | |
| 69 | |
| 70 bool system_install = IsSystemInstall(exe_path); | |
| 71 bool is_canary = IsCanary(exe_path); | |
|
robertshield
2014/02/11 22:26:58
is_canary is only used once, could drop the temp v
Cait (Slow)
2014/02/12 19:15:41
Done.
| |
| 72 | |
| 73 const wchar_t* chrome_guid = IsMultiInstall(exe_path) ? | |
| 74 kChromeMultiInstallGuid : kChromeSingleInstallGuid; | |
| 75 | |
| 76 if (is_canary) { | |
| 77 return ReadKeyValue(false /*user level install*/, kRegPathClientState, | |
| 78 kCanaryGuid, kRegValueUsageStats, &out_value) && | |
| 79 out_value == 1; | |
| 80 } else if (system_install) { | |
| 81 return (ReadKeyValue(system_install, kRegPathClientStateMedium, | |
| 82 chrome_guid, kRegValueUsageStats, &out_value) || | |
| 83 ReadKeyValue(system_install, kRegPathClientState, | |
| 84 chrome_guid, kRegValueUsageStats, &out_value)) && | |
| 85 out_value == 1; | |
| 86 } else { // user-level install: | |
| 87 return ReadKeyValue(system_install, kRegPathClientState, | |
| 88 chrome_guid, kRegValueUsageStats, &out_value) && | |
| 89 out_value == 1; | |
| 90 } | |
| 91 return false; | |
| 92 } | |
| OLD | NEW |