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

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

Issue 280023003: Implement networkingPrivate.getNetworks (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix nonchromeos Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « chromeos/network/network_state_handler.h ('k') | chromeos/network/network_util.h » ('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 "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
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 0 /* no limit */,
305 list);
302 } 306 }
303 307
304 void NetworkStateHandler::GetFavoriteListByType(const NetworkTypePattern& type, 308 void NetworkStateHandler::GetFavoriteListByType(const NetworkTypePattern& type,
309 bool configured_only,
310 bool visible_only,
311 int limit,
305 FavoriteStateList* list) const { 312 FavoriteStateList* list) const {
306 DCHECK(list); 313 DCHECK(list);
314 std::set<std::string> visible_networks;
315 if (visible_only) {
316 // Prepare a set of visible network service paths for fast lookup.
317 for (ManagedStateList::const_iterator iter = network_list_.begin();
318 iter != network_list_.end(); ++iter) {
319 visible_networks.insert((*iter)->path());
320 }
321 }
307 FavoriteStateList result; 322 FavoriteStateList result;
308 list->clear(); 323 list->clear();
324 int count = 0;
309 for (ManagedStateList::const_iterator iter = favorite_list_.begin(); 325 for (ManagedStateList::const_iterator iter = favorite_list_.begin();
310 iter != favorite_list_.end(); ++iter) { 326 iter != favorite_list_.end(); ++iter) {
311 const FavoriteState* favorite = (*iter)->AsFavoriteState(); 327 const FavoriteState* favorite = (*iter)->AsFavoriteState();
312 DCHECK(favorite); 328 DCHECK(favorite);
313 if (favorite->update_received() && favorite->IsInProfile() && 329 if (!favorite->update_received() || !favorite->Matches(type))
314 favorite->Matches(type)) { 330 continue;
315 list->push_back(favorite); 331 if (configured_only && !favorite->IsInProfile())
316 } 332 continue;
333 if (visible_only && !ContainsKey(visible_networks, favorite->path()))
334 continue;
335 list->push_back(favorite);
336 if (limit > 0 && ++count >= limit)
337 break;
317 } 338 }
318 } 339 }
319 340
320 const FavoriteState* NetworkStateHandler::GetFavoriteStateFromServicePath( 341 const FavoriteState* NetworkStateHandler::GetFavoriteStateFromServicePath(
321 const std::string& service_path, 342 const std::string& service_path,
322 bool configured_only) const { 343 bool configured_only) const {
323 ManagedState* managed = 344 ManagedState* managed =
324 GetModifiableManagedState(&favorite_list_, service_path); 345 GetModifiableManagedState(&favorite_list_, service_path);
325 if (!managed) 346 if (!managed)
326 return NULL; 347 return NULL;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 base::StringPrintf("Unknown device %s of connected ethernet service %s", 432 base::StringPrintf("Unknown device %s of connected ethernet service %s",
412 network->device_path().c_str(), 433 network->device_path().c_str(),
413 service_path.c_str())); 434 service_path.c_str()));
414 return NULL; 435 return NULL;
415 } 436 }
416 if (!device->eap_authentication_completed()) 437 if (!device->eap_authentication_completed())
417 return NULL; 438 return NULL;
418 439
419 FavoriteStateList list; 440 FavoriteStateList list;
420 GetFavoriteListByType(NetworkTypePattern::Primitive(shill::kTypeEthernetEap), 441 GetFavoriteListByType(NetworkTypePattern::Primitive(shill::kTypeEthernetEap),
442 true /* configured_only */,
443 false /* visible_only */,
444 1 /* limit */,
421 &list); 445 &list);
422 if (list.empty()) { 446 if (list.empty()) {
423 NET_LOG_ERROR("GetEAPForEthernet", 447 NET_LOG_ERROR("GetEAPForEthernet",
424 base::StringPrintf( 448 base::StringPrintf(
425 "Ethernet service %s connected using EAP, but no " 449 "Ethernet service %s connected using EAP, but no "
426 "EAP service found.", 450 "EAP service found.",
427 service_path.c_str())); 451 service_path.c_str()));
428 return NULL; 452 return NULL;
429 } 453 }
430 DCHECK(list.size() == 1);
431 return list.front(); 454 return list.front();
432 } 455 }
433 456
434 //------------------------------------------------------------------------------ 457 //------------------------------------------------------------------------------
435 // ShillPropertyHandler::Delegate overrides 458 // ShillPropertyHandler::Delegate overrides
436 459
437 void NetworkStateHandler::UpdateManagedList(ManagedState::ManagedType type, 460 void NetworkStateHandler::UpdateManagedList(ManagedState::ManagedType type,
438 const base::ListValue& entries) { 461 const base::ListValue& entries) {
439 ManagedStateList* managed_list = GetManagedList(type); 462 ManagedStateList* managed_list = GetManagedList(type);
440 NET_LOG_DEBUG(base::StringPrintf("UpdateManagedList:%d", type), 463 NET_LOG_DEBUG(base::StringPrintf("UpdateManagedList:%d", type),
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 if (type.MatchesType(shill::kTypeBluetooth)) 954 if (type.MatchesType(shill::kTypeBluetooth))
932 technologies.push_back(new std::string(shill::kTypeBluetooth)); 955 technologies.push_back(new std::string(shill::kTypeBluetooth));
933 if (type.MatchesType(shill::kTypeVPN)) 956 if (type.MatchesType(shill::kTypeVPN))
934 technologies.push_back(new std::string(shill::kTypeVPN)); 957 technologies.push_back(new std::string(shill::kTypeVPN));
935 958
936 CHECK_GT(technologies.size(), 0ul); 959 CHECK_GT(technologies.size(), 0ul);
937 return technologies.Pass(); 960 return technologies.Pass();
938 } 961 }
939 962
940 } // namespace chromeos 963 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/network_state_handler.h ('k') | chromeos/network/network_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698