Commit ffd29298 authored by imcheng@chromium.org's avatar imcheng@chromium.org

Added VLOG(1) loggings to mdns extensions API code to help debug.

BUG=

Review URL: https://codereview.chromium.org/139923002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@245267 0039d316-1c4b-4281-b951-d872f2087c98
parent f11cf777
...@@ -22,7 +22,7 @@ void FillServiceInfo(const ServiceDescription& service_description, ...@@ -22,7 +22,7 @@ void FillServiceInfo(const ServiceDescription& service_description,
} }
service->service_data = service_description.metadata; service->service_data = service_description.metadata;
DVLOG(1) << "Found " << service->service_name << ", " VLOG(1) << "Found " << service->service_name << ", "
<< service->service_host_port << ", " << service->service_host_port << ", "
<< service->ip_address; << service->ip_address;
} }
...@@ -58,14 +58,23 @@ void DnsSdDeviceLister::OnDeviceChanged( ...@@ -58,14 +58,23 @@ void DnsSdDeviceLister::OnDeviceChanged(
const ServiceDescription& service_description) { const ServiceDescription& service_description) {
DnsSdService service; DnsSdService service;
FillServiceInfo(service_description, &service); FillServiceInfo(service_description, &service);
VLOG(1) << "OnDeviceChanged: "
<< "service_name: " << service.service_name << ", "
<< "added: " << added << ", "
<< "service_type: " << device_lister_.service_type();
delegate_->ServiceChanged(device_lister_.service_type(), added, service); delegate_->ServiceChanged(device_lister_.service_type(), added, service);
} }
void DnsSdDeviceLister::OnDeviceRemoved(const std::string& service_name) { void DnsSdDeviceLister::OnDeviceRemoved(const std::string& service_name) {
VLOG(1) << "OnDeviceRemoved: "
<< "service_name: " << service_name << ", "
<< "service_type: " << device_lister_.service_type();
delegate_->ServiceRemoved(device_lister_.service_type(), service_name); delegate_->ServiceRemoved(device_lister_.service_type(), service_name);
} }
void DnsSdDeviceLister::OnDeviceCacheFlushed() { void DnsSdDeviceLister::OnDeviceCacheFlushed() {
VLOG(1) << "OnDeviceCacheFlushed: "
<< "service_type: " << device_lister_.service_type();
delegate_->ServicesFlushed(device_lister_.service_type()); delegate_->ServicesFlushed(device_lister_.service_type());
device_lister_.DiscoverNewDevices(false); device_lister_.DiscoverNewDevices(false);
} }
......
...@@ -53,7 +53,8 @@ bool DnsSdRegistry::ServiceTypeData::UpdateService( ...@@ -53,7 +53,8 @@ bool DnsSdRegistry::ServiceTypeData::UpdateService(
IsSameServiceName(service)); IsSameServiceName(service));
// Set to true when a service is updated in or added to the registry. // Set to true when a service is updated in or added to the registry.
bool updated_or_added = added; bool updated_or_added = added;
if (it != service_list_.end()) { bool known = (it != service_list_.end());
if (known) {
// If added == true, but we still found the service in our cache, then just // If added == true, but we still found the service in our cache, then just
// update the existing entry, but this should not happen! // update the existing entry, but this should not happen!
DCHECK(!added); DCHECK(!added);
...@@ -64,6 +65,11 @@ bool DnsSdRegistry::ServiceTypeData::UpdateService( ...@@ -64,6 +65,11 @@ bool DnsSdRegistry::ServiceTypeData::UpdateService(
} else if (added) { } else if (added) {
service_list_.push_back(service); service_list_.push_back(service);
} }
VLOG(1) << "UpdateService: " << service.service_name
<< ", added: " << added
<< ", known: " << known
<< ", updated or added: " << updated_or_added;
return updated_or_added; return updated_or_added;
}; };
...@@ -120,6 +126,8 @@ DnsSdDeviceLister* DnsSdRegistry::CreateDnsSdDeviceLister( ...@@ -120,6 +126,8 @@ DnsSdDeviceLister* DnsSdRegistry::CreateDnsSdDeviceLister(
} }
void DnsSdRegistry::RegisterDnsSdListener(std::string service_type) { void DnsSdRegistry::RegisterDnsSdListener(std::string service_type) {
VLOG(1) << "RegisterDnsSdListener: " << service_type
<< ", registered: " << IsRegistered(service_type);
if (service_type.empty()) if (service_type.empty())
return; return;
...@@ -139,6 +147,7 @@ void DnsSdRegistry::RegisterDnsSdListener(std::string service_type) { ...@@ -139,6 +147,7 @@ void DnsSdRegistry::RegisterDnsSdListener(std::string service_type) {
} }
void DnsSdRegistry::UnregisterDnsSdListener(std::string service_type) { void DnsSdRegistry::UnregisterDnsSdListener(std::string service_type) {
VLOG(1) << "UnregisterDnsSdListener: " << service_type;
DnsSdRegistry::DnsSdServiceTypeDataMap::iterator it = DnsSdRegistry::DnsSdServiceTypeDataMap::iterator it =
service_data_map_.find(service_type); service_data_map_.find(service_type);
if (it == service_data_map_.end()) if (it == service_data_map_.end())
...@@ -151,42 +160,58 @@ void DnsSdRegistry::UnregisterDnsSdListener(std::string service_type) { ...@@ -151,42 +160,58 @@ void DnsSdRegistry::UnregisterDnsSdListener(std::string service_type) {
void DnsSdRegistry::ServiceChanged(const std::string& service_type, void DnsSdRegistry::ServiceChanged(const std::string& service_type,
bool added, bool added,
const DnsSdService& service) { const DnsSdService& service) {
if (!IsRegistered(service_type)) VLOG(1) << "ServiceChanged: service_type: " << service_type
<< ", known: " << IsRegistered(service_type)
<< ", service: " << service.service_name
<< ", added: " << added;
if (!IsRegistered(service_type)) {
return; return;
}
VLOG(1) << "Service changed: " << service.service_name; bool is_updated =
if (service_data_map_[service_type]->UpdateService(added, service)) { service_data_map_[service_type]->UpdateService(added, service);
VLOG(1) << "ServiceChanged: is_updated: " << is_updated;
if (is_updated) {
DispatchApiEvent(service_type); DispatchApiEvent(service_type);
} else {
VLOG(1) << "Failed to find existing service to update: "
<< service.service_name;
} }
} }
void DnsSdRegistry::ServiceRemoved(const std::string& service_type, void DnsSdRegistry::ServiceRemoved(const std::string& service_type,
const std::string& service_name) { const std::string& service_name) {
if (!IsRegistered(service_type)) VLOG(1) << "ServiceRemoved: service_type: " << service_type
<< ", known: " << IsRegistered(service_type)
<< ", service: " << service_name;
if (!IsRegistered(service_type)) {
return; return;
}
VLOG(1) << "Removing service: " << service_name; bool is_removed =
if (service_data_map_[service_type]->RemoveService(service_name)) { service_data_map_[service_type]->RemoveService(service_name);
VLOG(1) << "ServiceRemoved: is_removed: " << is_removed;
if (is_removed)
DispatchApiEvent(service_type); DispatchApiEvent(service_type);
} else {
VLOG(1) << "Failed to remove service: " << service_name;
}
} }
void DnsSdRegistry::ServicesFlushed(const std::string& service_type) { void DnsSdRegistry::ServicesFlushed(const std::string& service_type) {
if (!IsRegistered(service_type)) VLOG(1) << "ServicesFlushed: service_type: " << service_type
<< ", known: " << IsRegistered(service_type);
if (!IsRegistered(service_type)) {
return; return;
}
bool is_cleared = service_data_map_[service_type]->ClearServices();
VLOG(1) << "ServicesFlushed: is_cleared: " << is_cleared;
if (service_data_map_[service_type]->ClearServices()) if (is_cleared)
DispatchApiEvent(service_type); DispatchApiEvent(service_type);
} }
void DnsSdRegistry::DispatchApiEvent(const std::string& service_type) { void DnsSdRegistry::DispatchApiEvent(const std::string& service_type) {
// TODO(justinlin): Make this MaybeDispatchApiEvent instead and dispatch if a // TODO(justinlin): Make this MaybeDispatchApiEvent instead and dispatch if a
// dirty bit is set. // dirty bit is set.
VLOG(1) << "DispatchApiEvent: service_type: " << service_type;
FOR_EACH_OBSERVER(DnsSdObserver, observers_, OnDnsSdEvent( FOR_EACH_OBSERVER(DnsSdObserver, observers_, OnDnsSdEvent(
service_type, service_data_map_[service_type]->GetServiceList())); service_type, service_data_map_[service_type]->GetServiceList()));
} }
......
...@@ -89,9 +89,6 @@ void MDnsAPI::UpdateMDnsListeners(const EventListenerInfo& details) { ...@@ -89,9 +89,6 @@ void MDnsAPI::UpdateMDnsListeners(const EventListenerInfo& details) {
for (EventListenerMap::ListenerList::const_iterator it = listeners.begin(); for (EventListenerMap::ListenerList::const_iterator it = listeners.begin();
it != listeners.end(); ++it) { it != listeners.end(); ++it) {
base::DictionaryValue* filter = ((*it)->filter.get()); base::DictionaryValue* filter = ((*it)->filter.get());
for (base::DictionaryValue::Iterator iter(*filter);
!iter.IsAtEnd(); iter.Advance()) {
}
std::string filter_value; std::string filter_value;
filter->GetStringASCII(kEventFilterServiceTypeKey, &filter_value); filter->GetStringASCII(kEventFilterServiceTypeKey, &filter_value);
...@@ -146,6 +143,8 @@ void MDnsAPI::OnDnsSdEvent(const std::string& service_type, ...@@ -146,6 +143,8 @@ void MDnsAPI::OnDnsSdEvent(const std::string& service_type,
event->restrict_to_browser_context = profile_; event->restrict_to_browser_context = profile_;
event->filter_info.SetServiceType(service_type); event->filter_info.SetServiceType(service_type);
VLOG(1) << "Broadcasting OnServiceList event: " << event.get();
// TODO(justinlin): To avoid having listeners without filters getting all // TODO(justinlin): To avoid having listeners without filters getting all
// events, modify API to have this event require filters. // events, modify API to have this event require filters.
extensions::ExtensionSystem::Get(profile_)->event_router()-> extensions::ExtensionSystem::Get(profile_)->event_router()->
......
...@@ -32,16 +32,21 @@ ServiceDiscoveryDeviceLister::~ServiceDiscoveryDeviceLister() { ...@@ -32,16 +32,21 @@ ServiceDiscoveryDeviceLister::~ServiceDiscoveryDeviceLister() {
} }
void ServiceDiscoveryDeviceLister::Start() { void ServiceDiscoveryDeviceLister::Start() {
VLOG(1) << "DeviceListerStart: service_type: " << service_type_;
CreateServiceWatcher(); CreateServiceWatcher();
} }
void ServiceDiscoveryDeviceLister::DiscoverNewDevices(bool force_update) { void ServiceDiscoveryDeviceLister::DiscoverNewDevices(bool force_update) {
VLOG(1) << "DiscoverNewDevices: service_type: " << service_type_;
service_watcher_->DiscoverNewServices(force_update); service_watcher_->DiscoverNewServices(force_update);
} }
void ServiceDiscoveryDeviceLister::OnServiceUpdated( void ServiceDiscoveryDeviceLister::OnServiceUpdated(
ServiceWatcher::UpdateType update, ServiceWatcher::UpdateType update,
const std::string& service_name) { const std::string& service_name) {
VLOG(1) << "OnServiceUpdated: service_type: " << service_type_
<< ", service_name: " << service_name
<< ", update: " << update;
if (update == ServiceWatcher::UPDATE_INVALIDATED) { if (update == ServiceWatcher::UPDATE_INVALIDATED) {
resolvers_.clear(); resolvers_.clear();
CreateServiceWatcher(); CreateServiceWatcher();
...@@ -58,6 +63,7 @@ void ServiceDiscoveryDeviceLister::OnServiceUpdated( ...@@ -58,6 +63,7 @@ void ServiceDiscoveryDeviceLister::OnServiceUpdated(
// If there is already a resolver working on this service, don't add one. // If there is already a resolver working on this service, don't add one.
if (insert_result.second) { if (insert_result.second) {
VLOG(1) << "Adding resolver for service_name: " << service_name;
scoped_ptr<ServiceResolver> resolver = scoped_ptr<ServiceResolver> resolver =
service_discovery_client_->CreateServiceResolver( service_discovery_client_->CreateServiceResolver(
service_name, base::Bind( service_name, base::Bind(
...@@ -68,6 +74,8 @@ void ServiceDiscoveryDeviceLister::OnServiceUpdated( ...@@ -68,6 +74,8 @@ void ServiceDiscoveryDeviceLister::OnServiceUpdated(
insert_result.first->second.reset(resolver.release()); insert_result.first->second.reset(resolver.release());
insert_result.first->second->StartResolving(); insert_result.first->second->StartResolving();
} else {
VLOG(1) << "Resolver already exists, service_name: " << service_name;
} }
} else { } else {
delegate_->OnDeviceRemoved(service_name); delegate_->OnDeviceRemoved(service_name);
...@@ -80,6 +88,9 @@ void ServiceDiscoveryDeviceLister::OnResolveComplete( ...@@ -80,6 +88,9 @@ void ServiceDiscoveryDeviceLister::OnResolveComplete(
std::string service_name, std::string service_name,
ServiceResolver::RequestStatus status, ServiceResolver::RequestStatus status,
const ServiceDescription& service_description) { const ServiceDescription& service_description) {
VLOG(1) << "OnResolveComplete: service_type: " << service_type_
<< ", service_name: " << service_name
<< ", status: " << status;
if (status == ServiceResolver::STATUS_SUCCESS) { if (status == ServiceResolver::STATUS_SUCCESS) {
delegate_->OnDeviceChanged(added, service_description); delegate_->OnDeviceChanged(added, service_description);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment