OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/extensions/api/mdns/dns_sd_registry.h" | 5 #include "chrome/browser/extensions/api/mdns/dns_sd_registry.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
8 #include "chrome/browser/extensions/api/mdns/dns_sd_device_lister.h" | 10 #include "chrome/browser/extensions/api/mdns/dns_sd_device_lister.h" |
9 #include "chrome/browser/local_discovery/service_discovery_shared_client.h" | 11 #include "chrome/browser/local_discovery/service_discovery_shared_client.h" |
10 | 12 |
11 using local_discovery::ServiceDiscoveryClient; | 13 using local_discovery::ServiceDiscoveryClient; |
12 using local_discovery::ServiceDiscoverySharedClient; | 14 using local_discovery::ServiceDiscoverySharedClient; |
13 | 15 |
14 namespace extensions { | 16 namespace extensions { |
15 | 17 |
16 namespace { | 18 namespace { |
17 // Predicate to test if two discovered services have the same service_name. | 19 // Predicate to test if two discovered services have the same service_name. |
18 class IsSameServiceName { | 20 class IsSameServiceName { |
19 public: | 21 public: |
20 explicit IsSameServiceName(const DnsSdService& service) : service_(service) {} | 22 explicit IsSameServiceName(const DnsSdService& service) : service_(service) {} |
21 bool operator()(const DnsSdService& other) const { | 23 bool operator()(const DnsSdService& other) const { |
22 return service_.service_name == other.service_name; | 24 return service_.service_name == other.service_name; |
23 } | 25 } |
24 | 26 |
25 private: | 27 private: |
26 const DnsSdService& service_; | 28 const DnsSdService& service_; |
27 }; | 29 }; |
28 } // namespace | 30 } // namespace |
29 | 31 |
30 DnsSdRegistry::ServiceTypeData::ServiceTypeData( | 32 DnsSdRegistry::ServiceTypeData::ServiceTypeData( |
31 scoped_ptr<DnsSdDeviceLister> lister) | 33 scoped_ptr<DnsSdDeviceLister> lister) |
32 : ref_count(1), lister_(lister.Pass()) {} | 34 : ref_count(1), lister_(std::move(lister)) {} |
33 | 35 |
34 DnsSdRegistry::ServiceTypeData::~ServiceTypeData() {} | 36 DnsSdRegistry::ServiceTypeData::~ServiceTypeData() {} |
35 | 37 |
36 void DnsSdRegistry::ServiceTypeData::ListenerAdded() { | 38 void DnsSdRegistry::ServiceTypeData::ListenerAdded() { |
37 ref_count++; | 39 ref_count++; |
38 } | 40 } |
39 | 41 |
40 bool DnsSdRegistry::ServiceTypeData::ListenerRemoved() { | 42 bool DnsSdRegistry::ServiceTypeData::ListenerRemoved() { |
41 return --ref_count == 0; | 43 return --ref_count == 0; |
42 } | 44 } |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 if (IsRegistered(service_type)) { | 152 if (IsRegistered(service_type)) { |
151 service_data_map_[service_type]->ListenerAdded(); | 153 service_data_map_[service_type]->ListenerAdded(); |
152 DispatchApiEvent(service_type); | 154 DispatchApiEvent(service_type); |
153 return; | 155 return; |
154 } | 156 } |
155 | 157 |
156 scoped_ptr<DnsSdDeviceLister> dns_sd_device_lister(CreateDnsSdDeviceLister( | 158 scoped_ptr<DnsSdDeviceLister> dns_sd_device_lister(CreateDnsSdDeviceLister( |
157 this, service_type, service_discovery_client_.get())); | 159 this, service_type, service_discovery_client_.get())); |
158 dns_sd_device_lister->Discover(false); | 160 dns_sd_device_lister->Discover(false); |
159 linked_ptr<ServiceTypeData> service_type_data( | 161 linked_ptr<ServiceTypeData> service_type_data( |
160 new ServiceTypeData(dns_sd_device_lister.Pass())); | 162 new ServiceTypeData(std::move(dns_sd_device_lister))); |
161 service_data_map_[service_type] = service_type_data; | 163 service_data_map_[service_type] = service_type_data; |
162 DispatchApiEvent(service_type); | 164 DispatchApiEvent(service_type); |
163 } | 165 } |
164 | 166 |
165 void DnsSdRegistry::UnregisterDnsSdListener(const std::string& service_type) { | 167 void DnsSdRegistry::UnregisterDnsSdListener(const std::string& service_type) { |
166 VLOG(1) << "UnregisterDnsSdListener: " << service_type; | 168 VLOG(1) << "UnregisterDnsSdListener: " << service_type; |
167 DnsSdRegistry::DnsSdServiceTypeDataMap::iterator it = | 169 DnsSdRegistry::DnsSdServiceTypeDataMap::iterator it = |
168 service_data_map_.find(service_type); | 170 service_data_map_.find(service_type); |
169 if (it == service_data_map_.end()) | 171 if (it == service_data_map_.end()) |
170 return; | 172 return; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 VLOG(1) << "DispatchApiEvent: service_type: " << service_type; | 230 VLOG(1) << "DispatchApiEvent: service_type: " << service_type; |
229 FOR_EACH_OBSERVER(DnsSdObserver, observers_, OnDnsSdEvent( | 231 FOR_EACH_OBSERVER(DnsSdObserver, observers_, OnDnsSdEvent( |
230 service_type, service_data_map_[service_type]->GetServiceList())); | 232 service_type, service_data_map_[service_type]->GetServiceList())); |
231 } | 233 } |
232 | 234 |
233 bool DnsSdRegistry::IsRegistered(const std::string& service_type) { | 235 bool DnsSdRegistry::IsRegistered(const std::string& service_type) { |
234 return service_data_map_.find(service_type) != service_data_map_.end(); | 236 return service_data_map_.find(service_type) != service_data_map_.end(); |
235 } | 237 } |
236 | 238 |
237 } // namespace extensions | 239 } // namespace extensions |
OLD | NEW |