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 "mojo/public/platform/native/system_thunks.h" | 12 #include "mojo/public/platform/native/system_thunks.h" |
13 | 13 |
14 namespace mojo { | 14 namespace mojo { |
15 namespace shell { | 15 namespace shell { |
16 | 16 |
17 InProcessDynamicServiceRunner::InProcessDynamicServiceRunner( | 17 InProcessDynamicServiceRunner::InProcessDynamicServiceRunner( |
18 Context* context) | 18 Context* context) |
19 : keep_alive_(context), | 19 : keep_alive_(context) { |
20 thread_(this, "app_thread") { | |
21 } | 20 } |
22 | 21 |
23 InProcessDynamicServiceRunner::~InProcessDynamicServiceRunner() { | 22 InProcessDynamicServiceRunner::~InProcessDynamicServiceRunner() { |
24 if (thread_.HasBeenStarted()) { | 23 if (thread_) { |
25 DCHECK(!thread_.HasBeenJoined()); | 24 DCHECK(thread_->HasBeenStarted()); |
26 thread_.Join(); | 25 DCHECK(!thread_->HasBeenJoined()); |
| 26 thread_->Join(); |
27 } | 27 } |
28 | 28 |
29 // It is important to let the thread exit before unloading the DSO because | 29 // It is important to let the thread exit before unloading the DSO because |
30 // the library may have registered thread-local data and destructors to run | 30 // the library may have registered thread-local data and destructors to run |
31 // on thread termination. | 31 // on thread termination. |
32 app_library_.Reset(base::NativeLibrary()); | 32 app_library_.Reset(base::NativeLibrary()); |
33 } | 33 } |
34 | 34 |
35 void InProcessDynamicServiceRunner::Start( | 35 void InProcessDynamicServiceRunner::Start( |
36 const base::FilePath& app_path, | 36 const base::FilePath& app_path, |
37 ScopedMessagePipeHandle service_handle, | 37 ScopedMessagePipeHandle service_handle, |
38 const base::Closure& app_completed_callback) { | 38 const base::Closure& app_completed_callback) { |
39 app_path_ = app_path; | 39 app_path_ = app_path; |
40 | 40 |
41 DCHECK(!service_handle_.is_valid()); | 41 DCHECK(!service_handle_.is_valid()); |
42 service_handle_ = service_handle.Pass(); | 42 service_handle_ = service_handle.Pass(); |
43 | 43 |
44 DCHECK(app_completed_callback_runner_.is_null()); | 44 DCHECK(app_completed_callback_runner_.is_null()); |
45 app_completed_callback_runner_ = base::Bind(&base::TaskRunner::PostTask, | 45 app_completed_callback_runner_ = base::Bind(&base::TaskRunner::PostTask, |
46 base::MessageLoopProxy::current(), | 46 base::MessageLoopProxy::current(), |
47 FROM_HERE, | 47 FROM_HERE, |
48 app_completed_callback); | 48 app_completed_callback); |
49 | 49 |
50 DCHECK(!thread_.HasBeenStarted()); | 50 DCHECK(!thread_); |
51 thread_.Start(); | 51 thread_.reset(new base::DelegateSimpleThread(this, "app_thread")); |
| 52 thread_->Start(); |
52 } | 53 } |
53 | 54 |
54 void InProcessDynamicServiceRunner::Run() { | 55 void InProcessDynamicServiceRunner::Run() { |
55 DVLOG(2) << "Loading/running Mojo app in process from library: " | 56 DVLOG(2) << "Loading/running Mojo app in process from library: " |
56 << app_path_.value(); | 57 << app_path_.value(); |
57 | 58 |
58 do { | 59 do { |
59 base::NativeLibraryLoadError error; | 60 base::NativeLibraryLoadError error; |
60 app_library_.Reset(base::LoadNativeLibrary(app_path_, &error)); | 61 app_library_.Reset(base::LoadNativeLibrary(app_path_, &error)); |
61 if (!app_library_.is_valid()) { | 62 if (!app_library_.is_valid()) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 LOG(ERROR) << "MojoMain returned an error: " << result; | 100 LOG(ERROR) << "MojoMain returned an error: " << result; |
100 } while (false); | 101 } while (false); |
101 | 102 |
102 bool success = app_completed_callback_runner_.Run(); | 103 bool success = app_completed_callback_runner_.Run(); |
103 app_completed_callback_runner_.Reset(); | 104 app_completed_callback_runner_.Reset(); |
104 LOG_IF(ERROR, !success) << "Failed post run app_completed_callback"; | 105 LOG_IF(ERROR, !success) << "Failed post run app_completed_callback"; |
105 } | 106 } |
106 | 107 |
107 } // namespace shell | 108 } // namespace shell |
108 } // namespace mojo | 109 } // namespace mojo |
OLD | NEW |