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

Side by Side Diff: chrome/browser/extensions/api/dial/dial_service.cc

Issue 2422963002: Remove FOR_EACH_OBSERVER macro usage in chrome/browser/extensions (Closed)
Patch Set: extensions Created 4 years, 2 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/extensions/api/dial/dial_service.h" 5 #include "chrome/browser/extensions/api/dial/dial_service.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <set> 10 #include <set>
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 555
556 void DialServiceImpl::NotifyOnDiscoveryRequest() { 556 void DialServiceImpl::NotifyOnDiscoveryRequest() {
557 DCHECK_CURRENTLY_ON(BrowserThread::IO); 557 DCHECK_CURRENTLY_ON(BrowserThread::IO);
558 // If discovery is inactive, no reason to notify observers. 558 // If discovery is inactive, no reason to notify observers.
559 if (!discovery_active_) { 559 if (!discovery_active_) {
560 VLOG(2) << "Request sent after discovery finished. Ignoring."; 560 VLOG(2) << "Request sent after discovery finished. Ignoring.";
561 return; 561 return;
562 } 562 }
563 563
564 VLOG(2) << "Notifying observers of discovery request"; 564 VLOG(2) << "Notifying observers of discovery request";
565 FOR_EACH_OBSERVER(Observer, observer_list_, OnDiscoveryRequest(this)); 565 for (auto& observer : observer_list_)
566 observer.OnDiscoveryRequest(this);
566 // If we need to send additional requests, schedule a timer to do so. 567 // If we need to send additional requests, schedule a timer to do so.
567 if (num_requests_sent_ < max_requests_ && num_requests_sent_ == 1) { 568 if (num_requests_sent_ < max_requests_ && num_requests_sent_ == 1) {
568 VLOG(2) << "Scheduling timer to send additional requests"; 569 VLOG(2) << "Scheduling timer to send additional requests";
569 // TODO(imcheng): Move this to SendOneRequest() once the implications are 570 // TODO(imcheng): Move this to SendOneRequest() once the implications are
570 // understood. 571 // understood.
571 request_timer_.Start(FROM_HERE, 572 request_timer_.Start(FROM_HERE,
572 request_interval_, 573 request_interval_,
573 this, 574 this,
574 &DialServiceImpl::SendOneRequest); 575 &DialServiceImpl::SendOneRequest);
575 } 576 }
576 } 577 }
577 578
578 void DialServiceImpl::NotifyOnDeviceDiscovered( 579 void DialServiceImpl::NotifyOnDeviceDiscovered(
579 const DialDeviceData& device_data) { 580 const DialDeviceData& device_data) {
580 DCHECK_CURRENTLY_ON(BrowserThread::IO); 581 DCHECK_CURRENTLY_ON(BrowserThread::IO);
581 if (!discovery_active_) { 582 if (!discovery_active_) {
582 VLOG(2) << "Got response after discovery finished. Ignoring."; 583 VLOG(2) << "Got response after discovery finished. Ignoring.";
583 return; 584 return;
584 } 585 }
585 FOR_EACH_OBSERVER(Observer, observer_list_, 586 for (auto& observer : observer_list_)
586 OnDeviceDiscovered(this, device_data)); 587 observer.OnDeviceDiscovered(this, device_data);
587 } 588 }
588 589
589 void DialServiceImpl::NotifyOnError() { 590 void DialServiceImpl::NotifyOnError() {
590 DCHECK_CURRENTLY_ON(BrowserThread::IO); 591 DCHECK_CURRENTLY_ON(BrowserThread::IO);
591 // TODO(imcheng): Modify upstream so that the device list is not cleared 592 // TODO(imcheng): Modify upstream so that the device list is not cleared
592 // when it could still potentially discover devices on other sockets. 593 // when it could still potentially discover devices on other sockets.
593 FOR_EACH_OBSERVER(Observer, observer_list_, 594 for (auto& observer : observer_list_) {
594 OnError(this, 595 observer.OnError(this, HasOpenSockets() ? DIAL_SERVICE_SOCKET_ERROR
595 HasOpenSockets() ? DIAL_SERVICE_SOCKET_ERROR 596 : DIAL_SERVICE_NO_INTERFACES);
596 : DIAL_SERVICE_NO_INTERFACES)); 597 }
597 } 598 }
598 599
599 void DialServiceImpl::FinishDiscovery() { 600 void DialServiceImpl::FinishDiscovery() {
600 DCHECK_CURRENTLY_ON(BrowserThread::IO); 601 DCHECK_CURRENTLY_ON(BrowserThread::IO);
601 DCHECK(discovery_active_); 602 DCHECK(discovery_active_);
602 VLOG(2) << "Discovery finished."; 603 VLOG(2) << "Discovery finished.";
603 // Close all open sockets. 604 // Close all open sockets.
604 dial_sockets_.clear(); 605 dial_sockets_.clear();
605 finish_timer_.Stop(); 606 finish_timer_.Stop();
606 request_timer_.Stop(); 607 request_timer_.Stop();
607 discovery_active_ = false; 608 discovery_active_ = false;
608 num_requests_sent_ = 0; 609 num_requests_sent_ = 0;
609 FOR_EACH_OBSERVER(Observer, observer_list_, OnDiscoveryFinished(this)); 610 for (auto& observer : observer_list_)
611 observer.OnDiscoveryFinished(this);
610 } 612 }
611 613
612 bool DialServiceImpl::HasOpenSockets() { 614 bool DialServiceImpl::HasOpenSockets() {
613 for (const auto& socket : dial_sockets_) { 615 for (const auto& socket : dial_sockets_) {
614 if (!socket->IsClosed()) 616 if (!socket->IsClosed())
615 return true; 617 return true;
616 } 618 }
617 return false; 619 return false;
618 } 620 }
619 621
620 } // namespace extensions 622 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698