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/runner/in_process_native_runner.h" | 5 #include "mojo/runner/in_process_native_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/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
11 #include "base/threading/platform_thread.h" | 11 #include "base/threading/platform_thread.h" |
12 #include "mojo/runner/native_application_support.h" | 12 #include "mojo/runner/native_application_support.h" |
13 | 13 |
14 namespace mojo { | 14 namespace mojo { |
15 namespace runner { | 15 namespace runner { |
16 | 16 |
17 InProcessNativeRunner::InProcessNativeRunner(Context* context) | 17 InProcessNativeRunner::InProcessNativeRunner(Context* context) |
18 : cleanup_(shell::NativeApplicationCleanup::DONT_DELETE), | 18 : app_library_(nullptr) {} |
19 app_library_(nullptr) { | |
20 } | |
21 | 19 |
22 InProcessNativeRunner::~InProcessNativeRunner() { | 20 InProcessNativeRunner::~InProcessNativeRunner() { |
23 // 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 |
24 // app_library_ is destructed), because the library may have registered | 22 // app_library_ is destructed), because the library may have registered |
25 // thread-local data and destructors to run on thread termination. | 23 // thread-local data and destructors to run on thread termination. |
26 if (thread_) { | 24 if (thread_) { |
27 DCHECK(thread_->HasBeenStarted()); | 25 DCHECK(thread_->HasBeenStarted()); |
28 DCHECK(!thread_->HasBeenJoined()); | 26 DCHECK(!thread_->HasBeenJoined()); |
29 thread_->Join(); | 27 thread_->Join(); |
30 } | 28 } |
31 } | 29 } |
32 | 30 |
33 void InProcessNativeRunner::Start( | 31 void InProcessNativeRunner::Start( |
34 const base::FilePath& app_path, | 32 const base::FilePath& app_path, |
35 bool start_sandboxed, | 33 bool start_sandboxed, |
36 shell::NativeApplicationCleanup cleanup, | |
37 InterfaceRequest<Application> application_request, | 34 InterfaceRequest<Application> application_request, |
38 const base::Closure& app_completed_callback) { | 35 const base::Closure& app_completed_callback) { |
39 app_path_ = app_path; | 36 app_path_ = app_path; |
40 cleanup_ = cleanup; | |
41 | 37 |
42 DCHECK(!application_request_.is_pending()); | 38 DCHECK(!application_request_.is_pending()); |
43 application_request_ = application_request.Pass(); | 39 application_request_ = application_request.Pass(); |
44 | 40 |
45 DCHECK(app_completed_callback_runner_.is_null()); | 41 DCHECK(app_completed_callback_runner_.is_null()); |
46 app_completed_callback_runner_ = base::Bind( | 42 app_completed_callback_runner_ = base::Bind( |
47 &base::TaskRunner::PostTask, base::ThreadTaskRunnerHandle::Get(), | 43 &base::TaskRunner::PostTask, base::ThreadTaskRunnerHandle::Get(), |
48 FROM_HERE, app_completed_callback); | 44 FROM_HERE, app_completed_callback); |
49 | 45 |
50 DCHECK(!thread_); | 46 DCHECK(!thread_); |
51 thread_.reset(new base::DelegateSimpleThread(this, "app_thread")); | 47 thread_.reset(new base::DelegateSimpleThread(this, "app_thread")); |
52 thread_->Start(); | 48 thread_->Start(); |
53 } | 49 } |
54 | 50 |
55 void InProcessNativeRunner::Run() { | 51 void InProcessNativeRunner::Run() { |
56 DVLOG(2) << "Loading/running Mojo app in process from library: " | 52 DVLOG(2) << "Loading/running Mojo app in process from library: " |
57 << app_path_.value() | 53 << app_path_.value() |
58 << " thread id=" << base::PlatformThread::CurrentId(); | 54 << " thread id=" << base::PlatformThread::CurrentId(); |
59 | 55 |
60 // TODO(vtl): ScopedNativeLibrary doesn't have a .get() method! | 56 // TODO(vtl): ScopedNativeLibrary doesn't have a .get() method! |
61 base::NativeLibrary app_library = LoadNativeApplication(app_path_, cleanup_); | 57 base::NativeLibrary app_library = LoadNativeApplication(app_path_); |
62 app_library_.Reset(app_library); | 58 app_library_.Reset(app_library); |
63 RunNativeApplication(app_library, application_request_.Pass()); | 59 RunNativeApplication(app_library, application_request_.Pass()); |
64 app_completed_callback_runner_.Run(); | 60 app_completed_callback_runner_.Run(); |
65 app_completed_callback_runner_.Reset(); | 61 app_completed_callback_runner_.Reset(); |
66 } | 62 } |
67 | 63 |
68 scoped_ptr<shell::NativeRunner> InProcessNativeRunnerFactory::Create( | 64 scoped_ptr<shell::NativeRunner> InProcessNativeRunnerFactory::Create() { |
69 const Options& options) { | |
70 return make_scoped_ptr(new InProcessNativeRunner(context_)); | 65 return make_scoped_ptr(new InProcessNativeRunner(context_)); |
71 } | 66 } |
72 | 67 |
73 } // namespace runner | 68 } // namespace runner |
74 } // namespace mojo | 69 } // namespace mojo |
OLD | NEW |