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 } | 13 } |
14 | 14 |
15 ServiceRegistryImpl::~ServiceRegistryImpl() { | 15 ServiceRegistryImpl::~ServiceRegistryImpl() { |
16 while (!pending_connects_.empty()) { | 16 while (!pending_connects_.empty()) { |
17 mojo::CloseRaw(pending_connects_.front().second); | 17 mojo::CloseRaw(pending_connects_.front().second); |
18 pending_connects_.pop(); | 18 pending_connects_.pop(); |
19 } | 19 } |
20 } | 20 } |
21 | 21 |
22 void ServiceRegistryImpl::Bind( | 22 void ServiceRegistryImpl::Bind( |
23 mojo::InterfaceRequest<mojo::ServiceProvider> request) { | 23 mojo::InterfaceRequest<mojo::ServiceProvider> request) { |
24 binding_.set_error_handler(this); | |
Ken Rockot(use gerrit already)
2015/05/05 17:59:23
nit: might as well just do this in the ctor
xhwang
2015/05/05 18:09:26
Done.
| |
24 binding_.Bind(request.Pass()); | 25 binding_.Bind(request.Pass()); |
25 } | 26 } |
26 | 27 |
27 void ServiceRegistryImpl::BindRemoteServiceProvider( | 28 void ServiceRegistryImpl::BindRemoteServiceProvider( |
28 mojo::ServiceProviderPtr service_provider) { | 29 mojo::ServiceProviderPtr service_provider) { |
29 CHECK(!remote_provider_); | 30 CHECK(!remote_provider_); |
30 remote_provider_ = service_provider.Pass(); | 31 remote_provider_ = service_provider.Pass(); |
31 while (!pending_connects_.empty()) { | 32 while (!pending_connects_.empty()) { |
32 remote_provider_->ConnectToService( | 33 remote_provider_->ConnectToService( |
33 mojo::String::From(pending_connects_.front().first), | 34 mojo::String::From(pending_connects_.front().first), |
(...skipping 17 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 |