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

Side by Side Diff: chromeos/network/network_state_handler.cc

Issue 2413963002: Replace FOR_EACH_OBSERVER in chromeos/ with range-based for (Closed)
Patch Set: Run the script again with '/mg' 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
« no previous file with comments | « chromeos/network/network_sms_handler.cc ('k') | chromeos/settings/timezone_settings.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chromeos/network/network_state_handler.h" 5 #include "chromeos/network/network_state_handler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/format_macros.h" 10 #include "base/format_macros.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 // Normally Shutdown() will get called in ~NetworkHandler, however unit 73 // Normally Shutdown() will get called in ~NetworkHandler, however unit
74 // tests do not use that class so this needs to call Shutdown when we 74 // tests do not use that class so this needs to call Shutdown when we
75 // destry the class. 75 // destry the class.
76 if (!did_shutdown_) 76 if (!did_shutdown_)
77 Shutdown(); 77 Shutdown();
78 } 78 }
79 79
80 void NetworkStateHandler::Shutdown() { 80 void NetworkStateHandler::Shutdown() {
81 DCHECK(!did_shutdown_); 81 DCHECK(!did_shutdown_);
82 did_shutdown_ = true; 82 did_shutdown_ = true;
83 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, OnShuttingDown()); 83 for (auto& observer : observers_)
84 observer.OnShuttingDown();
84 } 85 }
85 86
86 void NetworkStateHandler::InitShillPropertyHandler() { 87 void NetworkStateHandler::InitShillPropertyHandler() {
87 shill_property_handler_.reset(new internal::ShillPropertyHandler(this)); 88 shill_property_handler_.reset(new internal::ShillPropertyHandler(this));
88 shill_property_handler_->Init(); 89 shill_property_handler_->Init();
89 } 90 }
90 91
91 // static 92 // static
92 NetworkStateHandler* NetworkStateHandler::InitializeForTest() { 93 NetworkStateHandler* NetworkStateHandler::InitializeForTest() {
93 NetworkStateHandler* handler = new NetworkStateHandler(); 94 NetworkStateHandler* handler = new NetworkStateHandler();
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 689
689 void NetworkStateHandler::ManagedStateListChanged( 690 void NetworkStateHandler::ManagedStateListChanged(
690 ManagedState::ManagedType type) { 691 ManagedState::ManagedType type) {
691 SCOPED_NET_LOG_IF_SLOW(); 692 SCOPED_NET_LOG_IF_SLOW();
692 if (type == ManagedState::MANAGED_TYPE_NETWORK) { 693 if (type == ManagedState::MANAGED_TYPE_NETWORK) {
693 SortNetworkList(); 694 SortNetworkList();
694 UpdateNetworkStats(); 695 UpdateNetworkStats();
695 // Notify observers that the list of networks has changed. 696 // Notify observers that the list of networks has changed.
696 NET_LOG_EVENT("NOTIFY:NetworkListChanged", 697 NET_LOG_EVENT("NOTIFY:NetworkListChanged",
697 base::StringPrintf("Size:%" PRIuS, network_list_.size())); 698 base::StringPrintf("Size:%" PRIuS, network_list_.size()));
698 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 699 for (auto& observer : observers_)
699 NetworkListChanged()); 700 observer.NetworkListChanged();
700 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) { 701 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) {
701 std::string devices; 702 std::string devices;
702 for (auto iter = device_list_.begin(); iter != device_list_.end(); ++iter) { 703 for (auto iter = device_list_.begin(); iter != device_list_.end(); ++iter) {
703 if (iter != device_list_.begin()) 704 if (iter != device_list_.begin())
704 devices += ", "; 705 devices += ", ";
705 devices += (*iter)->name(); 706 devices += (*iter)->name();
706 } 707 }
707 NET_LOG_EVENT("DeviceList", devices); 708 NET_LOG_EVENT("DeviceList", devices);
708 NotifyDeviceListChanged(); 709 NotifyDeviceListChanged();
709 } else { 710 } else {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 guid = base::GenerateGUID(); 832 guid = base::GenerateGUID();
832 specifier_guid_map_[specifier] = guid; 833 specifier_guid_map_[specifier] = guid;
833 } 834 }
834 network->SetGuid(guid); 835 network->SetGuid(guid);
835 } 836 }
836 837
837 void NetworkStateHandler::NotifyDeviceListChanged() { 838 void NetworkStateHandler::NotifyDeviceListChanged() {
838 SCOPED_NET_LOG_IF_SLOW(); 839 SCOPED_NET_LOG_IF_SLOW();
839 NET_LOG_DEBUG("NOTIFY:DeviceListChanged", 840 NET_LOG_DEBUG("NOTIFY:DeviceListChanged",
840 base::StringPrintf("Size:%" PRIuS, device_list_.size())); 841 base::StringPrintf("Size:%" PRIuS, device_list_.size()));
841 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 842 for (auto& observer : observers_)
842 DeviceListChanged()); 843 observer.DeviceListChanged();
843 } 844 }
844 845
845 DeviceState* NetworkStateHandler::GetModifiableDeviceState( 846 DeviceState* NetworkStateHandler::GetModifiableDeviceState(
846 const std::string& device_path) const { 847 const std::string& device_path) const {
847 ManagedState* managed = GetModifiableManagedState(&device_list_, device_path); 848 ManagedState* managed = GetModifiableManagedState(&device_list_, device_path);
848 if (!managed) 849 if (!managed)
849 return nullptr; 850 return nullptr;
850 return managed->AsDeviceState(); 851 return managed->AsDeviceState();
851 } 852 }
852 853
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 default_network_path_.clear(); 904 default_network_path_.clear();
904 SortNetworkList(); 905 SortNetworkList();
905 NotifyDefaultNetworkChanged(nullptr); 906 NotifyDefaultNetworkChanged(nullptr);
906 } 907 }
907 } 908 }
908 std::string desc = "NetworkConnectionStateChanged"; 909 std::string desc = "NetworkConnectionStateChanged";
909 if (notify_default) 910 if (notify_default)
910 desc = "Default" + desc; 911 desc = "Default" + desc;
911 NET_LOG(EVENT) << "NOTIFY: " << desc << ": " << GetLogName(network) << ": " 912 NET_LOG(EVENT) << "NOTIFY: " << desc << ": " << GetLogName(network) << ": "
912 << network->connection_state(); 913 << network->connection_state();
913 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 914 for (auto& observer : observers_)
914 NetworkConnectionStateChanged(network)); 915 observer.NetworkConnectionStateChanged(network);
915 if (notify_default) 916 if (notify_default)
916 NotifyDefaultNetworkChanged(network); 917 NotifyDefaultNetworkChanged(network);
917 } 918 }
918 919
919 void NetworkStateHandler::NotifyDefaultNetworkChanged( 920 void NetworkStateHandler::NotifyDefaultNetworkChanged(
920 const NetworkState* default_network) { 921 const NetworkState* default_network) {
921 SCOPED_NET_LOG_IF_SLOW(); 922 SCOPED_NET_LOG_IF_SLOW();
922 NET_LOG_EVENT("NOTIFY:DefaultNetworkChanged", GetLogName(default_network)); 923 NET_LOG_EVENT("NOTIFY:DefaultNetworkChanged", GetLogName(default_network));
923 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 924 for (auto& observer : observers_)
924 DefaultNetworkChanged(default_network)); 925 observer.DefaultNetworkChanged(default_network);
925 } 926 }
926 927
927 void NetworkStateHandler::NotifyNetworkPropertiesUpdated( 928 void NetworkStateHandler::NotifyNetworkPropertiesUpdated(
928 const NetworkState* network) { 929 const NetworkState* network) {
929 SCOPED_NET_LOG_IF_SLOW(); 930 SCOPED_NET_LOG_IF_SLOW();
930 NET_LOG_DEBUG("NOTIFY:NetworkPropertiesUpdated", GetLogName(network)); 931 NET_LOG_DEBUG("NOTIFY:NetworkPropertiesUpdated", GetLogName(network));
931 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 932 for (auto& observer : observers_)
932 NetworkPropertiesUpdated(network)); 933 observer.NetworkPropertiesUpdated(network);
933 } 934 }
934 935
935 void NetworkStateHandler::NotifyDevicePropertiesUpdated( 936 void NetworkStateHandler::NotifyDevicePropertiesUpdated(
936 const DeviceState* device) { 937 const DeviceState* device) {
937 SCOPED_NET_LOG_IF_SLOW(); 938 SCOPED_NET_LOG_IF_SLOW();
938 NET_LOG_DEBUG("NOTIFY:DevicePropertiesUpdated", GetLogName(device)); 939 NET_LOG_DEBUG("NOTIFY:DevicePropertiesUpdated", GetLogName(device));
939 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 940 for (auto& observer : observers_)
940 DevicePropertiesUpdated(device)); 941 observer.DevicePropertiesUpdated(device);
941 } 942 }
942 943
943 void NetworkStateHandler::NotifyScanCompleted(const DeviceState* device) { 944 void NetworkStateHandler::NotifyScanCompleted(const DeviceState* device) {
944 SCOPED_NET_LOG_IF_SLOW(); 945 SCOPED_NET_LOG_IF_SLOW();
945 NET_LOG_DEBUG("NOTIFY:ScanCompleted", GetLogName(device)); 946 NET_LOG_DEBUG("NOTIFY:ScanCompleted", GetLogName(device));
946 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 947 for (auto& observer : observers_)
947 ScanCompleted(device)); 948 observer.ScanCompleted(device);
948 } 949 }
949 950
950 std::string NetworkStateHandler::GetTechnologyForType( 951 std::string NetworkStateHandler::GetTechnologyForType(
951 const NetworkTypePattern& type) const { 952 const NetworkTypePattern& type) const {
952 if (type.MatchesType(shill::kTypeEthernet)) 953 if (type.MatchesType(shill::kTypeEthernet))
953 return shill::kTypeEthernet; 954 return shill::kTypeEthernet;
954 955
955 if (type.MatchesType(shill::kTypeWifi)) 956 if (type.MatchesType(shill::kTypeWifi))
956 return shill::kTypeWifi; 957 return shill::kTypeWifi;
957 958
(...skipping 27 matching lines...) Expand all
985 if (type.MatchesType(shill::kTypeBluetooth)) 986 if (type.MatchesType(shill::kTypeBluetooth))
986 technologies.emplace_back(shill::kTypeBluetooth); 987 technologies.emplace_back(shill::kTypeBluetooth);
987 if (type.MatchesType(shill::kTypeVPN)) 988 if (type.MatchesType(shill::kTypeVPN))
988 technologies.emplace_back(shill::kTypeVPN); 989 technologies.emplace_back(shill::kTypeVPN);
989 990
990 CHECK_GT(technologies.size(), 0ul); 991 CHECK_GT(technologies.size(), 0ul);
991 return technologies; 992 return technologies;
992 } 993 }
993 994
994 } // namespace chromeos 995 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/network_sms_handler.cc ('k') | chromeos/settings/timezone_settings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698