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

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

Issue 1550593002: Switch to standard integer types in chrome/browser/, part 2 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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/local_discovery/service_discovery_host_client.h" 5 #include "chrome/browser/local_discovery/service_discovery_host_client.h"
6 6
7 #include <stddef.h>
8
7 #include "base/location.h" 9 #include "base/location.h"
8 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
9 #include "base/thread_task_runner_handle.h" 11 #include "base/thread_task_runner_handle.h"
12 #include "build/build_config.h"
10 #include "chrome/common/local_discovery/local_discovery_messages.h" 13 #include "chrome/common/local_discovery/local_discovery_messages.h"
11 #include "chrome/grit/generated_resources.h" 14 #include "chrome/grit/generated_resources.h"
12 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/utility_process_host.h" 16 #include "content/public/browser/utility_process_host.h"
14 #include "net/base/net_util.h" 17 #include "net/base/net_util.h"
15 #include "net/dns/mdns_client.h" 18 #include "net/dns/mdns_client.h"
16 #include "net/socket/socket_descriptor.h" 19 #include "net/socket/socket_descriptor.h"
17 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
18 21
19 #if defined(OS_POSIX) 22 #if defined(OS_POSIX)
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 DCHECK(started_); 96 DCHECK(started_);
94 host_->Send(new LocalDiscoveryMsg_SetActivelyRefreshServices( 97 host_->Send(new LocalDiscoveryMsg_SetActivelyRefreshServices(
95 id_, actively_refresh_services)); 98 id_, actively_refresh_services));
96 } 99 }
97 100
98 std::string GetServiceType() const override { return service_type_; } 101 std::string GetServiceType() const override { return service_type_; }
99 102
100 private: 103 private:
101 scoped_refptr<ServiceDiscoveryHostClient> host_; 104 scoped_refptr<ServiceDiscoveryHostClient> host_;
102 const std::string service_type_; 105 const std::string service_type_;
103 const uint64 id_; 106 const uint64_t id_;
104 bool started_; 107 bool started_;
105 }; 108 };
106 109
107 class ServiceDiscoveryHostClient::ServiceResolverProxy 110 class ServiceDiscoveryHostClient::ServiceResolverProxy
108 : public ServiceResolver { 111 : public ServiceResolver {
109 public: 112 public:
110 ServiceResolverProxy(ServiceDiscoveryHostClient* host, 113 ServiceResolverProxy(ServiceDiscoveryHostClient* host,
111 const std::string& service_name, 114 const std::string& service_name,
112 const ServiceResolver::ResolveCompleteCallback& callback) 115 const ServiceResolver::ResolveCompleteCallback& callback)
113 : host_(host), 116 : host_(host),
(...skipping 14 matching lines...) Expand all
128 DCHECK(!started_); 131 DCHECK(!started_);
129 host_->Send(new LocalDiscoveryMsg_ResolveService(id_, service_name_)); 132 host_->Send(new LocalDiscoveryMsg_ResolveService(id_, service_name_));
130 started_ = true; 133 started_ = true;
131 } 134 }
132 135
133 std::string GetName() const override { return service_name_; } 136 std::string GetName() const override { return service_name_; }
134 137
135 private: 138 private:
136 scoped_refptr<ServiceDiscoveryHostClient> host_; 139 scoped_refptr<ServiceDiscoveryHostClient> host_;
137 const std::string service_name_; 140 const std::string service_name_;
138 const uint64 id_; 141 const uint64_t id_;
139 bool started_; 142 bool started_;
140 }; 143 };
141 144
142 class ServiceDiscoveryHostClient::LocalDomainResolverProxy 145 class ServiceDiscoveryHostClient::LocalDomainResolverProxy
143 : public LocalDomainResolver { 146 : public LocalDomainResolver {
144 public: 147 public:
145 LocalDomainResolverProxy(ServiceDiscoveryHostClient* host, 148 LocalDomainResolverProxy(ServiceDiscoveryHostClient* host,
146 const std::string& domain, 149 const std::string& domain,
147 net::AddressFamily address_family, 150 net::AddressFamily address_family,
148 const LocalDomainResolver::IPAddressCallback& callback) 151 const LocalDomainResolver::IPAddressCallback& callback)
(...skipping 16 matching lines...) Expand all
165 DCHECK(!started_); 168 DCHECK(!started_);
166 host_->Send(new LocalDiscoveryMsg_ResolveLocalDomain(id_, domain_, 169 host_->Send(new LocalDiscoveryMsg_ResolveLocalDomain(id_, domain_,
167 address_family_)); 170 address_family_));
168 started_ = true; 171 started_ = true;
169 } 172 }
170 173
171 private: 174 private:
172 scoped_refptr<ServiceDiscoveryHostClient> host_; 175 scoped_refptr<ServiceDiscoveryHostClient> host_;
173 std::string domain_; 176 std::string domain_;
174 net::AddressFamily address_family_; 177 net::AddressFamily address_family_;
175 const uint64 id_; 178 const uint64_t id_;
176 bool started_; 179 bool started_;
177 }; 180 };
178 181
179 ServiceDiscoveryHostClient::ServiceDiscoveryHostClient() : current_id_(0) { 182 ServiceDiscoveryHostClient::ServiceDiscoveryHostClient() : current_id_(0) {
180 callback_runner_ = base::MessageLoop::current()->task_runner(); 183 callback_runner_ = base::MessageLoop::current()->task_runner();
181 io_runner_ = BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); 184 io_runner_ = BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
182 } 185 }
183 186
184 ServiceDiscoveryHostClient::~ServiceDiscoveryHostClient() { 187 ServiceDiscoveryHostClient::~ServiceDiscoveryHostClient() {
185 DCHECK(service_watcher_callbacks_.empty()); 188 DCHECK(service_watcher_callbacks_.empty());
(...skipping 20 matching lines...) Expand all
206 scoped_ptr<LocalDomainResolver> 209 scoped_ptr<LocalDomainResolver>
207 ServiceDiscoveryHostClient::CreateLocalDomainResolver( 210 ServiceDiscoveryHostClient::CreateLocalDomainResolver(
208 const std::string& domain, 211 const std::string& domain,
209 net::AddressFamily address_family, 212 net::AddressFamily address_family,
210 const LocalDomainResolver::IPAddressCallback& callback) { 213 const LocalDomainResolver::IPAddressCallback& callback) {
211 DCHECK_CURRENTLY_ON(BrowserThread::UI); 214 DCHECK_CURRENTLY_ON(BrowserThread::UI);
212 return scoped_ptr<LocalDomainResolver>(new LocalDomainResolverProxy( 215 return scoped_ptr<LocalDomainResolver>(new LocalDomainResolverProxy(
213 this, domain, address_family, callback)); 216 this, domain, address_family, callback));
214 } 217 }
215 218
216 uint64 ServiceDiscoveryHostClient::RegisterWatcherCallback( 219 uint64_t ServiceDiscoveryHostClient::RegisterWatcherCallback(
217 const ServiceWatcher::UpdatedCallback& callback) { 220 const ServiceWatcher::UpdatedCallback& callback) {
218 DCHECK_CURRENTLY_ON(BrowserThread::UI); 221 DCHECK_CURRENTLY_ON(BrowserThread::UI);
219 DCHECK(!ContainsKey(service_watcher_callbacks_, current_id_ + 1)); 222 DCHECK(!ContainsKey(service_watcher_callbacks_, current_id_ + 1));
220 service_watcher_callbacks_[++current_id_] = callback; 223 service_watcher_callbacks_[++current_id_] = callback;
221 return current_id_; 224 return current_id_;
222 } 225 }
223 226
224 uint64 ServiceDiscoveryHostClient::RegisterResolverCallback( 227 uint64_t ServiceDiscoveryHostClient::RegisterResolverCallback(
225 const ServiceResolver::ResolveCompleteCallback& callback) { 228 const ServiceResolver::ResolveCompleteCallback& callback) {
226 DCHECK_CURRENTLY_ON(BrowserThread::UI); 229 DCHECK_CURRENTLY_ON(BrowserThread::UI);
227 DCHECK(!ContainsKey(service_resolver_callbacks_, current_id_ + 1)); 230 DCHECK(!ContainsKey(service_resolver_callbacks_, current_id_ + 1));
228 service_resolver_callbacks_[++current_id_] = callback; 231 service_resolver_callbacks_[++current_id_] = callback;
229 return current_id_; 232 return current_id_;
230 } 233 }
231 234
232 uint64 ServiceDiscoveryHostClient::RegisterLocalDomainResolverCallback( 235 uint64_t ServiceDiscoveryHostClient::RegisterLocalDomainResolverCallback(
233 const LocalDomainResolver::IPAddressCallback& callback) { 236 const LocalDomainResolver::IPAddressCallback& callback) {
234 DCHECK_CURRENTLY_ON(BrowserThread::UI); 237 DCHECK_CURRENTLY_ON(BrowserThread::UI);
235 DCHECK(!ContainsKey(domain_resolver_callbacks_, current_id_ + 1)); 238 DCHECK(!ContainsKey(domain_resolver_callbacks_, current_id_ + 1));
236 domain_resolver_callbacks_[++current_id_] = callback; 239 domain_resolver_callbacks_[++current_id_] = callback;
237 return current_id_; 240 return current_id_;
238 } 241 }
239 242
240 void ServiceDiscoveryHostClient::UnregisterWatcherCallback(uint64 id) { 243 void ServiceDiscoveryHostClient::UnregisterWatcherCallback(uint64_t id) {
241 DCHECK_CURRENTLY_ON(BrowserThread::UI); 244 DCHECK_CURRENTLY_ON(BrowserThread::UI);
242 service_watcher_callbacks_.erase(id); 245 service_watcher_callbacks_.erase(id);
243 } 246 }
244 247
245 void ServiceDiscoveryHostClient::UnregisterResolverCallback(uint64 id) { 248 void ServiceDiscoveryHostClient::UnregisterResolverCallback(uint64_t id) {
246 DCHECK_CURRENTLY_ON(BrowserThread::UI); 249 DCHECK_CURRENTLY_ON(BrowserThread::UI);
247 service_resolver_callbacks_.erase(id); 250 service_resolver_callbacks_.erase(id);
248 } 251 }
249 252
250 void ServiceDiscoveryHostClient::UnregisterLocalDomainResolverCallback( 253 void ServiceDiscoveryHostClient::UnregisterLocalDomainResolverCallback(
251 uint64 id) { 254 uint64_t id) {
252 DCHECK_CURRENTLY_ON(BrowserThread::UI); 255 DCHECK_CURRENTLY_ON(BrowserThread::UI);
253 domain_resolver_callbacks_.erase(id); 256 domain_resolver_callbacks_.erase(id);
254 } 257 }
255 258
256 void ServiceDiscoveryHostClient::Start( 259 void ServiceDiscoveryHostClient::Start(
257 const base::Closure& error_callback) { 260 const base::Closure& error_callback) {
258 DCHECK_CURRENTLY_ON(BrowserThread::UI); 261 DCHECK_CURRENTLY_ON(BrowserThread::UI);
259 DCHECK(!utility_host_); 262 DCHECK(!utility_host_);
260 DCHECK(error_callback_.is_null()); 263 DCHECK(error_callback_.is_null());
261 error_callback_ = error_callback; 264 error_callback_ = error_callback;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 } 387 }
385 } 388 }
386 389
387 void ServiceDiscoveryHostClient::OnError() { 390 void ServiceDiscoveryHostClient::OnError() {
388 DCHECK_CURRENTLY_ON(BrowserThread::IO); 391 DCHECK_CURRENTLY_ON(BrowserThread::IO);
389 if (!error_callback_.is_null()) 392 if (!error_callback_.is_null())
390 callback_runner_->PostTask(FROM_HERE, error_callback_); 393 callback_runner_->PostTask(FROM_HERE, error_callback_);
391 } 394 }
392 395
393 void ServiceDiscoveryHostClient::OnWatcherCallback( 396 void ServiceDiscoveryHostClient::OnWatcherCallback(
394 uint64 id, 397 uint64_t id,
395 ServiceWatcher::UpdateType update, 398 ServiceWatcher::UpdateType update,
396 const std::string& service_name) { 399 const std::string& service_name) {
397 DCHECK_CURRENTLY_ON(BrowserThread::IO); 400 DCHECK_CURRENTLY_ON(BrowserThread::IO);
398 callback_runner_->PostTask( 401 callback_runner_->PostTask(
399 FROM_HERE, 402 FROM_HERE,
400 base::Bind(&ServiceDiscoveryHostClient::RunWatcherCallback, this, id, 403 base::Bind(&ServiceDiscoveryHostClient::RunWatcherCallback, this, id,
401 update, service_name)); 404 update, service_name));
402 } 405 }
403 406
404 void ServiceDiscoveryHostClient::OnResolverCallback( 407 void ServiceDiscoveryHostClient::OnResolverCallback(
405 uint64 id, 408 uint64_t id,
406 ServiceResolver::RequestStatus status, 409 ServiceResolver::RequestStatus status,
407 const ServiceDescription& description) { 410 const ServiceDescription& description) {
408 DCHECK_CURRENTLY_ON(BrowserThread::IO); 411 DCHECK_CURRENTLY_ON(BrowserThread::IO);
409 callback_runner_->PostTask( 412 callback_runner_->PostTask(
410 FROM_HERE, 413 FROM_HERE,
411 base::Bind(&ServiceDiscoveryHostClient::RunResolverCallback, this, id, 414 base::Bind(&ServiceDiscoveryHostClient::RunResolverCallback, this, id,
412 status, description)); 415 status, description));
413 } 416 }
414 417
415 void ServiceDiscoveryHostClient::OnLocalDomainResolverCallback( 418 void ServiceDiscoveryHostClient::OnLocalDomainResolverCallback(
416 uint64 id, 419 uint64_t id,
417 bool success, 420 bool success,
418 const net::IPAddressNumber& ip_address_ipv4, 421 const net::IPAddressNumber& ip_address_ipv4,
419 const net::IPAddressNumber& ip_address_ipv6) { 422 const net::IPAddressNumber& ip_address_ipv6) {
420 DCHECK_CURRENTLY_ON(BrowserThread::IO); 423 DCHECK_CURRENTLY_ON(BrowserThread::IO);
421 callback_runner_->PostTask( 424 callback_runner_->PostTask(
422 FROM_HERE, 425 FROM_HERE,
423 base::Bind(&ServiceDiscoveryHostClient::RunLocalDomainResolverCallback, 426 base::Bind(&ServiceDiscoveryHostClient::RunLocalDomainResolverCallback,
424 this, id, success, ip_address_ipv4, ip_address_ipv6)); 427 this, id, success, ip_address_ipv4, ip_address_ipv6));
425 } 428 }
426 429
427 void ServiceDiscoveryHostClient::RunWatcherCallback( 430 void ServiceDiscoveryHostClient::RunWatcherCallback(
428 uint64 id, 431 uint64_t id,
429 ServiceWatcher::UpdateType update, 432 ServiceWatcher::UpdateType update,
430 const std::string& service_name) { 433 const std::string& service_name) {
431 DCHECK_CURRENTLY_ON(BrowserThread::UI); 434 DCHECK_CURRENTLY_ON(BrowserThread::UI);
432 WatcherCallbacks::iterator it = service_watcher_callbacks_.find(id); 435 WatcherCallbacks::iterator it = service_watcher_callbacks_.find(id);
433 if (it != service_watcher_callbacks_.end() && !it->second.is_null()) 436 if (it != service_watcher_callbacks_.end() && !it->second.is_null())
434 it->second.Run(update, service_name); 437 it->second.Run(update, service_name);
435 } 438 }
436 439
437 void ServiceDiscoveryHostClient::RunResolverCallback( 440 void ServiceDiscoveryHostClient::RunResolverCallback(
438 uint64 id, 441 uint64_t id,
439 ServiceResolver::RequestStatus status, 442 ServiceResolver::RequestStatus status,
440 const ServiceDescription& description) { 443 const ServiceDescription& description) {
441 DCHECK_CURRENTLY_ON(BrowserThread::UI); 444 DCHECK_CURRENTLY_ON(BrowserThread::UI);
442 ResolverCallbacks::iterator it = service_resolver_callbacks_.find(id); 445 ResolverCallbacks::iterator it = service_resolver_callbacks_.find(id);
443 if (it != service_resolver_callbacks_.end() && !it->second.is_null()) 446 if (it != service_resolver_callbacks_.end() && !it->second.is_null())
444 it->second.Run(status, description); 447 it->second.Run(status, description);
445 } 448 }
446 449
447 void ServiceDiscoveryHostClient::RunLocalDomainResolverCallback( 450 void ServiceDiscoveryHostClient::RunLocalDomainResolverCallback(
448 uint64 id, 451 uint64_t id,
449 bool success, 452 bool success,
450 const net::IPAddressNumber& ip_address_ipv4, 453 const net::IPAddressNumber& ip_address_ipv4,
451 const net::IPAddressNumber& ip_address_ipv6) { 454 const net::IPAddressNumber& ip_address_ipv6) {
452 DCHECK_CURRENTLY_ON(BrowserThread::UI); 455 DCHECK_CURRENTLY_ON(BrowserThread::UI);
453 DomainResolverCallbacks::iterator it = domain_resolver_callbacks_.find(id); 456 DomainResolverCallbacks::iterator it = domain_resolver_callbacks_.find(id);
454 if (it != domain_resolver_callbacks_.end() && !it->second.is_null()) 457 if (it != domain_resolver_callbacks_.end() && !it->second.is_null())
455 it->second.Run(success, ip_address_ipv4, ip_address_ipv6); 458 it->second.Run(success, ip_address_ipv4, ip_address_ipv6);
456 } 459 }
457 460
458 } // namespace local_discovery 461 } // namespace local_discovery
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698