| 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 "base/stl_util.h" | 7 #include "base/stl_util.h" |
| 8 #include "chrome/browser/extensions/api/mdns/dns_sd_device_lister.h" | 8 #include "chrome/browser/extensions/api/mdns/dns_sd_device_lister.h" |
| 9 #include "chrome/browser/local_discovery/service_discovery_shared_client.h" | 9 #include "chrome/browser/local_discovery/service_discovery_shared_client.h" |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 } // namespace | 28 } // namespace |
| 29 | 29 |
| 30 DnsSdRegistry::ServiceTypeData::ServiceTypeData( | 30 DnsSdRegistry::ServiceTypeData::ServiceTypeData( |
| 31 scoped_ptr<DnsSdDeviceLister> lister) | 31 scoped_ptr<DnsSdDeviceLister> lister) |
| 32 : ref_count(1), lister_(lister.Pass()) {} | 32 : ref_count(1), lister_(lister.Pass()) {} |
| 33 | 33 |
| 34 DnsSdRegistry::ServiceTypeData::~ServiceTypeData() {} | 34 DnsSdRegistry::ServiceTypeData::~ServiceTypeData() {} |
| 35 | 35 |
| 36 void DnsSdRegistry::ServiceTypeData::ListenerAdded() { | 36 void DnsSdRegistry::ServiceTypeData::ListenerAdded() { |
| 37 ref_count++; | 37 ref_count++; |
| 38 }; | 38 } |
| 39 | 39 |
| 40 bool DnsSdRegistry::ServiceTypeData::ListenerRemoved() { | 40 bool DnsSdRegistry::ServiceTypeData::ListenerRemoved() { |
| 41 return --ref_count == 0; | 41 return --ref_count == 0; |
| 42 }; | 42 } |
| 43 | 43 |
| 44 int DnsSdRegistry::ServiceTypeData::GetListenerCount() { | 44 int DnsSdRegistry::ServiceTypeData::GetListenerCount() { |
| 45 return ref_count; | 45 return ref_count; |
| 46 } | 46 } |
| 47 | 47 |
| 48 bool DnsSdRegistry::ServiceTypeData::UpdateService( | 48 bool DnsSdRegistry::ServiceTypeData::UpdateService( |
| 49 bool added, const DnsSdService& service) { | 49 bool added, const DnsSdService& service) { |
| 50 DnsSdRegistry::DnsSdServiceList::iterator it = | 50 DnsSdRegistry::DnsSdServiceList::iterator it = |
| 51 std::find_if(service_list_.begin(), | 51 std::find_if(service_list_.begin(), |
| 52 service_list_.end(), | 52 service_list_.end(), |
| (...skipping 11 matching lines...) Expand all Loading... |
| 64 } | 64 } |
| 65 } else if (added) { | 65 } else if (added) { |
| 66 service_list_.push_back(service); | 66 service_list_.push_back(service); |
| 67 } | 67 } |
| 68 | 68 |
| 69 VLOG(1) << "UpdateService: " << service.service_name | 69 VLOG(1) << "UpdateService: " << service.service_name |
| 70 << ", added: " << added | 70 << ", added: " << added |
| 71 << ", known: " << known | 71 << ", known: " << known |
| 72 << ", updated or added: " << updated_or_added; | 72 << ", updated or added: " << updated_or_added; |
| 73 return updated_or_added; | 73 return updated_or_added; |
| 74 }; | 74 } |
| 75 | 75 |
| 76 bool DnsSdRegistry::ServiceTypeData::RemoveService( | 76 bool DnsSdRegistry::ServiceTypeData::RemoveService( |
| 77 const std::string& service_name) { | 77 const std::string& service_name) { |
| 78 for (DnsSdRegistry::DnsSdServiceList::iterator it = service_list_.begin(); | 78 for (DnsSdRegistry::DnsSdServiceList::iterator it = service_list_.begin(); |
| 79 it != service_list_.end(); ++it) { | 79 it != service_list_.end(); ++it) { |
| 80 if ((*it).service_name == service_name) { | 80 if ((*it).service_name == service_name) { |
| 81 service_list_.erase(it); | 81 service_list_.erase(it); |
| 82 return true; | 82 return true; |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 return false; | 85 return false; |
| 86 }; | 86 } |
| 87 | 87 |
| 88 bool DnsSdRegistry::ServiceTypeData::ClearServices() { | 88 bool DnsSdRegistry::ServiceTypeData::ClearServices() { |
| 89 lister_->Discover(false); |
| 90 |
| 89 if (service_list_.empty()) | 91 if (service_list_.empty()) |
| 90 return false; | 92 return false; |
| 91 | 93 |
| 92 service_list_.clear(); | 94 service_list_.clear(); |
| 93 return true; | 95 return true; |
| 94 } | 96 } |
| 95 | 97 |
| 96 const DnsSdRegistry::DnsSdServiceList& | 98 const DnsSdRegistry::DnsSdServiceList& |
| 97 DnsSdRegistry::ServiceTypeData::GetServiceList() { | 99 DnsSdRegistry::ServiceTypeData::GetServiceList() { |
| 98 return service_list_; | 100 return service_list_; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 VLOG(1) << "DispatchApiEvent: service_type: " << service_type; | 216 VLOG(1) << "DispatchApiEvent: service_type: " << service_type; |
| 215 FOR_EACH_OBSERVER(DnsSdObserver, observers_, OnDnsSdEvent( | 217 FOR_EACH_OBSERVER(DnsSdObserver, observers_, OnDnsSdEvent( |
| 216 service_type, service_data_map_[service_type]->GetServiceList())); | 218 service_type, service_data_map_[service_type]->GetServiceList())); |
| 217 } | 219 } |
| 218 | 220 |
| 219 bool DnsSdRegistry::IsRegistered(const std::string& service_type) { | 221 bool DnsSdRegistry::IsRegistered(const std::string& service_type) { |
| 220 return service_data_map_.find(service_type) != service_data_map_.end(); | 222 return service_data_map_.find(service_type) != service_data_map_.end(); |
| 221 } | 223 } |
| 222 | 224 |
| 223 } // namespace extensions | 225 } // namespace extensions |
| OLD | NEW |