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

Side by Side Diff: chrome/browser/local_discovery/service_discovery_host_client.cc

Issue 23548028: Added logging to local discovery code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
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/local_discovery/service_discovery_host_client.h" 5 #include "chrome/browser/local_discovery/service_discovery_host_client.h"
6 6
7 #if defined(OS_POSIX) 7 #if defined(OS_POSIX)
8 #include "base/file_descriptor_posix.h" 8 #include "base/file_descriptor_posix.h"
9 #endif // OS_POSIX 9 #endif // OS_POSIX
10 10
(...skipping 12 matching lines...) Expand all
23 ServiceWatcherProxy(ServiceDiscoveryHostClient* host, 23 ServiceWatcherProxy(ServiceDiscoveryHostClient* host,
24 const std::string& service_type, 24 const std::string& service_type,
25 const ServiceWatcher::UpdatedCallback& callback) 25 const ServiceWatcher::UpdatedCallback& callback)
26 : host_(host), 26 : host_(host),
27 service_type_(service_type), 27 service_type_(service_type),
28 id_(host_->RegisterWatcherCallback(callback)), 28 id_(host_->RegisterWatcherCallback(callback)),
29 started_(false) { 29 started_(false) {
30 } 30 }
31 31
32 virtual ~ServiceWatcherProxy() { 32 virtual ~ServiceWatcherProxy() {
33 VLOG(1) << "~ServiceWatcherProxy on browser process with id " << id_;
33 host_->UnregisterWatcherCallback(id_); 34 host_->UnregisterWatcherCallback(id_);
34 if (started_) 35 if (started_)
35 host_->Send(new LocalDiscoveryMsg_DestroyWatcher(id_)); 36 host_->Send(new LocalDiscoveryMsg_DestroyWatcher(id_));
36 } 37 }
37 38
38 virtual void Start() OVERRIDE { 39 virtual void Start() OVERRIDE {
40 VLOG(1) << "ServiceWatcher::Start on browser process with id " << id_;
39 DCHECK(!started_); 41 DCHECK(!started_);
40 host_->Send(new LocalDiscoveryMsg_StartWatcher(id_, service_type_)); 42 host_->Send(new LocalDiscoveryMsg_StartWatcher(id_, service_type_));
41 started_ = true; 43 started_ = true;
42 } 44 }
43 45
44 virtual void DiscoverNewServices(bool force_update) OVERRIDE { 46 virtual void DiscoverNewServices(bool force_update) OVERRIDE {
47 VLOG(1) << "ServiceWatcher::DiscoverNewServices on browser process with id "
48 << id_;
45 DCHECK(started_); 49 DCHECK(started_);
46 host_->Send(new LocalDiscoveryMsg_DiscoverServices(id_, force_update)); 50 host_->Send(new LocalDiscoveryMsg_DiscoverServices(id_, force_update));
47 } 51 }
48 52
49 virtual std::string GetServiceType() const OVERRIDE { 53 virtual std::string GetServiceType() const OVERRIDE {
50 return service_type_; 54 return service_type_;
51 } 55 }
52 56
53 private: 57 private:
54 scoped_refptr<ServiceDiscoveryHostClient> host_; 58 scoped_refptr<ServiceDiscoveryHostClient> host_;
55 const std::string service_type_; 59 const std::string service_type_;
56 const uint64 id_; 60 const uint64 id_;
57 bool started_; 61 bool started_;
58 }; 62 };
59 63
60 class ServiceDiscoveryHostClient::ServiceResolverProxy 64 class ServiceDiscoveryHostClient::ServiceResolverProxy
61 : public ServiceResolver { 65 : public ServiceResolver {
62 public: 66 public:
63 ServiceResolverProxy(ServiceDiscoveryHostClient* host, 67 ServiceResolverProxy(ServiceDiscoveryHostClient* host,
64 const std::string& service_name, 68 const std::string& service_name,
65 const ServiceResolver::ResolveCompleteCallback& callback) 69 const ServiceResolver::ResolveCompleteCallback& callback)
66 : host_(host), 70 : host_(host),
67 service_name_(service_name), 71 service_name_(service_name),
68 id_(host->RegisterResolverCallback(callback)), 72 id_(host->RegisterResolverCallback(callback)),
69 started_(false) { 73 started_(false) {
70 } 74 }
71 75
72 virtual ~ServiceResolverProxy() { 76 virtual ~ServiceResolverProxy() {
77 VLOG(1) << "~ServiceResolverProxy on browser process with id " << id_;
73 host_->UnregisterResolverCallback(id_); 78 host_->UnregisterResolverCallback(id_);
74 if (started_) 79 if (started_)
75 host_->Send(new LocalDiscoveryMsg_DestroyResolver(id_)); 80 host_->Send(new LocalDiscoveryMsg_DestroyResolver(id_));
76 } 81 }
77 82
78 virtual void StartResolving() OVERRIDE { 83 virtual void StartResolving() OVERRIDE {
84 VLOG(1)
85 << "ServiceResolverProxy::StartResolving on browser process with id "
86 << id_;
79 DCHECK(!started_); 87 DCHECK(!started_);
80 host_->Send(new LocalDiscoveryMsg_ResolveService(id_, service_name_)); 88 host_->Send(new LocalDiscoveryMsg_ResolveService(id_, service_name_));
81 started_ = true; 89 started_ = true;
82 } 90 }
83 91
84 virtual std::string GetName() const OVERRIDE { 92 virtual std::string GetName() const OVERRIDE {
85 return service_name_; 93 return service_name_;
86 } 94 }
87 95
88 private: 96 private:
(...skipping 11 matching lines...) Expand all
100 net::AddressFamily address_family, 108 net::AddressFamily address_family,
101 const LocalDomainResolver::IPAddressCallback& callback) 109 const LocalDomainResolver::IPAddressCallback& callback)
102 : host_(host), 110 : host_(host),
103 domain_(domain), 111 domain_(domain),
104 address_family_(address_family), 112 address_family_(address_family),
105 id_(host->RegisterLocalDomainResolverCallback(callback)), 113 id_(host->RegisterLocalDomainResolverCallback(callback)),
106 started_(false) { 114 started_(false) {
107 } 115 }
108 116
109 virtual ~LocalDomainResolverProxy() { 117 virtual ~LocalDomainResolverProxy() {
118 VLOG(1) << "~LocalDomainResolverProxy on browser process with id "
119 << id_;
110 host_->UnregisterLocalDomainResolverCallback(id_); 120 host_->UnregisterLocalDomainResolverCallback(id_);
111 if (started_) 121 if (started_)
112 host_->Send(new LocalDiscoveryMsg_DestroyLocalDomainResolver(id_)); 122 host_->Send(new LocalDiscoveryMsg_DestroyLocalDomainResolver(id_));
113 } 123 }
114 124
115 virtual void Start() OVERRIDE { 125 virtual void Start() OVERRIDE {
126 VLOG(1) << "LocalDomainResolverProxy::Start on browser process with id "
127 << id_;
116 DCHECK(!started_); 128 DCHECK(!started_);
117 host_->Send(new LocalDiscoveryMsg_ResolveLocalDomain(id_, domain_, 129 host_->Send(new LocalDiscoveryMsg_ResolveLocalDomain(id_, domain_,
118 address_family_)); 130 address_family_));
Vitaly Buka (NO REVIEWS) 2013/09/10 04:47:41 All messages above have no value. It's just dumpin
Noam Samuel 2013/09/10 23:01:52 If we can catch an RPC that is sent but not receiv
119 started_ = true; 131 started_ = true;
120 } 132 }
121 133
122 private: 134 private:
123 scoped_refptr<ServiceDiscoveryHostClient> host_; 135 scoped_refptr<ServiceDiscoveryHostClient> host_;
124 std::string domain_; 136 std::string domain_;
125 net::AddressFamily address_family_; 137 net::AddressFamily address_family_;
126 const uint64 id_; 138 const uint64 id_;
127 bool started_; 139 bool started_;
128 }; 140 };
129 141
142 std::string WatcherUpdateToString(ServiceWatcher::UpdateType update) {
143 switch (update) {
144 case ServiceWatcher::UPDATE_ADDED:
145 return "UPDATE_ADDED";
146 case ServiceWatcher::UPDATE_CHANGED:
147 return "UPDATE_CHANGED";
148 case ServiceWatcher::UPDATE_REMOVED:
149 return "UPDATE_REMOVED";
150 case ServiceWatcher::UPDATE_INVALIDATED:
151 return "UPDATE_INVALIDATED";
152 }
153 return "Unknown Update";
154 }
155
156 std::string ResolverStatusToString(ServiceResolver::RequestStatus status) {
157 switch (status) {
158 case ServiceResolver::STATUS_SUCCESS:
159 return "STATUS_SUCESS";
160 case ServiceResolver::STATUS_REQUEST_TIMEOUT:
161 return "STATUS_REQUEST_TIMEOUT";
162 case ServiceResolver::STATUS_KNOWN_NONEXISTENT:
163 return "STATUS_KNOWN_NONEXISTENT";
164 }
165 return "Unknown Status";
166 }
167
168
130 ServiceDiscoveryHostClient::ServiceDiscoveryHostClient() : current_id_(0) { 169 ServiceDiscoveryHostClient::ServiceDiscoveryHostClient() : current_id_(0) {
131 callback_runner_ = base::MessageLoop::current()->message_loop_proxy(); 170 callback_runner_ = base::MessageLoop::current()->message_loop_proxy();
132 } 171 }
133 172
134 ServiceDiscoveryHostClient::~ServiceDiscoveryHostClient() { 173 ServiceDiscoveryHostClient::~ServiceDiscoveryHostClient() {
135 // The ServiceDiscoveryHostClient may be destroyed from the IO thread or the 174 // The ServiceDiscoveryHostClient may be destroyed from the IO thread or the
136 // owning thread. 175 // owning thread.
137 DetachFromThread(); 176 DetachFromThread();
138 DCHECK(service_watcher_callbacks_.empty()); 177 DCHECK(service_watcher_callbacks_.empty());
139 DCHECK(service_resolver_callbacks_.empty()); 178 DCHECK(service_resolver_callbacks_.empty());
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 callback_runner_->PostTask( 381 callback_runner_->PostTask(
343 FROM_HERE, 382 FROM_HERE,
344 base::Bind(&ServiceDiscoveryHostClient::RunLocalDomainResolverCallback, 383 base::Bind(&ServiceDiscoveryHostClient::RunLocalDomainResolverCallback,
345 this, id, success, ip_address_ipv4, ip_address_ipv6)); 384 this, id, success, ip_address_ipv4, ip_address_ipv6));
346 } 385 }
347 386
348 void ServiceDiscoveryHostClient::RunWatcherCallback( 387 void ServiceDiscoveryHostClient::RunWatcherCallback(
349 uint64 id, 388 uint64 id,
350 ServiceWatcher::UpdateType update, 389 ServiceWatcher::UpdateType update,
351 const std::string& service_name) { 390 const std::string& service_name) {
391 VLOG(1) << "RunWatcherCallback on browser process with id " << id
392 << " and watcher update " << WatcherUpdateToString(update);
Vitaly Buka (NO REVIEWS) 2013/09/10 04:47:41 For consistenly I'd move this logging from here to
Noam Samuel 2013/09/10 23:23:34 Done.
352 DCHECK(CalledOnValidThread()); 393 DCHECK(CalledOnValidThread());
353 WatcherCallbacks::iterator it = service_watcher_callbacks_.find(id); 394 WatcherCallbacks::iterator it = service_watcher_callbacks_.find(id);
354 if (it != service_watcher_callbacks_.end() && !it->second.is_null()) 395 if (it != service_watcher_callbacks_.end() && !it->second.is_null())
355 it->second.Run(update, service_name); 396 it->second.Run(update, service_name);
356 } 397 }
357 398
358 void ServiceDiscoveryHostClient::RunResolverCallback( 399 void ServiceDiscoveryHostClient::RunResolverCallback(
359 uint64 id, 400 uint64 id,
360 ServiceResolver::RequestStatus status, 401 ServiceResolver::RequestStatus status,
361 const ServiceDescription& description) { 402 const ServiceDescription& description) {
403 VLOG(1) << "RunResolverCallback on browser process with id " << id
Vitaly Buka (NO REVIEWS) 2013/09/10 04:47:41 "on browser process" part is not needed
Noam Samuel 2013/09/10 23:23:34 Done.
404 << " and resolver status " << ResolverStatusToString(status);
362 DCHECK(CalledOnValidThread()); 405 DCHECK(CalledOnValidThread());
363 ResolverCallbacks::iterator it = service_resolver_callbacks_.find(id); 406 ResolverCallbacks::iterator it = service_resolver_callbacks_.find(id);
364 if (it != service_resolver_callbacks_.end() && !it->second.is_null()) 407 if (it != service_resolver_callbacks_.end() && !it->second.is_null())
365 it->second.Run(status, description); 408 it->second.Run(status, description);
366 } 409 }
367 410
368 void ServiceDiscoveryHostClient::RunLocalDomainResolverCallback( 411 void ServiceDiscoveryHostClient::RunLocalDomainResolverCallback(
369 uint64 id, 412 uint64 id,
370 bool success, 413 bool success,
371 const net::IPAddressNumber& ip_address_ipv4, 414 const net::IPAddressNumber& ip_address_ipv4,
372 const net::IPAddressNumber& ip_address_ipv6) { 415 const net::IPAddressNumber& ip_address_ipv6) {
416 VLOG(1) << "RunLocalDomainCallback on browser process with id " << id;
417
418 if (!ip_address_ipv4.empty())
419 VLOG(1) << "Local comain callback has valid ipv4 address with id " << id;
420 if (!ip_address_ipv6.empty())
421 VLOG(1) << "Local comain callback has valid ipv6 address with id " << id;
422
373 DCHECK(CalledOnValidThread()); 423 DCHECK(CalledOnValidThread());
374 DomainResolverCallbacks::iterator it = domain_resolver_callbacks_.find(id); 424 DomainResolverCallbacks::iterator it = domain_resolver_callbacks_.find(id);
375 if (it != domain_resolver_callbacks_.end() && !it->second.is_null()) 425 if (it != domain_resolver_callbacks_.end() && !it->second.is_null())
376 it->second.Run(success, ip_address_ipv4, ip_address_ipv6); 426 it->second.Run(success, ip_address_ipv4, ip_address_ipv6);
377 } 427 }
378 428
379 ServiceDiscoveryHostClientFactory::ServiceDiscoveryHostClientFactory() 429 ServiceDiscoveryHostClientFactory::ServiceDiscoveryHostClientFactory()
380 : instance_(NULL), references_(0) { 430 : instance_(NULL), references_(0) {
381 } 431 }
382 432
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 void ServiceDiscoveryHostClientFactory::ReleaseClientInternal() { 464 void ServiceDiscoveryHostClientFactory::ReleaseClientInternal() {
415 DCHECK(CalledOnValidThread()); 465 DCHECK(CalledOnValidThread());
416 references_--; 466 references_--;
417 if (references_ == 0) { 467 if (references_ == 0) {
418 instance_->Shutdown(); 468 instance_->Shutdown();
419 instance_ = NULL; 469 instance_ = NULL;
420 } 470 }
421 } 471 }
422 472
423 } // namespace local_discovery 473 } // namespace local_discovery
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698