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

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

Issue 275543005: Use GUID instead of ServicePath in networkingPrivate API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase 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
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/location.h" 10 #include "base/location.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
12 #include "base/stl_util.h" 13 #include "base/stl_util.h"
13 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
14 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
15 #include "base/values.h" 16 #include "base/values.h"
16 #include "chromeos/network/device_state.h" 17 #include "chromeos/network/device_state.h"
17 #include "chromeos/network/favorite_state.h" 18 #include "chromeos/network/favorite_state.h"
18 #include "chromeos/network/managed_state.h" 19 #include "chromeos/network/managed_state.h"
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 303
303 void NetworkStateHandler::GetFavoriteListByType(const NetworkTypePattern& type, 304 void NetworkStateHandler::GetFavoriteListByType(const NetworkTypePattern& type,
304 FavoriteStateList* list) const { 305 FavoriteStateList* list) const {
305 DCHECK(list); 306 DCHECK(list);
306 FavoriteStateList result; 307 FavoriteStateList result;
307 list->clear(); 308 list->clear();
308 for (ManagedStateList::const_iterator iter = favorite_list_.begin(); 309 for (ManagedStateList::const_iterator iter = favorite_list_.begin();
309 iter != favorite_list_.end(); ++iter) { 310 iter != favorite_list_.end(); ++iter) {
310 const FavoriteState* favorite = (*iter)->AsFavoriteState(); 311 const FavoriteState* favorite = (*iter)->AsFavoriteState();
311 DCHECK(favorite); 312 DCHECK(favorite);
312 if (favorite->update_received() && favorite->IsFavorite() && 313 if (favorite->update_received() && favorite->IsInProfile() &&
313 favorite->Matches(type)) { 314 favorite->Matches(type)) {
314 list->push_back(favorite); 315 list->push_back(favorite);
315 } 316 }
316 } 317 }
317 } 318 }
318 319
319 const FavoriteState* NetworkStateHandler::GetFavoriteState( 320 const FavoriteState* NetworkStateHandler::GetFavoriteState(
320 const std::string& service_path) const { 321 const std::string& service_path) const {
321 ManagedState* managed = 322 ManagedState* managed =
322 GetModifiableManagedState(&favorite_list_, service_path); 323 GetModifiableManagedState(&favorite_list_, service_path);
323 if (!managed) 324 if (!managed)
324 return NULL; 325 return NULL;
325 const FavoriteState* favorite = managed->AsFavoriteState(); 326 const FavoriteState* favorite = managed->AsFavoriteState();
326 DCHECK(favorite); 327 DCHECK(favorite);
327 if (!favorite->update_received() || !favorite->IsFavorite()) 328 if (!favorite->update_received() || !favorite->IsInProfile())
328 return NULL; 329 return NULL;
329 return favorite; 330 return favorite;
330 } 331 }
331 332
333 const FavoriteState* NetworkStateHandler::GetFavoriteStateFromGuid(
334 const std::string& guid) const {
335 for (ManagedStateList::const_iterator iter = favorite_list_.begin();
336 iter != favorite_list_.end(); ++iter) {
337 const FavoriteState* favorite = (*iter)->AsFavoriteState();
pneubeck (no reviews) 2014/05/12 13:37:07 skip if update_received()==false (might not be nec
stevenjb 2014/05/13 01:19:00 guid() will be "" until update_received() is true.
338 if (favorite->guid() == guid)
339 return favorite;
340 }
341 return NULL;
342 }
343
332 void NetworkStateHandler::RequestScan() const { 344 void NetworkStateHandler::RequestScan() const {
333 NET_LOG_USER("RequestScan", ""); 345 NET_LOG_USER("RequestScan", "");
334 shill_property_handler_->RequestScan(); 346 shill_property_handler_->RequestScan();
335 } 347 }
336 348
337 void NetworkStateHandler::WaitForScan(const std::string& type, 349 void NetworkStateHandler::WaitForScan(const std::string& type,
338 const base::Closure& callback) { 350 const base::Closure& callback) {
339 scan_complete_callbacks_[type].push_back(callback); 351 scan_complete_callbacks_[type].push_back(callback);
340 if (!GetScanningByType(NetworkTypePattern::Primitive(type))) 352 if (!GetScanningByType(NetworkTypePattern::Primitive(type)))
341 RequestScan(); 353 RequestScan();
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 ManagedState* managed = GetModifiableManagedState(managed_list, path); 494 ManagedState* managed = GetModifiableManagedState(managed_list, path);
483 if (!managed) { 495 if (!managed) {
484 if (type != ManagedState::MANAGED_TYPE_FAVORITE) { 496 if (type != ManagedState::MANAGED_TYPE_FAVORITE) {
485 // The network has been removed from the list of visible networks. 497 // The network has been removed from the list of visible networks.
486 NET_LOG_DEBUG("UpdateManagedStateProperties: Not found", path); 498 NET_LOG_DEBUG("UpdateManagedStateProperties: Not found", path);
487 return; 499 return;
488 } 500 }
489 // A Favorite may not have been created yet if it was added later (e.g. 501 // A Favorite may not have been created yet if it was added later (e.g.
490 // through ConfigureService) since ServiceCompleteList updates are not 502 // through ConfigureService) since ServiceCompleteList updates are not
491 // emitted. Add and update the state here. 503 // emitted. Add and update the state here.
492 managed = new FavoriteState(path); 504 managed = ManagedState::Create(type, path);
pneubeck (no reviews) 2014/05/12 13:37:07 optional: since |type| is constant, IMO the more s
stevenjb 2014/05/13 01:19:00 I didn't like that NSH sometimes uses one and not
493 managed_list->push_back(managed); 505 managed_list->push_back(managed);
494 } 506 }
495 managed->set_update_received(); 507 managed->set_update_received();
496 508
497 std::string desc = GetManagedStateLogType(managed) + " Properties Received"; 509 std::string desc = GetManagedStateLogType(managed) + " Properties Received";
498 NET_LOG_DEBUG(desc, GetManagedStateLogName(managed)); 510 NET_LOG_DEBUG(desc, GetManagedStateLogName(managed));
499 511
500 if (type == ManagedState::MANAGED_TYPE_NETWORK) { 512 if (type == ManagedState::MANAGED_TYPE_NETWORK) {
501 UpdateNetworkStateProperties(managed->AsNetworkState(), properties); 513 UpdateNetworkStateProperties(managed->AsNetworkState(), properties);
502 } else { 514 } else {
503 // Device, Favorite 515 // Device, Favorite
504 for (base::DictionaryValue::Iterator iter(properties); 516 for (base::DictionaryValue::Iterator iter(properties);
505 !iter.IsAtEnd(); iter.Advance()) { 517 !iter.IsAtEnd(); iter.Advance()) {
506 managed->PropertyChanged(iter.key(), iter.value()); 518 managed->PropertyChanged(iter.key(), iter.value());
507 } 519 }
508 managed->InitialPropertiesReceived(properties); 520 managed->InitialPropertiesReceived(properties);
509 } 521 }
522 UpdateGuid(managed);
510 managed->set_update_requested(false); 523 managed->set_update_requested(false);
511 } 524 }
512 525
513 void NetworkStateHandler::UpdateNetworkStateProperties( 526 void NetworkStateHandler::UpdateNetworkStateProperties(
514 NetworkState* network, 527 NetworkState* network,
515 const base::DictionaryValue& properties) { 528 const base::DictionaryValue& properties) {
516 DCHECK(network); 529 DCHECK(network);
517 bool network_property_updated = false; 530 bool network_property_updated = false;
518 std::string prev_connection_state = network->connection_state(); 531 std::string prev_connection_state = network->connection_state();
519 for (base::DictionaryValue::Iterator iter(properties); 532 for (base::DictionaryValue::Iterator iter(properties);
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 NET_LOG_DEBUG("FavoriteListChanged", 687 NET_LOG_DEBUG("FavoriteListChanged",
675 base::StringPrintf("Size:%" PRIuS, favorite_list_.size())); 688 base::StringPrintf("Size:%" PRIuS, favorite_list_.size()));
676 // The FavoriteState list only changes when the NetworkState list changes, 689 // The FavoriteState list only changes when the NetworkState list changes,
677 // so no need to signal observers here again. 690 // so no need to signal observers here again.
678 691
679 // Update UMA stats. 692 // Update UMA stats.
680 size_t shared = 0, unshared = 0; 693 size_t shared = 0, unshared = 0;
681 for (ManagedStateList::iterator iter = favorite_list_.begin(); 694 for (ManagedStateList::iterator iter = favorite_list_.begin();
682 iter != favorite_list_.end(); ++iter) { 695 iter != favorite_list_.end(); ++iter) {
683 FavoriteState* favorite = (*iter)->AsFavoriteState(); 696 FavoriteState* favorite = (*iter)->AsFavoriteState();
684 if (!favorite->IsFavorite()) 697 if (!favorite->IsInProfile())
685 continue; 698 continue;
686 if (favorite->IsPrivate()) 699 if (favorite->IsPrivate())
687 ++unshared; 700 ++unshared;
688 else 701 else
689 ++shared; 702 ++shared;
690 } 703 }
691 UMA_HISTOGRAM_COUNTS_100("Networks.RememberedShared", shared); 704 UMA_HISTOGRAM_COUNTS_100("Networks.RememberedShared", shared);
692 UMA_HISTOGRAM_COUNTS_100("Networks.RememberedUnshared", unshared); 705 UMA_HISTOGRAM_COUNTS_100("Networks.RememberedUnshared", unshared);
693 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) { 706 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) {
694 NotifyDeviceListChanged(); 707 NotifyDeviceListChanged();
(...skipping 26 matching lines...) Expand all
721 NET_LOG_ERROR( 734 NET_LOG_ERROR(
722 "DefaultNetwork is not connected: " + network->connection_state(), 735 "DefaultNetwork is not connected: " + network->connection_state(),
723 network->path()); 736 network->path());
724 } 737 }
725 NotifyDefaultNetworkChanged(network); 738 NotifyDefaultNetworkChanged(network);
726 } 739 }
727 740
728 //------------------------------------------------------------------------------ 741 //------------------------------------------------------------------------------
729 // Private methods 742 // Private methods
730 743
744 void NetworkStateHandler::UpdateGuid(ManagedState* managed) {
745 if (managed->managed_type() == ManagedState::MANAGED_TYPE_FAVORITE) {
746 // Ensure that a FavoriteState has a valid GUID.
pneubeck (no reviews) 2014/05/12 13:37:07 nit: a -> the (or even remove the comment)
stevenjb 2014/05/13 01:19:00 Done.
747 FavoriteState* favorite = managed->AsFavoriteState();
748 if (!favorite->guid().empty())
749 return;
750 std::string specifier = favorite->GetSpecifier();
751 std::string guid;
752 SpecifierGuidMap::iterator iter = specifier_guid_map_.find(specifier);
753 if (iter != specifier_guid_map_.end()) {
754 guid = iter->second;
755 } else {
756 guid = base::GenerateGUID();
757 specifier_guid_map_[specifier] = guid;
758 }
759 favorite->SetGuid(guid);
760 NetworkState* network = GetModifiableNetworkState(favorite->path());
761 if (network)
762 network->SetGuid(guid);
763 } else if (managed->managed_type() == ManagedState::MANAGED_TYPE_NETWORK) {
764 // If the GUID is not set and a corresponding FavoriteState exists, get the
pneubeck (no reviews) 2014/05/12 13:37:07 hm. There's a again a timing subtlety here, I thin
stevenjb 2014/05/13 01:19:00 I don't think we can ever entirely guarantee that
765 // GUID from the FavoriteState. Otherwise it will get set when the Favorite
766 // is created.
767 NetworkState* network = managed->AsNetworkState();
768 if (!network->guid().empty())
769 return;
770 FavoriteState* favorite = GetModifiableFavoriteState(network->path());
771 if (favorite && !favorite->guid().empty())
772 network->SetGuid(favorite->guid());
773 }
774 }
775
731 void NetworkStateHandler::NotifyDeviceListChanged() { 776 void NetworkStateHandler::NotifyDeviceListChanged() {
732 NET_LOG_DEBUG("NotifyDeviceListChanged", 777 NET_LOG_DEBUG("NotifyDeviceListChanged",
733 base::StringPrintf("Size:%" PRIuS, device_list_.size())); 778 base::StringPrintf("Size:%" PRIuS, device_list_.size()));
734 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 779 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_,
735 DeviceListChanged()); 780 DeviceListChanged());
736 } 781 }
737 782
738 DeviceState* NetworkStateHandler::GetModifiableDeviceState( 783 DeviceState* NetworkStateHandler::GetModifiableDeviceState(
739 const std::string& device_path) const { 784 const std::string& device_path) const {
740 ManagedState* managed = GetModifiableManagedState(&device_list_, device_path); 785 ManagedState* managed = GetModifiableManagedState(&device_list_, device_path);
741 if (!managed) 786 if (!managed)
742 return NULL; 787 return NULL;
743 return managed->AsDeviceState(); 788 return managed->AsDeviceState();
744 } 789 }
745 790
746 NetworkState* NetworkStateHandler::GetModifiableNetworkState( 791 NetworkState* NetworkStateHandler::GetModifiableNetworkState(
747 const std::string& service_path) const { 792 const std::string& service_path) const {
748 ManagedState* managed = 793 ManagedState* managed =
749 GetModifiableManagedState(&network_list_, service_path); 794 GetModifiableManagedState(&network_list_, service_path);
750 if (!managed) 795 if (!managed)
751 return NULL; 796 return NULL;
752 return managed->AsNetworkState(); 797 return managed->AsNetworkState();
753 } 798 }
754 799
800 FavoriteState* NetworkStateHandler::GetModifiableFavoriteState(
801 const std::string& service_path) const {
802 ManagedState* managed =
803 GetModifiableManagedState(&favorite_list_, service_path);
804 if (!managed)
805 return NULL;
806 return managed->AsFavoriteState();
807 }
808
755 ManagedState* NetworkStateHandler::GetModifiableManagedState( 809 ManagedState* NetworkStateHandler::GetModifiableManagedState(
756 const ManagedStateList* managed_list, 810 const ManagedStateList* managed_list,
757 const std::string& path) const { 811 const std::string& path) const {
758 for (ManagedStateList::const_iterator iter = managed_list->begin(); 812 for (ManagedStateList::const_iterator iter = managed_list->begin();
759 iter != managed_list->end(); ++iter) { 813 iter != managed_list->end(); ++iter) {
760 ManagedState* managed = *iter; 814 ManagedState* managed = *iter;
761 if (managed->path() == path) 815 if (managed->path() == path)
762 return managed; 816 return managed;
763 } 817 }
764 return NULL; 818 return NULL;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 if (type.MatchesType(shill::kTypeBluetooth)) 916 if (type.MatchesType(shill::kTypeBluetooth))
863 technologies.push_back(new std::string(shill::kTypeBluetooth)); 917 technologies.push_back(new std::string(shill::kTypeBluetooth));
864 if (type.MatchesType(shill::kTypeVPN)) 918 if (type.MatchesType(shill::kTypeVPN))
865 technologies.push_back(new std::string(shill::kTypeVPN)); 919 technologies.push_back(new std::string(shill::kTypeVPN));
866 920
867 CHECK_GT(technologies.size(), 0ul); 921 CHECK_GT(technologies.size(), 0ul);
868 return technologies.Pass(); 922 return technologies.Pass();
869 } 923 }
870 924
871 } // namespace chromeos 925 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698