OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/background/background_shell.h" | 5 #include "mojo/shell/background/background_shell.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "base/synchronization/waitable_event.h" | 12 #include "base/synchronization/waitable_event.h" |
13 #include "base/threading/simple_thread.h" | 13 #include "base/threading/simple_thread.h" |
14 #include "mojo/message_pump/message_pump_mojo.h" | 14 #include "mojo/message_pump/message_pump_mojo.h" |
15 #include "mojo/services/package_manager/package_manager.h" | 15 #include "mojo/services/package_manager/package_manager.h" |
16 #include "mojo/shell/application_manager.h" | |
17 #include "mojo/shell/connect_params.h" | 16 #include "mojo/shell/connect_params.h" |
18 #include "mojo/shell/loader.h" | 17 #include "mojo/shell/loader.h" |
19 #include "mojo/shell/public/cpp/shell_client.h" | 18 #include "mojo/shell/public/cpp/shell_client.h" |
20 #include "mojo/shell/public/cpp/shell_connection.h" | 19 #include "mojo/shell/public/cpp/shell_connection.h" |
| 20 #include "mojo/shell/shell.h" |
21 #include "mojo/shell/standalone/context.h" | 21 #include "mojo/shell/standalone/context.h" |
22 | 22 |
23 namespace mojo { | 23 namespace mojo { |
24 namespace shell { | 24 namespace shell { |
25 namespace { | 25 namespace { |
26 | 26 |
27 scoped_ptr<base::MessagePump> CreateMessagePumpMojo() { | 27 scoped_ptr<base::MessagePump> CreateMessagePumpMojo() { |
28 return make_scoped_ptr(new common::MessagePumpMojo); | 28 return make_scoped_ptr(new common::MessagePumpMojo); |
29 } | 29 } |
30 | 30 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 : SimpleThread("mojo-background-shell"), | 74 : SimpleThread("mojo-background-shell"), |
75 init_params_(std::move(init_params)) {} | 75 init_params_(std::move(init_params)) {} |
76 ~MojoThread() override {} | 76 ~MojoThread() override {} |
77 | 77 |
78 void CreateShellClientRequest(base::WaitableEvent* signal, | 78 void CreateShellClientRequest(base::WaitableEvent* signal, |
79 scoped_ptr<ConnectParams> params, | 79 scoped_ptr<ConnectParams> params, |
80 mojom::ShellClientRequest* request) { | 80 mojom::ShellClientRequest* request) { |
81 // Only valid to call this on the background thread. | 81 // Only valid to call this on the background thread. |
82 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 82 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
83 | 83 |
84 // Ownership of |loader| passes to ApplicationManager. | 84 // Ownership of |loader| passes to Shell. |
85 const std::string name = params->target().name(); | 85 const std::string name = params->target().name(); |
86 BackgroundLoader* loader = new BackgroundLoader( | 86 BackgroundLoader* loader = new BackgroundLoader( |
87 base::Bind(&MojoThread::OnGotApplicationRequest, base::Unretained(this), | 87 base::Bind(&MojoThread::OnGotApplicationRequest, base::Unretained(this), |
88 name, signal, request)); | 88 name, signal, request)); |
89 context_->application_manager()->SetLoaderForName(make_scoped_ptr(loader), | 89 context_->shell()->SetLoaderForName(make_scoped_ptr(loader), name); |
90 name); | 90 context_->shell()->Connect(std::move(params)); |
91 context_->application_manager()->Connect(std::move(params)); | |
92 // The request is asynchronously processed. When processed | 91 // The request is asynchronously processed. When processed |
93 // OnGotApplicationRequest() is called and we'll signal |signal|. | 92 // OnGotApplicationRequest() is called and we'll signal |signal|. |
94 } | 93 } |
95 | 94 |
96 base::MessageLoop* message_loop() { return message_loop_; } | 95 base::MessageLoop* message_loop() { return message_loop_; } |
97 | 96 |
98 // Stops the background thread. | 97 // Stops the background thread. |
99 void Stop() { | 98 void Stop() { |
100 DCHECK_NE(message_loop_, base::MessageLoop::current()); | 99 DCHECK_NE(message_loop_, base::MessageLoop::current()); |
101 message_loop_->task_runner()->PostTask( | 100 message_loop_->task_runner()->PostTask( |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 context_ = nullptr; | 138 context_ = nullptr; |
140 } | 139 } |
141 | 140 |
142 private: | 141 private: |
143 void OnGotApplicationRequest(const std::string& name, | 142 void OnGotApplicationRequest(const std::string& name, |
144 base::WaitableEvent* signal, | 143 base::WaitableEvent* signal, |
145 mojom::ShellClientRequest* request_result, | 144 mojom::ShellClientRequest* request_result, |
146 mojom::ShellClientRequest actual_request) { | 145 mojom::ShellClientRequest actual_request) { |
147 *request_result = std::move(actual_request); | 146 *request_result = std::move(actual_request); |
148 // Trigger destruction of the loader. | 147 // Trigger destruction of the loader. |
149 context_->application_manager()->SetLoaderForName(nullptr, name); | 148 context_->shell()->SetLoaderForName(nullptr, name); |
150 signal->Signal(); | 149 signal->Signal(); |
151 } | 150 } |
152 | 151 |
153 // We own this. It's created on the main thread, but destroyed on the | 152 // We own this. It's created on the main thread, but destroyed on the |
154 // background thread. | 153 // background thread. |
155 MojoMessageLoop* message_loop_ = nullptr; | 154 MojoMessageLoop* message_loop_ = nullptr; |
156 // Created in Run() on the background thread. | 155 // Created in Run() on the background thread. |
157 Context* context_ = nullptr; | 156 Context* context_ = nullptr; |
158 | 157 |
159 scoped_ptr<BackgroundShell::InitParams> init_params_; | 158 scoped_ptr<BackgroundShell::InitParams> init_params_; |
(...skipping 26 matching lines...) Expand all Loading... |
186 thread_->message_loop()->task_runner()->PostTask( | 185 thread_->message_loop()->task_runner()->PostTask( |
187 FROM_HERE, base::Bind(&MojoThread::CreateShellClientRequest, | 186 FROM_HERE, base::Bind(&MojoThread::CreateShellClientRequest, |
188 base::Unretained(thread_.get()), &signal, | 187 base::Unretained(thread_.get()), &signal, |
189 base::Passed(¶ms), &request)); | 188 base::Passed(¶ms), &request)); |
190 signal.Wait(); | 189 signal.Wait(); |
191 return request; | 190 return request; |
192 } | 191 } |
193 | 192 |
194 } // namespace shell | 193 } // namespace shell |
195 } // namespace mojo | 194 } // namespace mojo |
OLD | NEW |