| 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 <memory> |
| 8 #include <queue> | 9 #include <queue> |
| 9 #include <string> | 10 #include <string> |
| 10 | 11 |
| 11 #include "base/callback.h" | 12 #include "base/callback.h" |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 | 15 |
| 16 namespace base { | 16 namespace base { |
| 17 class DictionaryValue; | 17 class DictionaryValue; |
| 18 class SingleThreadTaskRunner; | 18 class SingleThreadTaskRunner; |
| 19 } // namespace base | 19 } // namespace base |
| 20 | 20 |
| 21 namespace remoting { | 21 namespace remoting { |
| 22 | 22 |
| 23 class AutoThread; | 23 class AutoThread; |
| 24 class AutoThreadTaskRunner; | 24 class AutoThreadTaskRunner; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 RESULT_CANCELLED = 2, | 59 RESULT_CANCELLED = 2, |
| 60 | 60 |
| 61 // TODO(sergeyu): Add more error codes when we know how to handle | 61 // TODO(sergeyu): Add more error codes when we know how to handle |
| 62 // them in the webapp. | 62 // them in the webapp. |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 // Callback type for GetConfig(). If the host is configured then a dictionary | 65 // Callback type for GetConfig(). If the host is configured then a dictionary |
| 66 // is returned containing host_id and xmpp_login, with security-sensitive | 66 // is returned containing host_id and xmpp_login, with security-sensitive |
| 67 // fields filtered out. An empty dictionary is returned if the host is not | 67 // fields filtered out. An empty dictionary is returned if the host is not |
| 68 // configured, and nullptr if the configuration is corrupt or cannot be read. | 68 // configured, and nullptr if the configuration is corrupt or cannot be read. |
| 69 typedef base::Callback<void (scoped_ptr<base::DictionaryValue> config)> | 69 typedef base::Callback<void(std::unique_ptr<base::DictionaryValue> config)> |
| 70 GetConfigCallback; | 70 GetConfigCallback; |
| 71 | 71 |
| 72 // Callback used for asynchronous operations, e.g. when | 72 // Callback used for asynchronous operations, e.g. when |
| 73 // starting/stopping the service. | 73 // starting/stopping the service. |
| 74 typedef base::Callback<void (AsyncResult result)> CompletionCallback; | 74 typedef base::Callback<void (AsyncResult result)> CompletionCallback; |
| 75 | 75 |
| 76 struct UsageStatsConsent { | 76 struct UsageStatsConsent { |
| 77 // Indicates whether crash dump reporting is supported by the host. | 77 // Indicates whether crash dump reporting is supported by the host. |
| 78 bool supported; | 78 bool supported; |
| 79 | 79 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 100 class Delegate { | 100 class Delegate { |
| 101 public: | 101 public: |
| 102 virtual ~Delegate() {} | 102 virtual ~Delegate() {} |
| 103 | 103 |
| 104 // Return the "installed/running" state of the daemon process. This method | 104 // Return the "installed/running" state of the daemon process. This method |
| 105 // should avoid accessing any data members of the implementation. | 105 // should avoid accessing any data members of the implementation. |
| 106 virtual State GetState() = 0; | 106 virtual State GetState() = 0; |
| 107 | 107 |
| 108 // Queries current host configuration. Any values that might be security | 108 // Queries current host configuration. Any values that might be security |
| 109 // sensitive have been filtered out. | 109 // sensitive have been filtered out. |
| 110 virtual scoped_ptr<base::DictionaryValue> GetConfig() = 0; | 110 virtual std::unique_ptr<base::DictionaryValue> GetConfig() = 0; |
| 111 | 111 |
| 112 // Starts the daemon process. This may require that the daemon be | 112 // Starts the daemon process. This may require that the daemon be |
| 113 // downloaded and installed. |done| is invoked on the calling thread when | 113 // downloaded and installed. |done| is invoked on the calling thread when |
| 114 // the operation is completed. | 114 // the operation is completed. |
| 115 virtual void SetConfigAndStart( | 115 virtual void SetConfigAndStart( |
| 116 scoped_ptr<base::DictionaryValue> config, | 116 std::unique_ptr<base::DictionaryValue> config, |
| 117 bool consent, | 117 bool consent, |
| 118 const CompletionCallback& done) = 0; | 118 const CompletionCallback& done) = 0; |
| 119 | 119 |
| 120 // Updates current host configuration with the values specified in | 120 // Updates current host configuration with the values specified in |
| 121 // |config|. Any value in the existing configuration that isn't specified in | 121 // |config|. Any value in the existing configuration that isn't specified in |
| 122 // |config| is preserved. |config| must not contain host_id or xmpp_login | 122 // |config| is preserved. |config| must not contain host_id or xmpp_login |
| 123 // values, because implementations of this method cannot change them. |done| | 123 // values, because implementations of this method cannot change them. |done| |
| 124 // is invoked on the calling thread when the operation is completed. | 124 // is invoked on the calling thread when the operation is completed. |
| 125 virtual void UpdateConfig( | 125 virtual void UpdateConfig(std::unique_ptr<base::DictionaryValue> config, |
| 126 scoped_ptr<base::DictionaryValue> config, | 126 const CompletionCallback& done) = 0; |
| 127 const CompletionCallback& done) = 0; | |
| 128 | 127 |
| 129 // Stops the daemon process. |done| is invoked on the calling thread when | 128 // Stops the daemon process. |done| is invoked on the calling thread when |
| 130 // the operation is completed. | 129 // the operation is completed. |
| 131 virtual void Stop(const CompletionCallback& done) = 0; | 130 virtual void Stop(const CompletionCallback& done) = 0; |
| 132 | 131 |
| 133 // Get the user's consent to crash reporting. | 132 // Get the user's consent to crash reporting. |
| 134 virtual UsageStatsConsent GetUsageStatsConsent() = 0; | 133 virtual UsageStatsConsent GetUsageStatsConsent() = 0; |
| 135 }; | 134 }; |
| 136 | 135 |
| 137 static scoped_refptr<DaemonController> Create(); | 136 static scoped_refptr<DaemonController> Create(); |
| 138 | 137 |
| 139 explicit DaemonController(scoped_ptr<Delegate> delegate); | 138 explicit DaemonController(std::unique_ptr<Delegate> delegate); |
| 140 | 139 |
| 141 // Return the "installed/running" state of the daemon process. | 140 // Return the "installed/running" state of the daemon process. |
| 142 // | 141 // |
| 143 // TODO(sergeyu): This method is called synchronously from the | 142 // TODO(sergeyu): This method is called synchronously from the |
| 144 // webapp. In most cases it requires IO operations, so it may block | 143 // webapp. In most cases it requires IO operations, so it may block |
| 145 // the user interface. Replace it with asynchronous notifications, | 144 // the user interface. Replace it with asynchronous notifications, |
| 146 // e.g. with StartStateNotifications()/StopStateNotifications() methods. | 145 // e.g. with StartStateNotifications()/StopStateNotifications() methods. |
| 147 State GetState(); | 146 State GetState(); |
| 148 | 147 |
| 149 // Queries current host configuration. The |done| is called | 148 // Queries current host configuration. The |done| is called |
| 150 // after the configuration is read, and any values that might be security | 149 // after the configuration is read, and any values that might be security |
| 151 // sensitive have been filtered out. | 150 // sensitive have been filtered out. |
| 152 void GetConfig(const GetConfigCallback& done); | 151 void GetConfig(const GetConfigCallback& done); |
| 153 | 152 |
| 154 // Start the daemon process. This may require that the daemon be | 153 // Start the daemon process. This may require that the daemon be |
| 155 // downloaded and installed. |done| is called when the | 154 // downloaded and installed. |done| is called when the |
| 156 // operation is finished or fails. | 155 // operation is finished or fails. |
| 157 // | 156 // |
| 158 // TODO(sergeyu): This method writes config and starts the host - | 157 // TODO(sergeyu): This method writes config and starts the host - |
| 159 // these two steps are merged for simplicity. Consider splitting it | 158 // these two steps are merged for simplicity. Consider splitting it |
| 160 // into SetConfig() and Start() once we have basic host setup flow | 159 // into SetConfig() and Start() once we have basic host setup flow |
| 161 // working. | 160 // working. |
| 162 void SetConfigAndStart(scoped_ptr<base::DictionaryValue> config, | 161 void SetConfigAndStart(std::unique_ptr<base::DictionaryValue> config, |
| 163 bool consent, | 162 bool consent, |
| 164 const CompletionCallback& done); | 163 const CompletionCallback& done); |
| 165 | 164 |
| 166 // Updates current host configuration with the values specified in | 165 // Updates current host configuration with the values specified in |
| 167 // |config|. Changes must take effect before the call completes. | 166 // |config|. Changes must take effect before the call completes. |
| 168 // Any value in the existing configuration that isn't specified in |config| | 167 // Any value in the existing configuration that isn't specified in |config| |
| 169 // is preserved. |config| must not contain host_id or xmpp_login values, | 168 // is preserved. |config| must not contain host_id or xmpp_login values, |
| 170 // because implementations of this method cannot change them. | 169 // because implementations of this method cannot change them. |
| 171 void UpdateConfig(scoped_ptr<base::DictionaryValue> config, | 170 void UpdateConfig(std::unique_ptr<base::DictionaryValue> config, |
| 172 const CompletionCallback& done); | 171 const CompletionCallback& done); |
| 173 | 172 |
| 174 // Stop the daemon process. It is permitted to call Stop while the daemon | 173 // Stop the daemon process. It is permitted to call Stop while the daemon |
| 175 // process is being installed, in which case the installation should be | 174 // process is being installed, in which case the installation should be |
| 176 // aborted if possible; if not then it is sufficient to ensure that the | 175 // aborted if possible; if not then it is sufficient to ensure that the |
| 177 // daemon process is not started automatically upon successful installation. | 176 // daemon process is not started automatically upon successful installation. |
| 178 // As with Start, Stop may return before the operation is complete--poll | 177 // As with Start, Stop may return before the operation is complete--poll |
| 179 // GetState until the state is STATE_STOPPED. | 178 // GetState until the state is STATE_STOPPED. |
| 180 void Stop(const CompletionCallback& done); | 179 void Stop(const CompletionCallback& done); |
| 181 | 180 |
| 182 // Get the user's consent to crash reporting. | 181 // Get the user's consent to crash reporting. |
| 183 void GetUsageStatsConsent(const GetUsageStatsConsentCallback& done); | 182 void GetUsageStatsConsent(const GetUsageStatsConsentCallback& done); |
| 184 | 183 |
| 185 private: | 184 private: |
| 186 friend class base::RefCountedThreadSafe<DaemonController>; | 185 friend class base::RefCountedThreadSafe<DaemonController>; |
| 187 virtual ~DaemonController(); | 186 virtual ~DaemonController(); |
| 188 | 187 |
| 189 // Blocking helper methods used to call the delegate. | 188 // Blocking helper methods used to call the delegate. |
| 190 void DoGetConfig(const GetConfigCallback& done); | 189 void DoGetConfig(const GetConfigCallback& done); |
| 191 void DoSetConfigAndStart(scoped_ptr<base::DictionaryValue> config, | 190 void DoSetConfigAndStart(std::unique_ptr<base::DictionaryValue> config, |
| 192 bool consent, | 191 bool consent, |
| 193 const CompletionCallback& done); | 192 const CompletionCallback& done); |
| 194 void DoUpdateConfig(scoped_ptr<base::DictionaryValue> config, | 193 void DoUpdateConfig(std::unique_ptr<base::DictionaryValue> config, |
| 195 const CompletionCallback& done); | 194 const CompletionCallback& done); |
| 196 void DoStop(const CompletionCallback& done); | 195 void DoStop(const CompletionCallback& done); |
| 197 void DoGetUsageStatsConsent(const GetUsageStatsConsentCallback& done); | 196 void DoGetUsageStatsConsent(const GetUsageStatsConsentCallback& done); |
| 198 | 197 |
| 199 // "Trampoline" callbacks that schedule the next pending request and then | 198 // "Trampoline" callbacks that schedule the next pending request and then |
| 200 // invoke the original caller-supplied callback. | 199 // invoke the original caller-supplied callback. |
| 201 void InvokeCompletionCallbackAndScheduleNext( | 200 void InvokeCompletionCallbackAndScheduleNext( |
| 202 const CompletionCallback& done, | 201 const CompletionCallback& done, |
| 203 AsyncResult result); | 202 AsyncResult result); |
| 204 void InvokeConfigCallbackAndScheduleNext( | 203 void InvokeConfigCallbackAndScheduleNext( |
| 205 const GetConfigCallback& done, | 204 const GetConfigCallback& done, |
| 206 scoped_ptr<base::DictionaryValue> config); | 205 std::unique_ptr<base::DictionaryValue> config); |
| 207 void InvokeConsentCallbackAndScheduleNext( | 206 void InvokeConsentCallbackAndScheduleNext( |
| 208 const GetUsageStatsConsentCallback& done, | 207 const GetUsageStatsConsentCallback& done, |
| 209 const UsageStatsConsent& consent); | 208 const UsageStatsConsent& consent); |
| 210 | 209 |
| 211 // Queue management methods. | 210 // Queue management methods. |
| 212 void ScheduleNext(); | 211 void ScheduleNext(); |
| 213 void ServiceOrQueueRequest(const base::Closure& request); | 212 void ServiceOrQueueRequest(const base::Closure& request); |
| 214 void ServiceNextRequest(); | 213 void ServiceNextRequest(); |
| 215 | 214 |
| 216 // Task runner on which all public methods of this class should be called. | 215 // Task runner on which all public methods of this class should be called. |
| 217 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_; | 216 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_; |
| 218 | 217 |
| 219 // Task runner used to run blocking calls to the delegate. A single thread | 218 // Task runner used to run blocking calls to the delegate. A single thread |
| 220 // task runner is used to guarantee that one method of the delegate is | 219 // task runner is used to guarantee that one method of the delegate is |
| 221 // called at a time. | 220 // called at a time. |
| 222 scoped_refptr<AutoThreadTaskRunner> delegate_task_runner_; | 221 scoped_refptr<AutoThreadTaskRunner> delegate_task_runner_; |
| 223 | 222 |
| 224 scoped_ptr<AutoThread> delegate_thread_; | 223 std::unique_ptr<AutoThread> delegate_thread_; |
| 225 | 224 |
| 226 scoped_ptr<Delegate> delegate_; | 225 std::unique_ptr<Delegate> delegate_; |
| 227 | 226 |
| 228 std::queue<base::Closure> pending_requests_; | 227 std::queue<base::Closure> pending_requests_; |
| 229 | 228 |
| 230 DISALLOW_COPY_AND_ASSIGN(DaemonController); | 229 DISALLOW_COPY_AND_ASSIGN(DaemonController); |
| 231 }; | 230 }; |
| 232 | 231 |
| 233 } // namespace remoting | 232 } // namespace remoting |
| 234 | 233 |
| 235 #endif // REMOTING_HOST_SETUP_DAEMON_CONTROLLER_H_ | 234 #endif // REMOTING_HOST_SETUP_DAEMON_CONTROLLER_H_ |
| OLD | NEW |