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/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/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
16 #include "base/scoped_native_library.h" | |
17 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
18 #include "base/synchronization/waitable_event.h" | 17 #include "base/synchronization/waitable_event.h" |
19 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
20 #include "base/threading/thread_checker.h" | 19 #include "base/threading/thread_checker.h" |
21 #include "mojo/common/message_pump_mojo.h" | 20 #include "mojo/common/message_pump_mojo.h" |
22 #include "mojo/edk/embedder/embedder.h" | 21 #include "mojo/edk/embedder/embedder.h" |
23 #include "mojo/edk/embedder/simple_platform_support.h" | 22 #include "mojo/edk/embedder/simple_platform_support.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" |
| 25 #include "mojo/shell/dynamic_service_runner.h" |
26 | 26 |
27 namespace mojo { | 27 namespace mojo { |
28 namespace shell { | 28 namespace shell { |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
32 // Blocker --------------------------------------------------------------------- | 32 // Blocker --------------------------------------------------------------------- |
33 | 33 |
34 // Blocks a thread until another thread unblocks it, at which point it unblocks | 34 // Blocks a thread until another thread unblocks it, at which point it unblocks |
35 // and runs a closure provided by that thread. | 35 // and runs a closure provided by that thread. |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 DCHECK(thread_checker_.CalledOnValidThread()); | 219 DCHECK(thread_checker_.CalledOnValidThread()); |
220 channel_info_ = channel_info; | 220 channel_info_ = channel_info; |
221 } | 221 } |
222 | 222 |
223 static void StartAppOnMainThread(const base::FilePath& app_path, | 223 static void StartAppOnMainThread(const base::FilePath& app_path, |
224 ScopedMessagePipeHandle service) { | 224 ScopedMessagePipeHandle service) { |
225 // TODO(vtl): This is copied from in_process_dynamic_service_runner.cc. | 225 // TODO(vtl): This is copied from in_process_dynamic_service_runner.cc. |
226 DVLOG(2) << "Loading/running Mojo app from " << app_path.value() | 226 DVLOG(2) << "Loading/running Mojo app from " << app_path.value() |
227 << " out of process"; | 227 << " out of process"; |
228 | 228 |
229 do { | 229 // We intentionally don't unload the native library as its lifetime is the |
230 base::NativeLibraryLoadError load_error; | 230 // same as that of the process. |
231 base::ScopedNativeLibrary app_library( | 231 DynamicServiceRunner::LoadAndRunService(app_path, service.Pass()); |
232 base::LoadNativeLibrary(app_path, &load_error)); | |
233 if (!app_library.is_valid()) { | |
234 LOG(ERROR) << "Failed to load library (error: " << load_error.ToString() | |
235 << ")"; | |
236 break; | |
237 } | |
238 | |
239 typedef MojoResult (*MojoMainFunction)(MojoHandle); | |
240 MojoMainFunction main_function = reinterpret_cast<MojoMainFunction>( | |
241 app_library.GetFunctionPointer("MojoMain")); | |
242 if (!main_function) { | |
243 LOG(ERROR) << "Entrypoint MojoMain not found"; | |
244 break; | |
245 } | |
246 | |
247 // TODO(vtl): Report the result back to our parent process. | |
248 // |MojoMain()| takes ownership of the service handle. | |
249 MojoResult result = main_function(service.release().value()); | |
250 if (result < MOJO_RESULT_OK) | |
251 LOG(ERROR) << "MojoMain returned an error: " << result; | |
252 } while (false); | |
253 } | 232 } |
254 | 233 |
255 base::ThreadChecker thread_checker_; | 234 base::ThreadChecker thread_checker_; |
256 AppContext* const app_context_; | 235 AppContext* const app_context_; |
257 Blocker::Unblocker unblocker_; | 236 Blocker::Unblocker unblocker_; |
258 | 237 |
259 embedder::ChannelInfo* channel_info_; | 238 embedder::ChannelInfo* channel_info_; |
260 | 239 |
261 DISALLOW_COPY_AND_ASSIGN(AppChildControllerImpl); | 240 DISALLOW_COPY_AND_ASSIGN(AppChildControllerImpl); |
262 }; | 241 }; |
(...skipping 20 matching lines...) Expand all Loading... |
283 base::Bind(&AppChildControllerImpl::Init, base::Unretained(&app_context), | 262 base::Bind(&AppChildControllerImpl::Init, base::Unretained(&app_context), |
284 base::Passed(platform_channel()), blocker.GetUnblocker())); | 263 base::Passed(platform_channel()), blocker.GetUnblocker())); |
285 // This will block, then run whatever the controller wants. | 264 // This will block, then run whatever the controller wants. |
286 blocker.Block(); | 265 blocker.Block(); |
287 | 266 |
288 app_context.Shutdown(); | 267 app_context.Shutdown(); |
289 } | 268 } |
290 | 269 |
291 } // namespace shell | 270 } // namespace shell |
292 } // namespace mojo | 271 } // namespace mojo |
OLD | NEW |