| 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 "services/shell/runner/host/native_application_support.h" | 5 #include "services/shell/runner/host/native_application_support.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "mojo/platform_handle/platform_handle_private_thunks.h" | |
| 14 #include "mojo/public/platform/native/system_thunks.h" | 13 #include "mojo/public/platform/native/system_thunks.h" |
| 15 | 14 |
| 16 namespace shell { | 15 namespace shell { |
| 17 | 16 |
| 18 namespace { | 17 namespace { |
| 19 | 18 |
| 20 template <typename Thunks> | 19 template <typename Thunks> |
| 21 bool SetThunks(Thunks (*make_thunks)(), | 20 bool SetThunks(Thunks (*make_thunks)(), |
| 22 const char* function_name, | 21 const char* function_name, |
| 23 base::NativeLibrary library) { | 22 base::NativeLibrary library) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 if (init_command_line_args) { | 74 if (init_command_line_args) { |
| 76 int argc = 0; | 75 int argc = 0; |
| 77 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 76 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
| 78 const char** argv = new const char*[cmd_line->argv().size()]; | 77 const char** argv = new const char*[cmd_line->argv().size()]; |
| 79 for (auto& arg : cmd_line->argv()) | 78 for (auto& arg : cmd_line->argv()) |
| 80 argv[argc++] = arg.c_str(); | 79 argv[argc++] = arg.c_str(); |
| 81 init_command_line_args(argc, argv); | 80 init_command_line_args(argc, argv); |
| 82 } | 81 } |
| 83 #endif | 82 #endif |
| 84 | 83 |
| 85 // Apps need not include platform handle thunks. | 84 #endif // !defined(COMPONENT_BUILD) |
| 86 SetThunks(&MojoMakePlatformHandlePrivateThunks, | |
| 87 "MojoSetPlatformHandlePrivateThunks", app_library); | |
| 88 #endif | |
| 89 | 85 |
| 90 typedef MojoResult (*MojoMainFunction)(MojoHandle); | 86 typedef MojoResult (*MojoMainFunction)(MojoHandle); |
| 91 MojoMainFunction main_function = reinterpret_cast<MojoMainFunction>( | 87 MojoMainFunction main_function = reinterpret_cast<MojoMainFunction>( |
| 92 base::GetFunctionPointerFromNativeLibrary(app_library, "MojoMain")); | 88 base::GetFunctionPointerFromNativeLibrary(app_library, "MojoMain")); |
| 93 if (!main_function) { | 89 if (!main_function) { |
| 94 LOG(ERROR) << "MojoMain not found"; | 90 LOG(ERROR) << "MojoMain not found"; |
| 95 return false; | 91 return false; |
| 96 } | 92 } |
| 97 // |MojoMain()| takes ownership of the service handle. | 93 // |MojoMain()| takes ownership of the service handle. |
| 98 MojoHandle handle = request.PassMessagePipe().release().value(); | 94 MojoHandle handle = request.PassMessagePipe().release().value(); |
| 99 MojoResult result = main_function(handle); | 95 MojoResult result = main_function(handle); |
| 100 if (result != MOJO_RESULT_OK) { | 96 if (result != MOJO_RESULT_OK) { |
| 101 LOG(ERROR) << "MojoMain returned error (result: " << result << ")"; | 97 LOG(ERROR) << "MojoMain returned error (result: " << result << ")"; |
| 102 } | 98 } |
| 103 return true; | 99 return true; |
| 104 } | 100 } |
| 105 | 101 |
| 106 } // namespace shell | 102 } // namespace shell |
| OLD | NEW |