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

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

Issue 2828663002: Rewrite base::Bind to base::BindOnce with base_bind_rewriters in //chrome/browser/{i,l,m,n,p,r}* (Closed)
Patch Set: Created 3 years, 8 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 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 } 137 }
138 138
139 private: 139 private:
140 net::InterfaceIndexFamilyList interfaces_; 140 net::InterfaceIndexFamilyList interfaces_;
141 }; 141 };
142 142
143 void InitMdns(const MdnsInitCallback& on_initialized, 143 void InitMdns(const MdnsInitCallback& on_initialized,
144 const net::InterfaceIndexFamilyList& interfaces, 144 const net::InterfaceIndexFamilyList& interfaces,
145 net::MDnsClient* mdns) { 145 net::MDnsClient* mdns) {
146 SocketFactory socket_factory(interfaces); 146 SocketFactory socket_factory(interfaces);
147 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 147 BrowserThread::PostTask(
148 base::Bind(on_initialized, 148 BrowserThread::UI, FROM_HERE,
149 mdns->StartListening(&socket_factory))); 149 base::BindOnce(on_initialized, mdns->StartListening(&socket_factory)));
150 } 150 }
151 151
152 template<class T> 152 template<class T>
153 class ProxyBase : public ServiceDiscoveryClientMdns::Proxy, public T { 153 class ProxyBase : public ServiceDiscoveryClientMdns::Proxy, public T {
154 public: 154 public:
155 typedef ProxyBase<T> Base; 155 typedef ProxyBase<T> Base;
156 156
157 explicit ProxyBase(ServiceDiscoveryClientMdns* client) 157 explicit ProxyBase(ServiceDiscoveryClientMdns* client)
158 : Proxy(client) { 158 : Proxy(client) {
159 } 159 }
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 // Only network changes resets counter. 375 // Only network changes resets counter.
376 restart_attempts_ = 0; 376 restart_attempts_ = 0;
377 ScheduleStartNewClient(); 377 ScheduleStartNewClient();
378 } 378 }
379 379
380 void ServiceDiscoveryClientMdns::ScheduleStartNewClient() { 380 void ServiceDiscoveryClientMdns::ScheduleStartNewClient() {
381 DCHECK_CURRENTLY_ON(BrowserThread::UI); 381 DCHECK_CURRENTLY_ON(BrowserThread::UI);
382 OnBeforeMdnsDestroy(); 382 OnBeforeMdnsDestroy();
383 if (restart_attempts_ < kMaxRestartAttempts) { 383 if (restart_attempts_ < kMaxRestartAttempts) {
384 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 384 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
385 FROM_HERE, base::Bind(&ServiceDiscoveryClientMdns::StartNewClient, 385 FROM_HERE,
386 weak_ptr_factory_.GetWeakPtr()), 386 base::BindOnce(&ServiceDiscoveryClientMdns::StartNewClient,
387 weak_ptr_factory_.GetWeakPtr()),
387 base::TimeDelta::FromSeconds(kRestartDelayOnNetworkChangeSeconds * 388 base::TimeDelta::FromSeconds(kRestartDelayOnNetworkChangeSeconds *
388 (1 << restart_attempts_))); 389 (1 << restart_attempts_)));
389 } else { 390 } else {
390 ReportSuccess(); 391 ReportSuccess();
391 } 392 }
392 } 393 }
393 394
394 void ServiceDiscoveryClientMdns::StartNewClient() { 395 void ServiceDiscoveryClientMdns::StartNewClient() {
395 DCHECK_CURRENTLY_ON(BrowserThread::UI); 396 DCHECK_CURRENTLY_ON(BrowserThread::UI);
396 ++restart_attempts_; 397 ++restart_attempts_;
397 DestroyMdns(); 398 DestroyMdns();
398 mdns_ = net::MDnsClient::CreateDefault(); 399 mdns_ = net::MDnsClient::CreateDefault();
399 client_.reset(new ServiceDiscoveryClientImpl(mdns_.get())); 400 client_.reset(new ServiceDiscoveryClientImpl(mdns_.get()));
400 BrowserThread::PostTaskAndReplyWithResult( 401 BrowserThread::PostTaskAndReplyWithResult(
401 BrowserThread::FILE, 402 BrowserThread::FILE,
402 FROM_HERE, 403 FROM_HERE,
403 base::Bind(&net::GetMDnsInterfacesToBind), 404 base::Bind(&net::GetMDnsInterfacesToBind),
404 base::Bind(&ServiceDiscoveryClientMdns::OnInterfaceListReady, 405 base::Bind(&ServiceDiscoveryClientMdns::OnInterfaceListReady,
405 weak_ptr_factory_.GetWeakPtr())); 406 weak_ptr_factory_.GetWeakPtr()));
406 } 407 }
407 408
408 void ServiceDiscoveryClientMdns::OnInterfaceListReady( 409 void ServiceDiscoveryClientMdns::OnInterfaceListReady(
409 const net::InterfaceIndexFamilyList& interfaces) { 410 const net::InterfaceIndexFamilyList& interfaces) {
410 mdns_runner_->PostTask( 411 mdns_runner_->PostTask(
411 FROM_HERE, 412 FROM_HERE,
412 base::Bind(&InitMdns, 413 base::BindOnce(&InitMdns,
413 base::Bind(&ServiceDiscoveryClientMdns::OnMdnsInitialized, 414 base::Bind(&ServiceDiscoveryClientMdns::OnMdnsInitialized,
414 weak_ptr_factory_.GetWeakPtr()), 415 weak_ptr_factory_.GetWeakPtr()),
415 interfaces, 416 interfaces, base::Unretained(mdns_.get())));
416 base::Unretained(mdns_.get())));
417 } 417 }
418 418
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
(...skipping 20 matching lines...) Expand all
447 OnBeforeMdnsDestroy(); 447 OnBeforeMdnsDestroy();
448 // After calling |Proxy::OnMdnsDestroy| all references to client_ and mdns_ 448 // After calling |Proxy::OnMdnsDestroy| all references to client_ and mdns_
449 // should be destroyed. 449 // should be destroyed.
450 if (client_) 450 if (client_)
451 mdns_runner_->DeleteSoon(FROM_HERE, client_.release()); 451 mdns_runner_->DeleteSoon(FROM_HERE, client_.release());
452 if (mdns_) 452 if (mdns_)
453 mdns_runner_->DeleteSoon(FROM_HERE, mdns_.release()); 453 mdns_runner_->DeleteSoon(FROM_HERE, mdns_.release());
454 } 454 }
455 455
456 } // namespace local_discovery 456 } // namespace local_discovery
OLDNEW
« no previous file with comments | « chrome/browser/local_discovery/service_discovery_client_impl.cc ('k') | chrome/browser/manifest/manifest_icon_downloader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698