| 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/media/router/discovery/mdns/dns_sd_registry.h" | 5 #include "chrome/browser/media/router/discovery/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/memory/ptr_util.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 it != service_list_.end(); ++it) { | 80 it != service_list_.end(); ++it) { |
| 81 if ((*it).service_name == service_name) { | 81 if ((*it).service_name == service_name) { |
| 82 service_list_.erase(it); | 82 service_list_.erase(it); |
| 83 return true; | 83 return true; |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 return false; | 86 return false; |
| 87 } | 87 } |
| 88 | 88 |
| 89 void DnsSdRegistry::ServiceTypeData::ForceDiscovery() { | 89 void DnsSdRegistry::ServiceTypeData::ForceDiscovery() { |
| 90 lister_->Discover(false); | 90 lister_->Discover(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 bool DnsSdRegistry::ServiceTypeData::ClearServices() { | 93 bool DnsSdRegistry::ServiceTypeData::ClearServices() { |
| 94 lister_->Discover(false); | 94 lister_->Discover(); |
| 95 | 95 |
| 96 if (service_list_.empty()) | 96 if (service_list_.empty()) |
| 97 return false; | 97 return false; |
| 98 | 98 |
| 99 service_list_.clear(); | 99 service_list_.clear(); |
| 100 return true; | 100 return true; |
| 101 } | 101 } |
| 102 | 102 |
| 103 const DnsSdRegistry::DnsSdServiceList& | 103 const DnsSdRegistry::DnsSdServiceList& |
| 104 DnsSdRegistry::ServiceTypeData::GetServiceList() { | 104 DnsSdRegistry::ServiceTypeData::GetServiceList() { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 | 163 |
| 164 if (IsRegistered(service_type)) { | 164 if (IsRegistered(service_type)) { |
| 165 service_data_map_[service_type]->ListenerAdded(); | 165 service_data_map_[service_type]->ListenerAdded(); |
| 166 DispatchApiEvent(service_type); | 166 DispatchApiEvent(service_type); |
| 167 return; | 167 return; |
| 168 } | 168 } |
| 169 | 169 |
| 170 std::unique_ptr<DnsSdDeviceLister> dns_sd_device_lister( | 170 std::unique_ptr<DnsSdDeviceLister> dns_sd_device_lister( |
| 171 CreateDnsSdDeviceLister(this, service_type, | 171 CreateDnsSdDeviceLister(this, service_type, |
| 172 service_discovery_client_.get())); | 172 service_discovery_client_.get())); |
| 173 dns_sd_device_lister->Discover(false); | 173 dns_sd_device_lister->Discover(); |
| 174 service_data_map_[service_type] = | 174 service_data_map_[service_type] = |
| 175 base::MakeUnique<ServiceTypeData>(std::move(dns_sd_device_lister)); | 175 base::MakeUnique<ServiceTypeData>(std::move(dns_sd_device_lister)); |
| 176 DispatchApiEvent(service_type); | 176 DispatchApiEvent(service_type); |
| 177 } | 177 } |
| 178 | 178 |
| 179 void DnsSdRegistry::UnregisterDnsSdListener(const std::string& service_type) { | 179 void DnsSdRegistry::UnregisterDnsSdListener(const std::string& service_type) { |
| 180 DCHECK(thread_checker_.CalledOnValidThread()); | 180 DCHECK(thread_checker_.CalledOnValidThread()); |
| 181 VLOG(1) << "UnregisterDnsSdListener: " << service_type; | 181 VLOG(1) << "UnregisterDnsSdListener: " << service_type; |
| 182 auto it = service_data_map_.find(service_type); | 182 auto it = service_data_map_.find(service_type); |
| 183 if (it == service_data_map_.end()) | 183 if (it == service_data_map_.end()) |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 service_data_map_[service_type]->GetServiceList()); | 248 service_data_map_[service_type]->GetServiceList()); |
| 249 } | 249 } |
| 250 } | 250 } |
| 251 | 251 |
| 252 bool DnsSdRegistry::IsRegistered(const std::string& service_type) { | 252 bool DnsSdRegistry::IsRegistered(const std::string& service_type) { |
| 253 DCHECK(thread_checker_.CalledOnValidThread()); | 253 DCHECK(thread_checker_.CalledOnValidThread()); |
| 254 return service_data_map_.find(service_type) != service_data_map_.end(); | 254 return service_data_map_.find(service_type) != service_data_map_.end(); |
| 255 } | 255 } |
| 256 | 256 |
| 257 } // namespace media_router | 257 } // namespace media_router |
| OLD | NEW |