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") { |
20 } | 21 } |
21 | 22 |
22 InProcessDynamicServiceRunner::~InProcessDynamicServiceRunner() { | 23 InProcessDynamicServiceRunner::~InProcessDynamicServiceRunner() { |
23 if (thread_) { | 24 if (thread_.HasBeenStarted()) { |
24 DCHECK(thread_->HasBeenStarted()); | 25 DCHECK(!thread_.HasBeenJoined()); |
25 DCHECK(!thread_->HasBeenJoined()); | 26 thread_.Join(); |
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_); | 50 DCHECK(!thread_.HasBeenStarted()); |
51 thread_.reset(new base::DelegateSimpleThread(this, "app_thread")); | 51 thread_.Start(); |
52 thread_->Start(); | |
53 } | 52 } |
54 | 53 |
55 void InProcessDynamicServiceRunner::Run() { | 54 void InProcessDynamicServiceRunner::Run() { |
56 DVLOG(2) << "Loading/running Mojo app in process from library: " | 55 DVLOG(2) << "Loading/running Mojo app in process from library: " |
57 << app_path_.value(); | 56 << app_path_.value(); |
58 | 57 |
59 do { | 58 do { |
60 base::NativeLibraryLoadError error; | 59 base::NativeLibraryLoadError error; |
61 app_library_.Reset(base::LoadNativeLibrary(app_path_, &error)); | 60 app_library_.Reset(base::LoadNativeLibrary(app_path_, &error)); |
62 if (!app_library_.is_valid()) { | 61 if (!app_library_.is_valid()) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 LOG(ERROR) << "MojoMain returned an error: " << result; | 99 LOG(ERROR) << "MojoMain returned an error: " << result; |
101 } while (false); | 100 } while (false); |
102 | 101 |
103 bool success = app_completed_callback_runner_.Run(); | 102 bool success = app_completed_callback_runner_.Run(); |
104 app_completed_callback_runner_.Reset(); | 103 app_completed_callback_runner_.Reset(); |
105 LOG_IF(ERROR, !success) << "Failed post run app_completed_callback"; | 104 LOG_IF(ERROR, !success) << "Failed post run app_completed_callback"; |
106 } | 105 } |
107 | 106 |
108 } // namespace shell | 107 } // namespace shell |
109 } // namespace mojo | 108 } // namespace mojo |
OLD | NEW |