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 <unistd.h> | 5 #include <unistd.h> |
6 | 6 |
7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
19 #include "base/synchronization/waitable_event.h" | 19 #include "base/synchronization/waitable_event.h" |
20 #include "base/thread_task_runner_handle.h" | 20 #include "base/thread_task_runner_handle.h" |
21 #include "base/threading/thread.h" | 21 #include "base/threading/thread.h" |
22 #include "base/threading/thread_checker.h" | 22 #include "base/threading/thread_checker.h" |
23 #include "mojo/edk/base_edk/platform_task_runner_impl.h" | 23 #include "mojo/edk/base_edk/platform_task_runner_impl.h" |
24 #include "mojo/edk/embedder/embedder.h" | 24 #include "mojo/edk/embedder/embedder.h" |
25 #include "mojo/edk/embedder/platform_channel_pair.h" | 25 #include "mojo/edk/embedder/platform_channel_pair.h" |
26 #include "mojo/edk/embedder/platform_task_runner.h" | |
27 #include "mojo/edk/embedder/scoped_platform_handle.h" | 26 #include "mojo/edk/embedder/scoped_platform_handle.h" |
28 #include "mojo/edk/embedder/simple_platform_support.h" | 27 #include "mojo/edk/embedder/simple_platform_support.h" |
29 #include "mojo/edk/embedder/slave_process_delegate.h" | 28 #include "mojo/edk/embedder/slave_process_delegate.h" |
| 29 #include "mojo/edk/platform/task_runner.h" |
30 #include "mojo/edk/util/ref_ptr.h" | 30 #include "mojo/edk/util/ref_ptr.h" |
31 #include "mojo/message_pump/message_pump_mojo.h" | 31 #include "mojo/message_pump/message_pump_mojo.h" |
32 #include "mojo/public/cpp/bindings/binding.h" | 32 #include "mojo/public/cpp/bindings/binding.h" |
33 #include "mojo/public/cpp/system/core.h" | 33 #include "mojo/public/cpp/system/core.h" |
34 #include "shell/child_controller.mojom.h" | 34 #include "shell/child_controller.mojom.h" |
35 #include "shell/child_switches.h" | 35 #include "shell/child_switches.h" |
36 #include "shell/init.h" | 36 #include "shell/init.h" |
37 #include "shell/native_application_support.h" | 37 #include "shell/native_application_support.h" |
38 | 38 |
39 using mojo::embedder::PlatformTaskRunner; | |
40 using mojo::util::MakeRefCounted; | 39 using mojo::util::MakeRefCounted; |
41 using mojo::util::RefPtr; | 40 using mojo::util::RefPtr; |
42 | 41 |
43 namespace shell { | 42 namespace shell { |
44 namespace { | 43 namespace { |
45 | 44 |
46 // Blocker --------------------------------------------------------------------- | 45 // Blocker --------------------------------------------------------------------- |
47 | 46 |
48 // Blocks a thread until another thread unblocks it, at which point it unblocks | 47 // Blocks a thread until another thread unblocks it, at which point it unblocks |
49 // and runs a closure provided by that thread. | 48 // and runs a closure provided by that thread. |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 } | 127 } |
129 | 128 |
130 void Shutdown() { | 129 void Shutdown() { |
131 Blocker blocker; | 130 Blocker blocker; |
132 shutdown_unblocker_ = blocker.GetUnblocker(); | 131 shutdown_unblocker_ = blocker.GetUnblocker(); |
133 controller_runner_->PostTask(base::Bind( | 132 controller_runner_->PostTask(base::Bind( |
134 &AppContext::ShutdownOnControllerThread, base::Unretained(this))); | 133 &AppContext::ShutdownOnControllerThread, base::Unretained(this))); |
135 blocker.Block(); | 134 blocker.Block(); |
136 } | 135 } |
137 | 136 |
138 const RefPtr<PlatformTaskRunner>& controller_runner() const { | 137 const RefPtr<mojo::platform::TaskRunner>& controller_runner() const { |
139 return controller_runner_; | 138 return controller_runner_; |
140 } | 139 } |
141 | 140 |
142 ChildControllerImpl* controller() const { return controller_.get(); } | 141 ChildControllerImpl* controller() const { return controller_.get(); } |
143 | 142 |
144 void set_controller(scoped_ptr<ChildControllerImpl> controller) { | 143 void set_controller(scoped_ptr<ChildControllerImpl> controller) { |
145 controller_ = controller.Pass(); | 144 controller_ = controller.Pass(); |
146 } | 145 } |
147 | 146 |
148 private: | 147 private: |
(...skipping 10 matching lines...) Expand all Loading... |
159 shutdown_unblocker_.Unblock(base::Closure()); | 158 shutdown_unblocker_.Unblock(base::Closure()); |
160 } | 159 } |
161 | 160 |
162 void OnMasterDisconnect() override { | 161 void OnMasterDisconnect() override { |
163 // We've lost the connection to the master process. This is not recoverable. | 162 // We've lost the connection to the master process. This is not recoverable. |
164 LOG(ERROR) << "Disconnected from master"; | 163 LOG(ERROR) << "Disconnected from master"; |
165 _exit(1); | 164 _exit(1); |
166 } | 165 } |
167 | 166 |
168 base::Thread io_thread_; | 167 base::Thread io_thread_; |
169 RefPtr<PlatformTaskRunner> io_runner_; | 168 RefPtr<mojo::platform::TaskRunner> io_runner_; |
170 | 169 |
171 base::Thread controller_thread_; | 170 base::Thread controller_thread_; |
172 RefPtr<PlatformTaskRunner> controller_runner_; | 171 RefPtr<mojo::platform::TaskRunner> controller_runner_; |
173 | 172 |
174 // Accessed only on the controller thread. | 173 // Accessed only on the controller thread. |
175 scoped_ptr<ChildControllerImpl> controller_; | 174 scoped_ptr<ChildControllerImpl> controller_; |
176 | 175 |
177 // Used to unblock the main thread on shutdown. | 176 // Used to unblock the main thread on shutdown. |
178 Blocker::Unblocker shutdown_unblocker_; | 177 Blocker::Unblocker shutdown_unblocker_; |
179 | 178 |
180 DISALLOW_COPY_AND_ASSIGN(AppContext); | 179 DISALLOW_COPY_AND_ASSIGN(AppContext); |
181 }; | 180 }; |
182 | 181 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 | 268 |
270 // We intentionally don't unload the native library as its lifetime is the | 269 // We intentionally don't unload the native library as its lifetime is the |
271 // same as that of the process. | 270 // same as that of the process. |
272 base::NativeLibrary app_library = LoadNativeApplication(app_path); | 271 base::NativeLibrary app_library = LoadNativeApplication(app_path); |
273 RunNativeApplication(app_library, application_request.Pass()); | 272 RunNativeApplication(app_library, application_request.Pass()); |
274 } | 273 } |
275 | 274 |
276 base::ThreadChecker thread_checker_; | 275 base::ThreadChecker thread_checker_; |
277 AppContext* const app_context_; | 276 AppContext* const app_context_; |
278 Blocker::Unblocker unblocker_; | 277 Blocker::Unblocker unblocker_; |
279 RefPtr<PlatformTaskRunner> mojo_task_runner_; | 278 RefPtr<mojo::platform::TaskRunner> mojo_task_runner_; |
280 StartAppCallback on_app_complete_; | 279 StartAppCallback on_app_complete_; |
281 | 280 |
282 mojo::embedder::ChannelInfo* channel_info_; | 281 mojo::embedder::ChannelInfo* channel_info_; |
283 mojo::Binding<ChildController> binding_; | 282 mojo::Binding<ChildController> binding_; |
284 | 283 |
285 DISALLOW_COPY_AND_ASSIGN(ChildControllerImpl); | 284 DISALLOW_COPY_AND_ASSIGN(ChildControllerImpl); |
286 }; | 285 }; |
287 | 286 |
288 } // namespace | 287 } // namespace |
289 } // namespace shell | 288 } // namespace shell |
(...skipping 27 matching lines...) Expand all Loading... |
317 app_context.controller_runner()->PostTask(base::Bind( | 316 app_context.controller_runner()->PostTask(base::Bind( |
318 &shell::ChildControllerImpl::Init, base::Unretained(&app_context), | 317 &shell::ChildControllerImpl::Init, base::Unretained(&app_context), |
319 child_connection_id, blocker.GetUnblocker())); | 318 child_connection_id, blocker.GetUnblocker())); |
320 // This will block, then run whatever the controller wants. | 319 // This will block, then run whatever the controller wants. |
321 blocker.Block(); | 320 blocker.Block(); |
322 | 321 |
323 app_context.Shutdown(); | 322 app_context.Shutdown(); |
324 | 323 |
325 return 0; | 324 return 0; |
326 } | 325 } |
OLD | NEW |