| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 #include "remoting/host/setup/daemon_controller.h" | 5 #include "remoting/host/setup/daemon_controller.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
| 12 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "remoting/base/auto_thread.h" | 15 #include "remoting/base/auto_thread.h" |
| 16 #include "remoting/base/auto_thread_task_runner.h" | 16 #include "remoting/base/auto_thread_task_runner.h" |
| 17 | 17 |
| 18 namespace remoting { | 18 namespace remoting { |
| 19 | 19 |
| 20 // Name of the Daemon Controller's worker thread. | 20 // Name of the Daemon Controller's worker thread. |
| 21 const char kDaemonControllerThreadName[] = "Daemon Controller thread"; | 21 const char kDaemonControllerThreadName[] = "Daemon Controller thread"; |
| 22 | 22 |
| 23 DaemonController::DaemonController(scoped_ptr<Delegate> delegate) | 23 DaemonController::DaemonController(std::unique_ptr<Delegate> delegate) |
| 24 : caller_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 24 : caller_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 25 delegate_(std::move(delegate)) { | 25 delegate_(std::move(delegate)) { |
| 26 // Launch the delegate thread. | 26 // Launch the delegate thread. |
| 27 delegate_thread_.reset(new AutoThread(kDaemonControllerThreadName)); | 27 delegate_thread_.reset(new AutoThread(kDaemonControllerThreadName)); |
| 28 #if defined(OS_WIN) | 28 #if defined(OS_WIN) |
| 29 delegate_thread_->SetComInitType(AutoThread::COM_INIT_STA); | 29 delegate_thread_->SetComInitType(AutoThread::COM_INIT_STA); |
| 30 delegate_task_runner_ = | 30 delegate_task_runner_ = |
| 31 delegate_thread_->StartWithType(base::MessageLoop::TYPE_UI); | 31 delegate_thread_->StartWithType(base::MessageLoop::TYPE_UI); |
| 32 #else | 32 #else |
| 33 delegate_task_runner_ = | 33 delegate_task_runner_ = |
| (...skipping 10 matching lines...) Expand all Loading... |
| 44 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 44 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 45 | 45 |
| 46 DaemonController::GetConfigCallback wrapped_done = base::Bind( | 46 DaemonController::GetConfigCallback wrapped_done = base::Bind( |
| 47 &DaemonController::InvokeConfigCallbackAndScheduleNext, this, done); | 47 &DaemonController::InvokeConfigCallbackAndScheduleNext, this, done); |
| 48 base::Closure request = base::Bind( | 48 base::Closure request = base::Bind( |
| 49 &DaemonController::DoGetConfig, this, wrapped_done); | 49 &DaemonController::DoGetConfig, this, wrapped_done); |
| 50 ServiceOrQueueRequest(request); | 50 ServiceOrQueueRequest(request); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void DaemonController::SetConfigAndStart( | 53 void DaemonController::SetConfigAndStart( |
| 54 scoped_ptr<base::DictionaryValue> config, | 54 std::unique_ptr<base::DictionaryValue> config, |
| 55 bool consent, | 55 bool consent, |
| 56 const CompletionCallback& done) { | 56 const CompletionCallback& done) { |
| 57 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 57 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 58 | 58 |
| 59 DaemonController::CompletionCallback wrapped_done = base::Bind( | 59 DaemonController::CompletionCallback wrapped_done = base::Bind( |
| 60 &DaemonController::InvokeCompletionCallbackAndScheduleNext, this, done); | 60 &DaemonController::InvokeCompletionCallbackAndScheduleNext, this, done); |
| 61 base::Closure request = base::Bind( | 61 base::Closure request = base::Bind( |
| 62 &DaemonController::DoSetConfigAndStart, this, base::Passed(&config), | 62 &DaemonController::DoSetConfigAndStart, this, base::Passed(&config), |
| 63 consent, wrapped_done); | 63 consent, wrapped_done); |
| 64 ServiceOrQueueRequest(request); | 64 ServiceOrQueueRequest(request); |
| 65 } | 65 } |
| 66 | 66 |
| 67 void DaemonController::UpdateConfig(scoped_ptr<base::DictionaryValue> config, | 67 void DaemonController::UpdateConfig( |
| 68 const CompletionCallback& done) { | 68 std::unique_ptr<base::DictionaryValue> config, |
| 69 const CompletionCallback& done) { |
| 69 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 70 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 70 | 71 |
| 71 DaemonController::CompletionCallback wrapped_done = base::Bind( | 72 DaemonController::CompletionCallback wrapped_done = base::Bind( |
| 72 &DaemonController::InvokeCompletionCallbackAndScheduleNext, this, done); | 73 &DaemonController::InvokeCompletionCallbackAndScheduleNext, this, done); |
| 73 base::Closure request = base::Bind( | 74 base::Closure request = base::Bind( |
| 74 &DaemonController::DoUpdateConfig, this, base::Passed(&config), | 75 &DaemonController::DoUpdateConfig, this, base::Passed(&config), |
| 75 wrapped_done); | 76 wrapped_done); |
| 76 ServiceOrQueueRequest(request); | 77 ServiceOrQueueRequest(request); |
| 77 } | 78 } |
| 78 | 79 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 102 delegate_task_runner_->DeleteSoon(FROM_HERE, delegate_.release()); | 103 delegate_task_runner_->DeleteSoon(FROM_HERE, delegate_.release()); |
| 103 | 104 |
| 104 // Stop the thread. | 105 // Stop the thread. |
| 105 delegate_task_runner_ = nullptr; | 106 delegate_task_runner_ = nullptr; |
| 106 caller_task_runner_->DeleteSoon(FROM_HERE, delegate_thread_.release()); | 107 caller_task_runner_->DeleteSoon(FROM_HERE, delegate_thread_.release()); |
| 107 } | 108 } |
| 108 | 109 |
| 109 void DaemonController::DoGetConfig(const GetConfigCallback& done) { | 110 void DaemonController::DoGetConfig(const GetConfigCallback& done) { |
| 110 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); | 111 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); |
| 111 | 112 |
| 112 scoped_ptr<base::DictionaryValue> config = delegate_->GetConfig(); | 113 std::unique_ptr<base::DictionaryValue> config = delegate_->GetConfig(); |
| 113 caller_task_runner_->PostTask(FROM_HERE, | 114 caller_task_runner_->PostTask(FROM_HERE, |
| 114 base::Bind(done, base::Passed(&config))); | 115 base::Bind(done, base::Passed(&config))); |
| 115 } | 116 } |
| 116 | 117 |
| 117 void DaemonController::DoSetConfigAndStart( | 118 void DaemonController::DoSetConfigAndStart( |
| 118 scoped_ptr<base::DictionaryValue> config, | 119 std::unique_ptr<base::DictionaryValue> config, |
| 119 bool consent, | 120 bool consent, |
| 120 const CompletionCallback& done) { | 121 const CompletionCallback& done) { |
| 121 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); | 122 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); |
| 122 | 123 |
| 123 delegate_->SetConfigAndStart(std::move(config), consent, done); | 124 delegate_->SetConfigAndStart(std::move(config), consent, done); |
| 124 } | 125 } |
| 125 | 126 |
| 126 void DaemonController::DoUpdateConfig( | 127 void DaemonController::DoUpdateConfig( |
| 127 scoped_ptr<base::DictionaryValue> config, | 128 std::unique_ptr<base::DictionaryValue> config, |
| 128 const CompletionCallback& done) { | 129 const CompletionCallback& done) { |
| 129 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); | 130 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); |
| 130 | 131 |
| 131 delegate_->UpdateConfig(std::move(config), done); | 132 delegate_->UpdateConfig(std::move(config), done); |
| 132 } | 133 } |
| 133 | 134 |
| 134 void DaemonController::DoStop(const CompletionCallback& done) { | 135 void DaemonController::DoStop(const CompletionCallback& done) { |
| 135 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); | 136 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); |
| 136 | 137 |
| 137 delegate_->Stop(done); | 138 delegate_->Stop(done); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 156 this, done, result)); | 157 this, done, result)); |
| 157 return; | 158 return; |
| 158 } | 159 } |
| 159 | 160 |
| 160 done.Run(result); | 161 done.Run(result); |
| 161 ScheduleNext(); | 162 ScheduleNext(); |
| 162 } | 163 } |
| 163 | 164 |
| 164 void DaemonController::InvokeConfigCallbackAndScheduleNext( | 165 void DaemonController::InvokeConfigCallbackAndScheduleNext( |
| 165 const GetConfigCallback& done, | 166 const GetConfigCallback& done, |
| 166 scoped_ptr<base::DictionaryValue> config) { | 167 std::unique_ptr<base::DictionaryValue> config) { |
| 167 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 168 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 168 | 169 |
| 169 done.Run(std::move(config)); | 170 done.Run(std::move(config)); |
| 170 ScheduleNext(); | 171 ScheduleNext(); |
| 171 } | 172 } |
| 172 | 173 |
| 173 void DaemonController::InvokeConsentCallbackAndScheduleNext( | 174 void DaemonController::InvokeConsentCallbackAndScheduleNext( |
| 174 const GetUsageStatsConsentCallback& done, | 175 const GetUsageStatsConsentCallback& done, |
| 175 const UsageStatsConsent& consent) { | 176 const UsageStatsConsent& consent) { |
| 176 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 177 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 192 if (!servicing_request) | 193 if (!servicing_request) |
| 193 ServiceNextRequest(); | 194 ServiceNextRequest(); |
| 194 } | 195 } |
| 195 | 196 |
| 196 void DaemonController::ServiceNextRequest() { | 197 void DaemonController::ServiceNextRequest() { |
| 197 if (!pending_requests_.empty()) | 198 if (!pending_requests_.empty()) |
| 198 delegate_task_runner_->PostTask(FROM_HERE, pending_requests_.front()); | 199 delegate_task_runner_->PostTask(FROM_HERE, pending_requests_.front()); |
| 199 } | 200 } |
| 200 | 201 |
| 201 } // namespace remoting | 202 } // namespace remoting |
| OLD | NEW |