Chromium Code Reviews| Index: chrome/installer/launcher_support/chrome_launcher_support.cc |
| diff --git a/chrome/installer/launcher_support/chrome_launcher_support.cc b/chrome/installer/launcher_support/chrome_launcher_support.cc |
| index c92f771a4735c3a0a141056e05840e2c98d9633a..b368a16e56603dfeba3f573edabadf4dca0482f3 100644 |
| --- a/chrome/installer/launcher_support/chrome_launcher_support.cc |
| +++ b/chrome/installer/launcher_support/chrome_launcher_support.cc |
| @@ -8,6 +8,7 @@ |
| #include <tchar.h> |
| #include "base/file_path.h" |
| #include "base/file_util.h" |
| +#include "base/logging.h" |
| #ifndef OFFICIAL_BUILD |
| #include "base/path_service.h" |
| #endif |
| @@ -16,14 +17,18 @@ |
| namespace { |
| -// TODO(erikwright): These constants are duplicated all over the place. |
| -// Consolidate them somehow. |
| +// http://crbug.com/148538 |
| +// TODO(huangs) Refactor the constants: |
| +const wchar_t kChromeBinariesRegClientStateKey[] = |
| + L"Software\\Google\\Update\\ClientState\\" |
| + L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}"; |
| const wchar_t kChromeRegClientStateKey[] = |
| L"Software\\Google\\Update\\ClientState\\" |
| L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; |
| const wchar_t kUninstallStringField[] = L"UninstallString"; |
| +// Copied from util_constants.cc. |
| const wchar_t kChromeExe[] = L"chrome.exe"; |
| #ifndef OFFICIAL_BUILD |
| @@ -38,10 +43,62 @@ FilePath GetDevelopmentChrome() { |
| } |
| #endif |
| +// Looks for setup.exe from the registry field UninstallString from |
|
erikwright (departed)
2012/09/14 01:21:36
nit: registry field -> value
"Reads the path to se
huangs
2012/09/14 04:03:14
Done. Have quotation around "ClientState", too.
|
| +// the registry key of a specified product. |
| +FilePath GetSetupExeFromRegistry(HKEY root_key, const wchar_t* subkey) { |
| + base::win::RegKey reg_key; |
| + if (reg_key.Open(root_key, subkey, KEY_QUERY_VALUE) == ERROR_SUCCESS) { |
| + string16 uninstall; |
| + if (reg_key.ReadValue(kUninstallStringField, &uninstall) == ERROR_SUCCESS) { |
| + FilePath setup_exe_path(uninstall); |
| + if (file_util::PathExists(setup_exe_path)) |
| + return setup_exe_path; |
| + } |
| + } |
| + return FilePath(); |
| +} |
| + |
| } // namespace |
| namespace chrome_launcher_support { |
| +FilePath GetSetupExeForInstallationLevel(InstallationLevel level) { |
| + HKEY root_key = (level == USER_LEVEL_INSTALLATION ? |
|
erikwright (departed)
2012/09/14 01:21:36
push this down into GetSetupExeFromRegistry (make
huangs
2012/09/14 04:03:14
Done. Also wrapping "namespace chrome_launch_supp
|
| + HKEY_CURRENT_USER : |
| + HKEY_LOCAL_MACHINE); |
| + FilePath setup_exe_path; |
|
erikwright (departed)
2012/09/14 01:21:36
combine declaration and assignment.
huangs
2012/09/14 04:03:14
Done.
|
| + // Look in the registry for Chrome Binaries first. |
| + setup_exe_path = |
| + GetSetupExeFromRegistry(root_key, kChromeBinariesRegClientStateKey); |
|
erikwright (departed)
2012/09/14 01:21:36
Define constants for the app guids and pass those
huangs
2012/09/14 04:03:14
Done. Duplicating the GUID definitions in update.c
|
| + // Faily the above, look in the registry for Chrome next. |
| + if (setup_exe_path.empty()) { |
| + setup_exe_path = |
| + GetSetupExeFromRegistry(root_key, kChromeRegClientStateKey); |
| + } |
| + // May have failed, and then setup_exe_path would be empty. |
| + return setup_exe_path; |
| +} |
| + |
| +FilePath GetChromePathForInstallationLevel(InstallationLevel level) { |
| + FilePath setup_exe_path(GetSetupExeForInstallationLevel(level)); |
| + if (!setup_exe_path.empty()) { |
| + FilePath chrome_exe_path; |
|
erikwright (departed)
2012/09/14 01:21:36
combine declaration and assignment.
huangs
2012/09/14 04:03:14
Done.
|
| + // The uninstall path contains the path to setup.exe which is two levels |
| + // down from chrome.exe. Move up two levels (plus one to drop the file |
| + // name) and look for chrome.exe from there. |
| + chrome_exe_path = |
| + setup_exe_path.DirName().DirName().DirName().Append(kChromeExe); |
| + if (!file_util::PathExists(chrome_exe_path)) { |
| + // By way of mild future proofing, look up one to see if there's a |
| + // chrome.exe in the version directory |
| + chrome_exe_path = chrome_exe_path.DirName().DirName().Append(kChromeExe); |
| + } |
| + if (file_util::PathExists(chrome_exe_path)) |
| + return chrome_exe_path; |
| + } |
| + return FilePath(); |
| +} |
| + |
| FilePath GetAnyChromePath() { |
| FilePath chrome_path; |
| #ifndef OFFICIAL_BUILD |
| @@ -52,43 +109,7 @@ FilePath GetAnyChromePath() { |
| chrome_path = GetChromePathForInstallationLevel(SYSTEM_LEVEL_INSTALLATION); |
| if (chrome_path.empty()) |
| chrome_path = GetChromePathForInstallationLevel(USER_LEVEL_INSTALLATION); |
| - |
| return chrome_path; |
| } |
| -FilePath GetChromePathForInstallationLevel(InstallationLevel level) { |
| - using base::win::RegKey; |
| - HKEY root_key = (level == USER_LEVEL_INSTALLATION ? |
| - HKEY_CURRENT_USER : |
| - HKEY_LOCAL_MACHINE); |
| - RegKey reg_key(root_key, kChromeRegClientStateKey, KEY_QUERY_VALUE); |
| - |
| - FilePath chrome_exe_path; |
| - |
| - if (reg_key.Valid()) { |
| - // Now grab the uninstall string from the appropriate ClientState key |
| - // and use that as the base for a path to chrome.exe. |
| - string16 uninstall; |
| - if (reg_key.ReadValue(kUninstallStringField, &uninstall) == ERROR_SUCCESS) { |
| - // The uninstall path contains the path to setup.exe which is two levels |
| - // down from chrome.exe. Move up two levels (plus one to drop the file |
| - // name) and look for chrome.exe from there. |
| - FilePath uninstall_path(uninstall); |
| - chrome_exe_path = |
| - uninstall_path.DirName().DirName().DirName().Append(kChromeExe); |
| - if (!file_util::PathExists(chrome_exe_path)) { |
| - // By way of mild future proofing, look up one to see if there's a |
| - // chrome.exe in the version directory |
| - chrome_exe_path = |
| - uninstall_path.DirName().DirName().Append(kChromeExe); |
| - } |
| - } |
| - } |
| - |
| - if (file_util::PathExists(chrome_exe_path)) |
| - return chrome_exe_path; |
| - |
| - return FilePath(); |
| -} |
| - |
| } // namespace chrome_launcher_support |