| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/tools/disable_outdated_build_detector/google_update_integration
.h" | 5 #include "chrome/tools/disable_outdated_build_detector/google_update_integration
.h" |
| 6 | 6 |
| 7 #include "base/strings/string_util.h" | 7 #include <stdlib.h> |
| 8 #include "base/strings/stringprintf.h" | |
| 9 #include "base/win/registry.h" | |
| 10 | 8 |
| 11 uint32_t OpenClientStateKey(bool system_level, | 9 #include <algorithm> |
| 12 App app, | 10 |
| 13 base::win::RegKey* key) { | 11 uint32_t OpenClientStateKey(bool system_level, App app, HKEY* key) { |
| 14 #if defined(GOOGLE_CHROME_BUILD) | 12 #if defined(GOOGLE_CHROME_BUILD) |
| 15 constexpr wchar_t kChromeAppGuid[] = | 13 constexpr wchar_t kChromeAppGuid[] = |
| 16 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; | 14 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; |
| 17 constexpr wchar_t kBinariesAppGuid[] = | 15 constexpr wchar_t kBinariesAppGuid[] = |
| 18 L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}"; | 16 L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}"; |
| 19 base::string16 path(base::StringPrintf( | 17 // presubmit: allow wstring |
| 20 L"Software\\Google\\Update\\ClientState\\%ls", | 18 std::wstring path(L"Software\\Google\\Update\\ClientState\\"); |
| 21 (app == App::CHROME_BINARIES ? kBinariesAppGuid : kChromeAppGuid))); | 19 path += (app == App::CHROME_BINARIES ? kBinariesAppGuid : kChromeAppGuid); |
| 22 #else | 20 #else |
| 23 base::string16 path(app == App::CHROME_BINARIES | 21 // presubmit: allow wstring |
| 24 ? L"Software\\Chromium Binaries" | 22 std::wstring path(app == App::CHROME_BINARIES ? L"Software\\Chromium Binaries" |
| 25 : L"Software\\Chromium"); | 23 : L"Software\\Chromium"); |
| 26 #endif | 24 #endif |
| 27 return key->Open(system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, | 25 return ::RegOpenKeyEx(system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, |
| 28 path.c_str(), | 26 path.c_str(), 0 /* ulOptions */, |
| 29 KEY_QUERY_VALUE | KEY_SET_VALUE | KEY_WOW64_32KEY); | 27 KEY_QUERY_VALUE | KEY_SET_VALUE | KEY_WOW64_32KEY, key); |
| 30 } | 28 } |
| 31 | 29 |
| 32 void WriteResultInfo(bool system_level, const ResultInfo& result_info) { | 30 void WriteResultInfo(bool system_level, const ResultInfo& result_info) { |
| 33 base::win::RegKey key; | 31 HKEY key = nullptr; |
| 34 uint32_t result = OpenClientStateKey(system_level, App::CHROME_BROWSER, &key); | 32 uint32_t result = OpenClientStateKey(system_level, App::CHROME_BROWSER, &key); |
| 35 if (result != ERROR_SUCCESS) | 33 if (result != ERROR_SUCCESS) |
| 36 return; | 34 return; |
| 37 key.WriteValue(kInstallerResult, | 35 ::RegSetValueEx( |
| 38 static_cast<uint32_t>(result_info.installer_result)); | 36 key, kInstallerResult, 0 /* Reserved */, REG_DWORD, |
| 39 key.WriteValue(kInstallerError, | 37 reinterpret_cast<const uint8_t*>(&result_info.installer_result), |
| 40 static_cast<uint32_t>(result_info.installer_error)); | 38 sizeof(DWORD)); |
| 41 if (result_info.installer_extra_code1) | 39 ::RegSetValueEx( |
| 42 key.WriteValue(kInstallerExtraCode1, result_info.installer_extra_code1); | 40 key, kInstallerError, 0 /* Reserved */, REG_DWORD, |
| 43 else | 41 reinterpret_cast<const uint8_t*>(&result_info.installer_error), |
| 44 key.DeleteValue(kInstallerExtraCode1); | 42 sizeof(DWORD)); |
| 43 if (result_info.installer_extra_code1) { |
| 44 ::RegSetValueEx( |
| 45 key, kInstallerExtraCode1, 0 /* Reserved */, REG_DWORD, |
| 46 reinterpret_cast<const uint8_t*>(&result_info.installer_extra_code1), |
| 47 sizeof(DWORD)); |
| 48 } else { |
| 49 ::RegDeleteValue(key, kInstallerExtraCode1); |
| 50 } |
| 51 ::RegCloseKey(key); |
| 45 } | 52 } |
| 46 | 53 |
| 47 // Copied from chrome/browser/google/google_brand.cc. | 54 // Copied from chrome/browser/google/google_brand.cc. |
| 48 bool IsOrganic(const base::string16& brand) { | 55 // presubmit: allow wstring |
| 49 static const wchar_t* const kBrands[] = { | 56 bool IsOrganic(const std::wstring& brand) { |
| 57 constexpr const wchar_t* kBrands[] = { |
| 50 L"CHCA", L"CHCB", L"CHCG", L"CHCH", L"CHCI", L"CHCJ", L"CHCK", L"CHCL", | 58 L"CHCA", L"CHCB", L"CHCG", L"CHCH", L"CHCI", L"CHCJ", L"CHCK", L"CHCL", |
| 51 L"CHFO", L"CHFT", L"CHHS", L"CHHM", L"CHMA", L"CHMB", L"CHME", L"CHMF", | 59 L"CHFO", L"CHFT", L"CHHS", L"CHHM", L"CHMA", L"CHMB", L"CHME", L"CHMF", |
| 52 L"CHMG", L"CHMH", L"CHMI", L"CHMQ", L"CHMV", L"CHNB", L"CHNC", L"CHNG", | 60 L"CHMG", L"CHMH", L"CHMI", L"CHMQ", L"CHMV", L"CHNB", L"CHNC", L"CHNG", |
| 53 L"CHNH", L"CHNI", L"CHOA", L"CHOB", L"CHOC", L"CHON", L"CHOO", L"CHOP", | 61 L"CHNH", L"CHNI", L"CHOA", L"CHOB", L"CHOC", L"CHON", L"CHOO", L"CHOP", |
| 54 L"CHOQ", L"CHOR", L"CHOS", L"CHOT", L"CHOU", L"CHOX", L"CHOY", L"CHOZ", | 62 L"CHOQ", L"CHOR", L"CHOS", L"CHOT", L"CHOU", L"CHOX", L"CHOY", L"CHOZ", |
| 55 L"CHPD", L"CHPE", L"CHPF", L"CHPG", L"ECBA", L"ECBB", L"ECDA", L"ECDB", | 63 L"CHPD", L"CHPE", L"CHPF", L"CHPG", L"ECBA", L"ECBB", L"ECDA", L"ECDB", |
| 56 L"ECSA", L"ECSB", L"ECVA", L"ECVB", L"ECWA", L"ECWB", L"ECWC", L"ECWD", | 64 L"ECSA", L"ECSB", L"ECVA", L"ECVB", L"ECWA", L"ECWB", L"ECWC", L"ECWD", |
| 57 L"ECWE", L"ECWF", L"EUBB", L"EUBC", L"GGLA", L"GGLS"}; | 65 L"ECWE", L"ECWF", L"EUBB", L"EUBC", L"GGLA", L"GGLS"}; |
| 58 const wchar_t* const* end = &kBrands[arraysize(kBrands)]; | 66 const wchar_t* const* end = &kBrands[_countof(kBrands)]; |
| 59 const wchar_t* const* found = std::find(&kBrands[0], end, brand); | 67 const wchar_t* const* found = std::find(&kBrands[0], end, brand); |
| 60 if (found != end) | 68 if (found != end) |
| 61 return true; | 69 return true; |
| 62 | 70 |
| 63 return base::StartsWith(brand, L"EUB", base::CompareCase::SENSITIVE) || | 71 return brand.size() > 3 && (std::equal(&brand[0], &brand[3], L"EUB") || |
| 64 base::StartsWith(brand, L"EUC", base::CompareCase::SENSITIVE) || | 72 std::equal(&brand[0], &brand[3], L"EUC") || |
| 65 base::StartsWith(brand, L"GGR", base::CompareCase::SENSITIVE); | 73 std::equal(&brand[0], &brand[3], L"GGR")); |
| 66 } | 74 } |
| OLD | NEW |