| 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> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "chrome/browser/extensions/api/mdns/dns_sd_device_lister.h" | 10 #include "chrome/browser/extensions/api/mdns/dns_sd_device_lister.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 bool operator()(const DnsSdService& other) const { | 23 bool operator()(const DnsSdService& other) const { |
| 24 return service_.service_name == other.service_name; | 24 return service_.service_name == other.service_name; |
| 25 } | 25 } |
| 26 | 26 |
| 27 private: | 27 private: |
| 28 const DnsSdService& service_; | 28 const DnsSdService& service_; |
| 29 }; | 29 }; |
| 30 } // namespace | 30 } // namespace |
| 31 | 31 |
| 32 DnsSdRegistry::ServiceTypeData::ServiceTypeData( | 32 DnsSdRegistry::ServiceTypeData::ServiceTypeData( |
| 33 scoped_ptr<DnsSdDeviceLister> lister) | 33 std::unique_ptr<DnsSdDeviceLister> lister) |
| 34 : ref_count(1), lister_(std::move(lister)) {} | 34 : ref_count(1), lister_(std::move(lister)) {} |
| 35 | 35 |
| 36 DnsSdRegistry::ServiceTypeData::~ServiceTypeData() {} | 36 DnsSdRegistry::ServiceTypeData::~ServiceTypeData() {} |
| 37 | 37 |
| 38 void DnsSdRegistry::ServiceTypeData::ListenerAdded() { | 38 void DnsSdRegistry::ServiceTypeData::ListenerAdded() { |
| 39 ref_count++; | 39 ref_count++; |
| 40 } | 40 } |
| 41 | 41 |
| 42 bool DnsSdRegistry::ServiceTypeData::ListenerRemoved() { | 42 bool DnsSdRegistry::ServiceTypeData::ListenerRemoved() { |
| 43 return --ref_count == 0; | 43 return --ref_count == 0; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 << ", registered: " << IsRegistered(service_type); | 148 << ", registered: " << IsRegistered(service_type); |
| 149 if (service_type.empty()) | 149 if (service_type.empty()) |
| 150 return; | 150 return; |
| 151 | 151 |
| 152 if (IsRegistered(service_type)) { | 152 if (IsRegistered(service_type)) { |
| 153 service_data_map_[service_type]->ListenerAdded(); | 153 service_data_map_[service_type]->ListenerAdded(); |
| 154 DispatchApiEvent(service_type); | 154 DispatchApiEvent(service_type); |
| 155 return; | 155 return; |
| 156 } | 156 } |
| 157 | 157 |
| 158 scoped_ptr<DnsSdDeviceLister> dns_sd_device_lister(CreateDnsSdDeviceLister( | 158 std::unique_ptr<DnsSdDeviceLister> dns_sd_device_lister( |
| 159 this, service_type, service_discovery_client_.get())); | 159 CreateDnsSdDeviceLister(this, service_type, |
| 160 service_discovery_client_.get())); |
| 160 dns_sd_device_lister->Discover(false); | 161 dns_sd_device_lister->Discover(false); |
| 161 linked_ptr<ServiceTypeData> service_type_data( | 162 linked_ptr<ServiceTypeData> service_type_data( |
| 162 new ServiceTypeData(std::move(dns_sd_device_lister))); | 163 new ServiceTypeData(std::move(dns_sd_device_lister))); |
| 163 service_data_map_[service_type] = service_type_data; | 164 service_data_map_[service_type] = service_type_data; |
| 164 DispatchApiEvent(service_type); | 165 DispatchApiEvent(service_type); |
| 165 } | 166 } |
| 166 | 167 |
| 167 void DnsSdRegistry::UnregisterDnsSdListener(const std::string& service_type) { | 168 void DnsSdRegistry::UnregisterDnsSdListener(const std::string& service_type) { |
| 168 VLOG(1) << "UnregisterDnsSdListener: " << service_type; | 169 VLOG(1) << "UnregisterDnsSdListener: " << service_type; |
| 169 DnsSdRegistry::DnsSdServiceTypeDataMap::iterator it = | 170 DnsSdRegistry::DnsSdServiceTypeDataMap::iterator it = |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 VLOG(1) << "DispatchApiEvent: service_type: " << service_type; | 231 VLOG(1) << "DispatchApiEvent: service_type: " << service_type; |
| 231 FOR_EACH_OBSERVER(DnsSdObserver, observers_, OnDnsSdEvent( | 232 FOR_EACH_OBSERVER(DnsSdObserver, observers_, OnDnsSdEvent( |
| 232 service_type, service_data_map_[service_type]->GetServiceList())); | 233 service_type, service_data_map_[service_type]->GetServiceList())); |
| 233 } | 234 } |
| 234 | 235 |
| 235 bool DnsSdRegistry::IsRegistered(const std::string& service_type) { | 236 bool DnsSdRegistry::IsRegistered(const std::string& service_type) { |
| 236 return service_data_map_.find(service_type) != service_data_map_.end(); | 237 return service_data_map_.find(service_type) != service_data_map_.end(); |
| 237 } | 238 } |
| 238 | 239 |
| 239 } // namespace extensions | 240 } // namespace extensions |
| OLD | NEW |