shill: Remove trivial use of iterators
Move trivial iterations through containers from using an iterator
to using range-based for loops. In instances where it makes sense
also use "auto" for iterators in non-trivial for loops as well.
BUG=None
TEST=Unit tests
Change-Id: I840d90fb62dc96d45f63144462b9a53b28c25ee9
Reviewed-on: https://chromium-review.googlesource.com/198051
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: Paul Stewart <pstew@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
diff --git a/HACKING b/HACKING
index 76f0040..0661219 100644
--- a/HACKING
+++ b/HACKING
@@ -131,4 +131,13 @@
Test that the property changes are handled correctly by adding test
cases similar to those in CellularServiceTest.PropertyChanges, and
- CellularServiceTest.CustomSetterNoopChange.
\ No newline at end of file
+ CellularServiceTest.CustomSetterNoopChange.
+
+- When performing trivial iteration through a container, prefer using
+ range based for loops, preferably:
+
+ for (const auto &element : container) {
+
+ Remove "const" where necessary if the element will be modified during
+ the loop. Removal of the "const" and reference for trivial types is
+ allowed but not necessary.
diff --git a/cellular_service.cc b/cellular_service.cc
index 380531f..be41575 100644
--- a/cellular_service.cc
+++ b/cellular_service.cc
@@ -191,8 +191,7 @@
}
Stringmap *CellularService::GetLastGoodApn() {
- Stringmap::iterator it =
- last_good_apn_info_.find(kApnProperty);
+ Stringmap::iterator it = last_good_apn_info_.find(kApnProperty);
if (it == last_good_apn_info_.end() || it->second.empty())
return NULL;
return &last_good_apn_info_;
diff --git a/connection.cc b/connection.cc
index 569c3df..e4efebf 100644
--- a/connection.cc
+++ b/connection.cc
@@ -505,8 +505,7 @@
void Connection::DetachBinder(Binder *binder) {
SLOG(Connection, 2) << __func__ << "(" << binder->name() << ")" << " @ "
<< interface_name_;
- for (deque<Binder *>::iterator it = binders_.begin();
- it != binders_.end(); ++it) {
+ for (auto it = binders_.begin(); it != binders_.end(); ++it) {
if (binder == *it) {
binders_.erase(it);
return;
diff --git a/crypto_provider.cc b/crypto_provider.cc
index 8d5c157..6b94f8f 100644
--- a/crypto_provider.cc
+++ b/crypto_provider.cc
@@ -33,8 +33,7 @@
}
string CryptoProvider::Encrypt(const string &plaintext) {
- for (Cryptos::iterator it = cryptos_.begin(); it != cryptos_.end(); ++it) {
- CryptoInterface *crypto = *it;
+ for (auto crypto : cryptos_) {
string ciphertext;
if (crypto->Encrypt(plaintext, &ciphertext)) {
const string prefix = crypto->GetID() + ":";
@@ -46,8 +45,7 @@
}
string CryptoProvider::Decrypt(const string &ciphertext) {
- for (Cryptos::iterator it = cryptos_.begin(); it != cryptos_.end(); ++it) {
- CryptoInterface *crypto = *it;
+ for (auto crypto : cryptos_) {
const string prefix = crypto->GetID() + ":";
if (StartsWithASCII(ciphertext, prefix, true)) {
string to_decrypt = ciphertext;
diff --git a/crypto_rot47.cc b/crypto_rot47.cc
index 79c427d..a934355 100644
--- a/crypto_rot47.cc
+++ b/crypto_rot47.cc
@@ -23,13 +23,12 @@
const char kRotMax = kRotMin + kRotSize - 1;
*ciphertext = plaintext;
- for (string::iterator ch = ciphertext->begin();
- ch != ciphertext->end(); ++ch) {
- if (*ch < kRotMin || *ch > kRotMax) {
+ for (auto &ch : *ciphertext) {
+ if (ch < kRotMin || ch > kRotMax) {
continue;
}
- int rot = *ch + kRotHalf;
- *ch = (rot > kRotMax) ? rot - kRotSize : rot;
+ int rot = ch + kRotHalf;
+ ch = (rot > kRotMax) ? rot - kRotSize : rot;
}
return true;
}
diff --git a/device_dbus_adaptor.cc b/device_dbus_adaptor.cc
index 1edf954..6a9863e 100644
--- a/device_dbus_adaptor.cc
+++ b/device_dbus_adaptor.cc
@@ -104,9 +104,8 @@
const vector<string> &value) {
SLOG(DBus, 2) << __func__ << ": " << name;
vector< ::DBus::Path> paths;
- vector<string>::const_iterator it;
- for (it = value.begin(); it != value.end(); ++it) {
- paths.push_back(*it);
+ for (const auto &element : value) {
+ paths.push_back(element);
}
PropertyChanged(name, DBusAdaptor::PathsToVariant(paths));
diff --git a/device_info.cc b/device_info.cc
index c2ce0c0..d9fafdb 100644
--- a/device_info.cc
+++ b/device_info.cc
@@ -137,10 +137,9 @@
vector<string> DeviceInfo::GetUninitializedTechnologies() const {
set<string> unique_technologies;
set<Technology::Identifier> initialized_technologies;
- for (map<int, Info>::const_iterator it = infos_.begin(); it != infos_.end();
- ++it) {
- Technology::Identifier technology = it->second.technology;
- if (it->second.device) {
+ for (const auto &info : infos_) {
+ Technology::Identifier technology = info.second.technology;
+ if (info.second.device) {
// If there is more than one device for a technology and at least
// one of them has been initialized, make sure that it doesn't get
// listed as uninitialized.
@@ -709,16 +708,15 @@
if (!info) {
return;
}
- const vector<AddressData> &addresses = info->ip_addresses;
- vector<AddressData>::const_iterator iter;
- for (iter = addresses.begin(); iter != addresses.end(); ++iter) {
- if (iter->address.family() == IPAddress::kFamilyIPv4 ||
- (iter->scope == RT_SCOPE_UNIVERSE &&
- (iter->flags & ~IFA_F_TEMPORARY) == 0)) {
+ for (const auto &address_info : info->ip_addresses) {
+ if (address_info.address.family() == IPAddress::kFamilyIPv4 ||
+ (address_info.scope == RT_SCOPE_UNIVERSE &&
+ (address_info.flags & ~IFA_F_TEMPORARY) == 0)) {
SLOG(Device, 2) << __func__ << ": removing ip address "
- << iter->address.ToString()
+ << address_info.address.ToString()
<< " from interface " << interface_index;
- rtnl_handler_->RemoveInterfaceAddress(interface_index, iter->address);
+ rtnl_handler_->RemoveInterfaceAddress(interface_index,
+ address_info.address);
}
}
}
diff --git a/dns_client.cc b/dns_client.cc
index e3ae826..f2d0ae4 100644
--- a/dns_client.cc
+++ b/dns_client.cc
@@ -87,11 +87,9 @@
memset(&options, 0, sizeof(options));
vector<struct in_addr> server_addresses;
- for (vector<string>::iterator it = dns_servers_.begin();
- it != dns_servers_.end();
- ++it) {
+ for (const auto &server : dns_servers_) {
struct in_addr addr;
- if (inet_aton(it->c_str(), &addr) != 0) {
+ if (inet_aton(server.c_str(), &addr) != 0) {
server_addresses.push_back(addr);
}
}
diff --git a/eap_credentials.cc b/eap_credentials.cc
index 6cfeda3..a2657da 100644
--- a/eap_credentials.cc
+++ b/eap_credentials.cc
@@ -139,10 +139,9 @@
append_uint32(WPASupplicant::kDefaultEngine);
}
- vector<KeyVal>::iterator it;
- for (it = propertyvals.begin(); it != propertyvals.end(); ++it) {
- if (strlen((*it).second) > 0) {
- (*params)[(*it).first].writer().append_string((*it).second);
+ for (const auto &keyval : propertyvals) {
+ if (strlen(keyval.second) > 0) {
+ (*params)[keyval.first].writer().append_string(keyval.second);
}
}
}
diff --git a/hook_table.cc b/hook_table.cc
index 6d23569..418ce07 100644
--- a/hook_table.cc
+++ b/hook_table.cc
@@ -74,16 +74,14 @@
// Otherwise, if the first action completes inline, its call to
// ActionComplete() will cause the |done| callback to be invoked before the
// rest of the actions get started.
- for (HookTableMap::iterator it = hook_table_.begin();
- it != hook_table_.end(); ++it) {
- HookAction *action = &it->second;
+ for (auto &hook_entry : hook_table_) {
+ HookAction *action = &hook_entry.second;
action->started = true;
action->completed = false;
}
// Now start the actions.
- for (HookTableMap::iterator it = hook_table_.begin();
- it != hook_table_.end(); ++it) {
- it->second.start.Run();
+ for (auto &hook_entry : hook_table_) {
+ hook_entry.second.start.Run();
}
}
diff --git a/http_proxy.cc b/http_proxy.cc
index 238a679..7d040ea 100644
--- a/http_proxy.cc
+++ b/http_proxy.cc
@@ -241,18 +241,17 @@
string host;
bool found_via = false;
bool found_connection = false;
- for (vector<string>::iterator it = client_headers_.begin();
- it != client_headers_.end(); ++it) {
- if (StartsWithASCII(*it, "Host:", false)) {
- host = it->substr(5);
- } else if (StartsWithASCII(*it, "Via:", false)) {
+ for (auto &header : client_headers_) {
+ if (StartsWithASCII(header, "Host:", false)) {
+ host = header.substr(5);
+ } else if (StartsWithASCII(header, "Via:", false)) {
found_via = true;
- (*it).append(StringPrintf(", %s shill-proxy", client_version_.c_str()));
- } else if (StartsWithASCII(*it, "Connection:", false)) {
+ header.append(StringPrintf(", %s shill-proxy", client_version_.c_str()));
+ } else if (StartsWithASCII(header, "Connection:", false)) {
found_connection = true;
- (*it).assign("Connection: close");
- } else if (StartsWithASCII(*it, "Proxy-Connection:", false)) {
- (*it).assign("Proxy-Connection: close");
+ header.assign("Connection: close");
+ } else if (StartsWithASCII(header, "Proxy-Connection:", false)) {
+ header.assign("Proxy-Connection: close");
}
}
@@ -267,9 +266,8 @@
// Assemble the request as it will be sent to the server.
client_data_.Clear();
if (!LowerCaseEqualsASCII(client_method_, kHTTPMethodConnect)) {
- for (vector<string>::iterator it = client_headers_.begin();
- it != client_headers_.end(); ++it) {
- client_data_.Append(ByteString(*it + "\r\n", false));
+ for (const auto &header : client_headers_) {
+ client_data_.Append(ByteString(header + "\r\n", false));
}
client_data_.Append(ByteString(string("\r\n"), false));
}
diff --git a/key_file_store.cc b/key_file_store.cc
index cfcd487..d0eb5c7 100644
--- a/key_file_store.cc
+++ b/key_file_store.cc
@@ -138,9 +138,9 @@
set<string> KeyFileStore::GetGroupsWithKey(const string &key) const {
set<string> groups = GetGroups();
set<string> groups_with_key;
- for (set<string>::iterator it = groups.begin(); it != groups.end(); ++it) {
- if (glib_->KeyFileHasKey(key_file_, (*it).c_str(), key.c_str(), NULL)) {
- groups_with_key.insert(*it);
+ for (const auto &group : groups) {
+ if (glib_->KeyFileHasKey(key_file_, group.c_str(), key.c_str(), NULL)) {
+ groups_with_key.insert(group);
}
}
return groups_with_key;
@@ -150,9 +150,9 @@
const KeyValueStore &properties) const {
set<string> groups = GetGroups();
set<string> groups_with_properties;
- for (set<string>::iterator it = groups.begin(); it != groups.end(); ++it) {
- if (DoesGroupMatchProperties(*it, properties)) {
- groups_with_properties.insert(*it);
+ for (const auto &group : groups) {
+ if (DoesGroupMatchProperties(group, properties)) {
+ groups_with_properties.insert(group);
}
}
return groups_with_properties;
@@ -339,9 +339,8 @@
const vector<string> &value) {
CHECK(key_file_);
vector<const char *> list;
- for (vector<string>::const_iterator it = value.begin();
- it != value.end(); ++it) {
- list.push_back(it->c_str());
+ for (const auto &string_entry : value) {
+ list.push_back(string_entry.c_str());
}
glib_->KeyFileSetStringList(key_file_,
group.c_str(),
@@ -372,32 +371,21 @@
bool KeyFileStore::DoesGroupMatchProperties(
const string &group, const KeyValueStore &properties) const {
map<string, bool>::const_iterator bool_it;
- for (bool_it = properties.bool_properties().begin();
- bool_it != properties.bool_properties().end();
- ++bool_it) {
+ for (const auto &property : properties.bool_properties()) {
bool value;
- if (!GetBool(group, bool_it->first, &value) ||
- value != bool_it->second) {
+ if (!GetBool(group, property.first, &value) || value != property.second) {
return false;
}
}
- map<string, int32>::const_iterator int_it;
- for (int_it = properties.int_properties().begin();
- int_it != properties.int_properties().end();
- ++int_it) {
+ for (const auto &property : properties.int_properties()) {
int value;
- if (!GetInt(group, int_it->first, &value) ||
- value != int_it->second) {
+ if (!GetInt(group, property.first, &value) || value != property.second) {
return false;
}
}
- map<string, string>::const_iterator string_it;
- for (string_it = properties.string_properties().begin();
- string_it != properties.string_properties().end();
- ++string_it) {
+ for (const auto &property : properties.string_properties()) {
string value;
- if (!GetString(group, string_it->first, &value) ||
- value != string_it->second) {
+ if (!GetString(group, property.first, &value) || value != property.second) {
return false;
}
}
diff --git a/manager.cc b/manager.cc
index 13e9409..cd1e072 100644
--- a/manager.cc
+++ b/manager.cc
@@ -212,7 +212,7 @@
#if !defined(DISABLE_CELLULAR)
modem_info_.Start();
#endif // DISABLE_CELLULAR
- for (auto provider_mapping : providers_) {
+ for (const auto &provider_mapping : providers_) {
provider_mapping.second->Start();
}
}
@@ -220,33 +220,27 @@
void Manager::Stop() {
running_ = false;
// Persist device information to disk;
- vector<DeviceRefPtr>::iterator devices_it;
- for (devices_it = devices_.begin(); devices_it != devices_.end();
- ++devices_it) {
- UpdateDevice(*devices_it);
+ for (const auto &device : devices_) {
+ UpdateDevice(device);
}
UpdateWiFiProvider();
// Persist profile, service information to disk.
- vector<ProfileRefPtr>::iterator profiles_it;
- for (profiles_it = profiles_.begin(); profiles_it != profiles_.end();
- ++profiles_it) {
+ for (const auto &profile : profiles_) {
// Since this happens in a loop, the current manager state is stored to
// all default profiles in the stack. This is acceptable because the
// only time multiple default profiles are loaded are during autotests.
- (*profiles_it)->Save();
+ profile->Save();
}
- vector<ServiceRefPtr>::iterator services_it;
Error e;
- for (services_it = services_.begin(); services_it != services_.end();
- ++services_it) {
- (*services_it)->Disconnect(&e);
+ for (const auto &service : services_) {
+ service->Disconnect(&e);
}
adaptor_->UpdateRunning();
- for (auto provider_mapping : providers_) {
+ for (const auto &provider_mapping : providers_) {
provider_mapping.second->Stop();
}
#if !defined(DISABLE_CELLULAR)
@@ -353,10 +347,8 @@
}
bool Manager::HasProfile(const Profile::Identifier &ident) {
- for (vector<ProfileRefPtr>::const_iterator it = profiles_.begin();
- it != profiles_.end();
- ++it) {
- if ((*it)->MatchesIdentifier(ident)) {
+ for (const auto &profile : profiles_) {
+ if (profile->MatchesIdentifier(ident)) {
return true;
}
}
@@ -432,7 +424,7 @@
// Offer the Profile contents to the service providers which will
// create new services if necessary.
- for (auto provider_mapping : providers_) {
+ for (const auto &provider_mapping : providers_) {
provider_mapping.second->CreateServicesFromProfile(profile);
}
@@ -628,8 +620,7 @@
bool Manager::HandleProfileEntryDeletion(const ProfileRefPtr &profile,
const std::string &entry_name) {
bool moved_services = false;
- for (vector<ServiceRefPtr>::iterator it = services_.begin();
- it != services_.end();) {
+ for (auto it = services_.begin(); it != services_.end();) {
if ((*it)->profile().get() == profile.get() &&
(*it)->GetStorageIdentifier() == entry_name) {
profile->AbandonService(*it);
@@ -660,11 +651,10 @@
ServiceRefPtr Manager::GetServiceWithStorageIdentifier(
const ProfileRefPtr &profile, const std::string &entry_name, Error *error) {
- for (vector<ServiceRefPtr>::iterator it = services_.begin();
- it != services_.end(); ++it) {
- if ((*it)->profile().get() == profile.get() &&
- (*it)->GetStorageIdentifier() == entry_name) {
- return *it;
+ for (const auto &service : services_) {
+ if (service->profile().get() == profile.get() &&
+ service->GetStorageIdentifier() == entry_name) {
+ return service;
}
}
@@ -680,10 +670,9 @@
ServiceRefPtr Manager::GetServiceWithGUID(
const std::string &guid, Error *error) {
- for (vector<ServiceRefPtr>::iterator it = services_.begin();
- it != services_.end(); ++it) {
- if ((*it)->guid() == guid) {
- return *it;
+ for (const auto &service : services_) {
+ if (service->guid() == guid) {
+ return service;
}
}
@@ -734,13 +723,11 @@
bool Manager::IsProfileBefore(const ProfileRefPtr &a,
const ProfileRefPtr &b) const {
DCHECK(a != b);
- for (vector<ProfileRefPtr>::const_iterator it = profiles_.begin();
- it != profiles_.end();
- ++it) {
- if (*it == a) {
+ for (const auto &profile : profiles_) {
+ if (profile == a) {
return true;
}
- if (*it == b) {
+ if (profile == b) {
return false;
}
}
@@ -770,10 +757,9 @@
Technology::Identifier technology) const {
vector<DeviceRefPtr> devices;
FilterByTechnology(technology, &devices);
- for (vector<DeviceRefPtr>::const_iterator it = devices.begin();
- it != devices.end(); ++it) {
- if ((*it)->enabled()) {
- return *it;
+ for (const auto &device : devices_) {
+ if (device->enabled()) {
+ return device;
}
}
return NULL;
@@ -803,11 +789,9 @@
ProfileRefPtr Manager::LookupProfileByRpcIdentifier(
const string &profile_rpcid) {
- for (vector<ProfileRefPtr>::iterator it = profiles_.begin();
- it != profiles_.end();
- ++it) {
- if (profile_rpcid == (*it)->GetRpcIdentifier()) {
- return *it;
+ for (const auto &profile : profiles_) {
+ if (profile_rpcid == profile->GetRpcIdentifier()) {
+ return profile;
}
}
return NULL;
@@ -893,9 +877,8 @@
void Manager::RegisterDevice(const DeviceRefPtr &to_manage) {
LOG(INFO) << "Device " << to_manage->FriendlyName() << " registered.";
- for (vector<DeviceRefPtr>::iterator it = devices_.begin();
- it != devices_.end(); ++it) {
- if (to_manage.get() == it->get())
+ for (const auto &device : devices_) {
+ if (to_manage == device)
return;
}
devices_.push_back(to_manage);
@@ -916,8 +899,7 @@
void Manager::DeregisterDevice(const DeviceRefPtr &to_forget) {
SLOG(Manager, 2) << __func__ << "(" << to_forget->FriendlyName() << ")";
- vector<DeviceRefPtr>::iterator it;
- for (it = devices_.begin(); it != devices_.end(); ++it) {
+ for (auto it = devices_.begin(); it != devices_.end(); ++it) {
if (to_forget.get() == it->get()) {
SLOG(Manager, 2) << "Deregistered device: " << to_forget->UniqueName();
UpdateDevice(to_forget);
@@ -934,18 +916,16 @@
void Manager::LoadDeviceFromProfiles(const DeviceRefPtr &device) {
// We are applying device properties from the DefaultProfile, and adding the
// union of hidden services in all loaded profiles to the device.
- for (vector<ProfileRefPtr>::iterator it = profiles_.begin();
- it != profiles_.end(); ++it) {
+ for (const auto &profile : profiles_) {
// Load device configuration, if any exists, as well as hidden services.
- (*it)->ConfigureDevice(device);
+ profile->ConfigureDevice(device);
}
}
void Manager::EmitDeviceProperties() {
- vector<DeviceRefPtr>::iterator it;
vector<string> device_paths;
- for (it = devices_.begin(); it != devices_.end(); ++it) {
- device_paths.push_back((*it)->GetRpcIdentifier());
+ for (const auto &device : devices_) {
+ device_paths.push_back(device->GetRpcIdentifier());
}
adaptor_->EmitRpcIdentifierArrayChanged(kDevicesProperty,
device_paths);
@@ -971,9 +951,8 @@
}
bool Manager::HasService(const ServiceRefPtr &service) {
- vector<ServiceRefPtr>::iterator it;
- for (it = services_.begin(); it != services_.end(); ++it) {
- if ((*it)->unique_name() == service->unique_name())
+ for (const auto &manager_service : services_) {
+ if (manager_service->unique_name() == service->unique_name())
return true;
}
return false;
@@ -985,9 +964,8 @@
MatchProfileWithService(to_manage);
// Now add to OUR list.
- vector<ServiceRefPtr>::iterator it;
- for (it = services_.begin(); it != services_.end(); ++it) {
- CHECK(to_manage->unique_name() != (*it)->unique_name());
+ for (const auto &service : services_) {
+ CHECK(to_manage->unique_name() != service->unique_name());
}
services_.push_back(to_manage);
SortServices();
@@ -1044,8 +1022,7 @@
// updating profile would be the DefaultProfile at the bottom of the stack.
// Autotests, differ from the normal scenario, however, in that they push a
// second test-only DefaultProfile.
- for (vector<ProfileRefPtr>::reverse_iterator rit = profiles_.rbegin();
- rit != profiles_.rend(); ++rit) {
+ for (auto rit = profiles_.rbegin(); rit != profiles_.rend(); ++rit) {
if ((*rit)->UpdateDevice(to_update)) {
return;
}
@@ -1058,8 +1035,7 @@
// updating profile would be the DefaultProfile at the bottom of the stack.
// Autotests, differ from the normal scenario, however, in that they push a
// second test-only DefaultProfile.
- for (vector<ProfileRefPtr>::reverse_iterator rit = profiles_.rbegin();
- rit != profiles_.rend(); ++rit) {
+ for (auto rit = profiles_.rbegin(); rit != profiles_.rend(); ++rit) {
if ((*rit)->UpdateWiFiProvider(*wifi_provider_)) {
return;
}
@@ -1259,10 +1235,8 @@
}
void Manager::NotifyDefaultServiceChanged(const ServiceRefPtr &service) {
- for (map<int, ServiceCallback>::const_iterator it =
- default_service_callbacks_.begin();
- it != default_service_callbacks_.end(); ++it) {
- it->second.Run(service);
+ for (const auto &callback : default_service_callbacks_) {
+ callback.second.Run(service);
}
metrics_->NotifyDefaultServiceChanged(service);
EmitDefaultService();
@@ -1277,9 +1251,8 @@
}
void Manager::OnSuspendImminent(int suspend_id) {
- vector<DeviceRefPtr>::iterator it;
- for (it = devices_.begin(); it != devices_.end(); ++it) {
- (*it)->OnBeforeSuspend();
+ for (const auto &device : devices_) {
+ device->OnBeforeSuspend();
}
if (!RunTerminationActionsAndNotifyMetrics(
Bind(&Manager::OnSuspendActionsComplete, AsWeakPtr(), suspend_id),
@@ -1291,14 +1264,12 @@
void Manager::OnSuspendDone(int suspend_id) {
metrics_->NotifySuspendDone();
- vector<ServiceRefPtr>::iterator sit;
- for (sit = services_.begin(); sit != services_.end(); ++sit) {
- (*sit)->OnAfterResume();
+ for (const auto &service : services_) {
+ service->OnAfterResume();
}
SortServices();
- vector<DeviceRefPtr>::iterator it;
- for (it = devices_.begin(); it != devices_.end(); ++it) {
- (*it)->OnAfterResume();
+ for (const auto &device : devices_) {
+ device->OnAfterResume();
}
}
@@ -1312,18 +1283,16 @@
void Manager::FilterByTechnology(Technology::Identifier tech,
vector<DeviceRefPtr> *found) const {
CHECK(found);
- vector<DeviceRefPtr>::const_iterator it;
- for (it = devices_.begin(); it != devices_.end(); ++it) {
- if ((*it)->technology() == tech)
- found->push_back(*it);
+ for (const auto &device : devices_) {
+ if (device->technology() == tech)
+ found->push_back(device);
}
}
ServiceRefPtr Manager::FindService(const string &name) {
- vector<ServiceRefPtr>::iterator it;
- for (it = services_.begin(); it != services_.end(); ++it) {
- if (name == (*it)->unique_name())
- return *it;
+ for (const auto &service : services_) {
+ if (name == service->unique_name())
+ return service;
}
return NULL;
}
@@ -1497,10 +1466,9 @@
}
// Perform auto-connect.
- for (vector<ServiceRefPtr>::iterator it = services_.begin();
- it != services_.end(); ++it) {
- if ((*it)->auto_connect()) {
- (*it)->AutoConnect();
+ for (const auto &service : services_) {
+ if (service->auto_connect()) {
+ service->AutoConnect();
}
}
}
@@ -1515,18 +1483,16 @@
sort(services_copy.begin(), services_copy.end(),
ServiceSorter(kCompareConnectivityState, technology_order_));
set<Technology::Identifier> connecting_technologies;
- for (vector<ServiceRefPtr>::const_iterator it = services_copy.begin();
- it != services_copy.end();
- ++it) {
- if (!(*it)->connectable()) {
+ for (const auto &service : services_copy) {
+ if (!service->connectable()) {
// Due to service sort order, it is guaranteed that no services beyond
// this one will be connectable either.
break;
}
- if (!(*it)->auto_connect() || !(*it)->IsVisible()) {
+ if (!service->auto_connect() || !service->IsVisible()) {
continue;
}
- Technology::Identifier technology = (*it)->technology();
+ Technology::Identifier technology = service->technology();
if (!Technology::IsPrimaryConnectivityTechnology(technology) &&
!IsOnline()) {
// Non-primary services need some other service connected first.
@@ -1536,17 +1502,17 @@
// We have already started a connection for this technology.
continue;
}
- if ((*it)->explicitly_disconnected())
+ if (service->explicitly_disconnected())
continue;
connecting_technologies.insert(technology);
- if (!(*it)->IsConnected() && !(*it)->IsConnecting()) {
+ if (!service->IsConnected() && !service->IsConnecting()) {
// At first blush, it may seem that using Service::AutoConnect might
// be the right choice, however Service::IsAutoConnectable and its
// overridden implementations consider a host of conditions which
// prevent it from attempting a connection which we'd like to ignore
// for the purposes of this user-initiated action.
Error error;
- (*it)->Connect(&error, __func__);
+ service->Connect(&error, __func__);
if (error.IsFailure()) {
LOG(ERROR) << "Connection failed: " << error.message();
}
@@ -1575,29 +1541,26 @@
vector<string> Manager::AvailableTechnologies(Error */*error*/) {
set<string> unique_technologies;
- for (vector<DeviceRefPtr>::iterator it = devices_.begin();
- it != devices_.end(); ++it) {
+ for (const auto &device : devices_) {
unique_technologies.insert(
- Technology::NameFromIdentifier((*it)->technology()));
+ Technology::NameFromIdentifier(device->technology()));
}
return vector<string>(unique_technologies.begin(), unique_technologies.end());
}
vector<string> Manager::ConnectedTechnologies(Error */*error*/) {
set<string> unique_technologies;
- for (vector<DeviceRefPtr>::iterator it = devices_.begin();
- it != devices_.end(); ++it) {
- if ((*it)->IsConnected())
+ for (const auto &device : devices_) {
+ if (device->IsConnected())
unique_technologies.insert(
- Technology::NameFromIdentifier((*it)->technology()));
+ Technology::NameFromIdentifier(device->technology()));
}
return vector<string>(unique_technologies.begin(), unique_technologies.end());
}
bool Manager::IsTechnologyConnected(Technology::Identifier technology) const {
- for (vector<DeviceRefPtr>::const_iterator it = devices_.begin();
- it != devices_.end(); ++it) {
- if ((*it)->technology() == technology && (*it)->IsConnected())
+ for (const auto &device : devices_) {
+ if (device->technology() == technology && device->IsConnected())
return true;
}
return false;
@@ -1610,11 +1573,10 @@
vector<string> Manager::EnabledTechnologies(Error */*error*/) {
set<string> unique_technologies;
- for (vector<DeviceRefPtr>::iterator it = devices_.begin();
- it != devices_.end(); ++it) {
- if ((*it)->enabled())
+ for (const auto &device : devices_) {
+ if (device->enabled())
unique_technologies.insert(
- Technology::NameFromIdentifier((*it)->technology()));
+ Technology::NameFromIdentifier(device->technology()));
}
return vector<string>(unique_technologies.begin(), unique_technologies.end());
}
@@ -1625,31 +1587,25 @@
RpcIdentifiers Manager::EnumerateDevices(Error */*error*/) {
RpcIdentifiers device_rpc_ids;
- for (vector<DeviceRefPtr>::const_iterator it = devices_.begin();
- it != devices_.end();
- ++it) {
- device_rpc_ids.push_back((*it)->GetRpcIdentifier());
+ for (const auto &device : devices_) {
+ device_rpc_ids.push_back(device->GetRpcIdentifier());
}
return device_rpc_ids;
}
RpcIdentifiers Manager::EnumerateProfiles(Error */*error*/) {
RpcIdentifiers profile_rpc_ids;
- for (vector<ProfileRefPtr>::const_iterator it = profiles_.begin();
- it != profiles_.end();
- ++it) {
- profile_rpc_ids.push_back((*it)->GetRpcIdentifier());
+ for (const auto &profile : profiles_) {
+ profile_rpc_ids.push_back(profile->GetRpcIdentifier());
}
return profile_rpc_ids;
}
vector<string> Manager::EnumerateAvailableServices(Error */*error*/) {
vector<string> service_rpc_ids;
- for (vector<ServiceRefPtr>::const_iterator it = services_.begin();
- it != services_.end();
- ++it) {
- if ((*it)->IsVisible()) {
- service_rpc_ids.push_back((*it)->GetRpcIdentifier());
+ for (const auto &service : services_) {
+ if (service->IsVisible()) {
+ service_rpc_ids.push_back(service->GetRpcIdentifier());
}
}
return service_rpc_ids;
@@ -1657,21 +1613,17 @@
RpcIdentifiers Manager::EnumerateCompleteServices(Error */*error*/) {
vector<string> service_rpc_ids;
- for (vector<ServiceRefPtr>::const_iterator it = services_.begin();
- it != services_.end();
- ++it) {
- service_rpc_ids.push_back((*it)->GetRpcIdentifier());
+ for (const auto &service : services_) {
+ service_rpc_ids.push_back(service->GetRpcIdentifier());
}
return service_rpc_ids;
}
RpcIdentifiers Manager::EnumerateWatchedServices(Error */*error*/) {
vector<string> service_rpc_ids;
- for (vector<ServiceRefPtr>::const_iterator it = services_.begin();
- it != services_.end();
- ++it) {
- if ((*it)->IsVisible() && (*it)->IsActive(NULL)) {
- service_rpc_ids.push_back((*it)->GetRpcIdentifier());
+ for (const auto &service : services_) {
+ if (service->IsVisible() && service->IsActive(NULL)) {
+ service_rpc_ids.push_back(service->GetRpcIdentifier());
}
}
return service_rpc_ids;
@@ -1936,10 +1888,9 @@
ServiceRefPtr Manager::FindMatchingService(const KeyValueStore &args,
Error *error) {
- for (vector<ServiceRefPtr>::iterator it = services_.begin();
- it != services_.end(); ++it) {
- if ((*it)->DoPropertiesMatch(args)) {
- return *it;
+ for (const auto &service : services_) {
+ if (service->DoPropertiesMatch(args)) {
+ return service;
}
}
error->Populate(Error::kNotFound, "Matching service was not found");
@@ -1974,9 +1925,8 @@
}
void Manager::RecheckPortal(Error */*error*/) {
- for (vector<DeviceRefPtr>::iterator it = devices_.begin();
- it != devices_.end(); ++it) {
- if ((*it)->RequestPortalDetection()) {
+ for (const auto &device : devices_) {
+ if (device->RequestPortalDetection()) {
// Only start Portal Detection on the device with the default connection.
// We will get a "true" return value when we've found that device, and
// can end our loop early as a result.
@@ -1986,13 +1936,12 @@
}
void Manager::RecheckPortalOnService(const ServiceRefPtr &service) {
- for (vector<DeviceRefPtr>::iterator it = devices_.begin();
- it != devices_.end(); ++it) {
- if ((*it)->IsConnectedToService(service)) {
+ for (const auto &device : devices_) {
+ if (device->IsConnectedToService(service)) {
// As opposed to RecheckPortal() above, we explicitly stop and then
// restart portal detection, since the service to recheck was explicitly
// specified.
- (*it)->RestartPortalDetection();
+ device->RestartPortalDetection();
break;
}
}
@@ -2003,11 +1952,9 @@
if (technology == kTypeWifi || technology == "") {
vector<DeviceRefPtr> wifi_devices;
FilterByTechnology(Technology::kWifi, &wifi_devices);
- for (vector<DeviceRefPtr>::iterator it = wifi_devices.begin();
- it != wifi_devices.end();
- ++it) {
+ for (const auto &wifi_device : wifi_devices) {
metrics_->NotifyUserInitiatedEvent(Metrics::kUserInitiatedEventWifiScan);
- (*it)->Scan(scan_type, error, __func__);
+ wifi_device->Scan(scan_type, error, __func__);
}
} else {
// TODO(quiche): support scanning for other technologies?
@@ -2018,10 +1965,8 @@
string Manager::GetTechnologyOrder() {
vector<string> technology_names;
- for (vector<Technology::Identifier>::iterator it = technology_order_.begin();
- it != technology_order_.end();
- ++it) {
- technology_names.push_back(Technology::NameFromIdentifier(*it));
+ for (const auto &technology : technology_order_) {
+ technology_names.push_back(Technology::NameFromIdentifier(technology));
}
return JoinString(technology_names, ',');
diff --git a/manager_dbus_adaptor.cc b/manager_dbus_adaptor.cc
index bf5b46e..7e75986 100644
--- a/manager_dbus_adaptor.cc
+++ b/manager_dbus_adaptor.cc
@@ -81,9 +81,8 @@
const vector<string> &value) {
SLOG(DBus, 2) << __func__ << ": " << name;
vector< ::DBus::Path> paths;
- vector<string>::const_iterator it;
- for (it = value.begin(); it != value.end(); ++it) {
- paths.push_back(*it);
+ for (const auto &element : value) {
+ paths.push_back(element);
}
PropertyChanged(name, DBusAdaptor::PathsToVariant(paths));
@@ -367,17 +366,13 @@
::DBus::Error &/*error*/) {
SLOG(DBus, 2) << __func__;
map<string, ::DBus::Variant> networks;
- map<string, GeolocationInfos> geoinfo_map =
- manager_->GetNetworksForGeolocation();
- for (map<string, GeolocationInfos>::iterator it = geoinfo_map.begin();
- it != geoinfo_map.end(); ++it) {
+ for (const auto &network : manager_->GetNetworksForGeolocation()) {
Stringmaps value;
// Convert GeolocationInfos to their Stringmaps equivalent.
- for(GeolocationInfos::const_iterator geoinfo_it = it->second.begin();
- geoinfo_it != it->second.end(); ++geoinfo_it) {
- value.push_back(geoinfo_it->properties());
+ for(const auto &info : network.second) {
+ value.push_back(info.properties());
}
- networks[it->first] = StringmapsToVariant(value);
+ networks[network.first] = StringmapsToVariant(value);
}
return networks;
}
diff --git a/memory_log.cc b/memory_log.cc
index 1841ee1..745fd08 100644
--- a/memory_log.cc
+++ b/memory_log.cc
@@ -144,9 +144,8 @@
<< strerror(errno);
}
ssize_t bytes_written = 0;
- std::deque<std::string>::iterator it;
- for (it = log_.begin(); it != log_.end(); it++) {
- bytes_written += fwrite(it->c_str(), 1, it->size(), f);
+ for (const auto &entry : log_) {
+ bytes_written += fwrite(entry.c_str(), 1, entry.size(), f);
if (ferror(f)) {
LOG(ERROR) << "Write to memory log dump file failed.";
return -1;
@@ -170,9 +169,8 @@
}
bool MemoryLog::TestContainsMessageWithText(const char *msg) {
- std::deque<std::string>::const_iterator it;
- for (it = log_.begin(); it != log_.end(); ++it) {
- if (it->find(msg) != std::string::npos) {
+ for (const auto &entry : log_) {
+ if (entry.find(msg) != std::string::npos) {
return true;
}
}
diff --git a/metrics.cc b/metrics.cc
index f6ab14d..6efc711 100644
--- a/metrics.cc
+++ b/metrics.cc
@@ -1141,7 +1141,6 @@
Service::ConnectState new_state) {
const char *state_string = Service::ConnectStateToString(new_state);
SLOG(Metrics, 5) << __func__ << ": new_state=" << state_string;
- TimerReportersList::iterator it;
TimerReportersList &start_timers = service_metrics->start_on_state[new_state];
for (auto &start_timer : start_timers) {
SLOG(Metrics, 5) << "Starting timer for " << start_timer->histogram_name()
diff --git a/modem_info.cc b/modem_info.cc
index 29a418f..7a15563 100644
--- a/modem_info.cc
+++ b/modem_info.cc
@@ -81,9 +81,8 @@
}
void ModemInfo::OnDeviceInfoAvailable(const string &link_name) {
- for (ModemManagers::iterator it = modem_managers_.begin();
- it != modem_managers_.end(); ++it) {
- (*it)->OnDeviceInfoAvailable(link_name);
+ for (const auto &manager : modem_managers_) {
+ manager->OnDeviceInfoAvailable(link_name);
}
}
diff --git a/netlink_manager.cc b/netlink_manager.cc
index 0701dab..b283560 100644
--- a/netlink_manager.cc
+++ b/netlink_manager.cc
@@ -384,9 +384,8 @@
bool NetlinkManager::FindBroadcastHandler(const NetlinkMessageHandler &handler)
const {
- list<NetlinkMessageHandler>::const_iterator i;
- for (i = broadcast_handlers_.begin(); i != broadcast_handlers_.end(); ++i) {
- if ((*i).Equals(handler)) {
+ for (const auto &broadcast_handler : broadcast_handlers_) {
+ if (broadcast_handler.Equals(handler)) {
return true;
}
}
diff --git a/power_manager.cc b/power_manager.cc
index 637de72..6b55dc2 100644
--- a/power_manager.cc
+++ b/power_manager.cc
@@ -119,9 +119,8 @@
// Forward the message to all in |suspend_delays_|, whether or not they are
// registered.
- for (SuspendDelayMap::const_iterator it = suspend_delays_.begin();
- it != suspend_delays_.end(); ++it) {
- SuspendImminentCallback callback = it->second.imminent_callback;
+ for (const auto &delay : suspend_delays_) {
+ SuspendImminentCallback callback = delay.second.imminent_callback;
CHECK(!callback.is_null());
callback.Run(suspend_id);
}
@@ -133,9 +132,8 @@
suspending_ = false;
// Forward the message to all in |suspend_delays_|, whether or not they are
// registered.
- for (SuspendDelayMap::const_iterator it = suspend_delays_.begin();
- it != suspend_delays_.end(); ++it) {
- SuspendDoneCallback callback = it->second.done_callback;
+ for (const auto &delay : suspend_delays_) {
+ SuspendDoneCallback callback = delay.second.done_callback;
CHECK(!callback.is_null());
callback.Run(suspend_id);
}
@@ -148,9 +146,8 @@
void PowerManager::OnPowerManagerAppeared(const string &/*name*/,
const string &/*owner*/) {
- for (SuspendDelayMap::iterator it = suspend_delays_.begin();
- it != suspend_delays_.end(); ++it) {
- SuspendDelay &delay = it->second;
+ for (auto &delay_entry : suspend_delays_) {
+ SuspendDelay &delay = delay_entry.second;
// Attempt to unregister a stale suspend delay. This guards against a race
// where |AddSuspendDelay| managed to register a suspend delay with the
// newly appeared powerd instance before this function had a chance to
diff --git a/profile.cc b/profile.cc
index 0ec0121..475ac31 100644
--- a/profile.cc
+++ b/profile.cc
@@ -223,8 +223,8 @@
if (token.empty()) {
return false;
}
- for (string::const_iterator it = token.begin(); it != token.end(); ++it) {
- if (!IsAsciiAlpha(*it) && !IsAsciiDigit(*it)) {
+ for (auto chr : token) {
+ if (!IsAsciiAlpha(chr) && !IsAsciiDigit(chr)) {
return false;
}
}
@@ -283,9 +283,7 @@
vector<string> profile_lines;
base::SplitStringDontTrim(profile_data, '\n', &profile_lines);
- vector<string>::const_iterator it;
- for (it = profile_lines.begin(); it != profile_lines.end(); ++it) {
- const string &line = *it;
+ for (const auto &line : profile_lines) {
if (line.empty()) {
// This will be the case on the last line, so let's not complain about it.
continue;
@@ -314,9 +312,8 @@
bool Profile::SaveUserProfileList(const FilePath &path,
const vector<ProfileRefPtr> &profiles) {
vector<string> lines;
- vector<ProfileRefPtr>::const_iterator it;
- for (it = profiles.begin(); it != profiles.end(); ++it) {
- Identifier &id = (*it)->name_;
+ for (const auto &profile : profiles) {
+ Identifier &id = profile->name_;
if (id.user.empty()) {
continue;
}
@@ -359,15 +356,13 @@
}
vector<string> Profile::EnumerateEntries(Error */*error*/) {
- set<string> groups(storage_->GetGroups());
vector<string> service_groups;
// Filter this list down to only entries that correspond
// to a technology. (wifi_*, etc)
- for (set<string>::iterator it = groups.begin();
- it != groups.end(); ++it) {
- if (Technology::IdentifierFromStorageGroup(*it) != Technology::kUnknown)
- service_groups.push_back(*it);
+ for (const auto &group : storage_->GetGroups()) {
+ if (Technology::IdentifierFromStorageGroup(group) != Technology::kUnknown)
+ service_groups.push_back(group);
}
return service_groups;
diff --git a/routing_table.cc b/routing_table.cc
index 23d3d5a..180be41 100644
--- a/routing_table.cc
+++ b/routing_table.cc
@@ -113,22 +113,18 @@
SLOG(Route, 2) << __func__ << " index " << interface_index
<< " family " << IPAddress::GetAddressFamilyName(family);
- base::hash_map<int, vector<RoutingTableEntry> >::iterator table =
- tables_.find(interface_index);
-
+ Tables::iterator table = tables_.find(interface_index);
if (table == tables_.end()) {
SLOG(Route, 2) << __func__ << " no table";
return false;
}
- vector<RoutingTableEntry>::iterator nent;
-
- for (nent = table->second.begin(); nent != table->second.end(); ++nent) {
- if (nent->dst.IsDefault() && nent->dst.family() == family) {
- *entry = &(*nent);
+ for (auto &nent : table->second) {
+ if (nent.dst.IsDefault() && nent.dst.family() == family) {
+ *entry = &nent;
SLOG(Route, 2) << __func__ << ": found"
- << " gateway " << nent->gateway.ToString()
- << " metric " << nent->metric;
+ << " gateway " << nent.gateway.ToString()
+ << " metric " << nent.metric;
return true;
}
}
@@ -182,30 +178,28 @@
IPAddress::Family address_family = ipconfig->properties().address_family;
const vector<IPConfig::Route> &routes = ipconfig->properties().routes;
- for (vector<IPConfig::Route>::const_iterator it = routes.begin();
- it != routes.end();
- ++it) {
+ for (const auto &route : routes) {
SLOG(Route, 3) << "Installing route:"
- << " Destination: " << it->host
- << " Netmask: " << it->netmask
- << " Gateway: " << it->gateway;
+ << " Destination: " << route.host
+ << " Netmask: " << route.netmask
+ << " Gateway: " << route.gateway;
IPAddress destination_address(address_family);
IPAddress source_address(address_family); // Left as default.
IPAddress gateway_address(address_family);
- if (!destination_address.SetAddressFromString(it->host)) {
+ if (!destination_address.SetAddressFromString(route.host)) {
LOG(ERROR) << "Failed to parse host "
- << it->host;
+ << route.host;
ret = false;
continue;
}
- if (!gateway_address.SetAddressFromString(it->gateway)) {
+ if (!gateway_address.SetAddressFromString(route.gateway)) {
LOG(ERROR) << "Failed to parse gateway "
- << it->gateway;
+ << route.gateway;
ret = false;
continue;
}
destination_address.set_prefix(
- IPAddress::GetPrefixLengthFromMask(address_family, it->netmask));
+ IPAddress::GetPrefixLengthFromMask(address_family, route.netmask));
if (!AddRoute(interface_index,
RoutingTableEntry(destination_address,
source_address,
@@ -222,17 +216,13 @@
void RoutingTable::FlushRoutes(int interface_index) {
SLOG(Route, 2) << __func__;
- base::hash_map<int, vector<RoutingTableEntry> >::iterator table =
- tables_.find(interface_index);
-
+ auto table = tables_.find(interface_index);
if (table == tables_.end()) {
return;
}
- vector<RoutingTableEntry>::iterator nent;
-
- for (nent = table->second.begin(); nent != table->second.end(); ++nent) {
- ApplyRoute(interface_index, *nent, RTNLMessage::kModeDelete, 0);
+ for (const auto &nent : table->second) {
+ ApplyRoute(interface_index, nent, RTNLMessage::kModeDelete, 0);
}
table->second.clear();
}
@@ -240,14 +230,11 @@
void RoutingTable::FlushRoutesWithTag(int tag) {
SLOG(Route, 2) << __func__;
- base::hash_map<int, vector<RoutingTableEntry> >::iterator table;
- for (table = tables_.begin(); table != tables_.end(); ++table) {
- vector<RoutingTableEntry>::iterator nent;
-
- for (nent = table->second.begin(); nent != table->second.end();) {
+ for (auto &table : tables_) {
+ for (auto nent = table.second.begin(); nent != table.second.end();) {
if (nent->tag == tag) {
- ApplyRoute(table->first, *nent, RTNLMessage::kModeDelete, 0);
- nent = table->second.erase(nent);
+ ApplyRoute(table.first, *nent, RTNLMessage::kModeDelete, 0);
+ nent = table.second.erase(nent);
} else {
++nent;
}
@@ -385,9 +372,8 @@
return;
}
- vector<RoutingTableEntry> &table = tables_[interface_index];
- vector<RoutingTableEntry>::iterator nent;
- for (nent = table.begin(); nent != table.end(); ++nent) {
+ TableEntryVector &table = tables_[interface_index];
+ for (auto nent = table.begin(); nent != table.end(); ++nent) {
if (nent->dst.Equals(entry.dst) &&
nent->src.Equals(entry.src) &&
nent->gateway.Equals(entry.gateway) &&
diff --git a/routing_table.h b/routing_table.h
index 59b9817..5d5556b 100644
--- a/routing_table.h
+++ b/routing_table.h
@@ -31,6 +31,10 @@
// default route for an interface or modifying its metric (priority).
class RoutingTable {
public:
+ typedef std::vector<RoutingTableEntry> TableEntryVector;
+ typedef base::hash_map<int, TableEntryVector> Tables; // NOLINT
+ // NOLINT above: hash_map from base, no need to #include <hash_map>.
+
struct Query {
// Callback::Run(interface_index, entry)
typedef base::Callback<void(int, const RoutingTableEntry &)> Callback;
@@ -147,8 +151,7 @@
static const char kRouteFlushPath4[];
static const char kRouteFlushPath6[];
- base::hash_map<int, std::vector<RoutingTableEntry> > tables_; // NOLINT
- // NOLINT above: hash_map from base, no need to #include <hash_map>.
+ Tables tables_;
base::Callback<void(const RTNLMessage &)> route_callback_;
scoped_ptr<RTNLListener> route_listener_;
diff --git a/rtnl_handler.cc b/rtnl_handler.cc
index 470cf04..c6780c1 100644
--- a/rtnl_handler.cc
+++ b/rtnl_handler.cc
@@ -116,9 +116,8 @@
}
void RTNLHandler::AddListener(RTNLListener *to_add) {
- std::vector<RTNLListener *>::iterator it;
- for (it = listeners_.begin(); it != listeners_.end(); ++it) {
- if (to_add == *it)
+ for (const auto &listener : listeners_) {
+ if (to_add == listener)
return;
}
listeners_.push_back(to_add);
@@ -126,8 +125,7 @@
}
void RTNLHandler::RemoveListener(RTNLListener *to_remove) {
- std::vector<RTNLListener *>::iterator it;
- for (it = listeners_.begin(); it != listeners_.end(); ++it) {
+ for (auto it = listeners_.begin(); it != listeners_.end(); ++it) {
if (to_remove == *it) {
listeners_.erase(it);
return;
@@ -179,9 +177,8 @@
}
void RTNLHandler::DispatchEvent(int type, const RTNLMessage &msg) {
- std::vector<RTNLListener *>::iterator it;
- for (it = listeners_.begin(); it != listeners_.end(); ++it) {
- (*it)->NotifyEvent(type, msg);
+ for (const auto &listener : listeners_) {
+ listener->NotifyEvent(type, msg);
}
}
diff --git a/scope_logger.cc b/scope_logger.cc
index 16e5869..0291f1f 100644
--- a/scope_logger.cc
+++ b/scope_logger.cc
@@ -158,10 +158,8 @@
CHECK_LT(scope, kNumScopes);
if (scope_enabled_[scope] != enabled) {
- ScopeEnableChangedCallbacks &callbacks = log_scope_callbacks_[scope];
- ScopeEnableChangedCallbacks::iterator it;
- for (it = callbacks.begin(); it != callbacks.end(); ++it) {
- (*it).Run(enabled);
+ for (const auto &callback : log_scope_callbacks_[scope]) {
+ callback.Run(enabled);
}
}
diff --git a/shill_main.cc b/shill_main.cc
index 7549ccc..71d54d4 100644
--- a/shill_main.cc
+++ b/shill_main.cc
@@ -174,9 +174,8 @@
base::SplitString(cl->GetSwitchValueASCII(switches::kDeviceBlackList),
',', &device_list);
- vector<string>::iterator i;
- for (i = device_list.begin(); i != device_list.end(); ++i) {
- daemon.AddDeviceToBlackList(*i);
+ for (const auto &device : device_list) {
+ daemon.AddDeviceToBlackList(device);
}
}
diff --git a/technology.cc b/technology.cc
index e8687e6..e2e8a59 100644
--- a/technology.cc
+++ b/technology.cc
@@ -105,20 +105,18 @@
if (!technologies_string.empty())
base::SplitString(technologies_string, ',', &technology_parts);
- for (vector<string>::iterator it = technology_parts.begin();
- it != technology_parts.end();
- ++it) {
- Technology::Identifier identifier = Technology::IdentifierFromName(*it);
+ for (const auto &name : technology_parts) {
+ Technology::Identifier identifier = Technology::IdentifierFromName(name);
if (identifier == Technology::kUnknown) {
Error::PopulateAndLog(error, Error::kInvalidArguments,
- *it + " is an unknown technology name");
+ name + " is an unknown technology name");
return false;
}
if (ContainsKey(seen, identifier)) {
Error::PopulateAndLog(error, Error::kInvalidArguments,
- *it + " is duplicated in the list");
+ name + " is duplicated in the list");
return false;
}
seen.insert(identifier);
diff --git a/traffic_monitor.cc b/traffic_monitor.cc
index 9b87457..4bca373 100644
--- a/traffic_monitor.cc
+++ b/traffic_monitor.cc
@@ -71,29 +71,28 @@
IPPortToTxQueueLengthMap *tx_queue_lengths) {
SLOG(Link, 3) << __func__;
string device_ip_address = device_->ipconfig()->properties().address;
- vector<SocketInfo>::const_iterator it;
- for (it = socket_infos.begin(); it != socket_infos.end(); ++it) {
- SLOG(Link, 4) << "SocketInfo(IP=" << it->local_ip_address().ToString()
- << ", TX=" << it->transmit_queue_value()
- << ", State=" << it->connection_state()
- << ", TimerState=" << it->timer_state();
- if (it->local_ip_address().ToString() != device_ip_address ||
- it->transmit_queue_value() == 0 ||
- it->connection_state() != SocketInfo::kConnectionStateEstablished ||
- (it->timer_state() != SocketInfo::kTimerStateRetransmitTimerPending &&
- it->timer_state() !=
+ for (const auto &info : socket_infos) {
+ SLOG(Link, 4) << "SocketInfo(IP=" << info.local_ip_address().ToString()
+ << ", TX=" << info.transmit_queue_value()
+ << ", State=" << info.connection_state()
+ << ", TimerState=" << info.timer_state();
+ if (info.local_ip_address().ToString() != device_ip_address ||
+ info.transmit_queue_value() == 0 ||
+ info.connection_state() != SocketInfo::kConnectionStateEstablished ||
+ (info.timer_state() != SocketInfo::kTimerStateRetransmitTimerPending &&
+ info.timer_state() !=
SocketInfo::kTimerStateZeroWindowProbeTimerPending)) {
SLOG(Link, 4) << "Connection Filtered.";
continue;
}
- SLOG(Link, 3) << "Monitoring connection: TX=" << it->transmit_queue_value()
- << " TimerState=" << it->timer_state();
+ SLOG(Link, 3) << "Monitoring connection: TX=" << info.transmit_queue_value()
+ << " TimerState=" << info.timer_state();
string local_ip_port =
StringPrintf("%s:%d",
- it->local_ip_address().ToString().c_str(),
- it->local_port());
- (*tx_queue_lengths)[local_ip_port] = it->transmit_queue_value();
+ info.local_ip_address().ToString().c_str(),
+ info.local_port());
+ (*tx_queue_lengths)[local_ip_port] = info.transmit_queue_value();
}
}
@@ -113,14 +112,11 @@
SLOG(Link, 3) << __func__ << ": No interesting socket info";
ResetCongestedTxQueuesStatsWithLogging();
} else {
- IPPortToTxQueueLengthMap::iterator old_tx_queue_it;
- for (old_tx_queue_it = old_tx_queue_lengths_.begin();
- old_tx_queue_it != old_tx_queue_lengths_.end();
- ++old_tx_queue_it) {
+ for (const auto &length_entry : old_tx_queue_lengths_) {
IPPortToTxQueueLengthMap::iterator curr_tx_queue_it =
- curr_tx_queue_lengths.find(old_tx_queue_it->first);
+ curr_tx_queue_lengths.find(length_entry.first);
if (curr_tx_queue_it == curr_tx_queue_lengths.end() ||
- curr_tx_queue_it->second < old_tx_queue_it->second) {
+ curr_tx_queue_it->second < length_entry.second) {
congested_tx_queues = false;
// TODO(armansito): If we had a false positive earlier, we may
// want to correct it here by invoking a "connection back to normal
@@ -171,14 +167,13 @@
const int64 kDnsTimedOutLowerThresholdSeconds =
kDnsTimedOutThresholdSeconds - kSamplingIntervalMilliseconds / 1000;
string device_ip_address = device_->ipconfig()->properties().address;
- vector<ConnectionInfo>::const_iterator it;
- for (it = connection_infos.begin(); it != connection_infos.end(); ++it) {
- if (it->protocol() != IPPROTO_UDP ||
- it->time_to_expire_seconds() > kDnsTimedOutThresholdSeconds ||
- it->time_to_expire_seconds() <= kDnsTimedOutLowerThresholdSeconds ||
- !it->is_unreplied() ||
- it->original_source_ip_address().ToString() != device_ip_address ||
- it->original_destination_port() != kDnsPort)
+ for (const auto &info : connection_infos) {
+ if (info.protocol() != IPPROTO_UDP ||
+ info.time_to_expire_seconds() > kDnsTimedOutThresholdSeconds ||
+ info.time_to_expire_seconds() <= kDnsTimedOutLowerThresholdSeconds ||
+ !info.is_unreplied() ||
+ info.original_source_ip_address().ToString() != device_ip_address ||
+ info.original_destination_port() != kDnsPort)
continue;
++accummulated_dns_failures_samples_;
diff --git a/vpn_provider.cc b/vpn_provider.cc
index d7c382d..61cd99a 100644
--- a/vpn_provider.cc
+++ b/vpn_provider.cc
@@ -113,10 +113,8 @@
bool VPNProvider::OnDeviceInfoAvailable(const string &link_name,
int interface_index) {
- for (vector<VPNServiceRefPtr>::const_iterator it = services_.begin();
- it != services_.end();
- ++it) {
- if ((*it)->driver()->ClaimInterface(link_name, interface_index)) {
+ for (const auto &service : services_) {
+ if (service->driver()->ClaimInterface(link_name, interface_index)) {
return true;
}
}
@@ -125,8 +123,7 @@
}
void VPNProvider::RemoveService(VPNServiceRefPtr service) {
- vector<VPNServiceRefPtr>::iterator it;
- it = std::find(services_.begin(), services_.end(), service);
+ const auto it = std::find(services_.begin(), services_.end(), service);
if (it != services_.end()) {
services_.erase(it);
}
@@ -135,30 +132,28 @@
void VPNProvider::CreateServicesFromProfile(const ProfileRefPtr &profile) {
SLOG(VPN, 2) << __func__;
const StoreInterface *storage = profile->GetConstStorage();
- set<string> groups =
- storage->GetGroupsWithKey(kProviderTypeProperty);
- for (set<string>::iterator it = groups.begin(); it != groups.end(); ++it) {
- if (!StartsWithASCII(*it, "vpn_", false)) {
+ for (const auto &group : storage->GetGroupsWithKey(kProviderTypeProperty)) {
+ if (!StartsWithASCII(group, "vpn_", false)) {
continue;
}
string type;
- if (!storage->GetString(*it, kProviderTypeProperty, &type)) {
- LOG(ERROR) << "Group " << *it << " is missing the "
+ if (!storage->GetString(group, kProviderTypeProperty, &type)) {
+ LOG(ERROR) << "Group " << group << " is missing the "
<< kProviderTypeProperty << " property.";
continue;
}
string name;
- if (!storage->GetString(*it, kNameProperty, &name)) {
- LOG(ERROR) << "Group " << *it << " is missing the "
+ if (!storage->GetString(group, kNameProperty, &name)) {
+ LOG(ERROR) << "Group " << group << " is missing the "
<< kNameProperty << " property.";
continue;
}
string host;
- if (!storage->GetString(*it, kProviderHostProperty, &host)) {
- LOG(ERROR) << "Group " << *it << " is missing the "
+ if (!storage->GetString(group, kProviderHostProperty, &host)) {
+ LOG(ERROR) << "Group " << group << " is missing the "
<< kProviderHostProperty << " property.";
continue;
}
@@ -167,20 +162,20 @@
if (service != NULL) {
// If the service already exists, it does not need to be configured,
// since PushProfile would have already called ConfigureService on it.
- SLOG(VPN, 2) << "Service already exists " << *it;
+ SLOG(VPN, 2) << "Service already exists " << group;
continue;
}
Error error;
- service = CreateService(type, name, *it, &error);
+ service = CreateService(type, name, group, &error);
if (service == NULL) {
- LOG(ERROR) << "Could not create service for " << *it;
+ LOG(ERROR) << "Could not create service for " << group;
continue;
}
if (!profile->ConfigureService(service)) {
- LOG(ERROR) << "Could not configure service for " << *it;
+ LOG(ERROR) << "Could not configure service for " << group;
continue;
}
}
@@ -242,13 +237,11 @@
VPNServiceRefPtr VPNProvider::FindService(const string &type,
const string &name,
const string &host) const {
- for (vector<VPNServiceRefPtr>::const_iterator it = services_.begin();
- it != services_.end();
- ++it) {
- if (type == (*it)->driver()->GetProviderType() &&
- name == (*it)->friendly_name() &&
- host == (*it)->driver()->GetHost()) {
- return *it;
+ for (const auto &service : services_) {
+ if (type == service->driver()->GetProviderType() &&
+ name == service->friendly_name() &&
+ host == service->driver()->GetHost()) {
+ return service;
}
}
return NULL;
@@ -273,9 +266,8 @@
}
bool VPNProvider::HasActiveService() const {
- for (vector<VPNServiceRefPtr>::const_iterator it = services_.begin();
- it != services_.end(); ++it) {
- if ((*it)->IsConnecting() || (*it)->IsConnected()) {
+ for (const auto &service : services_) {
+ if (service->IsConnecting() || service->IsConnected()) {
return true;
}
}
diff --git a/wifi.cc b/wifi.cc
index a547cf3..5a92983 100644
--- a/wifi.cc
+++ b/wifi.cc
@@ -329,14 +329,12 @@
// WiFi callbacks expect notifications even if the device is disabled.
DropConnection();
StopScanTimer();
- for (EndpointMap::iterator it = endpoint_by_rpcid_.begin();
- it != endpoint_by_rpcid_.end(); ++it) {
- provider_->OnEndpointRemoved(it->second);
+ for (const auto &endpoint : endpoint_by_rpcid_) {
+ provider_->OnEndpointRemoved(endpoint.second);
}
endpoint_by_rpcid_.clear();
- for (ReverseServiceMap::const_iterator it = rpcid_by_service_.begin();
- it != rpcid_by_service_.end(); ++it) {
- RemoveNetwork(it->second);
+ for (const auto &map_entry : rpcid_by_service_) {
+ RemoveNetwork(map_entry.second);
}
rpcid_by_service_.clear();
supplicant_interface_proxy_.reset(); // breaks a reference cycle
@@ -1034,8 +1032,7 @@
string WiFi::FindNetworkRpcidForService(
const WiFiService *service, Error *error) {
- ReverseServiceMap::const_iterator rpcid_it =
- rpcid_by_service_.find(service);
+ ReverseServiceMap::const_iterator rpcid_it = rpcid_by_service_.find(service);
if (rpcid_it == rpcid_by_service_.end()) {
const string error_message =
StringPrintf(
@@ -1538,13 +1535,13 @@
// static
string WiFi::LogSSID(const string &ssid) {
string out;
- for (string::const_iterator it = ssid.begin(); it != ssid.end(); ++it) {
+ for (const auto &chr : ssid) {
// Replace '[' and ']' (in addition to non-printable characters) so that
// it's easy to match the right substring through a non-greedy regex.
- if (*it == '[' || *it == ']' || !g_ascii_isprint(*it)) {
- base::StringAppendF(&out, "\\x%02x", *it);
+ if (chr == '[' || chr == ']' || !g_ascii_isprint(chr)) {
+ base::StringAppendF(&out, "\\x%02x", chr);
} else {
- out += *it;
+ out += chr;
}
}
return StringPrintf("[SSID=%s]", out.c_str());
@@ -1594,11 +1591,9 @@
vector<GeolocationInfo> WiFi::GetGeolocationObjects() const {
vector<GeolocationInfo> objects;
- for (EndpointMap::const_iterator it = endpoint_by_rpcid_.begin();
- it != endpoint_by_rpcid_.end();
- ++it) {
+ for (const auto &endpoint_entry : endpoint_by_rpcid_) {
GeolocationInfo geoinfo;
- WiFiEndpointRefPtr endpoint = it->second;
+ const WiFiEndpointRefPtr &endpoint = endpoint_entry.second;
geoinfo.AddField(kGeoMacAddressProperty, endpoint->bssid_string());
geoinfo.AddField(kGeoSignalStrengthProperty,
StringPrintf("%d", endpoint->signal_strength()));
diff --git a/wifi_endpoint.cc b/wifi_endpoint.cc
index f3a15eb..6349c26 100644
--- a/wifi_endpoint.cc
+++ b/wifi_endpoint.cc
@@ -160,13 +160,10 @@
}
if (!vendor_information_.oui_set.empty()) {
vector<string> oui_vector;
- set<uint32_t>::const_iterator it;
- for (it = vendor_information_.oui_set.begin();
- it != vendor_information_.oui_set.end();
- ++it) {
+ for (auto oui : vendor_information_.oui_set) {
oui_vector.push_back(
StringPrintf("%02x-%02x-%02x",
- *it >> 16, (*it >> 8) & 0xff, *it & 0xff));
+ oui >> 16, (oui >> 8) & 0xff, oui & 0xff));
}
vendor_information[kVendorOUIListProperty] =
JoinString(oui_vector, ' ');
@@ -377,13 +374,11 @@
security_method_properties.
find(WPASupplicant::kSecurityMethodPropertyKeyManagement)->second.
operator vector<string>();
- for (vector<string>::const_iterator it = key_management_vec.begin();
- it != key_management_vec.end();
- ++it) {
- if (EndsWith(*it, WPASupplicant::kKeyManagementMethodSuffixEAP, true)) {
+ for (const auto &method : key_management_vec) {
+ if (EndsWith(method, WPASupplicant::kKeyManagementMethodSuffixEAP, true)) {
key_management_methods->insert(kKeyManagement802_1x);
} else if (
- EndsWith(*it, WPASupplicant::kKeyManagementMethodSuffixPSK, true)) {
+ EndsWith(method, WPASupplicant::kKeyManagementMethodSuffixPSK, true)) {
key_management_methods->insert(kKeyManagementPSK);
}
}
diff --git a/wifi_provider.cc b/wifi_provider.cc
index 82f9298..6e5381e 100644
--- a/wifi_provider.cc
+++ b/wifi_provider.cc
@@ -97,35 +97,33 @@
const StoreInterface *storage = profile->GetConstStorage();
KeyValueStore args;
args.SetString(kTypeProperty, kTypeWifi);
- set<string> groups = storage->GetGroupsWithProperties(args);
bool created_hidden_service = false;
- for (set<string>::const_iterator it = groups.begin(); it != groups.end();
- ++it) {
+ for (const auto &group : storage->GetGroupsWithProperties(args)) {
string ssid_hex;
vector<uint8_t> ssid_bytes;
- if (!storage->GetString(*it, WiFiService::kStorageSSID, &ssid_hex) ||
+ if (!storage->GetString(group, WiFiService::kStorageSSID, &ssid_hex) ||
!base::HexStringToBytes(ssid_hex, &ssid_bytes)) {
- SLOG(WiFi, 2) << "Storage group " << *it << " is missing valid \""
+ SLOG(WiFi, 2) << "Storage group " << group << " is missing valid \""
<< WiFiService::kStorageSSID << "\" property";
continue;
}
string network_mode;
- if (!storage->GetString(*it, WiFiService::kStorageMode, &network_mode) ||
+ if (!storage->GetString(group, WiFiService::kStorageMode, &network_mode) ||
network_mode.empty()) {
- SLOG(WiFi, 2) << "Storage group " << *it << " is missing \""
+ SLOG(WiFi, 2) << "Storage group " << group << " is missing \""
<< WiFiService::kStorageMode << "\" property";
continue;
}
string security;
- if (!storage->GetString(*it, WiFiService::kStorageSecurity, &security) ||
+ if (!storage->GetString(group, WiFiService::kStorageSecurity, &security) ||
!WiFiService::IsValidSecurityMethod(security)) {
- SLOG(WiFi, 2) << "Storage group " << *it << " has missing or invalid \""
+ SLOG(WiFi, 2) << "Storage group " << group << " has missing or invalid \""
<< WiFiService::kStorageSecurity << "\" property";
continue;
}
bool is_hidden = false;
- if (!storage->GetBool(*it, WiFiService::kStorageHiddenSSID, &is_hidden)) {
- SLOG(WiFi, 2) << "Storage group " << *it << " is missing \""
+ if (!storage->GetBool(group, WiFiService::kStorageHiddenSSID, &is_hidden)) {
+ SLOG(WiFi, 2) << "Storage group " << group << " is missing \""
<< WiFiService::kStorageHiddenSSID << "\" property";
continue;
}
@@ -429,12 +427,10 @@
WiFiServiceRefPtr WiFiProvider::FindService(const vector<uint8_t> &ssid,
const string &mode,
const string &security) const {
- for (vector<WiFiServiceRefPtr>::const_iterator it = services_.begin();
- it != services_.end();
- ++it) {
- if ((*it)->ssid() == ssid && (*it)->mode() == mode &&
- (*it)->IsSecurityMatch(security)) {
- return *it;
+ for (const auto &service : services_) {
+ if (service->ssid() == ssid && service->mode() == mode &&
+ service->IsSecurityMatch(security)) {
+ return service;
}
}
return NULL;
@@ -443,11 +439,9 @@
ByteArrays WiFiProvider::GetHiddenSSIDList() {
// Create a unique set of hidden SSIDs.
set<ByteArray> hidden_ssids_set;
- for (vector<WiFiServiceRefPtr>::const_iterator it = services_.begin();
- it != services_.end();
- ++it) {
- if ((*it)->hidden_ssid() && (*it)->IsRemembered()) {
- hidden_ssids_set.insert((*it)->ssid());
+ for (const auto &service : services_) {
+ if (service->hidden_ssid() && service->IsRemembered()) {
+ hidden_ssids_set.insert(service->ssid());
}
}
SLOG(WiFi, 2) << "Found " << hidden_ssids_set.size() << " hidden services";
diff --git a/wifi_service.cc b/wifi_service.cc
index e1f95b4..65551a1 100644
--- a/wifi_service.cc
+++ b/wifi_service.cc
@@ -670,11 +670,10 @@
representative_endpoint = current_endpoint_;
} else {
int16 best_signal = std::numeric_limits<int16>::min();
- for (set<WiFiEndpointConstRefPtr>::iterator i = endpoints_.begin();
- i != endpoints_.end(); ++i) {
- if ((*i)->signal_strength() >= best_signal) {
- best_signal = (*i)->signal_strength();
- representative_endpoint = *i;
+ for (const auto &endpoint : endpoints_) {
+ if (endpoint->signal_strength() >= best_signal) {
+ best_signal = endpoint->signal_strength();
+ representative_endpoint = endpoint;
}
}
}
@@ -689,9 +688,8 @@
SetWiFi(wifi);
- for (set<WiFiEndpointConstRefPtr>::iterator i = endpoints_.begin();
- i != endpoints_.end(); ++i) {
- if ((*i)->ieee80211w_required()) {
+ for (const auto &endpoint : endpoints_) {
+ if (endpoint->ieee80211w_required()) {
// Never reset ieee80211w_required_ to false, so we track whether we have
// ever seen an AP that requires 802.11w.
ieee80211w_required_ = true;
@@ -789,12 +787,11 @@
// Find weakest cipher (across endpoints) of the strongest ciphers
// (per endpoint).
Service::CryptoAlgorithm cipher = Service::kCryptoAes;
- for (set<WiFiEndpointConstRefPtr>::iterator i = endpoints.begin();
- i != endpoints.end(); ++i) {
+ for (const auto &endpoint : endpoints) {
Service::CryptoAlgorithm endpoint_cipher;
- if ((*i)->has_rsn_property()) {
+ if (endpoint->has_rsn_property()) {
endpoint_cipher = Service::kCryptoAes;
- } else if ((*i)->has_wpa_property()) {
+ } else if (endpoint->has_wpa_property()) {
endpoint_cipher = Service::kCryptoRc4;
} else {
// We could be in the Dynamic WEP case here. But that's okay,
@@ -982,9 +979,7 @@
bool WiFiService::FixupServiceEntries(StoreInterface *storage) {
bool fixed_entry = false;
set<string> groups = storage->GetGroups();
- for (set<string>::const_iterator it = groups.begin(); it != groups.end();
- ++it) {
- const string &id = *it;
+ for (const auto &id : groups) {
string device_address, network_mode, security;
if (!ParseStorageIdentifier(id, &device_address,
&network_mode, &security)) {
diff --git a/wimax_provider.cc b/wimax_provider.cc
index c49a266..b2b0eac 100644
--- a/wimax_provider.cc
+++ b/wimax_provider.cc
@@ -109,26 +109,23 @@
SLOG(WiMax, 2) << __func__;
// Collects a set of live networks from all devices.
set<RpcIdentifier> live_networks;
- for (map<string, WiMaxRefPtr>::const_iterator it = devices_.begin();
- it != devices_.end(); ++it) {
- const set<RpcIdentifier> &networks = it->second->networks();
+ for (const auto &device : devices_) {
+ const set<RpcIdentifier> &networks = device.second->networks();
live_networks.insert(networks.begin(), networks.end());
}
// Removes dead networks from |networks_|.
- for (map<RpcIdentifier, NetworkInfo>::iterator it = networks_.begin();
- it != networks_.end(); ) {
+ for (auto it = networks_.begin(); it != networks_.end(); ) {
const RpcIdentifier &path = it->first;
if (ContainsKey(live_networks, path)) {
++it;
} else {
LOG(INFO) << "WiMAX network disappeared: " << path;
- networks_.erase(it++);
+ it = networks_.erase(it);
}
}
// Retrieves network info into |networks_| for the live networks.
- for (set<RpcIdentifier>::const_iterator it = live_networks.begin();
- it != live_networks.end(); ++it) {
- RetrieveNetworkInfo(*it);
+ for (const auto &network : live_networks) {
+ RetrieveNetworkInfo(network);
}
// Stops dead and starts live services based on the current |networks_|.
StopDeadServices();
@@ -220,9 +217,7 @@
bool created = false;
const StoreInterface *storage = profile->GetConstStorage();
set<string> groups = storage->GetGroupsWithKey(Service::kStorageType);
- for (set<string>::const_iterator it = groups.begin();
- it != groups.end(); ++it) {
- const string &storage_id = *it;
+ for (const auto &storage_id : groups) {
string type;
if (!storage->GetString(storage_id, Service::kStorageType, &type) ||
type != Technology::NameFromIdentifier(Technology::kWiMax)) {
@@ -270,9 +265,7 @@
void WiMaxProvider::OnDevicesChanged(const RpcIdentifiers &devices) {
SLOG(WiMax, 2) << __func__;
DestroyDeadDevices(devices);
- for (RpcIdentifiers::const_iterator it = devices.begin();
- it != devices.end(); ++it) {
- const RpcIdentifier &path = *it;
+ for (const auto &path : devices) {
string link_name = GetLinkName(path);
if (!link_name.empty()) {
CreateDevice(link_name, path);
@@ -319,25 +312,23 @@
void WiMaxProvider::DestroyDeadDevices(const RpcIdentifiers &live_devices) {
SLOG(WiMax, 2) << __func__ << "(" << live_devices.size() << ")";
- for (map<string, RpcIdentifier>::iterator it = pending_devices_.begin();
- it != pending_devices_.end(); ) {
+ for (auto it = pending_devices_.begin(); it != pending_devices_.end(); ) {
if (find(live_devices.begin(), live_devices.end(), it->second) ==
live_devices.end()) {
LOG(INFO) << "Forgetting pending device: " << it->second;
- pending_devices_.erase(it++);
+ it = pending_devices_.erase(it);
} else {
++it;
}
}
- for (map<string, WiMaxRefPtr>::iterator it = devices_.begin();
- it != devices_.end(); ) {
+ for (auto it = devices_.begin(); it != devices_.end(); ) {
if (find(live_devices.begin(), live_devices.end(), it->second->path()) ==
live_devices.end()) {
LOG(INFO) << "Destroying device: " << it->first;
const WiMaxRefPtr &device = it->second;
device->OnDeviceVanished();
manager_->device_info()->DeregisterDevice(device);
- devices_.erase(it++);
+ it = devices_.erase(it);
} else {
++it;
}
@@ -414,18 +405,16 @@
void WiMaxProvider::StartLiveServices() {
SLOG(WiMax, 2) << __func__ << "(" << networks_.size() << ")";
- for (map<RpcIdentifier, NetworkInfo>::const_iterator nit = networks_.begin();
- nit != networks_.end(); ++nit) {
- const RpcIdentifier &path = nit->first;
- const NetworkInfo &info = nit->second;
+ for (const auto &nit : networks_) {
+ const RpcIdentifier &path = nit.first;
+ const NetworkInfo &info = nit.second;
// Creates the default service for the network, if not already created.
GetUniqueService(info.id, info.name)->set_is_default(true);
// Starts services for this live network.
- for (map<string, WiMaxServiceRefPtr>::const_iterator it = services_.begin();
- it != services_.end(); ++it) {
- const WiMaxServiceRefPtr &service = it->second;
+ for (const auto &entry : services_) {
+ const WiMaxServiceRefPtr &service = entry.second;
if (service->network_id() != info.id || service->IsStarted()) {
continue;
}