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 "shell/in_process_dynamic_service_runner.h" | 5 #include "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/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
11 #include "base/threading/platform_thread.h" | 11 #include "base/threading/platform_thread.h" |
12 | 12 |
13 namespace mojo { | 13 namespace mojo { |
14 namespace shell { | 14 namespace shell { |
15 | 15 |
16 InProcessDynamicServiceRunner::InProcessDynamicServiceRunner(Context* context) | 16 InProcessDynamicServiceRunner::InProcessDynamicServiceRunner(Context* context) |
17 : app_library_(nullptr) { | 17 : clean_app_path_(false), app_library_(nullptr) { |
18 } | 18 } |
19 | 19 |
20 InProcessDynamicServiceRunner::~InProcessDynamicServiceRunner() { | 20 InProcessDynamicServiceRunner::~InProcessDynamicServiceRunner() { |
21 // It is important to let the thread exit before unloading the DSO (when | 21 // It is important to let the thread exit before unloading the DSO (when |
22 // app_library_ is destructed), because the library may have registered | 22 // app_library_ is destructed), because the library may have registered |
23 // thread-local data and destructors to run on thread termination. | 23 // thread-local data and destructors to run on thread termination. |
24 if (thread_) { | 24 if (thread_) { |
25 DCHECK(thread_->HasBeenStarted()); | 25 DCHECK(thread_->HasBeenStarted()); |
26 DCHECK(!thread_->HasBeenJoined()); | 26 DCHECK(!thread_->HasBeenJoined()); |
27 thread_->Join(); | 27 thread_->Join(); |
28 } | 28 } |
29 } | 29 } |
30 | 30 |
31 void InProcessDynamicServiceRunner::Start( | 31 void InProcessDynamicServiceRunner::Start( |
32 const base::FilePath& app_path, | 32 const base::FilePath& app_path, |
| 33 bool clean_app_path, |
33 ScopedMessagePipeHandle service_handle, | 34 ScopedMessagePipeHandle service_handle, |
34 const base::Closure& app_completed_callback) { | 35 const base::Closure& app_completed_callback) { |
35 app_path_ = app_path; | 36 app_path_ = app_path; |
| 37 clean_app_path_ = clean_app_path; |
36 | 38 |
37 DCHECK(!service_handle_.is_valid()); | 39 DCHECK(!service_handle_.is_valid()); |
38 service_handle_ = service_handle.Pass(); | 40 service_handle_ = service_handle.Pass(); |
39 | 41 |
40 DCHECK(app_completed_callback_runner_.is_null()); | 42 DCHECK(app_completed_callback_runner_.is_null()); |
41 app_completed_callback_runner_ = | 43 app_completed_callback_runner_ = |
42 base::Bind(&base::TaskRunner::PostTask, base::MessageLoopProxy::current(), | 44 base::Bind(&base::TaskRunner::PostTask, base::MessageLoopProxy::current(), |
43 FROM_HERE, app_completed_callback); | 45 FROM_HERE, app_completed_callback); |
44 | 46 |
45 DCHECK(!thread_); | 47 DCHECK(!thread_); |
46 thread_.reset(new base::DelegateSimpleThread(this, "app_thread")); | 48 thread_.reset(new base::DelegateSimpleThread(this, "app_thread")); |
47 thread_->Start(); | 49 thread_->Start(); |
48 } | 50 } |
49 | 51 |
50 void InProcessDynamicServiceRunner::Run() { | 52 void InProcessDynamicServiceRunner::Run() { |
51 DVLOG(2) << "Loading/running Mojo app in process from library: " | 53 DVLOG(2) << "Loading/running Mojo app in process from library: " |
52 << app_path_.value() | 54 << app_path_.value() |
53 << " thread id=" << base::PlatformThread::CurrentId(); | 55 << " thread id=" << base::PlatformThread::CurrentId(); |
54 | 56 |
55 app_library_.Reset(LoadAndRunService(app_path_, service_handle_.Pass())); | 57 app_library_.Reset( |
| 58 LoadAndRunService(app_path_, clean_app_path_, service_handle_.Pass())); |
56 app_completed_callback_runner_.Run(); | 59 app_completed_callback_runner_.Run(); |
57 app_completed_callback_runner_.Reset(); | 60 app_completed_callback_runner_.Reset(); |
58 } | 61 } |
59 | 62 |
60 } // namespace shell | 63 } // namespace shell |
61 } // namespace mojo | 64 } // namespace mojo |
OLD | NEW |