| 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/memory/ptr_util.h" |
| 9 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 10 #include "chrome/browser/extensions/api/mdns/dns_sd_device_lister.h" | 11 #include "chrome/browser/extensions/api/mdns/dns_sd_device_lister.h" |
| 11 #include "chrome/browser/local_discovery/service_discovery_shared_client.h" | 12 #include "chrome/browser/local_discovery/service_discovery_shared_client.h" |
| 12 #include "chrome/common/features.h" | 13 #include "chrome/common/features.h" |
| 13 | 14 |
| 14 using local_discovery::ServiceDiscoveryClient; | 15 using local_discovery::ServiceDiscoveryClient; |
| 15 using local_discovery::ServiceDiscoverySharedClient; | 16 using local_discovery::ServiceDiscoverySharedClient; |
| 16 | 17 |
| 17 namespace extensions { | 18 namespace extensions { |
| 18 | 19 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 if (IsRegistered(service_type)) { | 154 if (IsRegistered(service_type)) { |
| 154 service_data_map_[service_type]->ListenerAdded(); | 155 service_data_map_[service_type]->ListenerAdded(); |
| 155 DispatchApiEvent(service_type); | 156 DispatchApiEvent(service_type); |
| 156 return; | 157 return; |
| 157 } | 158 } |
| 158 | 159 |
| 159 std::unique_ptr<DnsSdDeviceLister> dns_sd_device_lister( | 160 std::unique_ptr<DnsSdDeviceLister> dns_sd_device_lister( |
| 160 CreateDnsSdDeviceLister(this, service_type, | 161 CreateDnsSdDeviceLister(this, service_type, |
| 161 service_discovery_client_.get())); | 162 service_discovery_client_.get())); |
| 162 dns_sd_device_lister->Discover(false); | 163 dns_sd_device_lister->Discover(false); |
| 163 linked_ptr<ServiceTypeData> service_type_data( | 164 service_data_map_[service_type] = |
| 164 new ServiceTypeData(std::move(dns_sd_device_lister))); | 165 base::MakeUnique<ServiceTypeData>(std::move(dns_sd_device_lister)); |
| 165 service_data_map_[service_type] = service_type_data; | |
| 166 DispatchApiEvent(service_type); | 166 DispatchApiEvent(service_type); |
| 167 } | 167 } |
| 168 | 168 |
| 169 void DnsSdRegistry::UnregisterDnsSdListener(const std::string& service_type) { | 169 void DnsSdRegistry::UnregisterDnsSdListener(const std::string& service_type) { |
| 170 VLOG(1) << "UnregisterDnsSdListener: " << service_type; | 170 VLOG(1) << "UnregisterDnsSdListener: " << service_type; |
| 171 DnsSdRegistry::DnsSdServiceTypeDataMap::iterator it = | 171 auto it = service_data_map_.find(service_type); |
| 172 service_data_map_.find(service_type); | |
| 173 if (it == service_data_map_.end()) | 172 if (it == service_data_map_.end()) |
| 174 return; | 173 return; |
| 175 | 174 |
| 176 if (service_data_map_[service_type]->ListenerRemoved()) | 175 if (service_data_map_[service_type]->ListenerRemoved()) |
| 177 service_data_map_.erase(it); | 176 service_data_map_.erase(it); |
| 178 } | 177 } |
| 179 | 178 |
| 180 void DnsSdRegistry::ServiceChanged(const std::string& service_type, | 179 void DnsSdRegistry::ServiceChanged(const std::string& service_type, |
| 181 bool added, | 180 bool added, |
| 182 const DnsSdService& service) { | 181 const DnsSdService& service) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 observer.OnDnsSdEvent(service_type, | 233 observer.OnDnsSdEvent(service_type, |
| 235 service_data_map_[service_type]->GetServiceList()); | 234 service_data_map_[service_type]->GetServiceList()); |
| 236 } | 235 } |
| 237 } | 236 } |
| 238 | 237 |
| 239 bool DnsSdRegistry::IsRegistered(const std::string& service_type) { | 238 bool DnsSdRegistry::IsRegistered(const std::string& service_type) { |
| 240 return service_data_map_.find(service_type) != service_data_map_.end(); | 239 return service_data_map_.find(service_type) != service_data_map_.end(); |
| 241 } | 240 } |
| 242 | 241 |
| 243 } // namespace extensions | 242 } // namespace extensions |
| OLD | NEW |