Move generic_handler.* to content\browser\webui since it's needed by all webui pages.
[chromium-blink-merge.git] / remoting / host / win / wts_console_session_process_driver.cc
blob1280ae852756e1ab94f2b4849bfbc905b4c2a094
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
3 // found in the LICENSE file.
5 #include "remoting/host/win/wts_console_session_process_driver.h"
7 #include "base/base_switches.h"
8 #include "base/file_path.h"
9 #include "base/logging.h"
10 #include "base/single_thread_task_runner.h"
11 #include "ipc/ipc_message.h"
12 #include "ipc/ipc_message_macros.h"
13 #include "remoting/host/chromoting_messages.h"
14 #include "remoting/host/ipc_constants.h"
15 #include "remoting/host/sas_injector.h"
16 #include "remoting/host/win/worker_process_launcher.h"
17 #include "remoting/host/win/wts_console_monitor.h"
18 #include "remoting/host/win/wts_session_process_delegate.h"
20 // The security descriptor of the named pipe the process running in the console
21 // session connects to. It gives full access to LocalSystem and denies access by
22 // anyone else.
23 const char kDaemonIpcSecurityDescriptor[] = "O:SYG:SYD:(A;;GA;;;SY)";
25 namespace remoting {
27 WtsConsoleSessionProcessDriver::WtsConsoleSessionProcessDriver(
28 const base::Closure& stopped_callback,
29 WtsConsoleMonitor* monitor,
30 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,
31 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner)
32 : Stoppable(caller_task_runner, stopped_callback),
33 caller_task_runner_(caller_task_runner),
34 io_task_runner_(io_task_runner),
35 monitor_(monitor) {
36 monitor_->AddWtsConsoleObserver(this);
39 WtsConsoleSessionProcessDriver::~WtsConsoleSessionProcessDriver() {
40 DCHECK(caller_task_runner_->BelongsToCurrentThread());
42 // Make sure that the object is completely stopped. The same check exists
43 // in Stoppable::~Stoppable() but this one helps us to fail early and
44 // predictably.
45 CHECK_EQ(stoppable_state(), Stoppable::kStopped);
47 monitor_->RemoveWtsConsoleObserver(this);
49 CHECK(launcher_.get() == NULL);
52 void WtsConsoleSessionProcessDriver::OnChannelConnected(int32 peer_pid) {
53 DCHECK(caller_task_runner_->BelongsToCurrentThread());
56 bool WtsConsoleSessionProcessDriver::OnMessageReceived(
57 const IPC::Message& message) {
58 DCHECK(caller_task_runner_->BelongsToCurrentThread());
60 bool handled = true;
61 IPC_BEGIN_MESSAGE_MAP(WtsConsoleSessionProcessDriver, message)
62 IPC_MESSAGE_HANDLER(ChromotingNetworkDaemonMsg_SendSasToConsole,
63 OnSendSasToConsole)
64 IPC_MESSAGE_UNHANDLED(handled = false)
65 IPC_END_MESSAGE_MAP()
66 return handled;
69 void WtsConsoleSessionProcessDriver::OnPermanentError() {
70 DCHECK(caller_task_runner_->BelongsToCurrentThread());
72 Stop();
75 void WtsConsoleSessionProcessDriver::OnSessionAttached(uint32 session_id) {
76 DCHECK(caller_task_runner_->BelongsToCurrentThread());
78 if (stoppable_state() != Stoppable::kRunning) {
79 return;
82 DCHECK(launcher_.get() == NULL);
84 // Construct the host binary name.
85 FilePath host_binary;
86 if (!GetInstalledBinaryPath(kHostBinaryName, &host_binary)) {
87 Stop();
88 return;
91 // Create a Delegate capable of launching an elevated process in the session.
92 scoped_ptr<WtsSessionProcessDelegate> delegate(
93 new WtsSessionProcessDelegate(caller_task_runner_,
94 io_task_runner_,
95 host_binary,
96 session_id,
97 true,
98 kDaemonIpcSecurityDescriptor));
100 // Use the Delegate to launch the host process.
101 launcher_.reset(new WorkerProcessLauncher(
102 caller_task_runner_, delegate.Pass(), this));
105 void WtsConsoleSessionProcessDriver::OnSessionDetached() {
106 DCHECK(caller_task_runner_->BelongsToCurrentThread());
107 DCHECK(launcher_.get() != NULL);
109 launcher_.reset();
112 void WtsConsoleSessionProcessDriver::DoStop() {
113 DCHECK(caller_task_runner_->BelongsToCurrentThread());
115 launcher_.reset();
116 CompleteStopping();
119 void WtsConsoleSessionProcessDriver::OnSendSasToConsole() {
120 DCHECK(caller_task_runner_->BelongsToCurrentThread());
122 if (!launcher_)
123 return;
125 if (!sas_injector_)
126 sas_injector_ = SasInjector::Create();
127 if (!sas_injector_->InjectSas())
128 LOG(ERROR) << "Failed to inject Secure Attention Sequence.";
131 } // namespace remoting