Chromium Code Reviews| 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/utility/local_discovery/service_discovery_message_handler.h" | 5 #include "chrome/utility/local_discovery/service_discovery_message_handler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "chrome/common/local_discovery/local_discovery_messages.h" | 10 #include "chrome/common/local_discovery/local_discovery_messages.h" |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 void ServiceDiscoveryMessageHandler::OnDestroyLocalDomainResolver(uint64 id) { | 261 void ServiceDiscoveryMessageHandler::OnDestroyLocalDomainResolver(uint64 id) { |
| 262 PostTask(FROM_HERE, | 262 PostTask(FROM_HERE, |
| 263 base::Bind( | 263 base::Bind( |
| 264 &ServiceDiscoveryMessageHandler::DestroyLocalDomainResolver, | 264 &ServiceDiscoveryMessageHandler::DestroyLocalDomainResolver, |
| 265 base::Unretained(this), id)); | 265 base::Unretained(this), id)); |
| 266 } | 266 } |
| 267 | 267 |
| 268 void ServiceDiscoveryMessageHandler::StartWatcher( | 268 void ServiceDiscoveryMessageHandler::StartWatcher( |
| 269 uint64 id, | 269 uint64 id, |
| 270 const std::string& service_type) { | 270 const std::string& service_type) { |
| 271 VLOG(1) << "StartWatcher on utility process with id " << id; | |
| 271 if (!service_discovery_client_) | 272 if (!service_discovery_client_) |
| 272 return; | 273 return; |
| 273 DCHECK(!ContainsKey(service_watchers_, id)); | 274 DCHECK(!ContainsKey(service_watchers_, id)); |
| 274 scoped_ptr<ServiceWatcher> watcher( | 275 scoped_ptr<ServiceWatcher> watcher( |
| 275 service_discovery_client_->CreateServiceWatcher( | 276 service_discovery_client_->CreateServiceWatcher( |
| 276 service_type, | 277 service_type, |
| 277 base::Bind(&ServiceDiscoveryMessageHandler::OnServiceUpdated, | 278 base::Bind(&ServiceDiscoveryMessageHandler::OnServiceUpdated, |
| 278 base::Unretained(this), id))); | 279 base::Unretained(this), id))); |
| 279 watcher->Start(); | 280 watcher->Start(); |
| 280 service_watchers_[id].reset(watcher.release()); | 281 service_watchers_[id].reset(watcher.release()); |
| 281 } | 282 } |
| 282 | 283 |
| 283 void ServiceDiscoveryMessageHandler::DiscoverServices(uint64 id, | 284 void ServiceDiscoveryMessageHandler::DiscoverServices(uint64 id, |
| 284 bool force_update) { | 285 bool force_update) { |
| 286 VLOG(1) << "DiscoverServices on utility process with id " << id; | |
| 285 if (!service_discovery_client_) | 287 if (!service_discovery_client_) |
| 286 return; | 288 return; |
| 287 DCHECK(ContainsKey(service_watchers_, id)); | 289 DCHECK(ContainsKey(service_watchers_, id)); |
| 288 service_watchers_[id]->DiscoverNewServices(force_update); | 290 service_watchers_[id]->DiscoverNewServices(force_update); |
| 289 } | 291 } |
| 290 | 292 |
| 291 void ServiceDiscoveryMessageHandler::DestroyWatcher(uint64 id) { | 293 void ServiceDiscoveryMessageHandler::DestroyWatcher(uint64 id) { |
| 294 VLOG(1) << "DestoryWatcher on utility process with id " << id; | |
| 292 if (!service_discovery_client_) | 295 if (!service_discovery_client_) |
| 293 return; | 296 return; |
| 294 service_watchers_.erase(id); | 297 service_watchers_.erase(id); |
| 295 } | 298 } |
| 296 | 299 |
| 297 void ServiceDiscoveryMessageHandler::ResolveService( | 300 void ServiceDiscoveryMessageHandler::ResolveService( |
| 298 uint64 id, | 301 uint64 id, |
| 299 const std::string& service_name) { | 302 const std::string& service_name) { |
| 303 VLOG(1) << "ResolveService on utility process with id " << id; | |
| 300 if (!service_discovery_client_) | 304 if (!service_discovery_client_) |
| 301 return; | 305 return; |
| 302 DCHECK(!ContainsKey(service_resolvers_, id)); | 306 DCHECK(!ContainsKey(service_resolvers_, id)); |
| 303 scoped_ptr<ServiceResolver> resolver( | 307 scoped_ptr<ServiceResolver> resolver( |
| 304 service_discovery_client_->CreateServiceResolver( | 308 service_discovery_client_->CreateServiceResolver( |
| 305 service_name, | 309 service_name, |
| 306 base::Bind(&ServiceDiscoveryMessageHandler::OnServiceResolved, | 310 base::Bind(&ServiceDiscoveryMessageHandler::OnServiceResolved, |
| 307 base::Unretained(this), id))); | 311 base::Unretained(this), id))); |
| 308 resolver->StartResolving(); | 312 resolver->StartResolving(); |
| 309 service_resolvers_[id].reset(resolver.release()); | 313 service_resolvers_[id].reset(resolver.release()); |
| 310 } | 314 } |
| 311 | 315 |
| 312 void ServiceDiscoveryMessageHandler::DestroyResolver(uint64 id) { | 316 void ServiceDiscoveryMessageHandler::DestroyResolver(uint64 id) { |
| 317 VLOG(1) << "DestroyResolver on utility process with id " << id; | |
|
Vitaly Buka (NO REVIEWS)
2013/09/10 04:47:41
no need utility "process part"
Noam Samuel
2013/09/10 23:23:34
Done.
| |
| 313 if (!service_discovery_client_) | 318 if (!service_discovery_client_) |
| 314 return; | 319 return; |
| 315 service_resolvers_.erase(id); | 320 service_resolvers_.erase(id); |
| 316 } | 321 } |
| 317 | 322 |
| 318 void ServiceDiscoveryMessageHandler::ResolveLocalDomain( | 323 void ServiceDiscoveryMessageHandler::ResolveLocalDomain( |
| 319 uint64 id, | 324 uint64 id, |
| 320 const std::string& domain, | 325 const std::string& domain, |
| 321 net::AddressFamily address_family) { | 326 net::AddressFamily address_family) { |
| 327 VLOG(1) << "ResolveLocalDomain on utility process with id " << id; | |
| 322 if (!service_discovery_client_) | 328 if (!service_discovery_client_) |
| 323 return; | 329 return; |
| 324 DCHECK(!ContainsKey(local_domain_resolvers_, id)); | 330 DCHECK(!ContainsKey(local_domain_resolvers_, id)); |
| 325 scoped_ptr<LocalDomainResolver> resolver( | 331 scoped_ptr<LocalDomainResolver> resolver( |
| 326 service_discovery_client_->CreateLocalDomainResolver( | 332 service_discovery_client_->CreateLocalDomainResolver( |
| 327 domain, address_family, | 333 domain, address_family, |
| 328 base::Bind(&ServiceDiscoveryMessageHandler::OnLocalDomainResolved, | 334 base::Bind(&ServiceDiscoveryMessageHandler::OnLocalDomainResolved, |
| 329 base::Unretained(this), id))); | 335 base::Unretained(this), id))); |
| 330 resolver->Start(); | 336 resolver->Start(); |
| 331 local_domain_resolvers_[id].reset(resolver.release()); | 337 local_domain_resolvers_[id].reset(resolver.release()); |
| 332 } | 338 } |
| 333 | 339 |
| 334 void ServiceDiscoveryMessageHandler::DestroyLocalDomainResolver(uint64 id) { | 340 void ServiceDiscoveryMessageHandler::DestroyLocalDomainResolver(uint64 id) { |
| 341 VLOG(1) << "DestroyLocalDomainResolver on utility process with id " << id; | |
| 335 if (!service_discovery_client_) | 342 if (!service_discovery_client_) |
| 336 return; | 343 return; |
| 337 local_domain_resolvers_.erase(id); | 344 local_domain_resolvers_.erase(id); |
| 338 } | 345 } |
| 339 | 346 |
| 340 void ServiceDiscoveryMessageHandler::ShutdownLocalDiscovery() { | 347 void ServiceDiscoveryMessageHandler::ShutdownLocalDiscovery() { |
| 348 VLOG(1) << "ShutdownLocalDiscovery on utility process"; | |
| 341 discovery_task_runner_->PostTask( | 349 discovery_task_runner_->PostTask( |
| 342 FROM_HERE, | 350 FROM_HERE, |
| 343 base::Bind(&ServiceDiscoveryMessageHandler::ShutdownOnIOThread, | 351 base::Bind(&ServiceDiscoveryMessageHandler::ShutdownOnIOThread, |
| 344 base::Unretained(this))); | 352 base::Unretained(this))); |
| 345 | 353 |
| 346 // This will wait for message loop to drain, so ShutdownOnIOThread will | 354 // This will wait for message loop to drain, so ShutdownOnIOThread will |
| 347 // definitely be called. | 355 // definitely be called. |
| 348 discovery_thread_.reset(); | 356 discovery_thread_.reset(); |
| 349 } | 357 } |
| 350 | 358 |
| 351 void ServiceDiscoveryMessageHandler::ShutdownOnIOThread() { | 359 void ServiceDiscoveryMessageHandler::ShutdownOnIOThread() { |
| 352 service_watchers_.clear(); | 360 service_watchers_.clear(); |
| 353 service_resolvers_.clear(); | 361 service_resolvers_.clear(); |
| 354 local_domain_resolvers_.clear(); | 362 local_domain_resolvers_.clear(); |
| 355 | 363 |
| 356 service_discovery_client_.reset(); | 364 service_discovery_client_.reset(); |
| 357 mdns_client_.reset(); | 365 mdns_client_.reset(); |
| 358 } | 366 } |
| 359 | 367 |
| 360 void ServiceDiscoveryMessageHandler::OnServiceUpdated( | 368 void ServiceDiscoveryMessageHandler::OnServiceUpdated( |
| 361 uint64 id, | 369 uint64 id, |
| 362 ServiceWatcher::UpdateType update, | 370 ServiceWatcher::UpdateType update, |
| 363 const std::string& name) { | 371 const std::string& name) { |
| 372 VLOG(1) << "OnServiceUpdated on utility process with id " << id; | |
| 364 DCHECK(service_discovery_client_); | 373 DCHECK(service_discovery_client_); |
| 365 utility_task_runner_->PostTask(FROM_HERE, | 374 utility_task_runner_->PostTask(FROM_HERE, |
| 366 base::Bind(&SendServiceUpdated, id, update, name)); | 375 base::Bind(&SendServiceUpdated, id, update, name)); |
| 367 } | 376 } |
| 368 | 377 |
| 369 void ServiceDiscoveryMessageHandler::OnServiceResolved( | 378 void ServiceDiscoveryMessageHandler::OnServiceResolved( |
| 370 uint64 id, | 379 uint64 id, |
| 371 ServiceResolver::RequestStatus status, | 380 ServiceResolver::RequestStatus status, |
| 372 const ServiceDescription& description) { | 381 const ServiceDescription& description) { |
| 382 VLOG(1) << "OnServiceResolved on utility process with id " << id; | |
| 373 DCHECK(service_discovery_client_); | 383 DCHECK(service_discovery_client_); |
| 374 utility_task_runner_->PostTask(FROM_HERE, | 384 utility_task_runner_->PostTask(FROM_HERE, |
| 375 base::Bind(&SendServiceResolved, id, status, description)); | 385 base::Bind(&SendServiceResolved, id, status, description)); |
| 376 } | 386 } |
| 377 | 387 |
| 378 void ServiceDiscoveryMessageHandler::OnLocalDomainResolved( | 388 void ServiceDiscoveryMessageHandler::OnLocalDomainResolved( |
| 379 uint64 id, | 389 uint64 id, |
| 380 bool success, | 390 bool success, |
| 381 const net::IPAddressNumber& address_ipv4, | 391 const net::IPAddressNumber& address_ipv4, |
| 382 const net::IPAddressNumber& address_ipv6) { | 392 const net::IPAddressNumber& address_ipv6) { |
| 393 VLOG(1) << "OnLocalDomainResolved on utility process with id " << id; | |
| 383 DCHECK(service_discovery_client_); | 394 DCHECK(service_discovery_client_); |
| 384 utility_task_runner_->PostTask(FROM_HERE, base::Bind(&SendLocalDomainResolved, | 395 utility_task_runner_->PostTask(FROM_HERE, base::Bind(&SendLocalDomainResolved, |
| 385 id, success, | 396 id, success, |
| 386 address_ipv4, | 397 address_ipv4, |
| 387 address_ipv6)); | 398 address_ipv6)); |
| 388 } | 399 } |
| 389 | 400 |
| 390 | 401 |
| 391 } // namespace local_discovery | 402 } // namespace local_discovery |
| OLD | NEW |