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

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

Issue 10048003: The Chromoting service should not start automatically unless it was configured from the webapp to d… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: CR feedback Created 8 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 | 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 // This file implements the Windows service controlling Me2Me host processes 5 // This file implements the Windows service controlling Me2Me host processes
6 // running within user sessions. 6 // running within user sessions.
7 7
8 #include "remoting/host/host_service_win.h" 8 #include "remoting/host/host_service_win.h"
9 9
10 #include <windows.h> 10 #include <windows.h>
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 service_name_(UTF8ToUTF16(kWindowsServiceName)), 105 service_name_(UTF8ToUTF16(kWindowsServiceName)),
106 service_status_handle_(0), 106 service_status_handle_(0),
107 shutting_down_(false), 107 shutting_down_(false),
108 stopped_event_(true, false) { 108 stopped_event_(true, false) {
109 } 109 }
110 110
111 HostService::~HostService() { 111 HostService::~HostService() {
112 } 112 }
113 113
114 void HostService::AddWtsConsoleObserver(WtsConsoleObserver* observer) { 114 void HostService::AddWtsConsoleObserver(WtsConsoleObserver* observer) {
115 DCHECK(message_loop_->message_loop_proxy()->BelongsToCurrentThread());
116
115 console_observers_.AddObserver(observer); 117 console_observers_.AddObserver(observer);
116 } 118 }
117 119
118 void HostService::RemoveWtsConsoleObserver(WtsConsoleObserver* observer) { 120 void HostService::RemoveWtsConsoleObserver(WtsConsoleObserver* observer) {
121 DCHECK(message_loop_->message_loop_proxy()->BelongsToCurrentThread());
122
119 console_observers_.RemoveObserver(observer); 123 console_observers_.RemoveObserver(observer);
120 } 124 }
121 125
126 void HostService::RequestRemoveWtsConsoleObserver(
127 WtsConsoleObserver* observer) {
128 DCHECK(message_loop_->message_loop_proxy()->BelongsToCurrentThread());
129
130 observer->OnSessionDetached();
131 console_observers_.RemoveObserver(observer);
132
133 // Stop the service if there are no more observers.
134 if (!console_observers_.might_have_observers()) {
135 message_loop_->PostTask(FROM_HERE, MessageLoop::QuitClosure());
136 }
137 }
138
122 void HostService::OnSessionChange() { 139 void HostService::OnSessionChange() {
123 // WTSGetActiveConsoleSessionId is a very cheap API. It basically reads 140 // WTSGetActiveConsoleSessionId is a very cheap API. It basically reads
124 // a single value from shared memory. Therefore it is better to check if 141 // a single value from shared memory. Therefore it is better to check if
125 // the console session is still the same every time a session change 142 // the console session is still the same every time a session change
126 // notification event is posted. This also takes care of coalescing multiple 143 // notification event is posted. This also takes care of coalescing multiple
127 // events into one since we look at the latest state. 144 // events into one since we look at the latest state.
128 uint32 console_session_id = kInvalidSession; 145 uint32 console_session_id = kInvalidSession;
129 if (!shutting_down_) { 146 if (!shutting_down_) {
130 console_session_id = WTSGetActiveConsoleSessionId(); 147 console_session_id = WTSGetActiveConsoleSessionId();
131 } 148 }
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 367
351 int HostService::Run() { 368 int HostService::Run() {
352 return (this->*run_routine_)(); 369 return (this->*run_routine_)();
353 } 370 }
354 371
355 void HostService::RunMessageLoop() { 372 void HostService::RunMessageLoop() {
356 // Launch the I/O thread. 373 // Launch the I/O thread.
357 base::Thread io_thread(kIoThreadName); 374 base::Thread io_thread(kIoThreadName);
358 base::Thread::Options io_thread_options(MessageLoop::TYPE_IO, 0); 375 base::Thread::Options io_thread_options(MessageLoop::TYPE_IO, 0);
359 if (!io_thread.StartWithOptions(io_thread_options)) { 376 if (!io_thread.StartWithOptions(io_thread_options)) {
377 LOG(FATAL) << "Failed to start the I/O thread";
360 shutting_down_ = true; 378 shutting_down_ = true;
361 stopped_event_.Signal(); 379 stopped_event_.Signal();
362 return; 380 return;
363 } 381 }
364 382
365 WtsSessionProcessLauncher launcher(this, host_binary_, &io_thread); 383 WtsSessionProcessLauncher launcher(this, host_binary_,
384 message_loop_->message_loop_proxy(),
385 io_thread.message_loop_proxy());
366 386
367 // Run the service. 387 // Run the service.
368 message_loop_->Run(); 388 message_loop_->Run();
369 389
370 // Clean up the observers by emulating detaching from the console. 390 // Clean up the observers by emulating detaching from the console.
371 shutting_down_ = true; 391 shutting_down_ = true;
372 OnSessionChange(); 392 OnSessionChange();
373 393
374 // Release the control handler. 394 // Release the control handler.
375 stopped_event_.Signal(); 395 stopped_event_.Signal();
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 } 607 }
588 608
589 remoting::HostService* service = remoting::HostService::GetInstance(); 609 remoting::HostService* service = remoting::HostService::GetInstance();
590 if (!service->InitWithCommandLine(command_line)) { 610 if (!service->InitWithCommandLine(command_line)) {
591 usage(argv[0]); 611 usage(argv[0]);
592 return kUsageExitCode; 612 return kUsageExitCode;
593 } 613 }
594 614
595 return service->Run(); 615 return service->Run();
596 } 616 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698