| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_client_mdns.h" | 5 #include "chrome/browser/local_discovery/service_discovery_client_mdns.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 void ServiceDiscoveryClientMdns::OnMdnsInitialized(bool success) { | 419 void ServiceDiscoveryClientMdns::OnMdnsInitialized(bool success) { |
| 420 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 420 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 421 if (!success) { | 421 if (!success) { |
| 422 ScheduleStartNewClient(); | 422 ScheduleStartNewClient(); |
| 423 return; | 423 return; |
| 424 } | 424 } |
| 425 ReportSuccess(); | 425 ReportSuccess(); |
| 426 | 426 |
| 427 // Initialization is done, no need to delay tasks. | 427 // Initialization is done, no need to delay tasks. |
| 428 need_dalay_mdns_tasks_ = false; | 428 need_dalay_mdns_tasks_ = false; |
| 429 FOR_EACH_OBSERVER(Proxy, proxies_, OnNewMdnsReady()); | 429 for (Proxy& observer : proxies_) |
| 430 observer.OnNewMdnsReady(); |
| 430 } | 431 } |
| 431 | 432 |
| 432 void ServiceDiscoveryClientMdns::ReportSuccess() { | 433 void ServiceDiscoveryClientMdns::ReportSuccess() { |
| 433 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 434 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 434 UMA_HISTOGRAM_COUNTS_100("LocalDiscovery.ClientRestartAttempts", | 435 UMA_HISTOGRAM_COUNTS_100("LocalDiscovery.ClientRestartAttempts", |
| 435 restart_attempts_); | 436 restart_attempts_); |
| 436 } | 437 } |
| 437 | 438 |
| 438 void ServiceDiscoveryClientMdns::OnBeforeMdnsDestroy() { | 439 void ServiceDiscoveryClientMdns::OnBeforeMdnsDestroy() { |
| 439 need_dalay_mdns_tasks_ = true; | 440 need_dalay_mdns_tasks_ = true; |
| 440 weak_ptr_factory_.InvalidateWeakPtrs(); | 441 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 441 FOR_EACH_OBSERVER(Proxy, proxies_, OnMdnsDestroy()); | 442 for (Proxy& observer : proxies_) |
| 443 observer.OnMdnsDestroy(); |
| 442 } | 444 } |
| 443 | 445 |
| 444 void ServiceDiscoveryClientMdns::DestroyMdns() { | 446 void ServiceDiscoveryClientMdns::DestroyMdns() { |
| 445 OnBeforeMdnsDestroy(); | 447 OnBeforeMdnsDestroy(); |
| 446 // After calling |Proxy::OnMdnsDestroy| all references to client_ and mdns_ | 448 // After calling |Proxy::OnMdnsDestroy| all references to client_ and mdns_ |
| 447 // should be destroyed. | 449 // should be destroyed. |
| 448 if (client_) | 450 if (client_) |
| 449 mdns_runner_->DeleteSoon(FROM_HERE, client_.release()); | 451 mdns_runner_->DeleteSoon(FROM_HERE, client_.release()); |
| 450 if (mdns_) | 452 if (mdns_) |
| 451 mdns_runner_->DeleteSoon(FROM_HERE, mdns_.release()); | 453 mdns_runner_->DeleteSoon(FROM_HERE, mdns_.release()); |
| 452 } | 454 } |
| 453 | 455 |
| 454 } // namespace local_discovery | 456 } // namespace local_discovery |
| OLD | NEW |