OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_container.h" | 5 #include "mojo/shell/app_container.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
| 9 #include "base/callback_helpers.h" |
9 #include "base/file_util.h" | 10 #include "base/file_util.h" |
10 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
11 #include "base/native_library.h" | 12 #include "base/native_library.h" |
| 13 #include "base/scoped_native_library.h" |
12 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
13 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
14 #include "mojo/public/system/core.h" | 16 #include "mojo/public/system/core.h" |
| 17 #include "mojo/public/utility/scoped_handle.h" |
15 #include "mojo/services/native_viewport/native_viewport_controller.h" | 18 #include "mojo/services/native_viewport/native_viewport_controller.h" |
16 #include "mojo/shell/context.h" | 19 #include "mojo/shell/context.h" |
17 | 20 |
18 typedef MojoResult (*MojoMainFunction)(mojo::Handle pipe); | 21 typedef MojoResult (*MojoMainFunction)(mojo::Handle pipe); |
19 | 22 |
20 namespace mojo { | 23 namespace mojo { |
21 namespace shell { | 24 namespace shell { |
22 | 25 |
23 void LaunchAppOnThread( | 26 void LaunchAppOnThread( |
24 const base::FilePath& app_path, | 27 const base::FilePath& app_path, |
25 Handle app_handle) { | 28 Handle app_handle_raw) { |
26 MojoResult result = MOJO_RESULT_OK; | 29 base::ScopedClosureRunner app_deleter( |
27 MojoMainFunction main_function = NULL; | 30 base::Bind(base::IgnoreResult(&base::DeleteFile), app_path, false)); |
| 31 ScopedHandle app_handle(app_handle_raw); |
28 | 32 |
29 base::NativeLibrary app_library = base::LoadNativeLibrary(app_path, NULL); | 33 base::ScopedNativeLibrary app_library( |
30 if (!app_library) { | 34 base::LoadNativeLibrary(app_path, NULL)); |
| 35 if (!app_library.is_valid()) { |
31 LOG(ERROR) << "Failed to load library: " << app_path.value().c_str(); | 36 LOG(ERROR) << "Failed to load library: " << app_path.value().c_str(); |
32 goto completed; | 37 return; |
33 } | 38 } |
34 | 39 |
35 main_function = reinterpret_cast<MojoMainFunction>( | 40 MojoMainFunction main_function = reinterpret_cast<MojoMainFunction>( |
36 base::GetFunctionPointerFromNativeLibrary(app_library, "MojoMain")); | 41 app_library.GetFunctionPointer("MojoMain")); |
37 if (!main_function) { | 42 if (!main_function) { |
38 LOG(ERROR) << "Entrypoint MojoMain not found."; | 43 LOG(ERROR) << "Entrypoint MojoMain not found."; |
39 goto completed; | 44 return; |
40 } | 45 } |
41 | 46 |
42 result = main_function(app_handle); | 47 MojoResult result = main_function(app_handle.get()); |
43 if (result < MOJO_RESULT_OK) { | 48 if (result < MOJO_RESULT_OK) { |
44 LOG(ERROR) << "MojoMain returned an error: " << result; | 49 LOG(ERROR) << "MojoMain returned an error: " << result; |
45 // TODO(*): error handling? | 50 return; |
46 goto completed; | |
47 } | 51 } |
48 | 52 |
49 LOG(INFO) << "MojoMain succeeded: " << result; | 53 LOG(INFO) << "MojoMain succeeded: " << result; |
50 | |
51 completed: | |
52 base::UnloadNativeLibrary(app_library); | |
53 base::DeleteFile(app_path, false); | |
54 Close(app_handle); | |
55 } | 54 } |
56 | 55 |
57 AppContainer::AppContainer(Context* context) | 56 AppContainer::AppContainer(Context* context) |
58 : context_(context) | 57 : context_(context) |
59 , weak_factory_(this) { | 58 , weak_factory_(this) { |
60 } | 59 } |
61 | 60 |
62 AppContainer::~AppContainer() { | 61 AppContainer::~AppContainer() { |
63 } | 62 } |
64 | 63 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 | 98 |
100 void AppContainer::AppCompleted() { | 99 void AppContainer::AppCompleted() { |
101 native_viewport_controller_->Close(); | 100 native_viewport_controller_->Close(); |
102 | 101 |
103 thread_.reset(); | 102 thread_.reset(); |
104 Close(shell_handle_); | 103 Close(shell_handle_); |
105 } | 104 } |
106 | 105 |
107 } // namespace shell | 106 } // namespace shell |
108 } // namespace mojo | 107 } // namespace mojo |
OLD | NEW |