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 #ifndef REMOTING_HOST_SETUP_DAEMON_CONTROLLER_H_ | 5 #ifndef REMOTING_HOST_SETUP_DAEMON_CONTROLLER_H_ |
| 6 #define REMOTING_HOST_SETUP_DAEMON_CONTROLLER_H_ | 6 #define REMOTING_HOST_SETUP_DAEMON_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <queue> | |
| 8 #include <string> | 9 #include <string> |
| 9 | 10 |
| 10 #include "base/callback_forward.h" | 11 #include "base/callback.h" |
| 12 #include "base/memory/ref_counted.h" | |
| 11 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 12 | 14 |
| 13 namespace base { | 15 namespace base { |
| 14 class DictionaryValue; | 16 class DictionaryValue; |
| 17 class SingleThreadTaskRunner; | |
| 15 } // namespace base | 18 } // namespace base |
| 16 | 19 |
| 17 namespace remoting { | 20 namespace remoting { |
| 18 | 21 |
| 19 class DaemonController { | 22 class AutoThread; |
| 23 class AutoThreadTaskRunner; | |
| 24 | |
| 25 class DaemonController : public base::RefCountedThreadSafe<DaemonController> { | |
| 20 public: | 26 public: |
| 21 // Note that these enumeration values are duplicated in host_controller.js and | 27 // Note that these enumeration values are duplicated in host_controller.js and |
| 22 // must be kept in sync. | 28 // must be kept in sync. |
| 23 enum State { | 29 enum State { |
| 24 // Placeholder state for platforms on which the daemon process is not | 30 // Placeholder state for platforms on which the daemon process is not |
| 25 // implemented. The web-app will not show the corresponding UI. This value | 31 // implemented. The web-app will not show the corresponding UI. This value |
| 26 // will eventually be deprecated or removed. | 32 // will eventually be deprecated or removed. |
| 27 STATE_NOT_IMPLEMENTED = -1, | 33 STATE_NOT_IMPLEMENTED = -1, |
| 28 // The daemon is not installed. This is functionally equivalent to | 34 // The daemon is not installed. This is functionally equivalent to |
| 29 // STATE_STOPPED, but the start method is expected to be significantly | 35 // STATE_STOPPED, but the start method is expected to be significantly |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 typedef base::Callback<void (scoped_ptr<base::DictionaryValue> config)> | 78 typedef base::Callback<void (scoped_ptr<base::DictionaryValue> config)> |
| 73 GetConfigCallback; | 79 GetConfigCallback; |
| 74 | 80 |
| 75 // Callback used for asynchronous operations, e.g. when | 81 // Callback used for asynchronous operations, e.g. when |
| 76 // starting/stopping the service. | 82 // starting/stopping the service. |
| 77 typedef base::Callback<void (AsyncResult result)> CompletionCallback; | 83 typedef base::Callback<void (AsyncResult result)> CompletionCallback; |
| 78 | 84 |
| 79 // Callback type for GetVersion(). | 85 // Callback type for GetVersion(). |
| 80 typedef base::Callback<void (const std::string&)> GetVersionCallback; | 86 typedef base::Callback<void (const std::string&)> GetVersionCallback; |
| 81 | 87 |
| 88 struct UsageStatsConsent { | |
|
Wez
2013/09/10 09:05:37
nit: UsageStatsConsentFlags?
alexeypa (please no reviews)
2013/09/10 16:59:22
It is long enough already.
| |
| 89 bool supported; | |
| 90 bool allowed; | |
| 91 bool set_by_policy; | |
| 92 }; | |
| 93 | |
| 82 // Callback type for GetUsageStatsConsent(). |supported| indicates whether | 94 // Callback type for GetUsageStatsConsent(). |supported| indicates whether |
| 83 // crash dump reporting is supported by the host. |allowed| indicates if | 95 // crash dump reporting is supported by the host. |allowed| indicates if |
| 84 // crash dump reporting is allowed by the user. |set_by_policy| carries | 96 // crash dump reporting is allowed by the user. |set_by_policy| carries |
| 85 // information whether the crash dump reporting is controlled by policy. | 97 // information whether the crash dump reporting is controlled by policy. |
|
Wez
2013/09/10 09:05:37
Move the member descriptions to document the struc
alexeypa (please no reviews)
2013/09/10 16:59:22
Done.
| |
| 86 typedef base::Callback<void ( | 98 typedef base::Callback<void (const UsageStatsConsent&)> |
| 87 bool supported, | 99 GetUsageStatsConsentCallback; |
| 88 bool allowed, | |
| 89 bool set_by_policy)> GetUsageStatsConsentCallback; | |
| 90 | 100 |
| 91 virtual ~DaemonController() {} | 101 // Interface representing the platform-spacific back-end. Most of its methods |
| 102 // are blocking and should called on a background thread. There are two | |
| 103 // exceptions: | |
| 104 // - GetState() is synchronous and called on the UI thread. It should avoid | |
| 105 // accessing any data members of the implementation. | |
| 106 // - SetConfigAndStart() is non blocking. |done| callback is posted to | |
| 107 // |task_runner| when the operation completes. | |
| 108 class Delegate { | |
| 109 public: | |
| 110 virtual ~Delegate() {} | |
| 111 | |
| 112 // Return the "installed/running" state of the daemon process. This method | |
| 113 // should avoid accessing any data members of the implementation. | |
| 114 virtual State GetState() = 0; | |
| 115 | |
| 116 // Queries current host configuration. Any values that might be security | |
| 117 // sensitive have been filtered out. | |
| 118 virtual scoped_ptr<base::DictionaryValue> GetConfig() = 0; | |
| 119 | |
| 120 // Starts the daemon process. This may require that the daemon be | |
| 121 // downloaded and installed. |done| is invoked when the operation is | |
| 122 // finished or fails. | |
|
Wez
2013/09/10 09:05:37
nit: Indicate which thread |done| is invoked upon.
alexeypa (please no reviews)
2013/09/10 16:59:22
Done.
| |
| 123 virtual void SetConfigAndStart( | |
| 124 scoped_ptr<base::DictionaryValue> config, | |
| 125 bool consent, | |
| 126 const CompletionCallback& done) = 0; | |
| 127 | |
| 128 // Updates current host configuration with the values specified in | |
| 129 // |config|. Any value in the existing configuration that isn't specified in | |
| 130 // |config| is preserved. |config| must not contain host_id or xmpp_login | |
| 131 // values, because implementations of this method cannot change them. | |
| 132 virtual void UpdateConfig( | |
| 133 scoped_ptr<base::DictionaryValue> config, | |
| 134 const CompletionCallback& done) = 0; | |
| 135 | |
| 136 // Stops the daemon process. | |
| 137 virtual void Stop(const CompletionCallback& done) = 0; | |
| 138 | |
| 139 // Caches the native handle of the plugin window so it can be used to focus | |
| 140 // elevation prompts properly. | |
| 141 virtual void SetWindow(void* window_handle) = 0; | |
| 142 | |
| 143 // Get the version of the daemon as a dotted decimal string of the form | |
| 144 // major.minor.build.patch, if it is installed, or "" otherwise. | |
| 145 virtual std::string GetVersion() = 0; | |
| 146 | |
| 147 // Get the user's consent to crash reporting. | |
| 148 virtual UsageStatsConsent GetUsageStatsConsent() = 0; | |
| 149 }; | |
| 150 | |
| 151 static scoped_refptr<DaemonController> Create(); | |
| 152 | |
| 153 explicit DaemonController(scoped_ptr<Delegate> delegate); | |
| 92 | 154 |
| 93 // Return the "installed/running" state of the daemon process. | 155 // Return the "installed/running" state of the daemon process. |
| 94 // | 156 // |
| 95 // TODO(sergeyu): This method is called synchronously from the | 157 // TODO(sergeyu): This method is called synchronously from the |
| 96 // webapp. In most cases it requires IO operations, so it may block | 158 // webapp. In most cases it requires IO operations, so it may block |
| 97 // the user interface. Replace it with asynchronous notifications, | 159 // the user interface. Replace it with asynchronous notifications, |
| 98 // e.g. with StartStateNotifications()/StopStateNotifications() methods. | 160 // e.g. with StartStateNotifications()/StopStateNotifications() methods. |
| 99 virtual State GetState() = 0; | 161 State GetState(); |
| 100 | 162 |
| 101 // Queries current host configuration. The |callback| is called | 163 // Queries current host configuration. The |done| is called |
| 102 // after the configuration is read, and any values that might be security | 164 // after the configuration is read, and any values that might be security |
| 103 // sensitive have been filtered out. | 165 // sensitive have been filtered out. |
| 104 virtual void GetConfig(const GetConfigCallback& callback) = 0; | 166 void GetConfig(const GetConfigCallback& done); |
| 105 | 167 |
| 106 // Start the daemon process. This may require that the daemon be | 168 // Start the daemon process. This may require that the daemon be |
| 107 // downloaded and installed. |done_callback| is called when the | 169 // downloaded and installed. |done| is called when the |
| 108 // operation is finished or fails. | 170 // operation is finished or fails. |
| 109 // | 171 // |
| 110 // TODO(sergeyu): This method writes config and starts the host - | 172 // TODO(sergeyu): This method writes config and starts the host - |
| 111 // these two steps are merged for simplicity. Consider splitting it | 173 // these two steps are merged for simplicity. Consider splitting it |
| 112 // into SetConfig() and Start() once we have basic host setup flow | 174 // into SetConfig() and Start() once we have basic host setup flow |
| 113 // working. | 175 // working. |
| 114 virtual void SetConfigAndStart(scoped_ptr<base::DictionaryValue> config, | 176 void SetConfigAndStart(scoped_ptr<base::DictionaryValue> config, |
| 115 bool consent, | 177 bool consent, |
| 116 const CompletionCallback& done) = 0; | 178 const CompletionCallback& done); |
| 117 | 179 |
| 118 // Updates current host configuration with the values specified in | 180 // Updates current host configuration with the values specified in |
| 119 // |config|. Changes must take effect before the call completes. | 181 // |config|. Changes must take effect before the call completes. |
| 120 // Any value in the existing configuration that isn't specified in |config| | 182 // Any value in the existing configuration that isn't specified in |config| |
| 121 // is preserved. |config| must not contain host_id or xmpp_login values, | 183 // is preserved. |config| must not contain host_id or xmpp_login values, |
| 122 // because implementations of this method cannot change them. | 184 // because implementations of this method cannot change them. |
| 123 virtual void UpdateConfig(scoped_ptr<base::DictionaryValue> config, | 185 void UpdateConfig(scoped_ptr<base::DictionaryValue> config, |
| 124 const CompletionCallback& done_callback) = 0; | 186 const CompletionCallback& done); |
| 125 | 187 |
| 126 // Stop the daemon process. It is permitted to call Stop while the daemon | 188 // Stop the daemon process. It is permitted to call Stop while the daemon |
| 127 // process is being installed, in which case the installation should be | 189 // process is being installed, in which case the installation should be |
| 128 // aborted if possible; if not then it is sufficient to ensure that the | 190 // aborted if possible; if not then it is sufficient to ensure that the |
| 129 // daemon process is not started automatically upon successful installation. | 191 // daemon process is not started automatically upon successful installation. |
| 130 // As with Start, Stop may return before the operation is complete--poll | 192 // As with Start, Stop may return before the operation is complete--poll |
| 131 // GetState until the state is STATE_STOPPED. | 193 // GetState until the state is STATE_STOPPED. |
| 132 virtual void Stop(const CompletionCallback& done_callback) = 0; | 194 void Stop(const CompletionCallback& done); |
| 133 | 195 |
| 134 // Caches the native handle of the plugin window so it can be used to focus | 196 // Caches the native handle of the plugin window so it can be used to focus |
| 135 // elevation prompts properly. | 197 // elevation prompts properly. |
| 136 virtual void SetWindow(void* window_handle) = 0; | 198 void SetWindow(void* window_handle); |
| 137 | 199 |
| 138 // Get the version of the daemon as a dotted decimal string of the form | 200 // Get the version of the daemon as a dotted decimal string of the form |
| 139 // major.minor.build.patch, if it is installed, or "" otherwise. | 201 // major.minor.build.patch, if it is installed, or "" otherwise. |
| 140 virtual void GetVersion(const GetVersionCallback& done_callback) = 0; | 202 void GetVersion(const GetVersionCallback& done); |
| 141 | 203 |
| 142 // Get the user's consent to crash reporting. | 204 // Get the user's consent to crash reporting. |
| 143 virtual void GetUsageStatsConsent( | 205 void GetUsageStatsConsent(const GetUsageStatsConsentCallback& done); |
| 144 const GetUsageStatsConsentCallback& done) = 0; | |
| 145 | 206 |
| 146 static scoped_ptr<DaemonController> Create(); | 207 private: |
| 208 friend class base::RefCountedThreadSafe<DaemonController>; | |
| 209 virtual ~DaemonController(); | |
| 210 | |
| 211 // Blocking helper methods used to call the delegate. | |
| 212 void DoGetConfig(const GetConfigCallback& done); | |
| 213 void DoSetConfigAndStart(scoped_ptr<base::DictionaryValue> config, | |
| 214 bool consent, | |
| 215 const CompletionCallback& done); | |
| 216 void DoUpdateConfig(scoped_ptr<base::DictionaryValue> config, | |
| 217 const CompletionCallback& done); | |
| 218 void DoStop(const CompletionCallback& done); | |
| 219 void DoSetWindow(void* window_handle, const base::Closure& done); | |
| 220 void DoGetVersion(const GetVersionCallback& done); | |
| 221 void DoGetUsageStatsConsent(const GetUsageStatsConsentCallback& done); | |
| 222 | |
| 223 // "Trampoline" callbacks that schedule the next pending request and then | |
| 224 // invoke the original caller-supplied callback. | |
| 225 void InvokeCompletionCallbackAndScheduleNext( | |
| 226 const CompletionCallback& done, | |
| 227 AsyncResult result); | |
| 228 void InvokeConfigCallbackAndScheduleNext( | |
| 229 const GetConfigCallback& done, | |
| 230 scoped_ptr<base::DictionaryValue> config); | |
| 231 void InvokeConsentCallbackAndScheduleNext( | |
| 232 const GetUsageStatsConsentCallback& done, | |
| 233 const UsageStatsConsent& consent); | |
| 234 void InvokeVersionCallbackAndScheduleNext( | |
| 235 const GetVersionCallback& done, | |
| 236 const std::string& version); | |
| 237 | |
| 238 // Queue management methods. | |
| 239 void ScheduleNext(); | |
| 240 void ServiceOrQueueRequest(const base::Closure& request); | |
| 241 void ServiceNextRequest(); | |
| 242 | |
| 243 // Task runner on which all public methods of this class should be called. | |
| 244 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_; | |
| 245 | |
| 246 // Task runner used to run blocking calls to the delegate. A single thread | |
| 247 // task runner is used to guarantee that one one method of the delegate is | |
|
Wez
2013/09/10 09:05:37
typo: one one
alexeypa (please no reviews)
2013/09/10 16:59:22
Done.
| |
| 248 // called at a time. | |
|
Wez
2013/09/10 09:05:37
nit: Couldn't any SequenceTaskRunner provide the n
alexeypa (please no reviews)
2013/09/10 16:59:22
No. |delegate_thread_| can be used to invoke COM m
| |
| 249 scoped_refptr<AutoThreadTaskRunner> delegate_task_runner_; | |
| 250 | |
| 251 scoped_ptr<AutoThread> delegate_thread_; | |
| 252 | |
| 253 scoped_ptr<Delegate> delegate_; | |
| 254 | |
| 255 std::queue<base::Closure> pending_requests_; | |
| 256 | |
| 257 DISALLOW_COPY_AND_ASSIGN(DaemonController); | |
| 147 }; | 258 }; |
| 148 | 259 |
| 149 } // namespace remoting | 260 } // namespace remoting |
| 150 | 261 |
| 151 #endif // REMOTING_HOST_SETUP_DAEMON_CONTROLLER_H_ | 262 #endif // REMOTING_HOST_SETUP_DAEMON_CONTROLLER_H_ |
| OLD | NEW |