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

Side by Side Diff: mojo/shell/app_child_process.cc

Issue 265793015: Mojo: Replace RemotePtr with InterfacePtr and InterfaceImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: snapshot Created 6 years, 7 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "mojo/shell/app_child_process.h" 5 #include "mojo/shell/app_child_process.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/scoped_native_library.h" 16 #include "base/scoped_native_library.h"
17 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
18 #include "base/synchronization/waitable_event.h" 18 #include "base/synchronization/waitable_event.h"
19 #include "base/threading/thread.h" 19 #include "base/threading/thread.h"
20 #include "base/threading/thread_checker.h" 20 #include "base/threading/thread_checker.h"
21 #include "mojo/common/message_pump_mojo.h" 21 #include "mojo/common/message_pump_mojo.h"
22 #include "mojo/embedder/embedder.h" 22 #include "mojo/embedder/embedder.h"
23 #include "mojo/public/cpp/bindings/remote_ptr.h"
24 #include "mojo/public/cpp/system/core.h" 23 #include "mojo/public/cpp/system/core.h"
25 #include "mojo/shell/app_child_process.mojom.h" 24 #include "mojo/shell/app_child_process.mojom.h"
26 25
27 namespace mojo { 26 namespace mojo {
28 namespace shell { 27 namespace shell {
29 28
30 namespace { 29 namespace {
31 30
32 // Blocker --------------------------------------------------------------------- 31 // Blocker ---------------------------------------------------------------------
33 32
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 scoped_refptr<base::SingleThreadTaskRunner> io_runner_; 137 scoped_refptr<base::SingleThreadTaskRunner> io_runner_;
139 138
140 base::Thread controller_thread_; 139 base::Thread controller_thread_;
141 scoped_refptr<base::SingleThreadTaskRunner> controller_runner_; 140 scoped_refptr<base::SingleThreadTaskRunner> controller_runner_;
142 141
143 DISALLOW_COPY_AND_ASSIGN(AppContext); 142 DISALLOW_COPY_AND_ASSIGN(AppContext);
144 }; 143 };
145 144
146 // AppChildControllerImpl ------------------------------------------------------ 145 // AppChildControllerImpl ------------------------------------------------------
147 146
148 class AppChildControllerImpl : public mojo_shell::AppChildController { 147 class AppChildControllerImpl : public AppChildController {
149 public: 148 public:
150 virtual ~AppChildControllerImpl() { 149 virtual ~AppChildControllerImpl() {
151 DCHECK(thread_checker_.CalledOnValidThread()); 150 DCHECK(thread_checker_.CalledOnValidThread());
152 } 151 }
153 152
154 // To be executed on the controller thread. Creates the |AppChildController|, 153 // To be executed on the controller thread. Creates the |AppChildController|,
155 // etc. 154 // etc.
156 static void Init( 155 static void Init(
157 AppContext* app_context, 156 AppContext* app_context,
158 embedder::ScopedPlatformHandle platform_channel, 157 embedder::ScopedPlatformHandle platform_channel,
159 const Blocker::Unblocker& unblocker) { 158 const Blocker::Unblocker& unblocker) {
160 DCHECK(app_context); 159 DCHECK(app_context);
161 DCHECK(platform_channel.is_valid()); 160 DCHECK(platform_channel.is_valid());
162 161
163 DCHECK(!app_context->controller()); 162 DCHECK(!app_context->controller());
163 // XXX need to use a AppChildControllerPtr here initialized with
164 // AppChildControllerImpl.
164 app_context->set_controller( 165 app_context->set_controller(
165 make_scoped_ptr(new AppChildControllerImpl(app_context, unblocker))); 166 make_scoped_ptr(new AppChildControllerImpl(app_context, unblocker)));
166 app_context->controller()->CreateChannel(platform_channel.Pass()); 167 app_context->controller()->CreateChannel(platform_channel.Pass());
167 } 168 }
168 169
169 void Shutdown() { 170 void Shutdown() {
170 DVLOG(2) << "AppChildControllerImpl::Shutdown()"; 171 DVLOG(2) << "AppChildControllerImpl::Shutdown()";
171 DCHECK(thread_checker_.CalledOnValidThread()); 172 DCHECK(thread_checker_.CalledOnValidThread());
172 173
173 // TODO(vtl): Pass in the result from |MainMain()|. 174 // TODO(vtl): Pass in the result from |MainMain()|.
174 controller_client_->AppCompleted(MOJO_RESULT_UNIMPLEMENTED); 175 controller_client_->AppCompleted(MOJO_RESULT_UNIMPLEMENTED);
175 176
176 // TODO(vtl): Drain then destroy the channel (on the I/O thread). 177 // TODO(vtl): Drain then destroy the channel (on the I/O thread).
177 178
178 // This will destroy this object. 179 // This will destroy this object.
179 app_context_->set_controller(scoped_ptr<AppChildControllerImpl>()); 180 app_context_->set_controller(scoped_ptr<AppChildControllerImpl>());
180 } 181 }
181 182
182 // |AppChildController| method: 183 // |AppChildController| methods:
184
185 virtual void SetClient(AppChildControllerClient* client) {
186 controller_client_ = client;
187 }
188
183 virtual void StartApp(const String& app_path, 189 virtual void StartApp(const String& app_path,
184 ScopedMessagePipeHandle service) OVERRIDE { 190 ScopedMessagePipeHandle service) OVERRIDE {
185 DVLOG(2) << "AppChildControllerImpl::StartApp(" 191 DVLOG(2) << "AppChildControllerImpl::StartApp("
186 << app_path.To<std::string>() << ", ...)"; 192 << app_path.To<std::string>() << ", ...)";
187 DCHECK(thread_checker_.CalledOnValidThread()); 193 DCHECK(thread_checker_.CalledOnValidThread());
188 194
195 // TODO(darin): Add TypeConverter for FilePath <-> mojo::String.
189 unblocker_.Unblock(base::Bind(&AppChildControllerImpl::StartAppOnMainThread, 196 unblocker_.Unblock(base::Bind(&AppChildControllerImpl::StartAppOnMainThread,
190 base::FilePath::FromUTF8Unsafe( 197 base::FilePath::FromUTF8Unsafe(
191 app_path.To<std::string>()), 198 app_path.To<std::string>()),
192 base::Passed(&service))); 199 base::Passed(&service)));
193 } 200 }
194 201
195 private: 202 private:
196 AppChildControllerImpl(AppContext* app_context, 203 AppChildControllerImpl(AppContext* app_context,
197 const Blocker::Unblocker& unblocker) 204 const Blocker::Unblocker& unblocker)
198 : app_context_(app_context), 205 : app_context_(app_context),
199 unblocker_(unblocker), 206 unblocker_(unblocker),
207 controller_client_(NULL),
200 channel_info_(NULL) { 208 channel_info_(NULL) {
201 } 209 }
202 210
203 void CreateChannel(embedder::ScopedPlatformHandle platform_channel) { 211 void CreateChannel(embedder::ScopedPlatformHandle platform_channel) {
204 DVLOG(2) << "AppChildControllerImpl::CreateChannel()"; 212 DVLOG(2) << "AppChildControllerImpl::CreateChannel()";
205 DCHECK(thread_checker_.CalledOnValidThread()); 213 DCHECK(thread_checker_.CalledOnValidThread());
206 214
207 ScopedMessagePipeHandle host_message_pipe(embedder::CreateChannel( 215 ScopedMessagePipeHandle host_message_pipe(embedder::CreateChannel(
208 platform_channel.Pass(), 216 platform_channel.Pass(),
209 app_context_->io_runner(), 217 app_context_->io_runner(),
210 base::Bind(&AppChildControllerImpl::DidCreateChannel, 218 base::Bind(&AppChildControllerImpl::DidCreateChannel,
211 base::Unretained(this)), 219 base::Unretained(this)),
212 base::MessageLoopProxy::current())); 220 base::MessageLoopProxy::current()));
213 controller_client_.reset( 221 controller_client_.reset(
214 mojo_shell::ScopedAppChildControllerClientHandle( 222 ScopedAppChildControllerClientHandle(
215 mojo_shell::AppChildControllerClientHandle( 223 AppChildControllerClientHandle(
216 host_message_pipe.release().value())), this); 224 host_message_pipe.release().value())), this);
217 } 225 }
218 226
219 // Callback for |embedder::CreateChannel()|. 227 // Callback for |embedder::CreateChannel()|.
220 void DidCreateChannel(embedder::ChannelInfo* channel_info) { 228 void DidCreateChannel(embedder::ChannelInfo* channel_info) {
221 DVLOG(2) << "AppChildControllerImpl::DidCreateChannel()"; 229 DVLOG(2) << "AppChildControllerImpl::DidCreateChannel()";
222 DCHECK(thread_checker_.CalledOnValidThread()); 230 DCHECK(thread_checker_.CalledOnValidThread());
223 channel_info_ = channel_info; 231 channel_info_ = channel_info;
224 } 232 }
225 233
(...skipping 29 matching lines...) Expand all
255 MojoResult result = main_function(service.release().value()); 263 MojoResult result = main_function(service.release().value());
256 if (result < MOJO_RESULT_OK) 264 if (result < MOJO_RESULT_OK)
257 LOG(ERROR) << "MojoMain returned an error: " << result; 265 LOG(ERROR) << "MojoMain returned an error: " << result;
258 } while (false); 266 } while (false);
259 } 267 }
260 268
261 base::ThreadChecker thread_checker_; 269 base::ThreadChecker thread_checker_;
262 AppContext* const app_context_; 270 AppContext* const app_context_;
263 Blocker::Unblocker unblocker_; 271 Blocker::Unblocker unblocker_;
264 272
265 RemotePtr<mojo_shell::AppChildControllerClient> controller_client_; 273 AppChildControllerClient* controller_client_;
266 embedder::ChannelInfo* channel_info_; 274 embedder::ChannelInfo* channel_info_;
267 275
268 DISALLOW_COPY_AND_ASSIGN(AppChildControllerImpl); 276 DISALLOW_COPY_AND_ASSIGN(AppChildControllerImpl);
269 }; 277 };
270 278
271 } // namespace 279 } // namespace
272 280
273 // AppChildProcess ------------------------------------------------------------- 281 // AppChildProcess -------------------------------------------------------------
274 282
275 AppChildProcess::AppChildProcess() { 283 AppChildProcess::AppChildProcess() {
(...skipping 17 matching lines...) Expand all
293 blocker.Block(); 301 blocker.Block();
294 302
295 app_context.controller_runner()->PostTask( 303 app_context.controller_runner()->PostTask(
296 FROM_HERE, 304 FROM_HERE,
297 base::Bind(&AppChildControllerImpl::Shutdown, 305 base::Bind(&AppChildControllerImpl::Shutdown,
298 base::Unretained(app_context.controller()))); 306 base::Unretained(app_context.controller())));
299 } 307 }
300 308
301 } // namespace shell 309 } // namespace shell
302 } // namespace mojo 310 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698