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 |
(...skipping 11 matching lines...) Expand all Loading... |
22 pending_connects_.pop(); | 22 pending_connects_.pop(); |
23 } | 23 } |
24 } | 24 } |
25 | 25 |
26 void ServiceRegistryImpl::BindRemoteServiceProvider( | 26 void ServiceRegistryImpl::BindRemoteServiceProvider( |
27 mojo::ScopedMessagePipeHandle handle) { | 27 mojo::ScopedMessagePipeHandle handle) { |
28 DCHECK(!bound_); | 28 DCHECK(!bound_); |
29 bound_ = true; | 29 bound_ = true; |
30 mojo::BindToPipe(this, handle.Pass()); | 30 mojo::BindToPipe(this, handle.Pass()); |
31 while (!pending_connects_.empty()) { | 31 while (!pending_connects_.empty()) { |
32 client()->GetInterface( | 32 client()->ConnectToService( |
33 mojo::String::From(pending_connects_.front().first), | 33 mojo::String::From(pending_connects_.front().first), |
34 mojo::ScopedMessagePipeHandle(pending_connects_.front().second)); | 34 mojo::ScopedMessagePipeHandle(pending_connects_.front().second)); |
35 pending_connects_.pop(); | 35 pending_connects_.pop(); |
36 } | 36 } |
37 } | 37 } |
38 | 38 |
39 void ServiceRegistryImpl::OnConnectionError() { | 39 void ServiceRegistryImpl::OnConnectionError() { |
40 // TODO(sammc): Support reporting this to our owner. | 40 // TODO(sammc): Support reporting this to our owner. |
41 } | 41 } |
42 | 42 |
43 void ServiceRegistryImpl::AddService( | 43 void ServiceRegistryImpl::AddService( |
44 const std::string& service_name, | 44 const std::string& service_name, |
45 const base::Callback<void(mojo::ScopedMessagePipeHandle)> service_factory) { | 45 const base::Callback<void(mojo::ScopedMessagePipeHandle)> service_factory) { |
46 bool inserted = service_factories_.insert( | 46 bool inserted = service_factories_.insert( |
47 std::make_pair(service_name, service_factory)).second; | 47 std::make_pair(service_name, service_factory)).second; |
48 DCHECK(inserted); | 48 DCHECK(inserted); |
49 } | 49 } |
50 | 50 |
51 void ServiceRegistryImpl::RemoveService(const std::string& service_name) { | 51 void ServiceRegistryImpl::RemoveService(const std::string& service_name) { |
52 service_factories_.erase(service_name); | 52 service_factories_.erase(service_name); |
53 } | 53 } |
54 | 54 |
55 void ServiceRegistryImpl::GetRemoteInterface( | 55 void ServiceRegistryImpl::ConnectToRemoteService( |
56 const base::StringPiece& service_name, | 56 const base::StringPiece& service_name, |
57 mojo::ScopedMessagePipeHandle handle) { | 57 mojo::ScopedMessagePipeHandle handle) { |
58 if (!bound_) { | 58 if (!bound_) { |
59 pending_connects_.push( | 59 pending_connects_.push( |
60 std::make_pair(service_name.as_string(), handle.release())); | 60 std::make_pair(service_name.as_string(), handle.release())); |
61 return; | 61 return; |
62 } | 62 } |
63 client()->GetInterface(mojo::String::From(service_name), handle.Pass()); | 63 client()->ConnectToService(mojo::String::From(service_name), handle.Pass()); |
64 } | 64 } |
65 | 65 |
66 void ServiceRegistryImpl::GetInterface( | 66 void ServiceRegistryImpl::ConnectToService( |
67 const mojo::String& name, | 67 const mojo::String& name, |
68 mojo::ScopedMessagePipeHandle client_handle) { | 68 mojo::ScopedMessagePipeHandle client_handle) { |
69 std::map<std::string, | 69 std::map<std::string, |
70 base::Callback<void(mojo::ScopedMessagePipeHandle)> >::iterator it = | 70 base::Callback<void(mojo::ScopedMessagePipeHandle)> >::iterator it = |
71 service_factories_.find(name); | 71 service_factories_.find(name); |
72 if (it == service_factories_.end()) | 72 if (it == service_factories_.end()) |
73 return; | 73 return; |
74 | 74 |
75 it->second.Run(client_handle.Pass()); | 75 it->second.Run(client_handle.Pass()); |
76 } | 76 } |
77 | 77 |
78 } // namespace content | 78 } // namespace content |
OLD | NEW |