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 |
21 void InterfaceRegistry::RemoveInterface(const std::string& name) { | 25 void InterfaceRegistry::RemoveInterface(const std::string& name) { |
22 auto it = name_to_binder_.find(name); | 26 auto it = name_to_binder_.find(name); |
23 if (it != name_to_binder_.end()) | 27 if (it != name_to_binder_.end()) |
24 name_to_binder_.erase(it); | 28 name_to_binder_.erase(it); |
25 } | 29 } |
26 | 30 |
27 // mojom::InterfaceProvider: | 31 // mojom::InterfaceProvider: |
28 void InterfaceRegistry::GetInterface(const mojo::String& interface_name, | 32 void InterfaceRegistry::GetInterface(const mojo::String& interface_name, |
29 mojo::ScopedMessagePipeHandle handle) { | 33 mojo::ScopedMessagePipeHandle handle) { |
30 auto iter = name_to_binder_.find(interface_name); | 34 auto iter = name_to_binder_.find(interface_name); |
(...skipping 13 matching lines...) Expand all Loading... |
44 if (!connection_ || | 48 if (!connection_ || |
45 (connection_ && connection_->AllowsInterface(interface_name))) { | 49 (connection_ && connection_->AllowsInterface(interface_name))) { |
46 RemoveInterface(interface_name); | 50 RemoveInterface(interface_name); |
47 name_to_binder_[interface_name] = std::move(binder); | 51 name_to_binder_[interface_name] = std::move(binder); |
48 return true; | 52 return true; |
49 } | 53 } |
50 return false; | 54 return false; |
51 } | 55 } |
52 | 56 |
53 } // namespace shell | 57 } // namespace shell |
OLD | NEW |