| 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/renderer/mojo/blink_service_registry_impl.h" | 5 #include "content/renderer/mojo/blink_service_registry_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/single_thread_task_runner.h" | |
| 10 #include "base/threading/thread_task_runner_handle.h" | |
| 11 #include "content/common/mojo/service_registry_impl.h" | 9 #include "content/common/mojo/service_registry_impl.h" |
| 12 | 10 |
| 13 namespace content { | 11 namespace content { |
| 14 | 12 |
| 15 BlinkServiceRegistryImpl::BlinkServiceRegistryImpl( | 13 BlinkServiceRegistryImpl::BlinkServiceRegistryImpl( |
| 16 base::WeakPtr<content::ServiceRegistry> service_registry) | 14 base::WeakPtr<content::ServiceRegistry> service_registry) |
| 17 : service_registry_(service_registry), | 15 : service_registry_(service_registry) {} |
| 18 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), | |
| 19 weak_ptr_factory_(this) {} | |
| 20 | 16 |
| 21 BlinkServiceRegistryImpl::~BlinkServiceRegistryImpl() = default; | 17 BlinkServiceRegistryImpl::~BlinkServiceRegistryImpl() = default; |
| 22 | 18 |
| 23 void BlinkServiceRegistryImpl::connectToRemoteService( | 19 void BlinkServiceRegistryImpl::connectToRemoteService( |
| 24 const char* name, | 20 const char* name, |
| 25 mojo::ScopedMessagePipeHandle handle) { | 21 mojo::ScopedMessagePipeHandle handle) { |
| 26 if (!main_thread_task_runner_->BelongsToCurrentThread()) { | |
| 27 main_thread_task_runner_->PostTask( | |
| 28 FROM_HERE, base::Bind(&BlinkServiceRegistryImpl::connectToRemoteService, | |
| 29 weak_ptr_factory_.GetWeakPtr(), name, | |
| 30 base::Passed(&handle))); | |
| 31 return; | |
| 32 } | |
| 33 | |
| 34 if (!service_registry_) | 22 if (!service_registry_) |
| 35 return; | 23 return; |
| 36 | 24 |
| 37 service_registry_->ConnectToRemoteService(name, std::move(handle)); | 25 service_registry_->ConnectToRemoteService(name, std::move(handle)); |
| 38 } | 26 } |
| 39 | 27 |
| 40 } // namespace content | 28 } // namespace content |
| OLD | NEW |