OLD | NEW |
---|---|
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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
9 #include "base/guid.h" | 9 #include "base/guid.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
291 for (ManagedStateList::const_iterator iter = device_list_.begin(); | 291 for (ManagedStateList::const_iterator iter = device_list_.begin(); |
292 iter != device_list_.end(); ++iter) { | 292 iter != device_list_.end(); ++iter) { |
293 const DeviceState* device = (*iter)->AsDeviceState(); | 293 const DeviceState* device = (*iter)->AsDeviceState(); |
294 DCHECK(device); | 294 DCHECK(device); |
295 if (device->update_received() && device->Matches(type)) | 295 if (device->update_received() && device->Matches(type)) |
296 list->push_back(device); | 296 list->push_back(device); |
297 } | 297 } |
298 } | 298 } |
299 | 299 |
300 void NetworkStateHandler::GetFavoriteList(FavoriteStateList* list) const { | 300 void NetworkStateHandler::GetFavoriteList(FavoriteStateList* list) const { |
301 GetFavoriteListByType(NetworkTypePattern::Default(), list); | 301 GetFavoriteListByType(NetworkTypePattern::Default(), |
302 true /* configured_only */, | |
303 false /* visible_only */, | |
304 list); | |
302 } | 305 } |
303 | 306 |
304 void NetworkStateHandler::GetFavoriteListByType(const NetworkTypePattern& type, | 307 void NetworkStateHandler::GetFavoriteListByType(const NetworkTypePattern& type, |
308 bool configured_only, | |
309 bool visible_only, | |
305 FavoriteStateList* list) const { | 310 FavoriteStateList* list) const { |
306 DCHECK(list); | 311 DCHECK(list); |
312 std::set<std::string> visible_networks; | |
313 if (visible_only) { | |
314 // Prepare a set of visible network service paths for fast lookup. | |
315 for (ManagedStateList::const_iterator iter = network_list_.begin(); | |
pneubeck (no reviews)
2014/05/15 18:28:38
I like this solution if we don't care about best r
stevenjb
2014/05/15 20:12:41
I thought about that, but honestly if performance
pneubeck (no reviews)
2014/05/16 13:18:55
Yes, totally reasonable.
| |
316 iter != network_list_.end(); ++iter) { | |
317 visible_networks.insert((*iter)->path()); | |
318 } | |
319 } | |
307 FavoriteStateList result; | 320 FavoriteStateList result; |
308 list->clear(); | 321 list->clear(); |
309 for (ManagedStateList::const_iterator iter = favorite_list_.begin(); | 322 for (ManagedStateList::const_iterator iter = favorite_list_.begin(); |
310 iter != favorite_list_.end(); ++iter) { | 323 iter != favorite_list_.end(); ++iter) { |
311 const FavoriteState* favorite = (*iter)->AsFavoriteState(); | 324 const FavoriteState* favorite = (*iter)->AsFavoriteState(); |
312 DCHECK(favorite); | 325 DCHECK(favorite); |
313 if (favorite->update_received() && favorite->IsInProfile() && | 326 if (!favorite->update_received() || !favorite->Matches(type)) |
314 favorite->Matches(type)) { | 327 continue; |
315 list->push_back(favorite); | 328 if (configured_only && !favorite->IsInProfile()) |
316 } | 329 continue; |
330 if (visible_only && !ContainsKey(visible_networks, favorite->path())) | |
331 continue; | |
332 list->push_back(favorite); | |
317 } | 333 } |
318 } | 334 } |
319 | 335 |
320 const FavoriteState* NetworkStateHandler::GetFavoriteStateFromServicePath( | 336 const FavoriteState* NetworkStateHandler::GetFavoriteStateFromServicePath( |
321 const std::string& service_path, | 337 const std::string& service_path, |
322 bool configured_only) const { | 338 bool configured_only) const { |
323 ManagedState* managed = | 339 ManagedState* managed = |
324 GetModifiableManagedState(&favorite_list_, service_path); | 340 GetModifiableManagedState(&favorite_list_, service_path); |
325 if (!managed) | 341 if (!managed) |
326 return NULL; | 342 return NULL; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
411 base::StringPrintf("Unknown device %s of connected ethernet service %s", | 427 base::StringPrintf("Unknown device %s of connected ethernet service %s", |
412 network->device_path().c_str(), | 428 network->device_path().c_str(), |
413 service_path.c_str())); | 429 service_path.c_str())); |
414 return NULL; | 430 return NULL; |
415 } | 431 } |
416 if (!device->eap_authentication_completed()) | 432 if (!device->eap_authentication_completed()) |
417 return NULL; | 433 return NULL; |
418 | 434 |
419 FavoriteStateList list; | 435 FavoriteStateList list; |
420 GetFavoriteListByType(NetworkTypePattern::Primitive(shill::kTypeEthernetEap), | 436 GetFavoriteListByType(NetworkTypePattern::Primitive(shill::kTypeEthernetEap), |
437 true /* configured_only */, | |
438 false /* visible_only */, | |
421 &list); | 439 &list); |
422 if (list.empty()) { | 440 if (list.empty()) { |
423 NET_LOG_ERROR("GetEAPForEthernet", | 441 NET_LOG_ERROR("GetEAPForEthernet", |
424 base::StringPrintf( | 442 base::StringPrintf( |
425 "Ethernet service %s connected using EAP, but no " | 443 "Ethernet service %s connected using EAP, but no " |
426 "EAP service found.", | 444 "EAP service found.", |
427 service_path.c_str())); | 445 service_path.c_str())); |
428 return NULL; | 446 return NULL; |
429 } | 447 } |
430 DCHECK(list.size() == 1); | 448 DCHECK(list.size() == 1); |
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
931 if (type.MatchesType(shill::kTypeBluetooth)) | 949 if (type.MatchesType(shill::kTypeBluetooth)) |
932 technologies.push_back(new std::string(shill::kTypeBluetooth)); | 950 technologies.push_back(new std::string(shill::kTypeBluetooth)); |
933 if (type.MatchesType(shill::kTypeVPN)) | 951 if (type.MatchesType(shill::kTypeVPN)) |
934 technologies.push_back(new std::string(shill::kTypeVPN)); | 952 technologies.push_back(new std::string(shill::kTypeVPN)); |
935 | 953 |
936 CHECK_GT(technologies.size(), 0ul); | 954 CHECK_GT(technologies.size(), 0ul); |
937 return technologies.Pass(); | 955 return technologies.Pass(); |
938 } | 956 } |
939 | 957 |
940 } // namespace chromeos | 958 } // namespace chromeos |
OLD | NEW |