OLD | NEW |
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/runner/child_process.h" | 5 #include "mojo/runner/child_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/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "mojo/edk/embedder/platform_channel_pair.h" | 25 #include "mojo/edk/embedder/platform_channel_pair.h" |
26 #include "mojo/edk/embedder/process_delegate.h" | 26 #include "mojo/edk/embedder/process_delegate.h" |
27 #include "mojo/edk/embedder/scoped_platform_handle.h" | 27 #include "mojo/edk/embedder/scoped_platform_handle.h" |
28 #include "mojo/edk/embedder/simple_platform_support.h" | 28 #include "mojo/edk/embedder/simple_platform_support.h" |
29 #include "mojo/public/cpp/system/core.h" | 29 #include "mojo/public/cpp/system/core.h" |
30 #include "mojo/runner/child_process.mojom.h" | 30 #include "mojo/runner/child_process.mojom.h" |
31 #include "mojo/runner/native_application_support.h" | 31 #include "mojo/runner/native_application_support.h" |
32 #include "mojo/runner/switches.h" | 32 #include "mojo/runner/switches.h" |
33 | 33 |
34 namespace mojo { | 34 namespace mojo { |
35 namespace shell { | 35 namespace runner { |
36 | 36 |
37 namespace { | 37 namespace { |
38 | 38 |
39 // Blocker --------------------------------------------------------------------- | 39 // Blocker --------------------------------------------------------------------- |
40 | 40 |
41 // Blocks a thread until another thread unblocks it, at which point it unblocks | 41 // Blocks a thread until another thread unblocks it, at which point it unblocks |
42 // and runs a closure provided by that thread. | 42 // and runs a closure provided by that thread. |
43 class Blocker { | 43 class Blocker { |
44 public: | 44 public: |
45 class Unblocker { | 45 class Unblocker { |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 | 213 |
214 // |ChildController| methods: | 214 // |ChildController| methods: |
215 void StartApp(const String& app_path, | 215 void StartApp(const String& app_path, |
216 bool clean_app_path, | 216 bool clean_app_path, |
217 InterfaceRequest<Application> application_request, | 217 InterfaceRequest<Application> application_request, |
218 const StartAppCallback& on_app_complete) override { | 218 const StartAppCallback& on_app_complete) override { |
219 DVLOG(2) << "ChildControllerImpl::StartApp(" << app_path << ", ...)"; | 219 DVLOG(2) << "ChildControllerImpl::StartApp(" << app_path << ", ...)"; |
220 DCHECK(thread_checker_.CalledOnValidThread()); | 220 DCHECK(thread_checker_.CalledOnValidThread()); |
221 | 221 |
222 on_app_complete_ = on_app_complete; | 222 on_app_complete_ = on_app_complete; |
223 unblocker_.Unblock(base::Bind(&ChildControllerImpl::StartAppOnMainThread, | 223 unblocker_.Unblock(base::Bind( |
224 base::FilePath::FromUTF8Unsafe(app_path), | 224 &ChildControllerImpl::StartAppOnMainThread, |
225 clean_app_path | 225 base::FilePath::FromUTF8Unsafe(app_path), |
226 ? NativeApplicationCleanup::DELETE | 226 clean_app_path ? shell::NativeApplicationCleanup::DELETE |
227 : NativeApplicationCleanup::DONT_DELETE, | 227 : shell::NativeApplicationCleanup::DONT_DELETE, |
228 base::Passed(&application_request))); | 228 base::Passed(&application_request))); |
229 } | 229 } |
230 | 230 |
231 void ExitNow(int32_t exit_code) override { | 231 void ExitNow(int32_t exit_code) override { |
232 DVLOG(2) << "ChildControllerImpl::ExitNow(" << exit_code << ")"; | 232 DVLOG(2) << "ChildControllerImpl::ExitNow(" << exit_code << ")"; |
233 _exit(exit_code); | 233 _exit(exit_code); |
234 } | 234 } |
235 | 235 |
236 private: | 236 private: |
237 ChildControllerImpl(AppContext* app_context, | 237 ChildControllerImpl(AppContext* app_context, |
238 const Blocker::Unblocker& unblocker) | 238 const Blocker::Unblocker& unblocker) |
239 : app_context_(app_context), | 239 : app_context_(app_context), |
240 unblocker_(unblocker), | 240 unblocker_(unblocker), |
241 channel_info_(nullptr), | 241 channel_info_(nullptr), |
242 binding_(this) { | 242 binding_(this) { |
243 binding_.set_error_handler(this); | 243 binding_.set_error_handler(this); |
244 } | 244 } |
245 | 245 |
246 // Callback for |embedder::CreateChannel()|. | 246 // Callback for |embedder::CreateChannel()|. |
247 void DidCreateChannel(embedder::ChannelInfo* channel_info) { | 247 void DidCreateChannel(embedder::ChannelInfo* channel_info) { |
248 DVLOG(2) << "ChildControllerImpl::DidCreateChannel()"; | 248 DVLOG(2) << "ChildControllerImpl::DidCreateChannel()"; |
249 DCHECK(thread_checker_.CalledOnValidThread()); | 249 DCHECK(thread_checker_.CalledOnValidThread()); |
250 channel_info_ = channel_info; | 250 channel_info_ = channel_info; |
251 } | 251 } |
252 | 252 |
253 static void StartAppOnMainThread( | 253 static void StartAppOnMainThread( |
254 const base::FilePath& app_path, | 254 const base::FilePath& app_path, |
255 NativeApplicationCleanup cleanup, | 255 shell::NativeApplicationCleanup cleanup, |
256 InterfaceRequest<Application> application_request) { | 256 InterfaceRequest<Application> application_request) { |
257 // TODO(vtl): This is copied from in_process_native_runner.cc. | 257 // TODO(vtl): This is copied from in_process_native_runner.cc. |
258 DVLOG(2) << "Loading/running Mojo app from " << app_path.value() | 258 DVLOG(2) << "Loading/running Mojo app from " << app_path.value() |
259 << " out of process"; | 259 << " out of process"; |
260 | 260 |
261 // We intentionally don't unload the native library as its lifetime is the | 261 // We intentionally don't unload the native library as its lifetime is the |
262 // same as that of the process. | 262 // same as that of the process. |
263 base::NativeLibrary app_library = LoadNativeApplication(app_path, cleanup); | 263 base::NativeLibrary app_library = LoadNativeApplication(app_path, cleanup); |
264 RunNativeApplication(app_library, application_request.Pass()); | 264 RunNativeApplication(app_library, application_request.Pass()); |
265 } | 265 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 base::Bind(&ChildControllerImpl::Init, base::Unretained(&app_context), | 310 base::Bind(&ChildControllerImpl::Init, base::Unretained(&app_context), |
311 base::Passed(&platform_channel), blocker.GetUnblocker())); | 311 base::Passed(&platform_channel), blocker.GetUnblocker())); |
312 // This will block, then run whatever the controller wants. | 312 // This will block, then run whatever the controller wants. |
313 blocker.Block(); | 313 blocker.Block(); |
314 | 314 |
315 app_context.Shutdown(); | 315 app_context.Shutdown(); |
316 | 316 |
317 return 0; | 317 return 0; |
318 } | 318 } |
319 | 319 |
320 } // namespace shell | 320 } // namespace runner |
321 } // namespace mojo | 321 } // namespace mojo |
OLD | NEW |