summaryrefslogtreecommitdiffstats
path: root/remoting/host/plugin
diff options
context:
space:
mode:
authorsimonmorris@chromium.org <simonmorris@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-02 21:36:29 +0000
committersimonmorris@chromium.org <simonmorris@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-02 21:36:29 +0000
commit22170488cc1a93770dcdd1b290208feb3c18e47e (patch)
tree2b2d23864f70ec3f244a83aba8eae53d75e1c362 /remoting/host/plugin
parentb592165f7de822d7bcaa3812ec11a4c4125d845a (diff)
downloadchromium_src-22170488cc1a93770dcdd1b290208feb3c18e47e.zip
chromium_src-22170488cc1a93770dcdd1b290208feb3c18e47e.tar.gz
chromium_src-22170488cc1a93770dcdd1b290208feb3c18e47e.tar.bz2
[Chromoting] Move DaemonInstallerWin to remoting/host/setup.
This is a follow-up to https://codereview.chromium.org/10985086. BUG=153453 Review URL: https://chromiumcodereview.appspot.com/11030019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@159773 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/host/plugin')
-rw-r--r--remoting/host/plugin/DEPS3
-rw-r--r--remoting/host/plugin/daemon_installer_win.cc409
-rw-r--r--remoting/host/plugin/daemon_installer_win.h52
3 files changed, 0 insertions, 464 deletions
diff --git a/remoting/host/plugin/DEPS b/remoting/host/plugin/DEPS
deleted file mode 100644
index 7251c42..0000000
--- a/remoting/host/plugin/DEPS
+++ /dev/null
@@ -1,3 +0,0 @@
-include_rules = [
- "+google_update",
-]
diff --git a/remoting/host/plugin/daemon_installer_win.cc b/remoting/host/plugin/daemon_installer_win.cc
deleted file mode 100644
index 1dd9d99..0000000
--- a/remoting/host/plugin/daemon_installer_win.cc
+++ /dev/null
@@ -1,409 +0,0 @@
-// 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 "remoting/host/plugin/daemon_installer_win.h"
-
-#include <windows.h>
-
-#include "base/bind.h"
-#include "base/message_loop.h"
-#include "base/process_util.h"
-#include "base/string16.h"
-#include "base/stringprintf.h"
-#include "base/time.h"
-#include "base/timer.h"
-#include "base/utf_string_conversions.h"
-#include "base/win/object_watcher.h"
-#include "base/win/registry.h"
-#include "base/win/scoped_bstr.h"
-#include "base/win/scoped_comptr.h"
-#include "base/win/scoped_handle.h"
-#include "base/win/scoped_variant.h"
-#include "base/win/windows_version.h"
-#include "google_update/google_update_idl.h"
-#include "remoting/base/dispatch_win.h"
-#include "remoting/host/win/omaha.h"
-
-using base::win::ScopedBstr;
-using base::win::ScopedComPtr;
-using base::win::ScopedVariant;
-
-namespace {
-
-// ProgID of the per-machine Omaha COM server.
-const wchar_t kGoogleUpdate[] = L"GoogleUpdate.Update3WebMachine";
-
-// The COM elevation moniker for the per-machine Omaha COM server.
-const wchar_t kGoogleUpdateElevationMoniker[] =
- L"Elevation:Administrator!new:GoogleUpdate.Update3WebMachine";
-
-// The registry key where the configuration of Omaha is stored.
-const wchar_t kOmahaUpdateKeyName[] = L"Software\\Google\\Update";
-
-// The name of the value where the full path to GoogleUpdate.exe is stored.
-const wchar_t kOmahaPathValueName[] = L"path";
-
-// The command line format string for GoogleUpdate.exe
-const wchar_t kGoogleUpdateCommandLineFormat[] =
- L"\"%ls\" /install \"bundlename=Chromoting%%20Host&appguid=%ls&"
- L"appname=Chromoting%%20Host&needsadmin=True&lang=%ls\"";
-
-// TODO(alexeypa): Get the desired laungage from the web app.
-const wchar_t kOmahaLanguage[] = L"en";
-
-// An empty string for optional parameters.
-const wchar_t kOmahaEmpty[] = L"";
-
-// The installation status polling interval.
-const int kOmahaPollIntervalMs = 500;
-
-} // namespace
-
-namespace remoting {
-
-// This class implements on-demand installation of the Chromoting Host via
-// per-machine Omaha instance.
-class DaemonComInstallerWin : public DaemonInstallerWin {
- public:
- DaemonComInstallerWin(const ScopedComPtr<IDispatch>& update3,
- const CompletionCallback& done);
-
- // DaemonInstallerWin implementation.
- virtual void Install() OVERRIDE;
-
- private:
- // Polls the installation status performing state-specific actions (such as
- // starting installation once download has finished).
- void PollInstallationStatus();
-
- // Omaha interfaces.
- ScopedVariant app_;
- ScopedVariant bundle_;
- ScopedComPtr<IDispatch> update3_;
-
- base::Timer polling_timer_;
-};
-
-// This class implements on-demand installation of the Chromoting Host by
-// launching a per-user instance of Omaha and requesting elevation.
-class DaemonCommandLineInstallerWin
- : public DaemonInstallerWin,
- public base::win::ObjectWatcher::Delegate {
- public:
- DaemonCommandLineInstallerWin(const CompletionCallback& done);
- ~DaemonCommandLineInstallerWin();
-
- // DaemonInstallerWin implementation.
- virtual void Install() OVERRIDE;
-
- // base::win::ObjectWatcher::Delegate implementation.
- virtual void OnObjectSignaled(HANDLE object) OVERRIDE;
-
- private:
- // Handle of the launched process.
- base::win::ScopedHandle process_;
-
- // Used to determine when the launched process terminates.
- base::win::ObjectWatcher process_watcher_;
-};
-
-DaemonComInstallerWin::DaemonComInstallerWin(
- const ScopedComPtr<IDispatch>& update3,
- const CompletionCallback& done)
- : DaemonInstallerWin(done),
- update3_(update3),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- polling_timer_(
- FROM_HERE,
- base::TimeDelta::FromMilliseconds(kOmahaPollIntervalMs),
- base::Bind(&DaemonComInstallerWin::PollInstallationStatus,
- base::Unretained(this)),
- false)) {
-}
-
-void DaemonComInstallerWin::Install() {
- // Create an app bundle.
- HRESULT hr = dispatch::Invoke(update3_.get(), L"createAppBundleWeb",
- DISPATCH_METHOD, bundle_.Receive());
- if (FAILED(hr)) {
- Done(hr);
- return;
- }
- if (bundle_.type() != VT_DISPATCH) {
- Done(DISP_E_TYPEMISMATCH);
- return;
- }
-
- hr = dispatch::Invoke(V_DISPATCH(&bundle_), L"initialize", DISPATCH_METHOD,
- NULL);
- if (FAILED(hr)) {
- Done(hr);
- return;
- }
-
- // Add Chromoting Host to the bundle.
- ScopedVariant appid(kHostOmahaAppid);
- ScopedVariant empty(kOmahaEmpty);
- ScopedVariant language(kOmahaLanguage);
- hr = dispatch::Invoke(V_DISPATCH(&bundle_), L"createApp", DISPATCH_METHOD,
- appid, empty, language, empty, NULL);
- if (FAILED(hr)) {
- Done(hr);
- return;
- }
-
- hr = dispatch::Invoke(V_DISPATCH(&bundle_), L"checkForUpdate",
- DISPATCH_METHOD, NULL);
- if (FAILED(hr)) {
- Done(hr);
- return;
- }
-
- hr = dispatch::Invoke(V_DISPATCH(&bundle_), L"appWeb",
- DISPATCH_PROPERTYGET, ScopedVariant(0), app_.Receive());
- if (FAILED(hr)) {
- Done(hr);
- return;
- }
- if (app_.type() != VT_DISPATCH) {
- Done(DISP_E_TYPEMISMATCH);
- return;
- }
-
- // Now poll for the installation status.
- PollInstallationStatus();
-}
-
-void DaemonComInstallerWin::PollInstallationStatus() {
- // Get the current application installation state.
- // N.B. The object underlying the ICurrentState interface has static data that
- // does not get updated as the server state changes. To get the most "current"
- // state, the currentState property needs to be queried again.
- ScopedVariant current_state;
- HRESULT hr = dispatch::Invoke(V_DISPATCH(&app_), L"currentState",
- DISPATCH_PROPERTYGET, current_state.Receive());
- if (FAILED(hr)) {
- Done(hr);
- return;
- }
- if (current_state.type() != VT_DISPATCH) {
- Done(DISP_E_TYPEMISMATCH);
- return;
- }
-
- ScopedVariant state;
- hr = dispatch::Invoke(V_DISPATCH(&current_state), L"stateValue",
- DISPATCH_PROPERTYGET, state.Receive());
- if (state.type() != VT_I4) {
- Done(DISP_E_TYPEMISMATCH);
- return;
- }
-
- // Perform state-specific actions.
- switch (V_I4(&state)) {
- case STATE_INIT:
- case STATE_WAITING_TO_CHECK_FOR_UPDATE:
- case STATE_CHECKING_FOR_UPDATE:
- case STATE_WAITING_TO_DOWNLOAD:
- case STATE_RETRYING_DOWNLOAD:
- case STATE_DOWNLOADING:
- case STATE_WAITING_TO_INSTALL:
- case STATE_INSTALLING:
- case STATE_PAUSED:
- break;
-
- case STATE_UPDATE_AVAILABLE:
- hr = dispatch::Invoke(V_DISPATCH(&bundle_), L"download",
- DISPATCH_METHOD, NULL);
- if (FAILED(hr)) {
- Done(hr);
- return;
- }
- break;
-
- case STATE_DOWNLOAD_COMPLETE:
- case STATE_EXTRACTING:
- case STATE_APPLYING_DIFFERENTIAL_PATCH:
- case STATE_READY_TO_INSTALL:
- hr = dispatch::Invoke(V_DISPATCH(&bundle_), L"install",
- DISPATCH_METHOD, NULL);
- if (FAILED(hr)) {
- Done(hr);
- return;
- }
- break;
-
- case STATE_INSTALL_COMPLETE:
- case STATE_NO_UPDATE:
- // Installation complete or not required. Report success.
- Done(S_OK);
- return;
-
- case STATE_ERROR: {
- ScopedVariant error_code;
- hr = dispatch::Invoke(V_DISPATCH(&current_state), L"errorCode",
- DISPATCH_PROPERTYGET, error_code.Receive());
- if (FAILED(hr)) {
- Done(hr);
- return;
- }
- if (error_code.type() != VT_UI4) {
- Done(DISP_E_TYPEMISMATCH);
- return;
- }
- Done(V_UI4(&error_code));
- return;
- }
-
- default:
- LOG(ERROR) << "Unknown bundle state: " << V_I4(&state) << ".";
- Done(E_FAIL);
- return;
- }
-
- // Keep polling.
- polling_timer_.Reset();
-}
-
-DaemonCommandLineInstallerWin::DaemonCommandLineInstallerWin(
- const CompletionCallback& done) : DaemonInstallerWin(done) {
-}
-
-DaemonCommandLineInstallerWin::~DaemonCommandLineInstallerWin() {
- process_watcher_.StopWatching();
-}
-
-void DaemonCommandLineInstallerWin::Install() {
- // Get the full path to GoogleUpdate.exe from the registry.
- base::win::RegKey update_key;
- LONG result = update_key.Open(HKEY_CURRENT_USER,
- kOmahaUpdateKeyName,
- KEY_READ);
- if (result != ERROR_SUCCESS) {
- Done(HRESULT_FROM_WIN32(result));
- return;
- }
-
- // presubmit: allow wstring
- std::wstring google_update;
- result = update_key.ReadValue(kOmahaPathValueName, &google_update);
- if (result != ERROR_SUCCESS) {
- Done(HRESULT_FROM_WIN32(result));
- return;
- }
-
- // Launch the updater process and wait for its termination.
- string16 command_line = WideToUTF16(
- StringPrintf(kGoogleUpdateCommandLineFormat,
- google_update.c_str(),
- kHostOmahaAppid,
- kOmahaLanguage));
-
- base::LaunchOptions options;
- if (!base::LaunchProcess(command_line, options, process_.Receive())) {
- result = GetLastError();
- Done(HRESULT_FROM_WIN32(result));
- return;
- }
-
- if (!process_watcher_.StartWatching(process_.Get(), this)) {
- result = GetLastError();
- Done(HRESULT_FROM_WIN32(result));
- return;
- }
-}
-
-void DaemonCommandLineInstallerWin::OnObjectSignaled(HANDLE object) {
- // Check if the updater process returned success.
- DWORD exit_code;
- if (GetExitCodeProcess(process_.Get(), &exit_code) && exit_code == 0) {
- Done(S_OK);
- } else {
- Done(E_FAIL);
- }
-}
-
-DaemonInstallerWin::DaemonInstallerWin(const CompletionCallback& done)
- : done_(done) {
-}
-
-DaemonInstallerWin::~DaemonInstallerWin() {
-}
-
-void DaemonInstallerWin::Done(HRESULT result) {
- done_.Run(result);
-}
-
-// static
-scoped_ptr<DaemonInstallerWin> DaemonInstallerWin::Create(
- HWND window_handle,
- CompletionCallback done) {
- HRESULT result = E_FAIL;
- ScopedComPtr<IDispatch> update3;
-
- // Check if the machine instance of Omaha is available. The COM elevation is
- // supported on Vista+, so on XP/W2K3 we assume that we are running under
- // a privileged user and get ACCESS_DENIED later if we are not.
- if (base::win::GetVersion() < base::win::VERSION_VISTA) {
- CLSID class_id;
- result = CLSIDFromProgID(kGoogleUpdate, &class_id);
- if (SUCCEEDED(result)) {
- result = CoCreateInstance(class_id,
- NULL,
- CLSCTX_LOCAL_SERVER,
- IID_IDispatch,
- update3.ReceiveVoid());
- }
- } else {
- BIND_OPTS3 bind_options;
- memset(&bind_options, 0, sizeof(bind_options));
- bind_options.cbStruct = sizeof(bind_options);
- bind_options.hwnd = GetTopLevelWindow(window_handle);
- bind_options.dwClassContext = CLSCTX_LOCAL_SERVER;
- result = CoGetObject(kGoogleUpdateElevationMoniker,
- &bind_options,
- IID_IDispatch,
- update3.ReceiveVoid());
- }
- if (SUCCEEDED(result)) {
- // The machine instance of Omaha is available and we successfully passed
- // the UAC prompt.
- return scoped_ptr<DaemonInstallerWin>(
- new DaemonComInstallerWin(update3, done));
- } else if (result == CO_E_CLASSSTRING) {
- // The machine instance of Omaha is not available so we will have to run
- // GoogleUpdate.exe manually passing "needsadmin=True". This will cause
- // Omaha to install the machine instance first and then install Chromoting
- // Host.
- return scoped_ptr<DaemonInstallerWin>(
- new DaemonCommandLineInstallerWin(done));
- } else {
- // The user declined the UAC prompt or some other error occured.
- done.Run(result);
- return scoped_ptr<DaemonInstallerWin>();
- }
-}
-
-HWND GetTopLevelWindow(HWND window) {
- if (window == NULL) {
- return NULL;
- }
-
- for (;;) {
- LONG style = GetWindowLong(window, GWL_STYLE);
- if ((style & WS_OVERLAPPEDWINDOW) == WS_OVERLAPPEDWINDOW ||
- (style & WS_POPUP) == WS_POPUP) {
- return window;
- }
-
- HWND parent = GetAncestor(window, GA_PARENT);
- if (parent == NULL) {
- return window;
- }
-
- window = parent;
- }
-}
-
-} // namespace remoting
diff --git a/remoting/host/plugin/daemon_installer_win.h b/remoting/host/plugin/daemon_installer_win.h
deleted file mode 100644
index 3709982..0000000
--- a/remoting/host/plugin/daemon_installer_win.h
+++ /dev/null
@@ -1,52 +0,0 @@
-// 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 REMOTING_HOST_DAEMON_INSTALLER_WIN_H_
-#define REMOTING_HOST_DAEMON_INSTALLER_WIN_H_
-
-#include <objbase.h>
-
-#include "base/basictypes.h"
-#include "base/callback.h"
-#include "base/memory/scoped_ptr.h"
-
-namespace remoting {
-
-class DaemonInstallerWin {
- public:
- typedef base::Callback<void (HRESULT result)> CompletionCallback;
-
- virtual ~DaemonInstallerWin();
-
- // Initiates download and installation of the Chromoting Host.
- virtual void Install() = 0;
-
- // Creates an instance of the Chromoting Host installer passing the completion
- // callback to be called when the installation finishes. In case of an error
- // returns NULL and passed the error code to |done|.
- static scoped_ptr<DaemonInstallerWin> Create(HWND window_handle,
- CompletionCallback done);
-
- protected:
- DaemonInstallerWin(const CompletionCallback& done);
-
- // Invokes the completion callback to report the installation result.
- void Done(HRESULT result);
-
- private:
- // The completion callback that should be called to report the installation
- // result.
- CompletionCallback done_;
-
- DISALLOW_COPY_AND_ASSIGN(DaemonInstallerWin);
-};
-
-// Returns the first top-level (i.e. WS_OVERLAPPED or WS_POPUP) window in
-// the chain of parents of |window|. Returns |window| if it represents
-// a top-level window. Returns NULL when |window| is NULL.
-HWND GetTopLevelWindow(HWND window);
-
-} // namespace remoting
-
-#endif // REMOTING_HOST_DAEMON_INSTALLER_WIN_H_