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 #include "remoting/host/plugin/daemon_controller.h" | 5 #include "remoting/host/plugin/daemon_controller.h" |
6 | 6 |
7 #include <objbase.h> | 7 #include <objbase.h> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 // Opens the Chromoting service returning its handle in |service_out|. | 95 // Opens the Chromoting service returning its handle in |service_out|. |
96 DWORD OpenService(ScopedScHandle* service_out); | 96 DWORD OpenService(ScopedScHandle* service_out); |
97 | 97 |
98 // The functions that actually do the work. They should be called in | 98 // The functions that actually do the work. They should be called in |
99 // the context of |worker_thread_|; | 99 // the context of |worker_thread_|; |
100 void DoGetConfig(const GetConfigCallback& callback); | 100 void DoGetConfig(const GetConfigCallback& callback); |
101 void DoInstallAsNeededAndStart(scoped_ptr<base::DictionaryValue> config, | 101 void DoInstallAsNeededAndStart(scoped_ptr<base::DictionaryValue> config, |
102 const CompletionCallback& done_callback); | 102 const CompletionCallback& done_callback); |
103 void DoSetConfigAndStart(scoped_ptr<base::DictionaryValue> config, | 103 void DoSetConfigAndStart(scoped_ptr<base::DictionaryValue> config, |
104 const CompletionCallback& done_callback); | 104 const CompletionCallback& done_callback); |
| 105 void DoUpdateConfig(scoped_ptr<base::DictionaryValue> config, |
| 106 const CompletionCallback& done_callback); |
105 void DoStop(const CompletionCallback& done_callback); | 107 void DoStop(const CompletionCallback& done_callback); |
106 | 108 |
107 // The worker thread used for servicing long running operations. | 109 // The worker thread used for servicing long running operations. |
108 ComThread worker_thread_; | 110 ComThread worker_thread_; |
109 | 111 |
110 scoped_ptr<DaemonInstallerWin> installer_; | 112 scoped_ptr<DaemonInstallerWin> installer_; |
111 | 113 |
112 DISALLOW_COPY_AND_ASSIGN(DaemonControllerWin); | 114 DISALLOW_COPY_AND_ASSIGN(DaemonControllerWin); |
113 }; | 115 }; |
114 | 116 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 | 207 |
206 worker_thread_.message_loop_proxy()->PostTask( | 208 worker_thread_.message_loop_proxy()->PostTask( |
207 FROM_HERE, base::Bind( | 209 FROM_HERE, base::Bind( |
208 &DaemonControllerWin::DoInstallAsNeededAndStart, | 210 &DaemonControllerWin::DoInstallAsNeededAndStart, |
209 base::Unretained(this), base::Passed(&config), done_callback)); | 211 base::Unretained(this), base::Passed(&config), done_callback)); |
210 } | 212 } |
211 | 213 |
212 void DaemonControllerWin::UpdateConfig( | 214 void DaemonControllerWin::UpdateConfig( |
213 scoped_ptr<base::DictionaryValue> config, | 215 scoped_ptr<base::DictionaryValue> config, |
214 const CompletionCallback& done_callback) { | 216 const CompletionCallback& done_callback) { |
215 NOTIMPLEMENTED(); | 217 |
216 done_callback.Run(RESULT_FAILED); | 218 worker_thread_.message_loop_proxy()->PostTask( |
| 219 FROM_HERE, base::Bind( |
| 220 &DaemonControllerWin::DoUpdateConfig, |
| 221 base::Unretained(this), base::Passed(&config), done_callback)); |
217 } | 222 } |
218 | 223 |
219 void DaemonControllerWin::Stop(const CompletionCallback& done_callback) { | 224 void DaemonControllerWin::Stop(const CompletionCallback& done_callback) { |
220 worker_thread_.message_loop_proxy()->PostTask( | 225 worker_thread_.message_loop_proxy()->PostTask( |
221 FROM_HERE, base::Bind( | 226 FROM_HERE, base::Bind( |
222 &DaemonControllerWin::DoStop, base::Unretained(this), | 227 &DaemonControllerWin::DoStop, base::Unretained(this), |
223 done_callback)); | 228 done_callback)); |
224 } | 229 } |
225 | 230 |
226 // static | 231 // static |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 if (FAILED(hr)) { | 403 if (FAILED(hr)) { |
399 done_callback.Run(HResultToAsyncResult(hr)); | 404 done_callback.Run(HResultToAsyncResult(hr)); |
400 return; | 405 return; |
401 } | 406 } |
402 | 407 |
403 // Start daemon. | 408 // Start daemon. |
404 hr = control->StartDaemon(); | 409 hr = control->StartDaemon(); |
405 done_callback.Run(HResultToAsyncResult(hr)); | 410 done_callback.Run(HResultToAsyncResult(hr)); |
406 } | 411 } |
407 | 412 |
| 413 void DaemonControllerWin::DoUpdateConfig( |
| 414 scoped_ptr<base::DictionaryValue> config, |
| 415 const CompletionCallback& done_callback) { |
| 416 // TODO(simonmorris): Much of this code was copied from DoSetConfigAndStart(). |
| 417 // Refactor. |
| 418 DCHECK(worker_thread_.message_loop_proxy()->BelongsToCurrentThread()); |
| 419 |
| 420 IDaemonControl* control = NULL; |
| 421 HRESULT hr = worker_thread_.ActivateElevatedController(&control); |
| 422 if (FAILED(hr)) { |
| 423 done_callback.Run(HResultToAsyncResult(hr)); |
| 424 return; |
| 425 } |
| 426 |
| 427 // Store the configuration. |
| 428 std::string file_content; |
| 429 base::JSONWriter::Write(config.get(), &file_content); |
| 430 |
| 431 ScopedBstr host_config(UTF8ToUTF16(file_content).c_str()); |
| 432 if (host_config == NULL) { |
| 433 done_callback.Run(HResultToAsyncResult(E_OUTOFMEMORY)); |
| 434 return; |
| 435 } |
| 436 |
| 437 hr = control->UpdateConfig(host_config); |
| 438 done_callback.Run(HResultToAsyncResult(hr)); |
| 439 } |
| 440 |
408 void DaemonControllerWin::DoStop(const CompletionCallback& done_callback) { | 441 void DaemonControllerWin::DoStop(const CompletionCallback& done_callback) { |
409 DCHECK(worker_thread_.message_loop_proxy()->BelongsToCurrentThread()); | 442 DCHECK(worker_thread_.message_loop_proxy()->BelongsToCurrentThread()); |
410 | 443 |
411 IDaemonControl* control = NULL; | 444 IDaemonControl* control = NULL; |
412 HRESULT hr = worker_thread_.ActivateElevatedController(&control); | 445 HRESULT hr = worker_thread_.ActivateElevatedController(&control); |
413 if (FAILED(hr)) { | 446 if (FAILED(hr)) { |
414 done_callback.Run(HResultToAsyncResult(hr)); | 447 done_callback.Run(HResultToAsyncResult(hr)); |
415 return; | 448 return; |
416 } | 449 } |
417 | 450 |
418 hr = control->StopDaemon(); | 451 hr = control->StopDaemon(); |
419 done_callback.Run(HResultToAsyncResult(hr)); | 452 done_callback.Run(HResultToAsyncResult(hr)); |
420 } | 453 } |
421 | 454 |
422 } // namespace | 455 } // namespace |
423 | 456 |
424 scoped_ptr<DaemonController> remoting::DaemonController::Create() { | 457 scoped_ptr<DaemonController> remoting::DaemonController::Create() { |
425 return scoped_ptr<DaemonController>(new DaemonControllerWin()); | 458 return scoped_ptr<DaemonController>(new DaemonControllerWin()); |
426 } | 459 } |
427 | 460 |
428 } // namespace remoting | 461 } // namespace remoting |
OLD | NEW |