Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(454)

Side by Side Diff: remoting/host/setup/daemon_controller_delegate_win.cc

Issue 232223003: Windows chromoting host installation via the NPAPI plugin (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_delegate_win.h" 5 #include "remoting/host/setup/daemon_controller_delegate_win.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/json/json_reader.h" 11 #include "base/json/json_reader.h"
12 #include "base/json/json_writer.h" 12 #include "base/json/json_writer.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/strings/string16.h" 14 #include "base/strings/string16.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "base/thread_task_runner_handle.h" 16 #include "base/thread_task_runner_handle.h"
17 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "base/timer/timer.h" 18 #include "base/timer/timer.h"
19 #include "base/values.h" 19 #include "base/values.h"
20 #include "base/win/scoped_bstr.h" 20 #include "base/win/scoped_bstr.h"
21 #include "base/win/scoped_comptr.h" 21 #include "base/win/scoped_comptr.h"
22 #include "base/win/windows_version.h" 22 #include "base/win/windows_version.h"
23 #include "remoting/base/scoped_sc_handle_win.h" 23 #include "remoting/base/scoped_sc_handle_win.h"
24 #include "remoting/host/branding.h" 24 #include "remoting/host/branding.h"
25 // chromoting_lib.h contains MIDL-generated declarations. 25 // chromoting_lib.h contains MIDL-generated declarations.
26 #include "remoting/host/chromoting_lib.h" 26 #include "remoting/host/chromoting_lib.h"
27 #include "remoting/host/setup/daemon_installer_win.h"
28 #include "remoting/host/usage_stats_consent.h" 27 #include "remoting/host/usage_stats_consent.h"
29 28
30 using base::win::ScopedBstr; 29 using base::win::ScopedBstr;
31 using base::win::ScopedComPtr; 30 using base::win::ScopedComPtr;
32 31
33 namespace remoting { 32 namespace remoting {
34 33
35 namespace { 34 namespace {
36 35
37 // ProgID of the daemon controller. 36 // ProgID of the daemon controller.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 return DaemonController::RESULT_OK; 120 return DaemonController::RESULT_OK;
122 } else if (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED)) { 121 } else if (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED)) {
123 return DaemonController::RESULT_CANCELLED; 122 return DaemonController::RESULT_CANCELLED;
124 } else { 123 } else {
125 // TODO(sergeyu): Report other errors to the webapp once it knows 124 // TODO(sergeyu): Report other errors to the webapp once it knows
126 // how to handle them. 125 // how to handle them.
127 return DaemonController::RESULT_FAILED; 126 return DaemonController::RESULT_FAILED;
128 } 127 }
129 } 128 }
130 129
130 void InvokeCompletionCallback(
131 const DaemonController::CompletionCallback& done, HRESULT hr) {
132 done.Run(HResultToAsyncResult(hr));
133 }
134
131 } // namespace 135 } // namespace
132 136
133 DaemonControllerDelegateWin::DaemonControllerDelegateWin() 137 DaemonControllerDelegateWin::DaemonControllerDelegateWin()
134 : control_is_elevated_(false), 138 : control_is_elevated_(false),
135 window_handle_(NULL) { 139 window_handle_(NULL) {
136 } 140 }
137 141
138 DaemonControllerDelegateWin::~DaemonControllerDelegateWin() { 142 DaemonControllerDelegateWin::~DaemonControllerDelegateWin() {
139 } 143 }
140 144
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 base::JSONReader::Read(base::UTF16ToUTF8(file_content), 190 base::JSONReader::Read(base::UTF16ToUTF8(file_content),
187 base::JSON_ALLOW_TRAILING_COMMAS)); 191 base::JSON_ALLOW_TRAILING_COMMAS));
188 192
189 if (!config || config->GetType() != base::Value::TYPE_DICTIONARY) 193 if (!config || config->GetType() != base::Value::TYPE_DICTIONARY)
190 return scoped_ptr<base::DictionaryValue>(); 194 return scoped_ptr<base::DictionaryValue>();
191 195
192 return scoped_ptr<base::DictionaryValue>( 196 return scoped_ptr<base::DictionaryValue>(
193 static_cast<base::DictionaryValue*>(config.release())); 197 static_cast<base::DictionaryValue*>(config.release()));
194 } 198 }
195 199
200 void DaemonControllerDelegateWin::InstallHost(
201 const DaemonController::CompletionCallback& done) {
202 DoInstallHost(base::Bind(&InvokeCompletionCallback, done));
203 }
204
196 void DaemonControllerDelegateWin::SetConfigAndStart( 205 void DaemonControllerDelegateWin::SetConfigAndStart(
197 scoped_ptr<base::DictionaryValue> config, 206 scoped_ptr<base::DictionaryValue> config,
198 bool consent, 207 bool consent,
199 const DaemonController::CompletionCallback& done) { 208 const DaemonController::CompletionCallback& done) {
209 DoInstallHost(
210 base::Bind(&DaemonControllerDelegateWin::StartHostWithConfig,
211 base::Unretained(this), base::Passed(&config), consent, done));
212 }
213
214 void DaemonControllerDelegateWin::DoInstallHost(
215 const DaemonInstallerWin::CompletionCallback& done) {
200 // Configure and start the Daemon Controller if it is installed already. 216 // Configure and start the Daemon Controller if it is installed already.
201 HRESULT hr = ActivateElevatedController(); 217 HRESULT hr = ActivateElevatedController();
202 if (SUCCEEDED(hr)) { 218 if (SUCCEEDED(hr)) {
203 OnInstallationComplete(config.Pass(), consent, done, S_OK); 219 done.Run(S_OK);
204 return; 220 return;
205 } 221 }
206 222
207 // Otherwise, install it if its COM registration entry is missing. 223 // Otherwise, install it if its COM registration entry is missing.
208 if (hr == CO_E_CLASSSTRING) { 224 if (hr == CO_E_CLASSSTRING) {
209 DCHECK(!installer_); 225 DCHECK(!installer_);
210 226
211 installer_ = DaemonInstallerWin::Create( 227 installer_ = DaemonInstallerWin::Create(
212 GetTopLevelWindow(window_handle_), 228 GetTopLevelWindow(window_handle_), done);
213 base::Bind(&DaemonControllerDelegateWin::OnInstallationComplete,
214 base::Unretained(this),
215 base::Passed(&config),
216 consent,
217 done));
218 installer_->Install(); 229 installer_->Install();
219 return; 230 return;
220 } 231 }
221 232
222 LOG(ERROR) << "Failed to initiate the Chromoting Host installation " 233 LOG(ERROR) << "Failed to initiate the Chromoting Host installation "
223 << "(error: 0x" << std::hex << hr << std::dec << ")."; 234 << "(error: 0x" << std::hex << hr << std::dec << ").";
224 done.Run(HResultToAsyncResult(hr)); 235 done.Run(hr);
225 } 236 }
226 237
227 void DaemonControllerDelegateWin::UpdateConfig( 238 void DaemonControllerDelegateWin::UpdateConfig(
228 scoped_ptr<base::DictionaryValue> config, 239 scoped_ptr<base::DictionaryValue> config,
229 const DaemonController::CompletionCallback& done) { 240 const DaemonController::CompletionCallback& done) {
230 HRESULT hr = ActivateElevatedController(); 241 HRESULT hr = ActivateElevatedController();
231 if (FAILED(hr)) { 242 if (FAILED(hr)) {
232 done.Run(HResultToAsyncResult(hr)); 243 InvokeCompletionCallback(done, hr);
233 return; 244 return;
234 } 245 }
235 246
236 // Update the configuration. 247 // Update the configuration.
237 ScopedBstr config_str(NULL); 248 ScopedBstr config_str(NULL);
238 ConfigToString(*config, &config_str); 249 ConfigToString(*config, &config_str);
239 if (config_str == NULL) { 250 if (config_str == NULL) {
240 done.Run(HResultToAsyncResult(E_OUTOFMEMORY)); 251 InvokeCompletionCallback(done, E_OUTOFMEMORY);
241 return; 252 return;
242 } 253 }
243 254
244 // Make sure that the PIN confirmation dialog is focused properly. 255 // Make sure that the PIN confirmation dialog is focused properly.
245 hr = control_->SetOwnerWindow( 256 hr = control_->SetOwnerWindow(
246 reinterpret_cast<LONG_PTR>(GetTopLevelWindow(window_handle_))); 257 reinterpret_cast<LONG_PTR>(GetTopLevelWindow(window_handle_)));
247 if (FAILED(hr)) { 258 if (FAILED(hr)) {
248 done.Run(HResultToAsyncResult(hr)); 259 InvokeCompletionCallback(done, hr);
249 return; 260 return;
250 } 261 }
251 262
252 hr = control_->UpdateConfig(config_str); 263 hr = control_->UpdateConfig(config_str);
253 done.Run(HResultToAsyncResult(hr)); 264 InvokeCompletionCallback(done, hr);
254 } 265 }
255 266
256 void DaemonControllerDelegateWin::Stop( 267 void DaemonControllerDelegateWin::Stop(
257 const DaemonController::CompletionCallback& done) { 268 const DaemonController::CompletionCallback& done) {
258 HRESULT hr = ActivateElevatedController(); 269 HRESULT hr = ActivateElevatedController();
259 if (SUCCEEDED(hr)) 270 if (SUCCEEDED(hr))
260 hr = control_->StopDaemon(); 271 hr = control_->StopDaemon();
261 272
262 done.Run(HResultToAsyncResult(hr)); 273 InvokeCompletionCallback(done, hr);
263 } 274 }
264 275
265 void DaemonControllerDelegateWin::SetWindow(void* window_handle) { 276 void DaemonControllerDelegateWin::SetWindow(void* window_handle) {
266 window_handle_ = reinterpret_cast<HWND>(window_handle); 277 window_handle_ = reinterpret_cast<HWND>(window_handle);
267 } 278 }
268 279
269 std::string DaemonControllerDelegateWin::GetVersion() { 280 std::string DaemonControllerDelegateWin::GetVersion() {
270 // Configure and start the Daemon Controller if it is installed already. 281 // Configure and start the Daemon Controller if it is installed already.
271 HRESULT hr = ActivateController(); 282 HRESULT hr = ActivateController();
272 if (FAILED(hr)) 283 if (FAILED(hr))
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 return S_OK; 398 return S_OK;
388 } 399 }
389 400
390 void DaemonControllerDelegateWin::ReleaseController() { 401 void DaemonControllerDelegateWin::ReleaseController() {
391 control_.Release(); 402 control_.Release();
392 control2_.Release(); 403 control2_.Release();
393 release_timer_.reset(); 404 release_timer_.reset();
394 control_is_elevated_ = false; 405 control_is_elevated_ = false;
395 } 406 }
396 407
397 void DaemonControllerDelegateWin::OnInstallationComplete( 408 void DaemonControllerDelegateWin::StartHostWithConfig(
398 scoped_ptr<base::DictionaryValue> config, 409 scoped_ptr<base::DictionaryValue> config,
399 bool consent, 410 bool consent,
400 const DaemonController::CompletionCallback& done, 411 const DaemonController::CompletionCallback& done,
401 HRESULT hr) { 412 HRESULT hr) {
402 installer_.reset(); 413 installer_.reset();
403 414
404 if (FAILED(hr)) { 415 if (FAILED(hr)) {
405 LOG(ERROR) << "Failed to install the Chromoting Host " 416 LOG(ERROR) << "Failed to install the Chromoting Host "
406 << "(error: 0x" << std::hex << hr << std::dec << ")."; 417 << "(error: 0x" << std::hex << hr << std::dec << ").";
407 done.Run(HResultToAsyncResult(hr)); 418 InvokeCompletionCallback(done, hr);
408 return; 419 return;
409 } 420 }
410 421
411 hr = ActivateElevatedController(); 422 hr = ActivateElevatedController();
412 if (FAILED(hr)) { 423 if (FAILED(hr)) {
413 done.Run(HResultToAsyncResult(hr)); 424 InvokeCompletionCallback(done, hr);
414 return; 425 return;
415 } 426 }
416 427
417 // Record the user's consent. 428 // Record the user's consent.
418 if (control2_) { 429 if (control2_) {
419 hr = control2_->SetUsageStatsConsent(consent); 430 hr = control2_->SetUsageStatsConsent(consent);
420 if (FAILED(hr)) { 431 if (FAILED(hr)) {
421 done.Run(HResultToAsyncResult(hr)); 432 InvokeCompletionCallback(done, hr);
422 return; 433 return;
423 } 434 }
424 } 435 }
425 436
426 // Set the configuration. 437 // Set the configuration.
427 ScopedBstr config_str(NULL); 438 ScopedBstr config_str(NULL);
428 ConfigToString(*config, &config_str); 439 ConfigToString(*config, &config_str);
429 if (config_str == NULL) { 440 if (config_str == NULL) {
430 done.Run(HResultToAsyncResult(E_OUTOFMEMORY)); 441 InvokeCompletionCallback(done, E_OUTOFMEMORY);
431 return; 442 return;
432 } 443 }
433 444
434 hr = control_->SetOwnerWindow( 445 hr = control_->SetOwnerWindow(
435 reinterpret_cast<LONG_PTR>(GetTopLevelWindow(window_handle_))); 446 reinterpret_cast<LONG_PTR>(GetTopLevelWindow(window_handle_)));
436 if (FAILED(hr)) { 447 if (FAILED(hr)) {
437 done.Run(HResultToAsyncResult(hr)); 448 InvokeCompletionCallback(done, hr);
438 return; 449 return;
439 } 450 }
440 451
441 hr = control_->SetConfig(config_str); 452 hr = control_->SetConfig(config_str);
442 if (FAILED(hr)) { 453 if (FAILED(hr)) {
443 done.Run(HResultToAsyncResult(hr)); 454 InvokeCompletionCallback(done, hr);
444 return; 455 return;
445 } 456 }
446 457
447 // Start daemon. 458 // Start daemon.
448 hr = control_->StartDaemon(); 459 hr = control_->StartDaemon();
449 done.Run(HResultToAsyncResult(hr)); 460 InvokeCompletionCallback(done, hr);
450 } 461 }
451 462
452 scoped_refptr<DaemonController> DaemonController::Create() { 463 scoped_refptr<DaemonController> DaemonController::Create() {
453 scoped_ptr<DaemonController::Delegate> delegate( 464 scoped_ptr<DaemonController::Delegate> delegate(
454 new DaemonControllerDelegateWin()); 465 new DaemonControllerDelegateWin());
455 return new DaemonController(delegate.Pass()); 466 return new DaemonController(delegate.Pass());
456 } 467 }
457 468
458 } // namespace remoting 469 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698