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

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

Issue 9705065: Introducing the WorkerProcessLauncher class implementing the common logic for spawning a worker pro… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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
(Empty)
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.
4 //
5 // This file implements the Windows service controlling Me2Me host processes
6 // running within user sessions.
Wez 2012/03/15 23:24:31 Stale comment?
alexeypa (please no reviews) 2012/03/16 17:43:50 Done.
7
8 #include "remoting/host/worker_process_launcher.h"
9
10 #include <limits>
11
12 #include "base/logging.h"
13 #include "base/process_util.h"
14 #include "base/rand_util.h"
15 #include "base/stringprintf.h"
16 #include "base/threading/thread.h"
17 #include "base/utf_string_conversions.h"
18 #include "ipc/ipc_channel_proxy.h"
19 #include "ipc/ipc_message.h"
20 #include "ipc/ipc_message_macros.h"
21
22 namespace {
23
24 // Generates random channel ID.
25 // N.B. Stolen from src/content/common/child_process_host_impl.cc
26 std::string GenerateRandomChannelId(void* instance) {
Wez 2012/03/15 23:24:31 nit: Since there's only one static function, use "
alexeypa (please no reviews) 2012/03/16 17:43:50 Done.
27 return base::StringPrintf("%d.%p.%d",
28 base::GetCurrentProcId(), instance,
29 base::RandInt(0, std::numeric_limits<int>::max()));
30 }
31
32 } // namespace
33
34 namespace remoting {
35
36 WorkerProcessLauncher::WorkerProcessLauncher(
37 base::MessageLoopProxy* ipc_message_loop)
38 : ipc_message_loop_(ipc_message_loop),
39 listener_(NULL) {
40 }
41
42 WorkerProcessLauncher::~WorkerProcessLauncher() {
43 Stop();
Wez 2012/03/15 23:24:31 Stop() is virtual, so someone naively deriving fro
alexeypa (please no reviews) 2012/03/16 17:43:50 It is not virtual any more after refactoring the c
44 }
45
46 bool WorkerProcessLauncher::Start(
47 IPC::Channel::Listener* listener,
48 const CreateChannelHandleCallback& create_channel_handle,
49 const LaunchWorkerCallback& launch_worker) {
50 DCHECK(ipc_channel_.get() == NULL);
51 DCHECK(listener_ == NULL);
52 DCHECK(process_.handle() == NULL);
53
54 std::string channel_name = GenerateRandomChannelId(this);
55
56 // Create the IPC channel offloading channel handle creation to the callback.
Wez 2012/03/15 23:24:31 typo: I think you're missing a comma in here.
alexeypa (please no reviews) 2012/03/16 17:43:50 Commas haven't been my string side ever. I split i
57 IPC::ChannelHandle channel_handle;
58 if (create_channel_handle.Run(channel_name, &channel_handle)) {
59 ipc_channel_.reset(new IPC::ChannelProxy(channel_handle,
60 IPC::Channel::MODE_SERVER,
61 this,
62 ipc_message_loop_));
63
64 // Try to launch the process and start waiting until it connects over
65 // the IPC channel.
Wez 2012/03/15 23:24:31 typo: ... start waiting until ... -> ... wait unti
Wez 2012/03/15 23:24:31 So this is a blocking operation?
alexeypa (please no reviews) 2012/03/16 17:43:50 Rephrased.
alexeypa (please no reviews) 2012/03/16 17:43:50 No, why? Rephrased.
66 if (launch_worker.Run(channel_name, &process_)) {
67 listener_ = listener;
68 return true;
69 }
70
71 ipc_channel_.reset();
72 }
73
74 return false;
75 }
76
77 void WorkerProcessLauncher::Stop() {
78 ipc_channel_.reset();
79 listener_ = NULL;
80 process_.Terminate(0);
81 process_.Close();
82 }
83
84 void WorkerProcessLauncher::Send(IPC::Message* message) {
85 ipc_channel_->Send(message);
86 }
87
88 bool WorkerProcessLauncher::OnMessageReceived(const IPC::Message& message) {
89 DCHECK(ipc_channel_.get() != NULL);
90 DCHECK(process_.handle() != NULL);
91
92 return listener_->OnMessageReceived(message);
93 }
94
95 void WorkerProcessLauncher::OnChannelConnected(int32 peer_pid) {
96 DCHECK(ipc_channel_.get() != NULL);
97 DCHECK(process_.handle() != NULL);
98
99 listener_->OnChannelConnected(peer_pid);
100 }
101
102 void WorkerProcessLauncher::OnChannelError() {
103 if (listener_) {
Wez 2012/03/15 23:24:31 How come you need to check |listener_| here but no
alexeypa (please no reviews) 2012/03/16 17:43:50 Exactly. This check is removed now.
104 DCHECK(ipc_channel_.get() != NULL);
105
106 listener_->OnChannelError();
107 Stop();
108 }
109 }
110
111 #if defined(OS_POSIX)
112
113 void WorkerProcessLauncher::OnChannelDenied() {
114 DCHECK(ipc_channel_.get() != NULL);
115
116 listener_->OnChannelDenied();
117 Stop();
118 }
119
120 void WorkerProcessLauncher::OnChannelListenError() {
121 DCHECK(ipc_channel_.get() != NULL);
122
123 listener_->OnChannelListenError();
124 Stop();
125 }
126
127 #endif // OS_POSIX
128
129 base::Process& WorkerProcessLauncher::get_process() {
130 return process_;
131 }
132
133 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698