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 "services/shell/public/cpp/interface_registry.h" | 5 #include "services/shell/public/cpp/interface_registry.h" |
6 | 6 |
7 #include "services/shell/public/cpp/connection.h" | 7 #include "services/shell/public/cpp/connection.h" |
8 | 8 |
9 namespace shell { | 9 namespace shell { |
10 | 10 |
11 InterfaceRegistry::InterfaceRegistry(Connection* connection) | 11 InterfaceRegistry::InterfaceRegistry(Connection* connection) |
12 : binding_(this), connection_(connection) {} | 12 : binding_(this), connection_(connection), weak_factory_(this) {} |
13 InterfaceRegistry::~InterfaceRegistry() {} | 13 InterfaceRegistry::~InterfaceRegistry() {} |
14 | 14 |
15 void InterfaceRegistry::Bind( | 15 void InterfaceRegistry::Bind( |
16 mojom::InterfaceProviderRequest local_interfaces_request) { | 16 mojom::InterfaceProviderRequest local_interfaces_request) { |
17 DCHECK(!binding_.is_bound()); | 17 DCHECK(!binding_.is_bound()); |
18 binding_.Bind(std::move(local_interfaces_request)); | 18 binding_.Bind(std::move(local_interfaces_request)); |
19 } | 19 } |
20 | 20 |
| 21 base::WeakPtr<InterfaceRegistry> InterfaceRegistry::GetWeakPtr() { |
| 22 return weak_factory_.GetWeakPtr(); |
| 23 } |
| 24 |
| 25 bool InterfaceRegistry::AddInterface( |
| 26 const std::string& name, |
| 27 const base::Callback<void(mojo::ScopedMessagePipeHandle)>& callback, |
| 28 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { |
| 29 return SetInterfaceBinderForName( |
| 30 base::WrapUnique( |
| 31 new internal::GenericCallbackBinder(callback, task_runner)), |
| 32 name); |
| 33 } |
| 34 |
21 void InterfaceRegistry::RemoveInterface(const std::string& name) { | 35 void InterfaceRegistry::RemoveInterface(const std::string& name) { |
22 auto it = name_to_binder_.find(name); | 36 auto it = name_to_binder_.find(name); |
23 if (it != name_to_binder_.end()) | 37 if (it != name_to_binder_.end()) |
24 name_to_binder_.erase(it); | 38 name_to_binder_.erase(it); |
25 } | 39 } |
26 | 40 |
27 // mojom::InterfaceProvider: | 41 // mojom::InterfaceProvider: |
28 void InterfaceRegistry::GetInterface(const mojo::String& interface_name, | 42 void InterfaceRegistry::GetInterface(const mojo::String& interface_name, |
29 mojo::ScopedMessagePipeHandle handle) { | 43 mojo::ScopedMessagePipeHandle handle) { |
30 auto iter = name_to_binder_.find(interface_name); | 44 auto iter = name_to_binder_.find(interface_name); |
(...skipping 13 matching lines...) Expand all Loading... |
44 if (!connection_ || | 58 if (!connection_ || |
45 (connection_ && connection_->AllowsInterface(interface_name))) { | 59 (connection_ && connection_->AllowsInterface(interface_name))) { |
46 RemoveInterface(interface_name); | 60 RemoveInterface(interface_name); |
47 name_to_binder_[interface_name] = std::move(binder); | 61 name_to_binder_[interface_name] = std::move(binder); |
48 return true; | 62 return true; |
49 } | 63 } |
50 return false; | 64 return false; |
51 } | 65 } |
52 | 66 |
53 } // namespace shell | 67 } // namespace shell |
OLD | NEW |