Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(580)

Side by Side Diff: chrome/browser/extensions/api/mdns/dns_sd_registry.cc

Issue 139923002: Added VLOG(1) loggings to mdns extensions API code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 if (it != service_list_.end()) { 56 if (it != service_list_.end()) {
Vitaly Buka (NO REVIEWS) 2014/01/15 22:11:42 How about just one log statement: VLOG(1) << "Upd
imcheng 2014/01/15 22:51:37 Done.
57 VLOG(1) << "Found service in cache: " << service.service_name;
57 // If added == true, but we still found the service in our cache, then just 58 // If added == true, but we still found the service in our cache, then just
58 // update the existing entry, but this should not happen! 59 // update the existing entry, but this should not happen!
59 DCHECK(!added); 60 DCHECK(!added);
60 if (*it != service) { 61 if (*it != service) {
62 VLOG(1) << "Service in cache was different, updating: "
63 << service.service_name;
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) {
68 VLOG(1) << "Service not found in cache, adding: " << service.service_name;
65 service_list_.push_back(service); 69 service_list_.push_back(service);
70 } else {
71 VLOG(1) << "Service not found in cache but claims added == false, "
72 << "this should not happen?: " << service.service_name;
66 } 73 }
74
75 VLOG(1) << "Updated or added service: " << service.service_name << "? : "
76 << updated_or_added;
67 return updated_or_added; 77 return updated_or_added;
68 }; 78 };
69 79
70 bool DnsSdRegistry::ServiceTypeData::RemoveService( 80 bool DnsSdRegistry::ServiceTypeData::RemoveService(
71 const std::string& service_name) { 81 const std::string& service_name) {
72 for (DnsSdRegistry::DnsSdServiceList::iterator it = service_list_.begin(); 82 for (DnsSdRegistry::DnsSdServiceList::iterator it = service_list_.begin();
73 it != service_list_.end(); ++it) { 83 it != service_list_.end(); ++it) {
74 if ((*it).service_name == service_name) { 84 if ((*it).service_name == service_name) {
75 service_list_.erase(it); 85 service_list_.erase(it);
76 return true; 86 return true;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 } 123 }
114 124
115 DnsSdDeviceLister* DnsSdRegistry::CreateDnsSdDeviceLister( 125 DnsSdDeviceLister* DnsSdRegistry::CreateDnsSdDeviceLister(
116 DnsSdDelegate* delegate, 126 DnsSdDelegate* delegate,
117 const std::string& service_type, 127 const std::string& service_type,
118 local_discovery::ServiceDiscoverySharedClient* discovery_client) { 128 local_discovery::ServiceDiscoverySharedClient* discovery_client) {
119 return new DnsSdDeviceLister(discovery_client, delegate, service_type); 129 return new DnsSdDeviceLister(discovery_client, delegate, service_type);
120 } 130 }
121 131
122 void DnsSdRegistry::RegisterDnsSdListener(std::string service_type) { 132 void DnsSdRegistry::RegisterDnsSdListener(std::string service_type) {
133 VLOG(1) << "Registering listener of service type: " << service_type;
Vitaly Buka (NO REVIEWS) 2014/01/15 22:11:42 Just one line in begining with input service_type
imcheng 2014/01/15 22:51:37 Done.
123 if (service_type.empty()) 134 if (service_type.empty())
124 return; 135 return;
125 136
126 if (IsRegistered(service_type)) { 137 if (IsRegistered(service_type)) {
138 VLOG(1) << "Service type " << service_type
139 << " was already registered; adding "
140 << "listener and dispatching event";
127 service_data_map_[service_type]->ListenerAdded(); 141 service_data_map_[service_type]->ListenerAdded();
128 DispatchApiEvent(service_type); 142 DispatchApiEvent(service_type);
129 return; 143 return;
130 } 144 }
131 145
146 VLOG(1) << "Creating DnsSdDeviceLister and discovering and dispatching event";
132 scoped_ptr<DnsSdDeviceLister> dns_sd_device_lister(CreateDnsSdDeviceLister( 147 scoped_ptr<DnsSdDeviceLister> dns_sd_device_lister(CreateDnsSdDeviceLister(
133 this, service_type, service_discovery_client_)); 148 this, service_type, service_discovery_client_));
134 dns_sd_device_lister->Discover(false); 149 dns_sd_device_lister->Discover(false);
135 linked_ptr<ServiceTypeData> service_type_data( 150 linked_ptr<ServiceTypeData> service_type_data(
136 new ServiceTypeData(dns_sd_device_lister.Pass())); 151 new ServiceTypeData(dns_sd_device_lister.Pass()));
137 service_data_map_[service_type] = service_type_data; 152 service_data_map_[service_type] = service_type_data;
138 DispatchApiEvent(service_type); 153 DispatchApiEvent(service_type);
139 } 154 }
140 155
141 void DnsSdRegistry::UnregisterDnsSdListener(std::string service_type) { 156 void DnsSdRegistry::UnregisterDnsSdListener(std::string service_type) {
157 VLOG(1) << "Unregistering listener of service type: " << service_type;
142 DnsSdRegistry::DnsSdServiceTypeDataMap::iterator it = 158 DnsSdRegistry::DnsSdServiceTypeDataMap::iterator it =
143 service_data_map_.find(service_type); 159 service_data_map_.find(service_type);
144 if (it == service_data_map_.end()) 160 if (it == service_data_map_.end())
145 return; 161 return;
146 162
147 if (service_data_map_[service_type]->ListenerRemoved()) 163 if (service_data_map_[service_type]->ListenerRemoved())
148 service_data_map_.erase(it); 164 service_data_map_.erase(it);
149 } 165 }
150 166
151 void DnsSdRegistry::ServiceChanged(const std::string& service_type, 167 void DnsSdRegistry::ServiceChanged(const std::string& service_type,
152 bool added, 168 bool added,
153 const DnsSdService& service) { 169 const DnsSdService& service) {
154 if (!IsRegistered(service_type)) 170 if (!IsRegistered(service_type)) {
171 VLOG(1) << "ServiceChanged: Service type: " << service_type
Vitaly Buka (NO REVIEWS) 2014/01/15 22:11:42 same
imcheng 2014/01/15 22:51:37 Done.
172 << " not registered; ignoring";
155 return; 173 return;
174 }
156 175
157 VLOG(1) << "Service changed: " << service.service_name; 176 VLOG(1) << "Service changed: " << service.service_name
177 << ", added? " << added;
158 if (service_data_map_[service_type]->UpdateService(added, service)) { 178 if (service_data_map_[service_type]->UpdateService(added, service)) {
179 VLOG(1) << "Updated service and dispatching event for service type: "
180 << service_type;
159 DispatchApiEvent(service_type); 181 DispatchApiEvent(service_type);
160 } else { 182 } else {
161 VLOG(1) << "Failed to find existing service to update: " 183 VLOG(1) << "Failed to find existing service to update: "
162 << service.service_name; 184 << service.service_name;
163 } 185 }
164 } 186 }
165 187
166 void DnsSdRegistry::ServiceRemoved(const std::string& service_type, 188 void DnsSdRegistry::ServiceRemoved(const std::string& service_type,
167 const std::string& service_name) { 189 const std::string& service_name) {
168 if (!IsRegistered(service_type)) 190 if (!IsRegistered(service_type)) {
191 VLOG(1) << "ServiceRemoved: Service type: " << service_type
192 << " not registered; ignoring";
Vitaly Buka (NO REVIEWS) 2014/01/15 22:11:42 same
imcheng 2014/01/15 22:51:37 Done.
169 return; 193 return;
194 }
170 195
171 VLOG(1) << "Removing service: " << service_name; 196 VLOG(1) << "Removing service: " << service_name;
172 if (service_data_map_[service_type]->RemoveService(service_name)) { 197 if (service_data_map_[service_type]->RemoveService(service_name)) {
198 VLOG(1) << "Removed service and dispatching event for service type: "
199 << service_type;
173 DispatchApiEvent(service_type); 200 DispatchApiEvent(service_type);
174 } else { 201 } else {
175 VLOG(1) << "Failed to remove service: " << service_name; 202 VLOG(1) << "Failed to remove service: " << service_name;
176 } 203 }
177 } 204 }
178 205
179 void DnsSdRegistry::ServicesFlushed(const std::string& service_type) { 206 void DnsSdRegistry::ServicesFlushed(const std::string& service_type) {
180 if (!IsRegistered(service_type)) 207 if (!IsRegistered(service_type)) {
208 VLOG(1) << "ServicesFlushed: Service type: " << service_type
Vitaly Buka (NO REVIEWS) 2014/01/15 22:11:42 same
imcheng 2014/01/15 22:51:37 Done.
209 << " not registered; ignoring";
181 return; 210 return;
211 }
182 212
183 if (service_data_map_[service_type]->ClearServices()) 213 VLOG(1) << "Flushing Service type: " << service_type;
214 if (service_data_map_[service_type]->ClearServices()) {
215 VLOG(1) << "Cleared services and dispatching event for service type: "
216 << service_type;
184 DispatchApiEvent(service_type); 217 DispatchApiEvent(service_type);
218 } else {
219 VLOG(1) << "Failed to clear services for service type: " << service_type;
220 }
185 } 221 }
186 222
187 void DnsSdRegistry::DispatchApiEvent(const std::string& service_type) { 223 void DnsSdRegistry::DispatchApiEvent(const std::string& service_type) {
188 // TODO(justinlin): Make this MaybeDispatchApiEvent instead and dispatch if a 224 // TODO(justinlin): Make this MaybeDispatchApiEvent instead and dispatch if a
189 // dirty bit is set. 225 // dirty bit is set.
226 VLOG(1) << "Calling observers OnDnsSdEvent with service type: "
227 << service_type;
190 FOR_EACH_OBSERVER(DnsSdObserver, observers_, OnDnsSdEvent( 228 FOR_EACH_OBSERVER(DnsSdObserver, observers_, OnDnsSdEvent(
191 service_type, service_data_map_[service_type]->GetServiceList())); 229 service_type, service_data_map_[service_type]->GetServiceList()));
192 } 230 }
193 231
194 bool DnsSdRegistry::IsRegistered(const std::string& service_type) { 232 bool DnsSdRegistry::IsRegistered(const std::string& service_type) {
195 return service_data_map_.find(service_type) != service_data_map_.end(); 233 return service_data_map_.find(service_type) != service_data_map_.end();
196 } 234 }
197 235
198 } // namespace extensions 236 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698