1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef REMOTING_HOST_SETUP_DAEMON_CONTROLLER_DELEGATE_WIN_H_ 6 #define REMOTING_HOST_SETUP_DAEMON_CONTROLLER_DELEGATE_WIN_H_ 7 8 #include "base/memory/scoped_ptr.h" 9 #include "base/timer/timer.h" 10 #include "base/win/scoped_comptr.h" 11 // chromoting_lib.h contains MIDL-generated declarations. 12 #include "remoting/host/chromoting_lib.h" 13 #include "remoting/host/setup/daemon_controller.h" 14 #include "remoting/host/setup/daemon_installer_win.h" 15 16 namespace remoting { 17 18 class DaemonInstallerWin; 19 20 class DaemonControllerDelegateWin : public DaemonController::Delegate { 21 public: 22 DaemonControllerDelegateWin(); 23 virtual ~DaemonControllerDelegateWin(); 24 25 // DaemonController::Delegate interface. 26 virtual DaemonController::State GetState() OVERRIDE; 27 virtual scoped_ptr<base::DictionaryValue> GetConfig() OVERRIDE; 28 virtual void InstallHost( 29 const DaemonController::CompletionCallback& done) OVERRIDE; 30 virtual void SetConfigAndStart( 31 scoped_ptr<base::DictionaryValue> config, 32 bool consent, 33 const DaemonController::CompletionCallback& done) OVERRIDE; 34 virtual void UpdateConfig( 35 scoped_ptr<base::DictionaryValue> config, 36 const DaemonController::CompletionCallback& done) OVERRIDE; 37 virtual void Stop(const DaemonController::CompletionCallback& done) OVERRIDE; 38 virtual void SetWindow(void* window_handle) OVERRIDE; 39 virtual std::string GetVersion() OVERRIDE; 40 virtual DaemonController::UsageStatsConsent GetUsageStatsConsent() OVERRIDE; 41 42 private: 43 // Activates an unprivileged instance of the daemon controller and caches it. 44 HRESULT ActivateController(); 45 46 // Activates an instance of the daemon controller and caches it. If COM 47 // Elevation is supported (Vista+) the activated instance is elevated, 48 // otherwise it is activated under credentials of the caller. 49 HRESULT ActivateElevatedController(); 50 51 // Releases the cached instance of the controller. 52 void ReleaseController(); 53 54 // Install the host and then invoke the callback. 55 void DoInstallHost(const DaemonInstallerWin::CompletionCallback& done); 56 57 // Procedes with the daemon configuration if the installation succeeded, 58 // otherwise reports the error. 59 void StartHostWithConfig( 60 scoped_ptr<base::DictionaryValue> config, 61 bool consent, 62 const DaemonController::CompletionCallback& done, 63 HRESULT hr); 64 65 // |control_| and |control2_| hold references to an instance of the daemon 66 // controller to prevent a UAC prompt on every operation. 67 base::win::ScopedComPtr<IDaemonControl> control_; 68 base::win::ScopedComPtr<IDaemonControl2> control2_; 69 70 // True if |control_| holds a reference to an elevated instance of the daemon 71 // controller. 72 bool control_is_elevated_; 73 74 // This timer is used to release |control_| after a timeout. 75 scoped_ptr<base::OneShotTimer<DaemonControllerDelegateWin> > release_timer_; 76 77 // Handle of the plugin window. 78 HWND window_handle_; 79 80 scoped_ptr<DaemonInstallerWin> installer_; 81 82 DISALLOW_COPY_AND_ASSIGN(DaemonControllerDelegateWin); 83 }; 84 85 } // namespace remoting 86 87 #endif // REMOTING_HOST_SETUP_DAEMON_CONTROLLER_DELEGATE_WIN_H_ 88