| 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 | |
| 158 class MessageLoopObserver : public base::MessageLoop::DestructionObserver { | 130 class MessageLoopObserver : public base::MessageLoop::DestructionObserver { |
| 159 public: | 131 public: |
| 160 explicit MessageLoopObserver(base::WeakPtr<IOThreadContext> context) | 132 explicit MessageLoopObserver(base::WeakPtr<IOThreadContext> context) |
| 161 : context_(context) { | 133 : context_(context) { |
| 162 base::MessageLoop::current()->AddDestructionObserver(this); | 134 base::MessageLoop::current()->AddDestructionObserver(this); |
| 163 } | 135 } |
| 164 | 136 |
| 165 ~MessageLoopObserver() override { | 137 ~MessageLoopObserver() override { |
| 166 base::MessageLoop::current()->RemoveDestructionObserver(this); | 138 base::MessageLoop::current()->RemoveDestructionObserver(this); |
| 167 } | 139 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 190 | 162 |
| 191 DISALLOW_COPY_AND_ASSIGN(MessageLoopObserver); | 163 DISALLOW_COPY_AND_ASSIGN(MessageLoopObserver); |
| 192 }; | 164 }; |
| 193 | 165 |
| 194 ~IOThreadContext() override {} | 166 ~IOThreadContext() override {} |
| 195 | 167 |
| 196 void StartOnIOThread() { | 168 void StartOnIOThread() { |
| 197 // Should bind |io_thread_checker_| to the context's thread. | 169 // Should bind |io_thread_checker_| to the context's thread. |
| 198 DCHECK(io_thread_checker_.CalledOnValidThread()); | 170 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 199 service_context_.reset(new service_manager::ServiceContext( | 171 service_context_.reset(new service_manager::ServiceContext( |
| 200 base::MakeUnique<ForwardingServiceImpl>(this), | 172 base::MakeUnique<service_manager::ForwardingService>(this), |
| 201 std::move(pending_service_request_), | 173 std::move(pending_service_request_), |
| 202 std::move(io_thread_connector_), | 174 std::move(io_thread_connector_), |
| 203 std::move(pending_connector_request_))); | 175 std::move(pending_connector_request_))); |
| 204 | 176 |
| 205 // MessageLoopObserver owns itself. | 177 // MessageLoopObserver owns itself. |
| 206 message_loop_observer_ = | 178 message_loop_observer_ = |
| 207 new MessageLoopObserver(weak_factory_.GetWeakPtr()); | 179 new MessageLoopObserver(weak_factory_.GetWeakPtr()); |
| 208 } | 180 } |
| 209 | 181 |
| 210 void ShutDownOnIOThread() { | 182 void ShutDownOnIOThread() { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 } | 216 } |
| 245 | 217 |
| 246 void OnBrowserConnectionLost() { | 218 void OnBrowserConnectionLost() { |
| 247 DCHECK(io_thread_checker_.CalledOnValidThread()); | 219 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 248 has_browser_connection_ = false; | 220 has_browser_connection_ = false; |
| 249 } | 221 } |
| 250 | 222 |
| 251 ///////////////////////////////////////////////////////////////////////////// | 223 ///////////////////////////////////////////////////////////////////////////// |
| 252 // service_manager::Service implementation | 224 // service_manager::Service implementation |
| 253 | 225 |
| 254 void OnStart(service_manager::ServiceContext* context) override { | 226 void OnStart() override { |
| 255 DCHECK(io_thread_checker_.CalledOnValidThread()); | 227 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 256 DCHECK(!initialize_handler_.is_null()); | 228 DCHECK(!initialize_handler_.is_null()); |
| 257 local_info_ = context->local_info(); | 229 local_info_ = context()->local_info(); |
| 258 | 230 |
| 259 InitializeCallback handler = base::ResetAndReturn(&initialize_handler_); | 231 InitializeCallback handler = base::ResetAndReturn(&initialize_handler_); |
| 260 callback_task_runner_->PostTask(FROM_HERE, | 232 callback_task_runner_->PostTask(FROM_HERE, |
| 261 base::Bind(handler, local_info_.identity)); | 233 base::Bind(handler, local_info_.identity)); |
| 262 } | 234 } |
| 263 | 235 |
| 264 bool OnConnect(const service_manager::ServiceInfo& remote_info, | 236 bool OnConnect(const service_manager::ServiceInfo& remote_info, |
| 265 service_manager::InterfaceRegistry* registry) override { | 237 service_manager::InterfaceRegistry* registry) override { |
| 266 DCHECK(io_thread_checker_.CalledOnValidThread()); | 238 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 267 | 239 |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 | 538 |
| 567 void ServiceManagerConnectionImpl::GetInterface( | 539 void ServiceManagerConnectionImpl::GetInterface( |
| 568 service_manager::mojom::InterfaceProvider* provider, | 540 service_manager::mojom::InterfaceProvider* provider, |
| 569 const std::string& interface_name, | 541 const std::string& interface_name, |
| 570 mojo::ScopedMessagePipeHandle request_handle) { | 542 mojo::ScopedMessagePipeHandle request_handle) { |
| 571 provider->GetInterface(interface_name, std::move(request_handle)); | 543 provider->GetInterface(interface_name, std::move(request_handle)); |
| 572 } | 544 } |
| 573 | 545 |
| 574 } // namespace content | 546 } // namespace content |
| 575 | 547 |
| OLD | NEW |