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 103c48828f3871366b10a8577aef6112f5e98315..a258cb9d3476bb1daded907adab646b3cd64d2a7 100644 |
--- a/chrome/installer/launcher_support/chrome_launcher_support.cc |
+++ b/chrome/installer/launcher_support/chrome_launcher_support.cc |
@@ -9,11 +9,14 @@ |
#include "base/file_path.h" |
#include "base/file_util.h" |
#include "base/logging.h" |
+#include "base/process_util.h" |
+#include "base/string16.h" |
+#include "base/win/registry.h" |
+#include "base/win/scoped_handle.h" |
+ |
#ifndef OFFICIAL_BUILD |
#include "base/path_service.h" |
#endif |
-#include "base/string16.h" |
-#include "base/win/registry.h" |
namespace chrome_launcher_support { |
@@ -21,7 +24,11 @@ namespace { |
// TODO(huangs) Refactor the constants: http://crbug.com/148538 |
const wchar_t kGoogleRegClientStateKey[] = |
- L"Software\\Google\\Update\\ClientState\\"; |
+ L"Software\\Google\\Update\\ClientState"; |
+const wchar_t kGoogleRegClientsKey[] = L"Software\\Google\\Update\\Clients"; |
+ |
+// Copied from binaries_installer_internal.cc |
+const wchar_t kAppHostAppId[] = L"{FDA71E6F-AC4C-4a00-8B70-9958A68906BF}"; |
// Copied from chrome_appid.cc. |
const wchar_t kBinariesAppGuid[] = L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}"; |
@@ -29,9 +36,16 @@ const wchar_t kBinariesAppGuid[] = L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}"; |
// Copied from google_chrome_distribution.cc. |
const wchar_t kBrowserAppGuid[] = L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; |
+// Copied from google_update_constants.cc |
+const wchar_t kRegCommandLineField[] = L"CommandLine"; |
+const wchar_t kRegCommandsKey[] = L"Commands"; |
+ |
// Copied from util_constants.cc. |
-const wchar_t kUninstallStringField[] = L"UninstallString"; |
+const wchar_t kChromeAppHostExe[] = L"app_host.exe"; |
const wchar_t kChromeExe[] = L"chrome.exe"; |
+const wchar_t kCmdQuickEnableApplicationHost[] = |
+ L"quick-enable-application-host"; |
+const wchar_t kUninstallStringField[] = L"UninstallString"; |
#ifndef OFFICIAL_BUILD |
FilePath GetDevelopmentChrome() { |
@@ -53,7 +67,7 @@ FilePath GetSetupExeFromRegistry(InstallationLevel level, |
HKEY root_key = (level == USER_LEVEL_INSTALLATION) ? |
HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; |
string16 subkey(kGoogleRegClientStateKey); |
- subkey.append(app_guid); |
+ subkey.append(1, L'\\').append(app_guid); |
base::win::RegKey reg_key; |
if (reg_key.Open(root_key, subkey.c_str(), |
KEY_QUERY_VALUE) == ERROR_SUCCESS) { |
@@ -67,6 +81,45 @@ FilePath GetSetupExeFromRegistry(InstallationLevel level, |
return FilePath(); |
} |
+string16 GetQuickEnableAppHostCommandFromRegistry(InstallationLevel level) { |
+ HKEY root_key = (level == USER_LEVEL_INSTALLATION) ? |
+ HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; |
+ string16 subkey(kGoogleRegClientsKey); |
+ subkey.append(1, L'\\').append(kBinariesAppGuid) |
+ .append(1, L'\\').append(kRegCommandsKey) |
+ .append(1, L'\\').append(kCmdQuickEnableApplicationHost); |
+ base::win::RegKey reg_key; |
+ string16 cmd; |
+ if (reg_key.Open(root_key, subkey.c_str(), |
+ KEY_QUERY_VALUE) == ERROR_SUCCESS) { |
+ // If read is unsuccessful, |cmd| remains empty. |
+ reg_key.ReadValue(kRegCommandLineField, &cmd); |
+ } |
+ return cmd; |
+} |
+ |
+// Returns the path to an installed |exe_file| (e.g. chrome.exe, app_host.exe) |
+// at the specified level, given |setup_exe_path| from Omaha client state. |
+// Returns empty FilePath if none found, or if |setup_exe_path| is empty. |
+FilePath FindExeRelativeToSetupExe(FilePath& setup_exe_path, |
+ const wchar_t* exe_file) { |
+ if (!setup_exe_path.empty()) { |
+ // The uninstall path contains the path to setup.exe, which is two levels |
+ // down from |exe_file|. Move up two levels (plus one to drop the file |
+ // name) and look for chrome.exe from there. |
+ FilePath exe_path( |
+ setup_exe_path.DirName().DirName().DirName().Append(exe_file)); |
+ if (file_util::PathExists(exe_path)) |
+ return exe_path; |
+ // By way of mild future proofing, look up one to see if there's a |
+ // |exe_file| in the version directory |
+ exe_path = setup_exe_path.DirName().DirName().Append(exe_file); |
+ if (file_util::PathExists(exe_path)) |
+ return exe_path; |
+ } |
+ return FilePath(); |
+} |
+ |
} // namespace |
FilePath GetSetupExeForInstallationLevel(InstallationLevel level) { |
@@ -81,21 +134,12 @@ FilePath GetSetupExeForInstallationLevel(InstallationLevel level) { |
FilePath GetChromePathForInstallationLevel(InstallationLevel level) { |
FilePath setup_exe_path(GetSetupExeForInstallationLevel(level)); |
erikwright (departed)
2012/10/03 15:58:35
inline setup_exe_path
huangs
2012/10/03 20:09:47
Done, but now FindExeRelativeToSetupExe() requires
|
- if (!setup_exe_path.empty()) { |
- // 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 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(); |
+ return FindExeRelativeToSetupExe(setup_exe_path, kChromeExe); |
+} |
+ |
+FilePath GetAppHostPathForInstallationLevel(InstallationLevel level) { |
+ FilePath setup_exe_path(GetSetupExeFromRegistry(level, kAppHostAppId)); |
erikwright (departed)
2012/10/03 15:58:35
inline setup_exe_path
huangs
2012/10/03 20:09:47
Done. Same as above.
|
+ return FindExeRelativeToSetupExe(setup_exe_path, kChromeAppHostExe); |
} |
FilePath GetAnyChromePath() { |
@@ -111,4 +155,37 @@ FilePath GetAnyChromePath() { |
return chrome_path; |
} |
+FilePath GetAnyAppHostPath() { |
+ FilePath app_host_path( |
+ GetAppHostPathForInstallationLevel(SYSTEM_LEVEL_INSTALLATION)); |
+ if (app_host_path.empty()) |
+ app_host_path = GetAppHostPathForInstallationLevel(USER_LEVEL_INSTALLATION); |
+ return app_host_path; |
+} |
+ |
+bool IsAppHostPresent() { |
+ FilePath app_host_exe = GetAnyAppHostPath(); |
+ return !app_host_exe.empty() && file_util::PathExists(app_host_exe); |
+} |
+ |
+bool LaunchQuickEnableAppHost(base::win::ScopedHandle* process) { |
erikwright (departed)
2012/10/03 15:58:35
This doesn't really belong here.
Move it into app
huangs
2012/10/03 20:09:47
Done, and removed useless #include's, but now GetQ
|
+ DCHECK(!process->IsValid()); |
+ bool success = false; |
+ string16 cmd_str(GetQuickEnableAppHostCommandFromRegistry( |
+ SYSTEM_LEVEL_INSTALLATION)); |
+ if (cmd_str.empty()) { // Try user-level if absent from system-level. |
+ cmd_str = GetQuickEnableAppHostCommandFromRegistry( |
+ USER_LEVEL_INSTALLATION); |
+ } |
+ if (!cmd_str.empty()) { |
+ VLOG(1) << "Quick-enabling application host: " << cmd_str; |
+ if (!base::LaunchProcess(cmd_str, base::LaunchOptions(), |
+ process->Receive())) { |
+ LOG(ERROR) << "Failed to quick-enable application host."; |
+ } |
+ success = process->IsValid(); |
+ } |
+ return success; |
+} |
+ |
} // namespace chrome_launcher_support |