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 "content/common/service_manager/service_manager_connection_impl.h" | 5 #include "content/common/service_manager/service_manager_connection_impl.h" |
6 | 6 |
7 #include <queue> | 7 #include <queue> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 const service_manager::InterfaceRegistry::Binder& binder) { | 120 const service_manager::InterfaceRegistry::Binder& binder) { |
121 DCHECK(!started_); | 121 DCHECK(!started_); |
122 default_browser_binder_ = base::Bind( | 122 default_browser_binder_ = base::Bind( |
123 &IOThreadContext::CallBinderOnTaskRunner, | 123 &IOThreadContext::CallBinderOnTaskRunner, |
124 base::ThreadTaskRunnerHandle::Get(), binder); | 124 base::ThreadTaskRunnerHandle::Get(), binder); |
125 } | 125 } |
126 | 126 |
127 private: | 127 private: |
128 friend class base::RefCountedThreadSafe<IOThreadContext>; | 128 friend class base::RefCountedThreadSafe<IOThreadContext>; |
129 | 129 |
| 130 // A forwarding service_manager::Service implementation to account for the |
| 131 // fact that IOThreadContext is a Service which owns its ServiceContext, but |
| 132 // ServiceContext should own its Service. |
| 133 // |
| 134 // TODO(rockot): Clean this up. |
| 135 class ForwardingServiceImpl : public service_manager::Service { |
| 136 public: |
| 137 explicit ForwardingServiceImpl(service_manager::Service* service) |
| 138 : service_(service) {} |
| 139 ~ForwardingServiceImpl() override {} |
| 140 |
| 141 // service_manager::Service: |
| 142 void OnStart(service_manager::ServiceContext* context) override { |
| 143 service_->OnStart(context); |
| 144 } |
| 145 |
| 146 bool OnConnect(const service_manager::ServiceInfo& remote_info, |
| 147 service_manager::InterfaceRegistry* registry) override { |
| 148 return service_->OnConnect(remote_info, registry); |
| 149 } |
| 150 |
| 151 bool OnStop() override { return service_->OnStop(); } |
| 152 |
| 153 private: |
| 154 service_manager::Service* const service_; |
| 155 DISALLOW_COPY_AND_ASSIGN(ForwardingServiceImpl); |
| 156 }; |
| 157 |
130 class MessageLoopObserver : public base::MessageLoop::DestructionObserver { | 158 class MessageLoopObserver : public base::MessageLoop::DestructionObserver { |
131 public: | 159 public: |
132 explicit MessageLoopObserver(base::WeakPtr<IOThreadContext> context) | 160 explicit MessageLoopObserver(base::WeakPtr<IOThreadContext> context) |
133 : context_(context) { | 161 : context_(context) { |
134 base::MessageLoop::current()->AddDestructionObserver(this); | 162 base::MessageLoop::current()->AddDestructionObserver(this); |
135 } | 163 } |
136 | 164 |
137 ~MessageLoopObserver() override { | 165 ~MessageLoopObserver() override { |
138 base::MessageLoop::current()->RemoveDestructionObserver(this); | 166 base::MessageLoop::current()->RemoveDestructionObserver(this); |
139 } | 167 } |
(...skipping 22 matching lines...) Expand all Loading... |
162 | 190 |
163 DISALLOW_COPY_AND_ASSIGN(MessageLoopObserver); | 191 DISALLOW_COPY_AND_ASSIGN(MessageLoopObserver); |
164 }; | 192 }; |
165 | 193 |
166 ~IOThreadContext() override {} | 194 ~IOThreadContext() override {} |
167 | 195 |
168 void StartOnIOThread() { | 196 void StartOnIOThread() { |
169 // Should bind |io_thread_checker_| to the context's thread. | 197 // Should bind |io_thread_checker_| to the context's thread. |
170 DCHECK(io_thread_checker_.CalledOnValidThread()); | 198 DCHECK(io_thread_checker_.CalledOnValidThread()); |
171 service_context_.reset(new service_manager::ServiceContext( | 199 service_context_.reset(new service_manager::ServiceContext( |
172 base::MakeUnique<service_manager::ForwardingService>(this), | 200 base::MakeUnique<ForwardingServiceImpl>(this), |
173 std::move(pending_service_request_), | 201 std::move(pending_service_request_), |
174 std::move(io_thread_connector_), | 202 std::move(io_thread_connector_), |
175 std::move(pending_connector_request_))); | 203 std::move(pending_connector_request_))); |
176 | 204 |
177 // MessageLoopObserver owns itself. | 205 // MessageLoopObserver owns itself. |
178 message_loop_observer_ = | 206 message_loop_observer_ = |
179 new MessageLoopObserver(weak_factory_.GetWeakPtr()); | 207 new MessageLoopObserver(weak_factory_.GetWeakPtr()); |
180 } | 208 } |
181 | 209 |
182 void ShutDownOnIOThread() { | 210 void ShutDownOnIOThread() { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 } | 244 } |
217 | 245 |
218 void OnBrowserConnectionLost() { | 246 void OnBrowserConnectionLost() { |
219 DCHECK(io_thread_checker_.CalledOnValidThread()); | 247 DCHECK(io_thread_checker_.CalledOnValidThread()); |
220 has_browser_connection_ = false; | 248 has_browser_connection_ = false; |
221 } | 249 } |
222 | 250 |
223 ///////////////////////////////////////////////////////////////////////////// | 251 ///////////////////////////////////////////////////////////////////////////// |
224 // service_manager::Service implementation | 252 // service_manager::Service implementation |
225 | 253 |
226 void OnStart() override { | 254 void OnStart(service_manager::ServiceContext* context) override { |
227 DCHECK(io_thread_checker_.CalledOnValidThread()); | 255 DCHECK(io_thread_checker_.CalledOnValidThread()); |
228 DCHECK(!initialize_handler_.is_null()); | 256 DCHECK(!initialize_handler_.is_null()); |
229 local_info_ = context()->local_info(); | 257 local_info_ = context->local_info(); |
230 | 258 |
231 InitializeCallback handler = base::ResetAndReturn(&initialize_handler_); | 259 InitializeCallback handler = base::ResetAndReturn(&initialize_handler_); |
232 callback_task_runner_->PostTask(FROM_HERE, | 260 callback_task_runner_->PostTask(FROM_HERE, |
233 base::Bind(handler, local_info_.identity)); | 261 base::Bind(handler, local_info_.identity)); |
234 } | 262 } |
235 | 263 |
236 bool OnConnect(const service_manager::ServiceInfo& remote_info, | 264 bool OnConnect(const service_manager::ServiceInfo& remote_info, |
237 service_manager::InterfaceRegistry* registry) override { | 265 service_manager::InterfaceRegistry* registry) override { |
238 DCHECK(io_thread_checker_.CalledOnValidThread()); | 266 DCHECK(io_thread_checker_.CalledOnValidThread()); |
239 | 267 |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 | 566 |
539 void ServiceManagerConnectionImpl::GetInterface( | 567 void ServiceManagerConnectionImpl::GetInterface( |
540 service_manager::mojom::InterfaceProvider* provider, | 568 service_manager::mojom::InterfaceProvider* provider, |
541 const std::string& interface_name, | 569 const std::string& interface_name, |
542 mojo::ScopedMessagePipeHandle request_handle) { | 570 mojo::ScopedMessagePipeHandle request_handle) { |
543 provider->GetInterface(interface_name, std::move(request_handle)); | 571 provider->GetInterface(interface_name, std::move(request_handle)); |
544 } | 572 } |
545 | 573 |
546 } // namespace content | 574 } // namespace content |
547 | 575 |
OLD | NEW |