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

Side by Side Diff: remoting/host/desktop_session_win.cc

Issue 17261013: Change the daemon start type to 'manual' if the host ID has been deleted. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
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/desktop_session_win.h" 5 #include "remoting/host/desktop_session_win.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <sddl.h> 8 #include <sddl.h>
9 9
10 #include "base/base_switches.h" 10 #include "base/base_switches.h"
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 void RdpSession::OnRdpConnected(const net::IPEndPoint& client_endpoint) { 266 void RdpSession::OnRdpConnected(const net::IPEndPoint& client_endpoint) {
267 DCHECK(caller_task_runner()->BelongsToCurrentThread()); 267 DCHECK(caller_task_runner()->BelongsToCurrentThread());
268 268
269 StopMonitoring(); 269 StopMonitoring();
270 StartMonitoring(client_endpoint); 270 StartMonitoring(client_endpoint);
271 } 271 }
272 272
273 void RdpSession::OnRdpClosed() { 273 void RdpSession::OnRdpClosed() {
274 DCHECK(caller_task_runner()->BelongsToCurrentThread()); 274 DCHECK(caller_task_runner()->BelongsToCurrentThread());
275 275
276 OnPermanentError(); 276 TerminateSession();
277 } 277 }
278 278
279 void RdpSession::SetScreenResolution(const ScreenResolution& resolution) { 279 void RdpSession::SetScreenResolution(const ScreenResolution& resolution) {
280 DCHECK(caller_task_runner()->BelongsToCurrentThread()); 280 DCHECK(caller_task_runner()->BelongsToCurrentThread());
281 281
282 // TODO(alexeypa): implement resize-to-client for RDP sessions here. 282 // TODO(alexeypa): implement resize-to-client for RDP sessions here.
283 // See http://crbug.com/137696. 283 // See http://crbug.com/137696.
284 NOTIMPLEMENTED(); 284 NOTIMPLEMENTED();
285 } 285 }
286 286
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 418 DCHECK(caller_task_runner_->BelongsToCurrentThread());
419 419
420 StopMonitoring(); 420 StopMonitoring();
421 } 421 }
422 422
423 void DesktopSessionWin::OnSessionAttachTimeout() { 423 void DesktopSessionWin::OnSessionAttachTimeout() {
424 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 424 DCHECK(caller_task_runner_->BelongsToCurrentThread());
425 425
426 LOG(ERROR) << "Session attach notification didn't arrived within " 426 LOG(ERROR) << "Session attach notification didn't arrived within "
427 << kSessionAttachTimeoutSeconds << " seconds."; 427 << kSessionAttachTimeoutSeconds << " seconds.";
428 OnPermanentError(); 428 TerminateSession();
429 } 429 }
430 430
431 void DesktopSessionWin::StartMonitoring( 431 void DesktopSessionWin::StartMonitoring(
432 const net::IPEndPoint& client_endpoint) { 432 const net::IPEndPoint& client_endpoint) {
433 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 433 DCHECK(caller_task_runner_->BelongsToCurrentThread());
434 DCHECK(!monitoring_notifications_); 434 DCHECK(!monitoring_notifications_);
435 DCHECK(!session_attach_timer_.IsRunning()); 435 DCHECK(!session_attach_timer_.IsRunning());
436 436
437 ReportElapsedTime("started monitoring"); 437 ReportElapsedTime("started monitoring");
438 438
(...skipping 12 matching lines...) Expand all
451 ReportElapsedTime("stopped monitoring"); 451 ReportElapsedTime("stopped monitoring");
452 452
453 monitoring_notifications_ = false; 453 monitoring_notifications_ = false;
454 monitor_->RemoveWtsTerminalObserver(this); 454 monitor_->RemoveWtsTerminalObserver(this);
455 } 455 }
456 456
457 session_attach_timer_.Stop(); 457 session_attach_timer_.Stop();
458 OnSessionDetached(); 458 OnSessionDetached();
459 } 459 }
460 460
461 void DesktopSessionWin::TerminateSession() {
462 DCHECK(caller_task_runner_->BelongsToCurrentThread());
463
464 StopMonitoring();
465
466 // This call will delete |this| so it should be at the very end of the method.
467 daemon_process()->CloseDesktopSession(id());
468 }
469
461 void DesktopSessionWin::OnChannelConnected(int32 peer_pid) { 470 void DesktopSessionWin::OnChannelConnected(int32 peer_pid) {
462 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 471 DCHECK(caller_task_runner_->BelongsToCurrentThread());
463 472
464 ReportElapsedTime("channel connected"); 473 ReportElapsedTime("channel connected");
465 474
466 // Obtain the handle of the desktop process. It will be passed to the network 475 // Obtain the handle of the desktop process. It will be passed to the network
467 // process to use to duplicate handles of shared memory objects from 476 // process to use to duplicate handles of shared memory objects from
468 // the desktop process. 477 // the desktop process.
469 desktop_process_.Set(OpenProcess(PROCESS_DUP_HANDLE, false, peer_pid)); 478 desktop_process_.Set(OpenProcess(PROCESS_DUP_HANDLE, false, peer_pid));
470 if (!desktop_process_.IsValid()) { 479 if (!desktop_process_.IsValid()) {
(...skipping 17 matching lines...) Expand all
488 IPC_END_MESSAGE_MAP() 497 IPC_END_MESSAGE_MAP()
489 498
490 if (!handled) { 499 if (!handled) {
491 LOG(ERROR) << "Received unexpected IPC type: " << message.type(); 500 LOG(ERROR) << "Received unexpected IPC type: " << message.type();
492 CrashDesktopProcess(FROM_HERE); 501 CrashDesktopProcess(FROM_HERE);
493 } 502 }
494 503
495 return handled; 504 return handled;
496 } 505 }
497 506
498 void DesktopSessionWin::OnPermanentError() { 507 void DesktopSessionWin::OnPermanentError(int exit_code) {
499 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 508 DCHECK(caller_task_runner_->BelongsToCurrentThread());
500 509
501 StopMonitoring(); 510 TerminateSession();
502
503 // This call will delete |this| so it should be at the very end of the method.
504 daemon_process()->CloseDesktopSession(id());
505 } 511 }
506 512
507 void DesktopSessionWin::OnSessionAttached(uint32 session_id) { 513 void DesktopSessionWin::OnSessionAttached(uint32 session_id) {
508 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 514 DCHECK(caller_task_runner_->BelongsToCurrentThread());
509 DCHECK(!launcher_); 515 DCHECK(!launcher_);
510 DCHECK(monitoring_notifications_); 516 DCHECK(monitoring_notifications_);
511 517
512 ReportElapsedTime("attached"); 518 ReportElapsedTime("attached");
513 519
514 // Launch elevated on Win8 to be able to inject Alt+Tab. 520 // Launch elevated on Win8 to be able to inject Alt+Tab.
515 bool launch_elevated = base::win::GetVersion() >= base::win::VERSION_WIN8; 521 bool launch_elevated = base::win::GetVersion() >= base::win::VERSION_WIN8;
516 522
517 // Get the name of the executable to run. |kDesktopBinaryName| specifies 523 // Get the name of the executable to run. |kDesktopBinaryName| specifies
518 // uiAccess="true" in it's manifest. 524 // uiAccess="true" in it's manifest.
519 base::FilePath desktop_binary; 525 base::FilePath desktop_binary;
520 bool result; 526 bool result;
521 if (launch_elevated) { 527 if (launch_elevated) {
522 result = GetInstalledBinaryPath(kDesktopBinaryName, &desktop_binary); 528 result = GetInstalledBinaryPath(kDesktopBinaryName, &desktop_binary);
523 } else { 529 } else {
524 result = GetInstalledBinaryPath(kHostBinaryName, &desktop_binary); 530 result = GetInstalledBinaryPath(kHostBinaryName, &desktop_binary);
525 } 531 }
526 532
527 if (!result) { 533 if (!result) {
528 OnPermanentError(); 534 TerminateSession();
529 return; 535 return;
530 } 536 }
531 537
532 session_attach_timer_.Stop(); 538 session_attach_timer_.Stop();
533 539
534 scoped_ptr<CommandLine> target(new CommandLine(desktop_binary)); 540 scoped_ptr<CommandLine> target(new CommandLine(desktop_binary));
535 target->AppendSwitchASCII(kProcessTypeSwitchName, kProcessTypeDesktop); 541 target->AppendSwitchASCII(kProcessTypeSwitchName, kProcessTypeDesktop);
536 // Copy the command line switches enabling verbose logging. 542 // Copy the command line switches enabling verbose logging.
537 target->CopySwitchesFrom(*CommandLine::ForCurrentProcess(), 543 target->CopySwitchesFrom(*CommandLine::ForCurrentProcess(),
538 kCopiedSwitchNames, 544 kCopiedSwitchNames,
539 arraysize(kCopiedSwitchNames)); 545 arraysize(kCopiedSwitchNames));
540 546
541 // Create a delegate capable of launching a process in a different session. 547 // Create a delegate capable of launching a process in a different session.
542 scoped_ptr<WtsSessionProcessDelegate> delegate( 548 scoped_ptr<WtsSessionProcessDelegate> delegate(
543 new WtsSessionProcessDelegate(io_task_runner_, 549 new WtsSessionProcessDelegate(io_task_runner_,
544 target.Pass(), 550 target.Pass(),
545 launch_elevated, 551 launch_elevated,
546 WideToUTF8(kDaemonIpcSecurityDescriptor))); 552 WideToUTF8(kDaemonIpcSecurityDescriptor)));
547 if (!delegate->Initialize(session_id)) { 553 if (!delegate->Initialize(session_id)) {
548 OnPermanentError(); 554 TerminateSession();
549 return; 555 return;
550 } 556 }
551 557
552 // Create a launcher for the desktop process, using the per-session delegate. 558 // Create a launcher for the desktop process, using the per-session delegate.
553 launcher_.reset(new WorkerProcessLauncher(delegate.Pass(), this)); 559 launcher_.reset(new WorkerProcessLauncher(delegate.Pass(), this));
554 } 560 }
555 561
556 void DesktopSessionWin::OnSessionDetached() { 562 void DesktopSessionWin::OnSessionDetached() {
557 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 563 DCHECK(caller_task_runner_->BelongsToCurrentThread());
558 564
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 exploded.hour, 606 exploded.hour,
601 exploded.minute, 607 exploded.minute,
602 exploded.second, 608 exploded.second,
603 exploded.millisecond, 609 exploded.millisecond,
604 passed.c_str()); 610 passed.c_str());
605 611
606 last_timestamp_ = now; 612 last_timestamp_ = now;
607 } 613 }
608 614
609 } // namespace remoting 615 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698