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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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(), |
53 IsSameServiceName(service)); | 53 IsSameServiceName(service)); |
54 // Set to true when a service is updated in or added to the registry. | 54 // Set to true when a service is updated in or added to the registry. |
55 bool updated_or_added = added; | 55 bool updated_or_added = added; |
56 VLOG(1) << "UpdateService: " << service.service_name | |
57 << ", added: " << added | |
58 << ", known: " << (it != service_list_.end()); | |
56 if (it != service_list_.end()) { | 59 if (it != service_list_.end()) { |
57 // If added == true, but we still found the service in our cache, then just | 60 // If added == true, but we still found the service in our cache, then just |
58 // update the existing entry, but this should not happen! | 61 // update the existing entry, but this should not happen! |
59 DCHECK(!added); | 62 DCHECK(!added); |
60 if (*it != service) { | 63 if (*it != service) { |
61 *it = service; | 64 *it = service; |
62 updated_or_added = true; | 65 updated_or_added = true; |
63 } | 66 } |
64 } else if (added) { | 67 } else if (added) { |
65 service_list_.push_back(service); | 68 service_list_.push_back(service); |
66 } | 69 } |
70 | |
71 VLOG(1) << "Updated or added service: " << service.service_name << "? : " | |
Vitaly Buka (NO REVIEWS)
2014/01/15 23:08:51
function never returns between logs, wot can combi
imcheng
2014/01/15 23:30:18
Done.
| |
72 << updated_or_added; | |
67 return updated_or_added; | 73 return updated_or_added; |
68 }; | 74 }; |
69 | 75 |
70 bool DnsSdRegistry::ServiceTypeData::RemoveService( | 76 bool DnsSdRegistry::ServiceTypeData::RemoveService( |
71 const std::string& service_name) { | 77 const std::string& service_name) { |
72 for (DnsSdRegistry::DnsSdServiceList::iterator it = service_list_.begin(); | 78 for (DnsSdRegistry::DnsSdServiceList::iterator it = service_list_.begin(); |
73 it != service_list_.end(); ++it) { | 79 it != service_list_.end(); ++it) { |
74 if ((*it).service_name == service_name) { | 80 if ((*it).service_name == service_name) { |
75 service_list_.erase(it); | 81 service_list_.erase(it); |
76 return true; | 82 return true; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 } | 119 } |
114 | 120 |
115 DnsSdDeviceLister* DnsSdRegistry::CreateDnsSdDeviceLister( | 121 DnsSdDeviceLister* DnsSdRegistry::CreateDnsSdDeviceLister( |
116 DnsSdDelegate* delegate, | 122 DnsSdDelegate* delegate, |
117 const std::string& service_type, | 123 const std::string& service_type, |
118 local_discovery::ServiceDiscoverySharedClient* discovery_client) { | 124 local_discovery::ServiceDiscoverySharedClient* discovery_client) { |
119 return new DnsSdDeviceLister(discovery_client, delegate, service_type); | 125 return new DnsSdDeviceLister(discovery_client, delegate, service_type); |
120 } | 126 } |
121 | 127 |
122 void DnsSdRegistry::RegisterDnsSdListener(std::string service_type) { | 128 void DnsSdRegistry::RegisterDnsSdListener(std::string service_type) { |
129 VLOG(1) << "RegisterDnsSdListener: " << service_type | |
130 << ", registered: " << IsRegistered(service_type); | |
Vitaly Buka (NO REVIEWS)
2014/01/15 23:08:51
missalinged
| |
123 if (service_type.empty()) | 131 if (service_type.empty()) |
124 return; | 132 return; |
125 | 133 |
126 if (IsRegistered(service_type)) { | 134 if (IsRegistered(service_type)) { |
127 service_data_map_[service_type]->ListenerAdded(); | 135 service_data_map_[service_type]->ListenerAdded(); |
128 DispatchApiEvent(service_type); | 136 DispatchApiEvent(service_type); |
129 return; | 137 return; |
130 } | 138 } |
131 | 139 |
132 scoped_ptr<DnsSdDeviceLister> dns_sd_device_lister(CreateDnsSdDeviceLister( | 140 scoped_ptr<DnsSdDeviceLister> dns_sd_device_lister(CreateDnsSdDeviceLister( |
133 this, service_type, service_discovery_client_)); | 141 this, service_type, service_discovery_client_)); |
134 dns_sd_device_lister->Discover(false); | 142 dns_sd_device_lister->Discover(false); |
135 linked_ptr<ServiceTypeData> service_type_data( | 143 linked_ptr<ServiceTypeData> service_type_data( |
136 new ServiceTypeData(dns_sd_device_lister.Pass())); | 144 new ServiceTypeData(dns_sd_device_lister.Pass())); |
137 service_data_map_[service_type] = service_type_data; | 145 service_data_map_[service_type] = service_type_data; |
138 DispatchApiEvent(service_type); | 146 DispatchApiEvent(service_type); |
139 } | 147 } |
140 | 148 |
141 void DnsSdRegistry::UnregisterDnsSdListener(std::string service_type) { | 149 void DnsSdRegistry::UnregisterDnsSdListener(std::string service_type) { |
150 VLOG(1) << "UnregisterDnsSdListener: " << service_type; | |
142 DnsSdRegistry::DnsSdServiceTypeDataMap::iterator it = | 151 DnsSdRegistry::DnsSdServiceTypeDataMap::iterator it = |
143 service_data_map_.find(service_type); | 152 service_data_map_.find(service_type); |
144 if (it == service_data_map_.end()) | 153 if (it == service_data_map_.end()) |
145 return; | 154 return; |
146 | 155 |
147 if (service_data_map_[service_type]->ListenerRemoved()) | 156 if (service_data_map_[service_type]->ListenerRemoved()) |
148 service_data_map_.erase(it); | 157 service_data_map_.erase(it); |
149 } | 158 } |
150 | 159 |
151 void DnsSdRegistry::ServiceChanged(const std::string& service_type, | 160 void DnsSdRegistry::ServiceChanged(const std::string& service_type, |
152 bool added, | 161 bool added, |
153 const DnsSdService& service) { | 162 const DnsSdService& service) { |
154 if (!IsRegistered(service_type)) | 163 VLOG(1) << "ServiceChanged: service_type: " << service_type |
164 << ", known: " << IsRegistered(service_type) | |
165 << ", service: " << service.service_name | |
166 << ", added: " << added; | |
Vitaly Buka (NO REVIEWS)
2014/01/15 23:08:51
missaligned
imcheng
2014/01/15 23:30:18
Done.
| |
167 if (!IsRegistered(service_type)) { | |
155 return; | 168 return; |
169 } | |
156 | 170 |
157 VLOG(1) << "Service changed: " << service.service_name; | 171 VLOG(1) << "Service changed: " << service.service_name; |
Vitaly Buka (NO REVIEWS)
2014/01/15 23:08:51
dont need line 171
imcheng
2014/01/15 23:30:18
Done.
| |
158 if (service_data_map_[service_type]->UpdateService(added, service)) { | 172 if (service_data_map_[service_type]->UpdateService(added, service)) { |
173 VLOG(1) << "Updated service and dispatching event for service type: " | |
174 << service_type; | |
Vitaly Buka (NO REVIEWS)
2014/01/15 23:08:51
missaligned
imcheng
2014/01/15 23:30:18
Done.
| |
159 DispatchApiEvent(service_type); | 175 DispatchApiEvent(service_type); |
160 } else { | 176 } else { |
161 VLOG(1) << "Failed to find existing service to update: " | 177 VLOG(1) << "Failed to find existing service to update: " |
162 << service.service_name; | 178 << service.service_name; |
163 } | 179 } |
164 } | 180 } |
165 | 181 |
166 void DnsSdRegistry::ServiceRemoved(const std::string& service_type, | 182 void DnsSdRegistry::ServiceRemoved(const std::string& service_type, |
167 const std::string& service_name) { | 183 const std::string& service_name) { |
168 if (!IsRegistered(service_type)) | 184 VLOG(1) << "ServiceRemoved: service_type: " << service_type |
185 << "known: " << IsRegistered(service_type) | |
Vitaly Buka (NO REVIEWS)
2014/01/15 23:08:51
", known:...
imcheng
2014/01/15 23:30:18
Done.
| |
186 << ", service: " << service_name; | |
187 if (!IsRegistered(service_type)) { | |
169 return; | 188 return; |
189 } | |
170 | 190 |
171 VLOG(1) << "Removing service: " << service_name; | |
172 if (service_data_map_[service_type]->RemoveService(service_name)) { | 191 if (service_data_map_[service_type]->RemoveService(service_name)) { |
Vitaly Buka (NO REVIEWS)
2014/01/15 23:08:51
bool is_removed = service_data_map_[service_type]-
imcheng
2014/01/15 23:30:18
Done.
| |
192 VLOG(1) << "Removed service and dispatching event for service type: " | |
193 << service_type; | |
Vitaly Buka (NO REVIEWS)
2014/01/15 23:08:51
missaligned
imcheng
2014/01/15 23:30:18
Done.
| |
173 DispatchApiEvent(service_type); | 194 DispatchApiEvent(service_type); |
174 } else { | 195 } else { |
175 VLOG(1) << "Failed to remove service: " << service_name; | 196 VLOG(1) << "Failed to remove service: " << service_name; |
176 } | 197 } |
177 } | 198 } |
178 | 199 |
179 void DnsSdRegistry::ServicesFlushed(const std::string& service_type) { | 200 void DnsSdRegistry::ServicesFlushed(const std::string& service_type) { |
180 if (!IsRegistered(service_type)) | 201 VLOG(1) << "ServicesFlushed: service_type: " << service_type |
202 << ", known: " << IsRegistered(service_type); | |
Vitaly Buka (NO REVIEWS)
2014/01/15 23:08:51
missaligned
imcheng
2014/01/15 23:30:18
Done.
| |
203 if (!IsRegistered(service_type)) { | |
181 return; | 204 return; |
205 } | |
182 | 206 |
183 if (service_data_map_[service_type]->ClearServices()) | 207 if (service_data_map_[service_type]->ClearServices()) { |
208 VLOG(1) << "Cleared services and dispatching event for service type: " | |
Vitaly Buka (NO REVIEWS)
2014/01/15 23:08:51
same
imcheng
2014/01/15 23:30:18
Done.
| |
209 << service_type; | |
184 DispatchApiEvent(service_type); | 210 DispatchApiEvent(service_type); |
211 } else { | |
212 VLOG(1) << "Failed to clear services for service type: " << service_type; | |
213 } | |
185 } | 214 } |
186 | 215 |
187 void DnsSdRegistry::DispatchApiEvent(const std::string& service_type) { | 216 void DnsSdRegistry::DispatchApiEvent(const std::string& service_type) { |
188 // TODO(justinlin): Make this MaybeDispatchApiEvent instead and dispatch if a | 217 // TODO(justinlin): Make this MaybeDispatchApiEvent instead and dispatch if a |
189 // dirty bit is set. | 218 // dirty bit is set. |
219 VLOG(1) << "DispatchApiEvent: service_type: " << service_type; | |
190 FOR_EACH_OBSERVER(DnsSdObserver, observers_, OnDnsSdEvent( | 220 FOR_EACH_OBSERVER(DnsSdObserver, observers_, OnDnsSdEvent( |
191 service_type, service_data_map_[service_type]->GetServiceList())); | 221 service_type, service_data_map_[service_type]->GetServiceList())); |
192 } | 222 } |
193 | 223 |
194 bool DnsSdRegistry::IsRegistered(const std::string& service_type) { | 224 bool DnsSdRegistry::IsRegistered(const std::string& service_type) { |
195 return service_data_map_.find(service_type) != service_data_map_.end(); | 225 return service_data_map_.find(service_type) != service_data_map_.end(); |
196 } | 226 } |
197 | 227 |
198 } // namespace extensions | 228 } // namespace extensions |
OLD | NEW |