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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "mojo/common/common_type_converters.h" | 9 #include "mojo/common/common_type_converters.h" |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 CHECK(!remote_provider_); | 32 CHECK(!remote_provider_); |
33 remote_provider_ = std::move(service_provider); | 33 remote_provider_ = std::move(service_provider); |
34 while (!pending_connects_.empty()) { | 34 while (!pending_connects_.empty()) { |
35 remote_provider_->GetInterface( | 35 remote_provider_->GetInterface( |
36 mojo::String::From(pending_connects_.front().first), | 36 mojo::String::From(pending_connects_.front().first), |
37 mojo::ScopedMessagePipeHandle(pending_connects_.front().second)); | 37 mojo::ScopedMessagePipeHandle(pending_connects_.front().second)); |
38 pending_connects_.pop(); | 38 pending_connects_.pop(); |
39 } | 39 } |
40 } | 40 } |
41 | 41 |
42 void ServiceRegistryImpl::AddServiceOverrideForTesting( | |
43 const std::string& service_name, | |
44 const ServiceFactory& factory) { | |
45 service_overrides_[service_name] = factory; | |
46 } | |
47 | |
48 void ServiceRegistryImpl::ClearServiceOverridesForTesting() { | |
49 service_overrides_.clear(); | |
50 } | |
51 | |
52 void ServiceRegistryImpl::AddService(const std::string& service_name, | 42 void ServiceRegistryImpl::AddService(const std::string& service_name, |
53 const ServiceFactory service_factory) { | 43 const ServiceFactory service_factory) { |
54 service_factories_[service_name] = service_factory; | 44 service_factories_[service_name] = service_factory; |
55 } | 45 } |
56 | 46 |
57 void ServiceRegistryImpl::RemoveService(const std::string& service_name) { | 47 void ServiceRegistryImpl::RemoveService(const std::string& service_name) { |
58 service_factories_.erase(service_name); | 48 service_factories_.erase(service_name); |
59 } | 49 } |
60 | 50 |
61 void ServiceRegistryImpl::ConnectToRemoteService( | 51 void ServiceRegistryImpl::ConnectToRemoteService( |
62 const base::StringPiece& service_name, | 52 const base::StringPiece& service_name, |
63 mojo::ScopedMessagePipeHandle handle) { | 53 mojo::ScopedMessagePipeHandle handle) { |
64 auto override_it = service_overrides_.find(service_name.as_string()); | 54 auto override_it = service_overrides_.find(service_name.as_string()); |
65 if (override_it != service_overrides_.end()) { | 55 if (override_it != service_overrides_.end()) { |
66 override_it->second.Run(std::move(handle)); | 56 override_it->second.Run(std::move(handle)); |
67 return; | 57 return; |
68 } | 58 } |
69 | 59 |
70 if (!remote_provider_) { | 60 if (!remote_provider_) { |
71 pending_connects_.push( | 61 pending_connects_.push( |
72 std::make_pair(service_name.as_string(), handle.release())); | 62 std::make_pair(service_name.as_string(), handle.release())); |
73 return; | 63 return; |
74 } | 64 } |
75 remote_provider_->GetInterface( | 65 remote_provider_->GetInterface( |
76 mojo::String::From(service_name.as_string()), std::move(handle)); | 66 mojo::String::From(service_name.as_string()), std::move(handle)); |
77 } | 67 } |
78 | 68 |
| 69 void ServiceRegistryImpl::AddServiceOverrideForTesting( |
| 70 const std::string& service_name, |
| 71 const ServiceFactory& factory) { |
| 72 service_overrides_[service_name] = factory; |
| 73 } |
| 74 |
| 75 void ServiceRegistryImpl::ClearServiceOverridesForTesting() { |
| 76 service_overrides_.clear(); |
| 77 } |
| 78 |
79 bool ServiceRegistryImpl::IsBound() const { | 79 bool ServiceRegistryImpl::IsBound() const { |
80 return binding_.is_bound(); | 80 return binding_.is_bound(); |
81 } | 81 } |
82 | 82 |
83 base::WeakPtr<ServiceRegistry> ServiceRegistryImpl::GetWeakPtr() { | 83 base::WeakPtr<ServiceRegistry> ServiceRegistryImpl::GetWeakPtr() { |
84 return weak_factory_.GetWeakPtr(); | 84 return weak_factory_.GetWeakPtr(); |
85 } | 85 } |
86 | 86 |
87 void ServiceRegistryImpl::GetInterface( | 87 void ServiceRegistryImpl::GetInterface( |
88 const mojo::String& name, | 88 const mojo::String& name, |
(...skipping 10 matching lines...) Expand all Loading... |
99 } | 99 } |
100 | 100 |
101 it->second.Run(std::move(client_handle)); | 101 it->second.Run(std::move(client_handle)); |
102 } | 102 } |
103 | 103 |
104 void ServiceRegistryImpl::OnConnectionError() { | 104 void ServiceRegistryImpl::OnConnectionError() { |
105 binding_.Close(); | 105 binding_.Close(); |
106 } | 106 } |
107 | 107 |
108 } // namespace content | 108 } // namespace content |
OLD | NEW |