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/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/message_loop/message_loop_proxy.h" | 12 #include "base/message_loop/message_loop_proxy.h" |
| 13 #include "base/scoped_native_library.h" | 13 #include "base/scoped_native_library.h" |
| 14 #include "mojo/public/platform/native/system_thunks.h" | |
| 14 | 15 |
| 15 namespace mojo { | 16 namespace mojo { |
| 16 namespace shell { | 17 namespace shell { |
| 17 | 18 |
| 18 InProcessDynamicServiceRunner::InProcessDynamicServiceRunner( | 19 InProcessDynamicServiceRunner::InProcessDynamicServiceRunner( |
| 19 Context* /*context*/) | 20 Context* /*context*/) |
| 20 : thread_(this, "app_thread") { | 21 : thread_(this, "app_thread") { |
| 21 } | 22 } |
| 22 | 23 |
| 23 InProcessDynamicServiceRunner::~InProcessDynamicServiceRunner() { | 24 InProcessDynamicServiceRunner::~InProcessDynamicServiceRunner() { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 do { | 57 do { |
| 57 base::NativeLibraryLoadError error; | 58 base::NativeLibraryLoadError error; |
| 58 base::ScopedNativeLibrary app_library( | 59 base::ScopedNativeLibrary app_library( |
| 59 base::LoadNativeLibrary(app_path_, &error)); | 60 base::LoadNativeLibrary(app_path_, &error)); |
| 60 if (!app_library.is_valid()) { | 61 if (!app_library.is_valid()) { |
| 61 LOG(ERROR) << "Failed to load library (error: " << error.ToString() | 62 LOG(ERROR) << "Failed to load library (error: " << error.ToString() |
| 62 << ")"; | 63 << ")"; |
| 63 break; | 64 break; |
| 64 } | 65 } |
| 65 | 66 |
| 67 MojoSetSystemThunksFn mojo_set_system_thunks_fn = | |
| 68 reinterpret_cast<MojoSetSystemThunksFn>(app_library.GetFunctionPointer( | |
| 69 "MojoSetSystemThunks")); | |
| 70 if (!mojo_set_system_thunks_fn) { | |
| 71 LOG(ERROR) << "Entrypoint MojoSetSystemThunks not found"; | |
| 72 break; | |
| 73 } | |
| 74 MojoSystemThunks system_thunks = MojoMakeSystemThunks(); | |
| 75 size_t exported_size = mojo_set_system_thunks_fn(&system_thunks); | |
| 76 if (exported_size > sizeof(MojoSystemThunks)) { | |
| 77 LOG(ERROR) | |
| 78 << "Invalid DSO. Expected MojoSystemThunks size: " | |
| 79 << exported_size; | |
| 80 } | |
|
viettrungluu
2014/04/09 23:06:44
break;
DaveMoore
2014/04/10 18:58:58
Done.
| |
| 81 | |
| 66 typedef MojoResult (*MojoMainFunction)(MojoHandle); | 82 typedef MojoResult (*MojoMainFunction)(MojoHandle); |
| 67 MojoMainFunction main_function = reinterpret_cast<MojoMainFunction>( | 83 MojoMainFunction main_function = reinterpret_cast<MojoMainFunction>( |
| 68 app_library.GetFunctionPointer("MojoMain")); | 84 app_library.GetFunctionPointer("MojoMain")); |
| 69 if (!main_function) { | 85 if (!main_function) { |
| 70 LOG(ERROR) << "Entrypoint MojoMain not found"; | 86 LOG(ERROR) << "Entrypoint MojoMain not found"; |
| 71 break; | 87 break; |
| 72 } | 88 } |
| 73 | 89 |
| 74 // |MojoMain()| takes ownership of the service handle. | 90 // |MojoMain()| takes ownership of the service handle. |
| 75 MojoResult result = main_function(service_handle_.release().value()); | 91 MojoResult result = main_function(service_handle_.release().value()); |
| 76 if (result < MOJO_RESULT_OK) | 92 if (result < MOJO_RESULT_OK) |
| 77 LOG(ERROR) << "MojoMain returned an error: " << result; | 93 LOG(ERROR) << "MojoMain returned an error: " << result; |
| 78 } while (false); | 94 } while (false); |
| 79 | 95 |
| 80 bool success = app_completed_callback_runner_.Run(); | 96 bool success = app_completed_callback_runner_.Run(); |
| 81 app_completed_callback_runner_.Reset(); | 97 app_completed_callback_runner_.Reset(); |
| 82 LOG_IF(ERROR, !success) << "Failed post run app_completed_callback"; | 98 LOG_IF(ERROR, !success) << "Failed post run app_completed_callback"; |
| 83 } | 99 } |
| 84 | 100 |
| 85 } // namespace shell | 101 } // namespace shell |
| 86 } // namespace mojo | 102 } // namespace mojo |
| OLD | NEW |