Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/installer/launcher_support/chrome_launcher_support.h" | 5 #include "chrome/installer/launcher_support/chrome_launcher_support.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <tchar.h> | 8 #include <tchar.h> |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/logging.h" | |
| 11 #ifndef OFFICIAL_BUILD | 12 #ifndef OFFICIAL_BUILD |
| 12 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 13 #endif | 14 #endif |
| 14 #include "base/string16.h" | 15 #include "base/string16.h" |
| 15 #include "base/win/registry.h" | 16 #include "base/win/registry.h" |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 // TODO(erikwright): These constants are duplicated all over the place. | 20 // http://crbug.com/148538 |
| 20 // Consolidate them somehow. | 21 // TODO(huangs) Refactor the constants: |
| 22 const wchar_t kChromeBinariesRegClientStateKey[] = | |
| 23 L"Software\\Google\\Update\\ClientState\\" | |
| 24 L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}"; | |
| 21 const wchar_t kChromeRegClientStateKey[] = | 25 const wchar_t kChromeRegClientStateKey[] = |
| 22 L"Software\\Google\\Update\\ClientState\\" | 26 L"Software\\Google\\Update\\ClientState\\" |
| 23 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; | 27 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; |
| 24 | 28 |
| 25 const wchar_t kUninstallStringField[] = L"UninstallString"; | 29 const wchar_t kUninstallStringField[] = L"UninstallString"; |
| 26 | 30 |
| 31 // Copied from util_constants.cc. | |
| 27 const wchar_t kChromeExe[] = L"chrome.exe"; | 32 const wchar_t kChromeExe[] = L"chrome.exe"; |
| 28 | 33 |
| 29 #ifndef OFFICIAL_BUILD | 34 #ifndef OFFICIAL_BUILD |
| 30 FilePath GetDevelopmentChrome() { | 35 FilePath GetDevelopmentChrome() { |
| 31 FilePath current_directory; | 36 FilePath current_directory; |
| 32 if (PathService::Get(base::DIR_EXE, ¤t_directory)) { | 37 if (PathService::Get(base::DIR_EXE, ¤t_directory)) { |
| 33 FilePath chrome_exe_path(current_directory.Append(kChromeExe)); | 38 FilePath chrome_exe_path(current_directory.Append(kChromeExe)); |
| 34 if (file_util::PathExists(chrome_exe_path)) | 39 if (file_util::PathExists(chrome_exe_path)) |
| 35 return chrome_exe_path; | 40 return chrome_exe_path; |
| 36 } | 41 } |
| 37 return FilePath(); | 42 return FilePath(); |
| 38 } | 43 } |
| 39 #endif | 44 #endif |
| 40 | 45 |
| 46 // 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.
| |
| 47 // the registry key of a specified product. | |
| 48 FilePath GetSetupExeFromRegistry(HKEY root_key, const wchar_t* subkey) { | |
| 49 base::win::RegKey reg_key; | |
| 50 if (reg_key.Open(root_key, subkey, KEY_QUERY_VALUE) == ERROR_SUCCESS) { | |
| 51 string16 uninstall; | |
| 52 if (reg_key.ReadValue(kUninstallStringField, &uninstall) == ERROR_SUCCESS) { | |
| 53 FilePath setup_exe_path(uninstall); | |
| 54 if (file_util::PathExists(setup_exe_path)) | |
| 55 return setup_exe_path; | |
| 56 } | |
| 57 } | |
| 58 return FilePath(); | |
| 59 } | |
| 60 | |
| 41 } // namespace | 61 } // namespace |
| 42 | 62 |
| 43 namespace chrome_launcher_support { | 63 namespace chrome_launcher_support { |
| 44 | 64 |
| 65 FilePath GetSetupExeForInstallationLevel(InstallationLevel level) { | |
| 66 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
| |
| 67 HKEY_CURRENT_USER : | |
| 68 HKEY_LOCAL_MACHINE); | |
| 69 FilePath setup_exe_path; | |
|
erikwright (departed)
2012/09/14 01:21:36
combine declaration and assignment.
huangs
2012/09/14 04:03:14
Done.
| |
| 70 // Look in the registry for Chrome Binaries first. | |
| 71 setup_exe_path = | |
| 72 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
| |
| 73 // Faily the above, look in the registry for Chrome next. | |
| 74 if (setup_exe_path.empty()) { | |
| 75 setup_exe_path = | |
| 76 GetSetupExeFromRegistry(root_key, kChromeRegClientStateKey); | |
| 77 } | |
| 78 // May have failed, and then setup_exe_path would be empty. | |
| 79 return setup_exe_path; | |
| 80 } | |
| 81 | |
| 82 FilePath GetChromePathForInstallationLevel(InstallationLevel level) { | |
| 83 FilePath setup_exe_path(GetSetupExeForInstallationLevel(level)); | |
| 84 if (!setup_exe_path.empty()) { | |
| 85 FilePath chrome_exe_path; | |
|
erikwright (departed)
2012/09/14 01:21:36
combine declaration and assignment.
huangs
2012/09/14 04:03:14
Done.
| |
| 86 // The uninstall path contains the path to setup.exe which is two levels | |
| 87 // down from chrome.exe. Move up two levels (plus one to drop the file | |
| 88 // name) and look for chrome.exe from there. | |
| 89 chrome_exe_path = | |
| 90 setup_exe_path.DirName().DirName().DirName().Append(kChromeExe); | |
| 91 if (!file_util::PathExists(chrome_exe_path)) { | |
| 92 // By way of mild future proofing, look up one to see if there's a | |
| 93 // chrome.exe in the version directory | |
| 94 chrome_exe_path = chrome_exe_path.DirName().DirName().Append(kChromeExe); | |
| 95 } | |
| 96 if (file_util::PathExists(chrome_exe_path)) | |
| 97 return chrome_exe_path; | |
| 98 } | |
| 99 return FilePath(); | |
| 100 } | |
| 101 | |
| 45 FilePath GetAnyChromePath() { | 102 FilePath GetAnyChromePath() { |
| 46 FilePath chrome_path; | 103 FilePath chrome_path; |
| 47 #ifndef OFFICIAL_BUILD | 104 #ifndef OFFICIAL_BUILD |
| 48 // For development mode, chrome.exe should be in same dir as the stub. | 105 // For development mode, chrome.exe should be in same dir as the stub. |
| 49 chrome_path = GetDevelopmentChrome(); | 106 chrome_path = GetDevelopmentChrome(); |
| 50 #endif | 107 #endif |
| 51 if (chrome_path.empty()) | 108 if (chrome_path.empty()) |
| 52 chrome_path = GetChromePathForInstallationLevel(SYSTEM_LEVEL_INSTALLATION); | 109 chrome_path = GetChromePathForInstallationLevel(SYSTEM_LEVEL_INSTALLATION); |
| 53 if (chrome_path.empty()) | 110 if (chrome_path.empty()) |
| 54 chrome_path = GetChromePathForInstallationLevel(USER_LEVEL_INSTALLATION); | 111 chrome_path = GetChromePathForInstallationLevel(USER_LEVEL_INSTALLATION); |
| 55 | |
| 56 return chrome_path; | 112 return chrome_path; |
| 57 } | 113 } |
| 58 | 114 |
| 59 FilePath GetChromePathForInstallationLevel(InstallationLevel level) { | |
| 60 using base::win::RegKey; | |
| 61 HKEY root_key = (level == USER_LEVEL_INSTALLATION ? | |
| 62 HKEY_CURRENT_USER : | |
| 63 HKEY_LOCAL_MACHINE); | |
| 64 RegKey reg_key(root_key, kChromeRegClientStateKey, KEY_QUERY_VALUE); | |
| 65 | |
| 66 FilePath chrome_exe_path; | |
| 67 | |
| 68 if (reg_key.Valid()) { | |
| 69 // Now grab the uninstall string from the appropriate ClientState key | |
| 70 // and use that as the base for a path to chrome.exe. | |
| 71 string16 uninstall; | |
| 72 if (reg_key.ReadValue(kUninstallStringField, &uninstall) == ERROR_SUCCESS) { | |
| 73 // The uninstall path contains the path to setup.exe which is two levels | |
| 74 // down from chrome.exe. Move up two levels (plus one to drop the file | |
| 75 // name) and look for chrome.exe from there. | |
| 76 FilePath uninstall_path(uninstall); | |
| 77 chrome_exe_path = | |
| 78 uninstall_path.DirName().DirName().DirName().Append(kChromeExe); | |
| 79 if (!file_util::PathExists(chrome_exe_path)) { | |
| 80 // By way of mild future proofing, look up one to see if there's a | |
| 81 // chrome.exe in the version directory | |
| 82 chrome_exe_path = | |
| 83 uninstall_path.DirName().DirName().Append(kChromeExe); | |
| 84 } | |
| 85 } | |
| 86 } | |
| 87 | |
| 88 if (file_util::PathExists(chrome_exe_path)) | |
| 89 return chrome_exe_path; | |
| 90 | |
| 91 return FilePath(); | |
| 92 } | |
| 93 | |
| 94 } // namespace chrome_launcher_support | 115 } // namespace chrome_launcher_support |
| OLD | NEW |