summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorerikwright@chromium.org <erikwright@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-21 18:49:29 +0000
committererikwright@chromium.org <erikwright@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-21 18:49:29 +0000
commit3227e09afc75fe5c3dca8e109969e0535331ba17 (patch)
tree6015c4003dde228c9829db420fa8fc1cf30e20ef
parentb8d40382752651e5d0922f3417c4e2cae01467c3 (diff)
downloadchromium_src-3227e09afc75fe5c3dca8e109969e0535331ba17.zip
chromium_src-3227e09afc75fe5c3dca8e109969e0535331ba17.tar.gz
chromium_src-3227e09afc75fe5c3dca8e109969e0535331ba17.tar.bz2
Factor out logic to find chrome.exe from Omaha client state.
Besides these two clients, will also be used by the Chrome Application Host stub. R=robertshield,abodenha CC=grt BUG=None TEST=None Review URL: https://chromiumcodereview.appspot.com/10546149 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@143423 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/chrome_installer.gypi20
-rw-r--r--chrome/installer/gcapi/gcapi.cc27
-rw-r--r--chrome/installer/launcher_support/chrome_launcher_support.cc94
-rw-r--r--chrome/installer/launcher_support/chrome_launcher_support.h31
-rw-r--r--cloud_print/service/DEPS1
-rw-r--r--cloud_print/service/service.gyp9
-rw-r--r--cloud_print/service/win/chrome_launcher.cc63
-rw-r--r--cloud_print/service/win/chrome_launcher.h3
-rw-r--r--cloud_print/service/win/cloud_print_service.cc5
9 files changed, 163 insertions, 90 deletions
diff --git a/chrome/chrome_installer.gypi b/chrome/chrome_installer.gypi
index 337611c..f1f07ac 100644
--- a/chrome/chrome_installer.gypi
+++ b/chrome/chrome_installer.gypi
@@ -30,6 +30,7 @@
'dependencies': [
'installer_util',
'../base/base.gyp:base',
+ '../chrome/chrome.gyp:launcher_support',
'../google_update/google_update.gyp:google_update',
],
'include_dirs': [
@@ -171,6 +172,25 @@
},
},
{
+ 'target_name': 'launcher_support',
+ 'type': 'static_library',
+ 'include_dirs': [
+ '..',
+ ],
+ 'direct_dependent_settings': {
+ 'include_dirs': [
+ '..',
+ ],
+ },
+ 'dependencies': [
+ '<(DEPTH)/base/base.gyp:base',
+ ],
+ 'sources': [
+ 'installer/launcher_support/chrome_launcher_support.cc',
+ 'installer/launcher_support/chrome_launcher_support.h',
+ ],
+ },
+ {
'target_name': 'mini_installer_test',
'type': 'executable',
'dependencies': [
diff --git a/chrome/installer/gcapi/gcapi.cc b/chrome/installer/gcapi/gcapi.cc
index 73c5b73..960f41d 100644
--- a/chrome/installer/gcapi/gcapi.cc
+++ b/chrome/installer/gcapi/gcapi.cc
@@ -33,6 +33,7 @@
#include "base/win/scoped_handle.h"
#include "chrome/installer/gcapi/gcapi_omaha_experiment.h"
#include "chrome/installer/gcapi/gcapi_reactivation.h"
+#include "chrome/installer/launcher_support/chrome_launcher_support.h"
#include "chrome/installer/util/google_update_constants.h"
#include "chrome/installer/util/util_constants.h"
#include "google_update/google_update_idl.h"
@@ -373,30 +374,8 @@ BOOL __stdcall LaunchGoogleChrome() {
// Now grab the uninstall string from the appropriate ClientState key
// and use that as the base for a path to chrome.exe.
- FilePath chrome_exe_path;
- RegKey client_state(install_key, kChromeRegClientStateKey, KEY_QUERY_VALUE);
- if (client_state.Valid()) {
- std::wstring uninstall_string;
- if (client_state.ReadValue(installer::kUninstallStringField,
- &uninstall_string) == 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_string);
- chrome_exe_path = uninstall_path.DirName()
- .DirName()
- .DirName()
- .Append(installer::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(installer::kChromeExe);
- }
- }
- }
-
- if (!file_util::PathExists(chrome_exe_path)) {
+ FilePath chrome_exe_path(chrome_launcher_support::GetAnyChromePath());
+ if (chrome_exe_path.empty()) {
return false;
}
diff --git a/chrome/installer/launcher_support/chrome_launcher_support.cc b/chrome/installer/launcher_support/chrome_launcher_support.cc
new file mode 100644
index 0000000..c92f771
--- /dev/null
+++ b/chrome/installer/launcher_support/chrome_launcher_support.cc
@@ -0,0 +1,94 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/installer/launcher_support/chrome_launcher_support.h"
+
+#include <windows.h>
+#include <tchar.h>
+#include "base/file_path.h"
+#include "base/file_util.h"
+#ifndef OFFICIAL_BUILD
+#include "base/path_service.h"
+#endif
+#include "base/string16.h"
+#include "base/win/registry.h"
+
+namespace {
+
+// TODO(erikwright): These constants are duplicated all over the place.
+// Consolidate them somehow.
+const wchar_t kChromeRegClientStateKey[] =
+ L"Software\\Google\\Update\\ClientState\\"
+ L"{8A69D345-D564-463c-AFF1-A69D9E530F96}";
+
+const wchar_t kUninstallStringField[] = L"UninstallString";
+
+const wchar_t kChromeExe[] = L"chrome.exe";
+
+#ifndef OFFICIAL_BUILD
+FilePath GetDevelopmentChrome() {
+ FilePath current_directory;
+ if (PathService::Get(base::DIR_EXE, &current_directory)) {
+ FilePath chrome_exe_path(current_directory.Append(kChromeExe));
+ if (file_util::PathExists(chrome_exe_path))
+ return chrome_exe_path;
+ }
+ return FilePath();
+}
+#endif
+
+} // namespace
+
+namespace chrome_launcher_support {
+
+FilePath GetAnyChromePath() {
+ FilePath chrome_path;
+#ifndef OFFICIAL_BUILD
+ // For development mode, chrome.exe should be in same dir as the stub.
+ chrome_path = GetDevelopmentChrome();
+#endif
+ if (chrome_path.empty())
+ 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
diff --git a/chrome/installer/launcher_support/chrome_launcher_support.h b/chrome/installer/launcher_support/chrome_launcher_support.h
new file mode 100644
index 0000000..50c72d3
--- /dev/null
+++ b/chrome/installer/launcher_support/chrome_launcher_support.h
@@ -0,0 +1,31 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_INSTALLER_LAUNCHER_SUPPORT_CHROME_LAUNCHER_SUPPORT_H_
+#define CHROME_INSTALLER_LAUNCHER_SUPPORT_CHROME_LAUNCHER_SUPPORT_H_
+#pragma once
+
+class FilePath;
+
+namespace chrome_launcher_support {
+
+enum InstallationLevel {
+ USER_LEVEL_INSTALLATION,
+ SYSTEM_LEVEL_INSTALLATION
+};
+
+// Returns the path to an installed chrome.exe, or an empty path. Prefers a
+// system-level installation to a user-level installation. Uses Omaha client
+// state to identify a Chrome installation location.
+// In non-official builds, to ease development, this will first look for a
+// chrome.exe in the same directory as the current executable.
+FilePath GetAnyChromePath();
+
+// Returns the path to an installed chrome.exe at the specified level, if it can
+// be found via Omaha client state.
+FilePath GetChromePathForInstallationLevel(InstallationLevel level);
+
+} // namespace chrome_launcher_support
+
+#endif // CHROME_INSTALLER_LAUNCHER_SUPPORT_CHROME_LAUNCHER_SUPPORT_H_
diff --git a/cloud_print/service/DEPS b/cloud_print/service/DEPS
index 8fa9d48..33757a3 100644
--- a/cloud_print/service/DEPS
+++ b/cloud_print/service/DEPS
@@ -1,3 +1,4 @@
include_rules = [
+ "+chrome/installer/launcher_support",
"+net",
]
diff --git a/cloud_print/service/service.gyp b/cloud_print/service/service.gyp
index 096e0d8..35c448d 100644
--- a/cloud_print/service/service.gyp
+++ b/cloud_print/service/service.gyp
@@ -26,7 +26,14 @@
'service_switches.h',
'win/chrome_launcher.cc',
'win/chrome_launcher.h',
- ]
+ ],
+ 'conditions': [
+ ['OS=="win"', {
+ 'dependencies': [
+ '<(DEPTH)/chrome/chrome.gyp:launcher_support',
+ ],
+ }],
+ ],
},
{
'target_name': 'cloud_print_service',
diff --git a/cloud_print/service/win/chrome_launcher.cc b/cloud_print/service/win/chrome_launcher.cc
index 5921fd0..5df9bae 100644
--- a/cloud_print/service/win/chrome_launcher.cc
+++ b/cloud_print/service/win/chrome_launcher.cc
@@ -5,28 +5,15 @@
#include "cloud_print/service/win/chrome_launcher.h"
#include "base/command_line.h"
-#include "base/file_util.h"
-#include "base/path_service.h"
#include "base/process.h"
#include "base/process_util.h"
-#include "base/win/registry.h"
#include "base/win/scoped_handle.h"
#include "base/win/scoped_process_information.h"
+#include "chrome/installer/launcher_support/chrome_launcher_support.h"
#include "cloud_print/service/service_switches.h"
namespace {
-const wchar_t kChromeRegClientStateKey[] =
- L"Software\\Google\\Update\\ClientState\\"
- L"{8A69D345-D564-463c-AFF1-A69D9E530F96}";
-
-const wchar_t kGoogleChromeExePath[] =
- L"Google\\Chrome\\Application\\chrome.exe";
-
-const wchar_t kUninstallStringField[] = L"UninstallString";
-
-const wchar_t kChromeExe[] = L"chrome.exe";
-
const int kShutdownTimeoutMs = 30 * 1000;
void ShutdownChrome(HANDLE process, DWORD thread_id) {
@@ -62,21 +49,6 @@ bool LaunchProcess(const CommandLine& cmdline,
return true;
}
-FilePath GetAnyChromePath() {
- FilePath chrome_path = ChromeLauncher::GetChromePath(HKEY_LOCAL_MACHINE);
- if (!chrome_path.empty())
- return chrome_path;
- chrome_path = ChromeLauncher::GetChromePath(HKEY_CURRENT_USER);
- if (!chrome_path.empty())
- return chrome_path;
- if (PathService::Get(base::DIR_PROGRAM_FILES, &chrome_path)) {
- chrome_path.Append(kGoogleChromeExePath);
- if (file_util::PathExists(chrome_path))
- return chrome_path;
- }
- return FilePath();
-}
-
} // namespace
ChromeLauncher::ChromeLauncher(const FilePath& user_data)
@@ -106,7 +78,7 @@ void ChromeLauncher::Run() {
for (base::TimeDelta time_out = default_time_out;;
time_out = std::min(time_out * 2, max_time_out)) {
- FilePath chrome_path = GetAnyChromePath();
+ FilePath chrome_path = chrome_launcher_support::GetAnyChromePath();
if (!chrome_path.empty()) {
CommandLine cmd(chrome_path);
@@ -138,35 +110,4 @@ void ChromeLauncher::Run() {
}
}
-FilePath ChromeLauncher::GetChromePath(HKEY key) {
- using base::win::RegKey;
- RegKey reg_key(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();
-}
diff --git a/cloud_print/service/win/chrome_launcher.h b/cloud_print/service/win/chrome_launcher.h
index 8b98141..bc257ff 100644
--- a/cloud_print/service/win/chrome_launcher.h
+++ b/cloud_print/service/win/chrome_launcher.h
@@ -23,8 +23,6 @@ class ChromeLauncher : public base::DelegateSimpleThread::Delegate {
virtual void Run() OVERRIDE;
- static FilePath GetChromePath(HKEY key);
-
private:
FilePath user_data_;
base::WaitableEvent stop_event_;
@@ -34,4 +32,3 @@ class ChromeLauncher : public base::DelegateSimpleThread::Delegate {
};
#endif // CLOUD_PRINT_SERVICE_CHROME_LAUNCHER_H_
-
diff --git a/cloud_print/service/win/cloud_print_service.cc b/cloud_print/service/win/cloud_print_service.cc
index f87c2888..7c88591 100644
--- a/cloud_print/service/win/cloud_print_service.cc
+++ b/cloud_print/service/win/cloud_print_service.cc
@@ -15,6 +15,7 @@
#include "base/path_service.h"
#include "base/string_util.h"
#include "base/win/scoped_handle.h"
+#include "chrome/installer/launcher_support/chrome_launcher_support.h"
#include "cloud_print/service/service_state.h"
#include "cloud_print/service/service_switches.h"
#include "cloud_print/service/win/chrome_launcher.h"
@@ -182,13 +183,15 @@ class CloudPrintServiceModule
}
HRESULT InstallService() {
+ using namespace chrome_launcher_support;
+
// TODO(vitalybuka): consider "lite" version if we don't want unregister
// printers here.
HRESULT hr = UninstallService();
if (FAILED(hr))
return hr;
- if (ChromeLauncher::GetChromePath(HKEY_LOCAL_MACHINE).empty()) {
+ if (GetChromePathForInstallationLevel(SYSTEM_LEVEL_INSTALLATION).empty()) {
LOG(ERROR) << "Found no Chrome installed for all users.";
return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
}