Chromium Code Reviews| 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/in_process_dynamic_service_runner.h" | 5 #include "mojo/shell/in_process_dynamic_service_runner.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/location.h" | 9 #include "base/location.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/message_loop/message_loop_proxy.h" | 11 #include "base/message_loop/message_loop_proxy.h" |
| 12 #include "base/scoped_native_library.h" | |
| 13 #include "mojo/public/platform/native/system_thunks.h" | 12 #include "mojo/public/platform/native/system_thunks.h" |
| 14 | 13 |
| 15 namespace mojo { | 14 namespace mojo { |
| 16 namespace shell { | 15 namespace shell { |
| 17 | 16 |
| 18 InProcessDynamicServiceRunner::InProcessDynamicServiceRunner( | 17 InProcessDynamicServiceRunner::InProcessDynamicServiceRunner( |
| 19 Context* context) | 18 Context* context) |
| 20 : keep_alive_(context), | 19 : keep_alive_(context), |
| 21 thread_(this, "app_thread") { | 20 thread_(this, "app_thread") { |
| 22 } | 21 } |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 46 DCHECK(!thread_.HasBeenStarted()); | 45 DCHECK(!thread_.HasBeenStarted()); |
| 47 thread_.Start(); | 46 thread_.Start(); |
| 48 } | 47 } |
| 49 | 48 |
| 50 void InProcessDynamicServiceRunner::Run() { | 49 void InProcessDynamicServiceRunner::Run() { |
| 51 DVLOG(2) << "Loading/running Mojo app in process from library: " | 50 DVLOG(2) << "Loading/running Mojo app in process from library: " |
| 52 << app_path_.value(); | 51 << app_path_.value(); |
| 53 | 52 |
| 54 do { | 53 do { |
| 55 base::NativeLibraryLoadError error; | 54 base::NativeLibraryLoadError error; |
| 56 base::ScopedNativeLibrary app_library( | 55 app_library_.Reset(base::LoadNativeLibrary(app_path_, &error)); |
| 57 base::LoadNativeLibrary(app_path_, &error)); | 56 if (!app_library_.is_valid()) { |
| 58 if (!app_library.is_valid()) { | |
| 59 LOG(ERROR) << "Failed to load app library (error: " << error.ToString() | 57 LOG(ERROR) << "Failed to load app library (error: " << error.ToString() |
| 60 << ")"; | 58 << ")"; |
| 61 break; | 59 break; |
| 62 } | 60 } |
| 63 | 61 |
| 64 MojoSetSystemThunksFn mojo_set_system_thunks_fn = | 62 MojoSetSystemThunksFn mojo_set_system_thunks_fn = |
| 65 reinterpret_cast<MojoSetSystemThunksFn>(app_library.GetFunctionPointer( | 63 reinterpret_cast<MojoSetSystemThunksFn>(app_library_.GetFunctionPointer( |
| 66 "MojoSetSystemThunks")); | 64 "MojoSetSystemThunks")); |
| 67 if (mojo_set_system_thunks_fn) { | 65 if (mojo_set_system_thunks_fn) { |
| 68 MojoSystemThunks system_thunks = MojoMakeSystemThunks(); | 66 MojoSystemThunks system_thunks = MojoMakeSystemThunks(); |
| 69 size_t expected_size = mojo_set_system_thunks_fn(&system_thunks); | 67 size_t expected_size = mojo_set_system_thunks_fn(&system_thunks); |
| 70 if (expected_size > sizeof(MojoSystemThunks)) { | 68 if (expected_size > sizeof(MojoSystemThunks)) { |
| 71 LOG(ERROR) | 69 LOG(ERROR) |
| 72 << "Invalid app library: expected MojoSystemThunks size: " | 70 << "Invalid app library: expected MojoSystemThunks size: " |
| 73 << expected_size; | 71 << expected_size; |
| 74 break; | 72 break; |
| 75 } | 73 } |
| 76 } else { | 74 } else { |
| 77 // In the component build, Mojo Apps link against mojo_system_impl. | 75 // In the component build, Mojo Apps link against mojo_system_impl. |
| 78 #if !defined(COMPONENT_BUILD) | 76 #if !defined(COMPONENT_BUILD) |
| 79 // Strictly speaking this is not required, but it's very unusual to have | 77 // Strictly speaking this is not required, but it's very unusual to have |
| 80 // an app that doesn't require the basic system library. | 78 // an app that doesn't require the basic system library. |
| 81 LOG(WARNING) << "MojoSetSystemThunks not found in app library"; | 79 LOG(WARNING) << "MojoSetSystemThunks not found in app library"; |
| 82 #endif | 80 #endif |
| 83 } | 81 } |
| 84 | 82 |
| 85 typedef MojoResult (*MojoMainFunction)(MojoHandle); | 83 typedef MojoResult (*MojoMainFunction)(MojoHandle); |
| 86 MojoMainFunction main_function = reinterpret_cast<MojoMainFunction>( | 84 MojoMainFunction main_function = reinterpret_cast<MojoMainFunction>( |
| 87 app_library.GetFunctionPointer("MojoMain")); | 85 app_library_.GetFunctionPointer("MojoMain")); |
| 88 if (!main_function) { | 86 if (!main_function) { |
| 89 LOG(ERROR) << "Entrypoint MojoMain not found"; | 87 LOG(ERROR) << "Entrypoint MojoMain not found"; |
| 90 break; | 88 break; |
| 91 } | 89 } |
| 92 | 90 |
| 93 // |MojoMain()| takes ownership of the service handle. | 91 // |MojoMain()| takes ownership of the service handle. |
| 94 MojoResult result = main_function(service_handle_.release().value()); | 92 MojoResult result = main_function(service_handle_.release().value()); |
| 95 if (result < MOJO_RESULT_OK) | 93 if (result < MOJO_RESULT_OK) |
| 96 LOG(ERROR) << "MojoMain returned an error: " << result; | 94 LOG(ERROR) << "MojoMain returned an error: " << result; |
| 95 // TODO(tim): Remove this ugly hack. | |
|
darin (slow to review)
2014/07/19 21:18:00
nit: can you explain what this ugly hack is achiev
tim (not reviewing)
2014/07/19 21:59:42
Sorry about that. What was happening was:
What's
| |
| 96 #if defined(COMPONENT_BUILD) | |
| 97 app_library_.Reset(base::NativeLibrary()); | |
| 98 #endif | |
| 97 } while (false); | 99 } while (false); |
| 98 | 100 |
| 99 bool success = app_completed_callback_runner_.Run(); | 101 bool success = app_completed_callback_runner_.Run(); |
| 100 app_completed_callback_runner_.Reset(); | 102 app_completed_callback_runner_.Reset(); |
| 101 LOG_IF(ERROR, !success) << "Failed post run app_completed_callback"; | 103 LOG_IF(ERROR, !success) << "Failed post run app_completed_callback"; |
| 102 } | 104 } |
| 103 | 105 |
| 104 } // namespace shell | 106 } // namespace shell |
| 105 } // namespace mojo | 107 } // namespace mojo |
| OLD | NEW |