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(); |
| 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::GetFavoriteState( | 336 const FavoriteState* NetworkStateHandler::GetFavoriteState( |
321 const std::string& service_path) const { | 337 const std::string& service_path) const { |
322 ManagedState* managed = | 338 ManagedState* managed = |
323 GetModifiableManagedState(&favorite_list_, service_path); | 339 GetModifiableManagedState(&favorite_list_, service_path); |
324 if (!managed) | 340 if (!managed) |
325 return NULL; | 341 return NULL; |
326 const FavoriteState* favorite = managed->AsFavoriteState(); | 342 const FavoriteState* favorite = managed->AsFavoriteState(); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 base::StringPrintf("Unknown device %s of connected ethernet service %s", | 423 base::StringPrintf("Unknown device %s of connected ethernet service %s", |
408 network->device_path().c_str(), | 424 network->device_path().c_str(), |
409 service_path.c_str())); | 425 service_path.c_str())); |
410 return NULL; | 426 return NULL; |
411 } | 427 } |
412 if (!device->eap_authentication_completed()) | 428 if (!device->eap_authentication_completed()) |
413 return NULL; | 429 return NULL; |
414 | 430 |
415 FavoriteStateList list; | 431 FavoriteStateList list; |
416 GetFavoriteListByType(NetworkTypePattern::Primitive(shill::kTypeEthernetEap), | 432 GetFavoriteListByType(NetworkTypePattern::Primitive(shill::kTypeEthernetEap), |
| 433 true /* configured_only */, |
| 434 false /* visible_only */, |
417 &list); | 435 &list); |
418 if (list.empty()) { | 436 if (list.empty()) { |
419 NET_LOG_ERROR("GetEAPForEthernet", | 437 NET_LOG_ERROR("GetEAPForEthernet", |
420 base::StringPrintf( | 438 base::StringPrintf( |
421 "Ethernet service %s connected using EAP, but no " | 439 "Ethernet service %s connected using EAP, but no " |
422 "EAP service found.", | 440 "EAP service found.", |
423 service_path.c_str())); | 441 service_path.c_str())); |
424 return NULL; | 442 return NULL; |
425 } | 443 } |
426 DCHECK(list.size() == 1); | 444 DCHECK(list.size() == 1); |
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
916 if (type.MatchesType(shill::kTypeBluetooth)) | 934 if (type.MatchesType(shill::kTypeBluetooth)) |
917 technologies.push_back(new std::string(shill::kTypeBluetooth)); | 935 technologies.push_back(new std::string(shill::kTypeBluetooth)); |
918 if (type.MatchesType(shill::kTypeVPN)) | 936 if (type.MatchesType(shill::kTypeVPN)) |
919 technologies.push_back(new std::string(shill::kTypeVPN)); | 937 technologies.push_back(new std::string(shill::kTypeVPN)); |
920 | 938 |
921 CHECK_GT(technologies.size(), 0ul); | 939 CHECK_GT(technologies.size(), 0ul); |
922 return technologies.Pass(); | 940 return technologies.Pass(); |
923 } | 941 } |
924 | 942 |
925 } // namespace chromeos | 943 } // namespace chromeos |
OLD | NEW |