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 "services/shell/background/background_shell.h" | 5 #include "services/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/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/message_loop/message_pump_default.h" | 12 #include "base/message_loop/message_pump_default.h" |
13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
15 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
16 #include "base/threading/simple_thread.h" | 16 #include "base/threading/simple_thread.h" |
17 #include "services/catalog/store.h" | 17 #include "services/catalog/store.h" |
18 #include "services/shell/connect_params.h" | 18 #include "services/shell/connect_params.h" |
19 #include "services/shell/public/cpp/shell_client.h" | 19 #include "services/shell/public/cpp/service.h" |
20 #include "services/shell/public/cpp/shell_connection.h" | 20 #include "services/shell/public/cpp/shell_connection.h" |
21 #include "services/shell/shell.h" | 21 #include "services/shell/shell.h" |
22 #include "services/shell/standalone/context.h" | 22 #include "services/shell/standalone/context.h" |
23 | 23 |
24 namespace shell { | 24 namespace shell { |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 std::unique_ptr<base::MessagePump> CreateDefaultMessagePump() { | 28 std::unique_ptr<base::MessagePump> CreateDefaultMessagePump() { |
29 return base::WrapUnique(new base::MessagePumpDefault); | 29 return base::WrapUnique(new base::MessagePumpDefault); |
(...skipping 15 matching lines...) Expand all Loading... |
45 } // namespace | 45 } // namespace |
46 | 46 |
47 // Manages the thread to startup mojo. | 47 // Manages the thread to startup mojo. |
48 class BackgroundShell::MojoThread : public base::SimpleThread { | 48 class BackgroundShell::MojoThread : public base::SimpleThread { |
49 public: | 49 public: |
50 explicit MojoThread(std::unique_ptr<BackgroundShell::InitParams> init_params) | 50 explicit MojoThread(std::unique_ptr<BackgroundShell::InitParams> init_params) |
51 : SimpleThread("mojo-background-shell"), | 51 : SimpleThread("mojo-background-shell"), |
52 init_params_(std::move(init_params)) {} | 52 init_params_(std::move(init_params)) {} |
53 ~MojoThread() override {} | 53 ~MojoThread() override {} |
54 | 54 |
55 void CreateShellClientRequest(base::WaitableEvent* signal, | 55 void CreateServiceRequest(base::WaitableEvent* signal, |
56 const std::string& name, | 56 const std::string& name, |
57 mojom::ShellClientRequest* request) { | 57 mojom::ServiceRequest* request) { |
58 // Only valid to call this on the background thread. | 58 // Only valid to call this on the background thread. |
59 DCHECK(message_loop_->task_runner()->BelongsToCurrentThread()); | 59 DCHECK(message_loop_->task_runner()->BelongsToCurrentThread()); |
60 *request = context_->shell()->InitInstanceForEmbedder(name); | 60 *request = context_->shell()->InitInstanceForEmbedder(name); |
61 signal->Signal(); | 61 signal->Signal(); |
62 } | 62 } |
63 | 63 |
64 void Connect(std::unique_ptr<ConnectParams> params) { | 64 void Connect(std::unique_ptr<ConnectParams> params) { |
65 context_->shell()->Connect(std::move(params)); | 65 context_->shell()->Connect(std::move(params)); |
66 } | 66 } |
67 | 67 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 BackgroundShell::~BackgroundShell() { | 139 BackgroundShell::~BackgroundShell() { |
140 thread_->Stop(); | 140 thread_->Stop(); |
141 } | 141 } |
142 | 142 |
143 void BackgroundShell::Init(std::unique_ptr<InitParams> init_params) { | 143 void BackgroundShell::Init(std::unique_ptr<InitParams> init_params) { |
144 DCHECK(!thread_); | 144 DCHECK(!thread_); |
145 thread_.reset(new MojoThread(std::move(init_params))); | 145 thread_.reset(new MojoThread(std::move(init_params))); |
146 thread_->Start(); | 146 thread_->Start(); |
147 } | 147 } |
148 | 148 |
149 mojom::ShellClientRequest BackgroundShell::CreateShellClientRequest( | 149 mojom::ServiceRequest BackgroundShell::CreateServiceRequest( |
150 const std::string& name) { | 150 const std::string& name) { |
151 std::unique_ptr<ConnectParams> params(new ConnectParams); | 151 std::unique_ptr<ConnectParams> params(new ConnectParams); |
152 params->set_source(CreateShellIdentity()); | 152 params->set_source(CreateShellIdentity()); |
153 params->set_target(Identity(name, mojom::kRootUserID)); | 153 params->set_target(Identity(name, mojom::kRootUserID)); |
154 mojom::ShellClientRequest request; | 154 mojom::ServiceRequest request; |
155 base::WaitableEvent signal(base::WaitableEvent::ResetPolicy::MANUAL, | 155 base::WaitableEvent signal(base::WaitableEvent::ResetPolicy::MANUAL, |
156 base::WaitableEvent::InitialState::NOT_SIGNALED); | 156 base::WaitableEvent::InitialState::NOT_SIGNALED); |
157 thread_->message_loop()->task_runner()->PostTask( | 157 thread_->message_loop()->task_runner()->PostTask( |
158 FROM_HERE, | 158 FROM_HERE, |
159 base::Bind(&MojoThread::CreateShellClientRequest, | 159 base::Bind(&MojoThread::CreateServiceRequest, |
160 base::Unretained(thread_.get()), &signal, name, &request)); | 160 base::Unretained(thread_.get()), &signal, name, &request)); |
161 signal.Wait(); | 161 signal.Wait(); |
162 thread_->message_loop()->task_runner()->PostTask( | 162 thread_->message_loop()->task_runner()->PostTask( |
163 FROM_HERE, | 163 FROM_HERE, |
164 base::Bind(&MojoThread::Connect, base::Unretained(thread_.get()), | 164 base::Bind(&MojoThread::Connect, base::Unretained(thread_.get()), |
165 base::Passed(¶ms))); | 165 base::Passed(¶ms))); |
166 return request; | 166 return request; |
167 } | 167 } |
168 | 168 |
169 void BackgroundShell::ExecuteOnShellThread( | 169 void BackgroundShell::ExecuteOnShellThread( |
170 const ShellThreadCallback& callback) { | 170 const ShellThreadCallback& callback) { |
171 thread_->message_loop()->task_runner()->PostTask( | 171 thread_->message_loop()->task_runner()->PostTask( |
172 FROM_HERE, base::Bind(&MojoThread::RunShellCallback, | 172 FROM_HERE, base::Bind(&MojoThread::RunShellCallback, |
173 base::Unretained(thread_.get()), callback)); | 173 base::Unretained(thread_.get()), callback)); |
174 } | 174 } |
175 | 175 |
176 } // namespace shell | 176 } // namespace shell |
OLD | NEW |