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

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: Fixup Created 8 years, 2 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/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"
(...skipping 23 matching lines...) Expand all
34 class WtsConsoleMonitor; 34 class WtsConsoleMonitor;
35 35
36 class DaemonProcessWin : public DaemonProcess { 36 class DaemonProcessWin : public DaemonProcess {
37 public: 37 public:
38 DaemonProcessWin( 38 DaemonProcessWin(
39 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, 39 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,
40 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, 40 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
41 const base::Closure& stopped_callback); 41 const base::Closure& stopped_callback);
42 virtual ~DaemonProcessWin(); 42 virtual ~DaemonProcessWin();
43 43
44 // Sends an IPC message to the worker process. This method can be called only 44 // WorkerProcessIpcDelegate implementation.
45 // after successful Start() and until Stop() is called or an error occurred. 45 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE;
46
47 // DaemonProcess overrides.
46 virtual void SendToNetwork(IPC::Message* message) OVERRIDE; 48 virtual void SendToNetwork(IPC::Message* message) OVERRIDE;
49 virtual bool OnDesktopSessionAgentAttached(
50 int terminal_id,
51 base::ProcessHandle desktop_process,
52 IPC::PlatformFileForTransit desktop_pipe) OVERRIDE;
47 53
48 protected: 54 protected:
49 // Stoppable implementation. 55 // Stoppable implementation.
50 virtual void DoStop() OVERRIDE; 56 virtual void DoStop() OVERRIDE;
51 57
52 // DaemonProcess implementation. 58 // DaemonProcess implementation.
53 virtual scoped_ptr<DesktopSession> DoCreateDesktopSession( 59 virtual scoped_ptr<DesktopSession> DoCreateDesktopSession(
54 int terminal_id) OVERRIDE; 60 int terminal_id) OVERRIDE;
55 virtual void LaunchNetworkProcess() OVERRIDE; 61 virtual void LaunchNetworkProcess() OVERRIDE;
56 62
57 private: 63 private:
58 scoped_ptr<WorkerProcessLauncher> network_launcher_; 64 scoped_ptr<WorkerProcessLauncher> network_launcher_;
59 65
66 // Handle of the network process.
67 ScopedHandle network_process_;
68
60 DISALLOW_COPY_AND_ASSIGN(DaemonProcessWin); 69 DISALLOW_COPY_AND_ASSIGN(DaemonProcessWin);
61 }; 70 };
62 71
63 DaemonProcessWin::DaemonProcessWin( 72 DaemonProcessWin::DaemonProcessWin(
64 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, 73 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,
65 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, 74 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
66 const base::Closure& stopped_callback) 75 const base::Closure& stopped_callback)
67 : DaemonProcess(caller_task_runner, io_task_runner, stopped_callback) { 76 : DaemonProcess(caller_task_runner, io_task_runner, stopped_callback) {
68 } 77 }
69 78
70 DaemonProcessWin::~DaemonProcessWin() { 79 DaemonProcessWin::~DaemonProcessWin() {
71 // Make sure that the object is completely stopped. The same check exists 80 // 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 81 // in Stoppable::~Stoppable() but this one helps us to fail early and
73 // predictably. 82 // predictably.
74 CHECK_EQ(stoppable_state(), Stoppable::kStopped); 83 CHECK_EQ(stoppable_state(), Stoppable::kStopped);
75 } 84 }
76 85
86 void DaemonProcessWin::OnChannelConnected(int32 peer_pid) {
87 // Obtain the handle of the network process.
88 network_process_.Set(OpenProcess(PROCESS_DUP_HANDLE, false, peer_pid));
89 if (!network_process_.IsValid()) {
90 RestartNetworkProcess(FROM_HERE);
91 return;
92 }
93
94 DaemonProcess::OnChannelConnected(peer_pid);
95 }
96
77 void DaemonProcessWin::SendToNetwork(IPC::Message* message) { 97 void DaemonProcessWin::SendToNetwork(IPC::Message* message) {
78 if (network_launcher_) { 98 if (network_launcher_) {
79 network_launcher_->Send(message); 99 network_launcher_->Send(message);
80 } else { 100 } else {
81 delete message; 101 delete message;
82 } 102 }
83 } 103 }
84 104
105 bool DaemonProcessWin::OnDesktopSessionAgentAttached(
Sergey Ulanov 2012/10/24 20:12:01 Did you mean to implement this method in DaemonPro
alexeypa (please no reviews) 2012/10/24 21:41:51 Done.
106 int terminal_id,
107 base::ProcessHandle desktop_process,
108 IPC::PlatformFileForTransit desktop_pipe) {
109 // Prepare |desktop_process| handle for sending over to the network process.
110 IPC::PlatformFileForTransit desktop_process_for_transit =
111 IPC::GetFileHandleForProcess(desktop_process, network_process_, false);
112 if (desktop_process_for_transit == IPC::InvalidPlatformFileForTransit()) {
113 LOG(ERROR) << "Failed to duplicate the desktop process handle";
114 return false;
115 }
116
117 // Posix: |desktop_pipe| is an auto-close base::FileDescriptor. The IPC
118 // subsystem will make sure that it is properly closed.
119 // Windows: |desktop_pipe| is a handle in the desktop process. It will be
120 // duplicated directly from the desktop process by the network process.
121 #if defined(OS_POSIX)
122 DCHECK(desktop_pipe.auto_close);
123 #endif // defined(OS_POSIX)
124
125 SendToNetwork(new ChromotingDaemonNetworkMsg_DesktopAttached(
126 terminal_id, desktop_process_for_transit, desktop_pipe));
127 return true;
128 }
129
85 void DaemonProcessWin::DoStop() { 130 void DaemonProcessWin::DoStop() {
86 DCHECK(caller_task_runner()->BelongsToCurrentThread()); 131 DCHECK(caller_task_runner()->BelongsToCurrentThread());
87 132
88 network_launcher_.reset(); 133 network_launcher_.reset();
89 DaemonProcess::DoStop(); 134 DaemonProcess::DoStop();
90 } 135 }
91 136
92 scoped_ptr<DesktopSession> DaemonProcessWin::DoCreateDesktopSession( 137 scoped_ptr<DesktopSession> DaemonProcessWin::DoCreateDesktopSession(
93 int terminal_id) { 138 int terminal_id) {
94 DCHECK(caller_task_runner()->BelongsToCurrentThread()); 139 DCHECK(caller_task_runner()->BelongsToCurrentThread());
(...skipping 26 matching lines...) Expand all
121 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, 166 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
122 const base::Closure& stopped_callback) { 167 const base::Closure& stopped_callback) {
123 scoped_ptr<DaemonProcessWin> daemon_process( 168 scoped_ptr<DaemonProcessWin> daemon_process(
124 new DaemonProcessWin(caller_task_runner, io_task_runner, 169 new DaemonProcessWin(caller_task_runner, io_task_runner,
125 stopped_callback)); 170 stopped_callback));
126 daemon_process->Initialize(); 171 daemon_process->Initialize();
127 return daemon_process.PassAs<DaemonProcess>(); 172 return daemon_process.PassAs<DaemonProcess>();
128 } 173 }
129 174
130 } // namespace remoting 175 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698