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

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

Issue 11231060: [Chromoting] The desktop process now creates a pre-connected pipe and passes (with some help of the… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 8 years, 1 month 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
« no previous file with comments | « remoting/host/daemon_process_unittest.cc ('k') | remoting/host/desktop_process.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/daemon_process.h" 5 #include "remoting/host/daemon_process.h"
6 6
7 #include "base/base_switches.h" 7 #include "base/base_switches.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/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
14 #include "base/time.h" 14 #include "base/time.h"
15 #include "base/timer.h" 15 #include "base/timer.h"
16 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "base/win/scoped_handle.h" 17 #include "base/win/scoped_handle.h"
18 #include "ipc/ipc_message.h" 18 #include "ipc/ipc_message.h"
19 #include "ipc/ipc_message_macros.h" 19 #include "ipc/ipc_message_macros.h"
20 #include "remoting/base/auto_thread_task_runner.h"
20 #include "remoting/host/chromoting_messages.h" 21 #include "remoting/host/chromoting_messages.h"
21 #include "remoting/host/desktop_session_win.h" 22 #include "remoting/host/desktop_session_win.h"
22 #include "remoting/host/host_exit_codes.h" 23 #include "remoting/host/host_exit_codes.h"
23 #include "remoting/host/ipc_consts.h" 24 #include "remoting/host/ipc_consts.h"
24 #include "remoting/host/win/host_service.h" 25 #include "remoting/host/win/host_service.h"
25 #include "remoting/host/win/launch_process_with_token.h" 26 #include "remoting/host/win/launch_process_with_token.h"
26 #include "remoting/host/win/unprivileged_process_delegate.h" 27 #include "remoting/host/win/unprivileged_process_delegate.h"
27 #include "remoting/host/win/worker_process_launcher.h" 28 #include "remoting/host/win/worker_process_launcher.h"
28 29
29 using base::win::ScopedHandle; 30 using base::win::ScopedHandle;
30 using base::TimeDelta; 31 using base::TimeDelta;
31 32
32 namespace remoting { 33 namespace remoting {
33 34
34 class WtsConsoleMonitor; 35 class WtsConsoleMonitor;
35 36
36 class DaemonProcessWin : public DaemonProcess { 37 class DaemonProcessWin : public DaemonProcess {
37 public: 38 public:
38 DaemonProcessWin( 39 DaemonProcessWin(
39 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, 40 scoped_refptr<AutoThreadTaskRunner> caller_task_runner,
40 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, 41 scoped_refptr<AutoThreadTaskRunner> io_task_runner,
41 const base::Closure& stopped_callback); 42 const base::Closure& stopped_callback);
42 virtual ~DaemonProcessWin(); 43 virtual ~DaemonProcessWin();
43 44
44 // Sends an IPC message to the worker process. This method can be called only 45 // WorkerProcessIpcDelegate implementation.
45 // after successful Start() and until Stop() is called or an error occurred. 46 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE;
47
48 // DaemonProcess overrides.
46 virtual void SendToNetwork(IPC::Message* message) OVERRIDE; 49 virtual void SendToNetwork(IPC::Message* message) OVERRIDE;
50 virtual bool OnDesktopSessionAgentAttached(
51 int terminal_id,
52 base::ProcessHandle desktop_process,
53 IPC::PlatformFileForTransit desktop_pipe) OVERRIDE;
47 54
48 protected: 55 protected:
49 // Stoppable implementation. 56 // Stoppable implementation.
50 virtual void DoStop() OVERRIDE; 57 virtual void DoStop() OVERRIDE;
51 58
52 // DaemonProcess implementation. 59 // DaemonProcess implementation.
53 virtual scoped_ptr<DesktopSession> DoCreateDesktopSession( 60 virtual scoped_ptr<DesktopSession> DoCreateDesktopSession(
54 int terminal_id) OVERRIDE; 61 int terminal_id) OVERRIDE;
55 virtual void LaunchNetworkProcess() OVERRIDE; 62 virtual void LaunchNetworkProcess() OVERRIDE;
56 63
57 private: 64 private:
58 scoped_ptr<WorkerProcessLauncher> network_launcher_; 65 scoped_ptr<WorkerProcessLauncher> network_launcher_;
59 66
67 // Handle of the network process.
68 ScopedHandle network_process_;
69
60 DISALLOW_COPY_AND_ASSIGN(DaemonProcessWin); 70 DISALLOW_COPY_AND_ASSIGN(DaemonProcessWin);
61 }; 71 };
62 72
63 DaemonProcessWin::DaemonProcessWin( 73 DaemonProcessWin::DaemonProcessWin(
64 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, 74 scoped_refptr<AutoThreadTaskRunner> caller_task_runner,
65 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, 75 scoped_refptr<AutoThreadTaskRunner> io_task_runner,
66 const base::Closure& stopped_callback) 76 const base::Closure& stopped_callback)
67 : DaemonProcess(caller_task_runner, io_task_runner, stopped_callback) { 77 : DaemonProcess(caller_task_runner, io_task_runner, stopped_callback) {
68 } 78 }
69 79
70 DaemonProcessWin::~DaemonProcessWin() { 80 DaemonProcessWin::~DaemonProcessWin() {
71 // Make sure that the object is completely stopped. The same check exists 81 // Make sure that the object is completely stopped. The same check exists
72 // in Stoppable::~Stoppable() but this one helps us to fail early and 82 // in Stoppable::~Stoppable() but this one helps us to fail early and
73 // predictably. 83 // predictably.
74 CHECK_EQ(stoppable_state(), Stoppable::kStopped); 84 CHECK_EQ(stoppable_state(), Stoppable::kStopped);
75 } 85 }
76 86
87 void DaemonProcessWin::OnChannelConnected(int32 peer_pid) {
88 // Obtain the handle of the network process.
89 network_process_.Set(OpenProcess(PROCESS_DUP_HANDLE, false, peer_pid));
90 if (!network_process_.IsValid()) {
91 CrashNetworkProcess(FROM_HERE);
92 return;
93 }
94
95 DaemonProcess::OnChannelConnected(peer_pid);
96 }
97
77 void DaemonProcessWin::SendToNetwork(IPC::Message* message) { 98 void DaemonProcessWin::SendToNetwork(IPC::Message* message) {
78 if (network_launcher_) { 99 if (network_launcher_) {
79 network_launcher_->Send(message); 100 network_launcher_->Send(message);
80 } else { 101 } else {
81 delete message; 102 delete message;
82 } 103 }
83 } 104 }
84 105
106 bool DaemonProcessWin::OnDesktopSessionAgentAttached(
107 int terminal_id,
108 base::ProcessHandle desktop_process,
109 IPC::PlatformFileForTransit desktop_pipe) {
110 // Prepare |desktop_process| handle for sending over to the network process.
111 // |desktop_pipe| is a handle in the desktop process. It will be duplicated
112 // by the network process directly from the desktop process.
113 IPC::PlatformFileForTransit desktop_process_for_transit =
114 IPC::GetFileHandleForProcess(desktop_process, network_process_, false);
115 if (desktop_process_for_transit == IPC::InvalidPlatformFileForTransit()) {
116 LOG(ERROR) << "Failed to duplicate the desktop process handle";
117 return false;
118 }
119
120 SendToNetwork(new ChromotingDaemonNetworkMsg_DesktopAttached(
121 terminal_id, desktop_process_for_transit, desktop_pipe));
122 return true;
123 }
124
85 void DaemonProcessWin::DoStop() { 125 void DaemonProcessWin::DoStop() {
86 DCHECK(caller_task_runner()->BelongsToCurrentThread()); 126 DCHECK(caller_task_runner()->BelongsToCurrentThread());
87 127
88 network_launcher_.reset(); 128 network_launcher_.reset();
89 DaemonProcess::DoStop(); 129 DaemonProcess::DoStop();
90 } 130 }
91 131
92 scoped_ptr<DesktopSession> DaemonProcessWin::DoCreateDesktopSession( 132 scoped_ptr<DesktopSession> DaemonProcessWin::DoCreateDesktopSession(
93 int terminal_id) { 133 int terminal_id) {
94 DCHECK(caller_task_runner()->BelongsToCurrentThread()); 134 DCHECK(caller_task_runner()->BelongsToCurrentThread());
(...skipping 15 matching lines...) Expand all
110 } 150 }
111 151
112 scoped_ptr<UnprivilegedProcessDelegate> delegate( 152 scoped_ptr<UnprivilegedProcessDelegate> delegate(
113 new UnprivilegedProcessDelegate(caller_task_runner(), io_task_runner(), 153 new UnprivilegedProcessDelegate(caller_task_runner(), io_task_runner(),
114 host_binary)); 154 host_binary));
115 network_launcher_.reset(new WorkerProcessLauncher( 155 network_launcher_.reset(new WorkerProcessLauncher(
116 caller_task_runner(), delegate.Pass(), this)); 156 caller_task_runner(), delegate.Pass(), this));
117 } 157 }
118 158
119 scoped_ptr<DaemonProcess> DaemonProcess::Create( 159 scoped_ptr<DaemonProcess> DaemonProcess::Create(
120 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, 160 scoped_refptr<AutoThreadTaskRunner> caller_task_runner,
121 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, 161 scoped_refptr<AutoThreadTaskRunner> io_task_runner,
122 const base::Closure& stopped_callback) { 162 const base::Closure& stopped_callback) {
123 scoped_ptr<DaemonProcessWin> daemon_process( 163 scoped_ptr<DaemonProcessWin> daemon_process(
124 new DaemonProcessWin(caller_task_runner, io_task_runner, 164 new DaemonProcessWin(caller_task_runner, io_task_runner,
125 stopped_callback)); 165 stopped_callback));
126 daemon_process->Initialize(); 166 daemon_process->Initialize();
127 return daemon_process.PassAs<DaemonProcess>(); 167 return daemon_process.PassAs<DaemonProcess>();
128 } 168 }
129 169
130 } // namespace remoting 170 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/daemon_process_unittest.cc ('k') | remoting/host/desktop_process.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698