| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/mojo/service_registry_impl.h" | 5 #include "content/common/mojo/service_registry_impl.h" |
| 6 | 6 |
| 7 #include "mojo/common/common_type_converters.h" | 7 #include "mojo/common/common_type_converters.h" |
| 8 | 8 |
| 9 namespace content { | 9 namespace content { |
| 10 | 10 |
| 11 ServiceRegistryImpl::ServiceRegistryImpl() | 11 ServiceRegistryImpl::ServiceRegistryImpl() |
| 12 : binding_(this), weak_factory_(this) { | 12 : binding_(this), weak_factory_(this) { |
| 13 binding_.set_error_handler(this); |
| 13 } | 14 } |
| 14 | 15 |
| 15 ServiceRegistryImpl::~ServiceRegistryImpl() { | 16 ServiceRegistryImpl::~ServiceRegistryImpl() { |
| 16 while (!pending_connects_.empty()) { | 17 while (!pending_connects_.empty()) { |
| 17 mojo::CloseRaw(pending_connects_.front().second); | 18 mojo::CloseRaw(pending_connects_.front().second); |
| 18 pending_connects_.pop(); | 19 pending_connects_.pop(); |
| 19 } | 20 } |
| 20 } | 21 } |
| 21 | 22 |
| 22 void ServiceRegistryImpl::Bind( | 23 void ServiceRegistryImpl::Bind( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 51 mojo::ScopedMessagePipeHandle handle) { | 52 mojo::ScopedMessagePipeHandle handle) { |
| 52 if (!remote_provider_) { | 53 if (!remote_provider_) { |
| 53 pending_connects_.push( | 54 pending_connects_.push( |
| 54 std::make_pair(service_name.as_string(), handle.release())); | 55 std::make_pair(service_name.as_string(), handle.release())); |
| 55 return; | 56 return; |
| 56 } | 57 } |
| 57 remote_provider_->ConnectToService(mojo::String::From(service_name), | 58 remote_provider_->ConnectToService(mojo::String::From(service_name), |
| 58 handle.Pass()); | 59 handle.Pass()); |
| 59 } | 60 } |
| 60 | 61 |
| 62 bool ServiceRegistryImpl::IsBound() const { |
| 63 return binding_.is_bound(); |
| 64 } |
| 65 |
| 61 base::WeakPtr<ServiceRegistry> ServiceRegistryImpl::GetWeakPtr() { | 66 base::WeakPtr<ServiceRegistry> ServiceRegistryImpl::GetWeakPtr() { |
| 62 return weak_factory_.GetWeakPtr(); | 67 return weak_factory_.GetWeakPtr(); |
| 63 } | 68 } |
| 64 | 69 |
| 65 void ServiceRegistryImpl::ConnectToService( | 70 void ServiceRegistryImpl::ConnectToService( |
| 66 const mojo::String& name, | 71 const mojo::String& name, |
| 67 mojo::ScopedMessagePipeHandle client_handle) { | 72 mojo::ScopedMessagePipeHandle client_handle) { |
| 68 std::map<std::string, | 73 std::map<std::string, |
| 69 base::Callback<void(mojo::ScopedMessagePipeHandle)> >::iterator it = | 74 base::Callback<void(mojo::ScopedMessagePipeHandle)> >::iterator it = |
| 70 service_factories_.find(name); | 75 service_factories_.find(name); |
| 71 if (it == service_factories_.end()) | 76 if (it == service_factories_.end()) |
| 72 return; | 77 return; |
| 73 | 78 |
| 74 it->second.Run(client_handle.Pass()); | 79 it->second.Run(client_handle.Pass()); |
| 75 } | 80 } |
| 76 | 81 |
| 82 void ServiceRegistryImpl::OnConnectionError() { |
| 83 binding_.Close(); |
| 84 } |
| 85 |
| 77 } // namespace content | 86 } // namespace content |
| OLD | NEW |