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

Side by Side Diff: chrome/browser/chromeos/cros/network_library.cc

Issue 7247021: Add remembered virtual networks to NetworkLibrary and internet options. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 6 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/chromeos/cros/network_library.h" 5 #include "chrome/browser/chromeos/cros/network_library.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 9
10 #include "base/i18n/icu_encoding_detection.h" 10 #include "base/i18n/icu_encoding_detection.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 // wifi_networks_: ordered vector of WifiNetwork* entries in network_map_, 48 // wifi_networks_: ordered vector of WifiNetwork* entries in network_map_,
49 // in descending order of importance. 49 // in descending order of importance.
50 // CellularNetwork 50 // CellularNetwork
51 // active_cellular_: Cellular version of wifi_. 51 // active_cellular_: Cellular version of wifi_.
52 // cellular_networks_: Cellular version of wifi_. 52 // cellular_networks_: Cellular version of wifi_.
53 // network_unique_id_map_: map<unique_id,Network*> for visible networks. 53 // network_unique_id_map_: map<unique_id,Network*> for visible networks.
54 // remembered_network_map_: a canonical map<path,Network*> for all networks 54 // remembered_network_map_: a canonical map<path,Network*> for all networks
55 // remembered in the active Profile ("favorites"). 55 // remembered in the active Profile ("favorites").
56 // remembered_wifi_networks_: ordered vector of WifiNetwork* entries in 56 // remembered_wifi_networks_: ordered vector of WifiNetwork* entries in
57 // remembered_network_map_, in descending order of preference. 57 // remembered_network_map_, in descending order of preference.
58 // remembered_virtual_networks_: ordered vector of VirtualNetwork* entries in
59 // remembered_network_map_, in descending order of preference.
58 // 60 //
59 // network_manager_monitor_: a handle to the libcros network Manager handler. 61 // network_manager_monitor_: a handle to the libcros network Manager handler.
60 // NetworkManagerStatusChanged: This handles all messages from the Manager. 62 // NetworkManagerStatusChanged: This handles all messages from the Manager.
61 // Messages are parsed here and the appropriate updates are then requested. 63 // Messages are parsed here and the appropriate updates are then requested.
62 // 64 //
63 // UpdateNetworkServiceList: This is the primary Manager handler. It handles 65 // UpdateNetworkServiceList: This is the primary Manager handler. It handles
64 // the "Services" message which list all visible networks. The handler 66 // the "Services" message which list all visible networks. The handler
65 // rebuilds the network lists without destroying existing Network structures, 67 // rebuilds the network lists without destroying existing Network structures,
66 // then requests neccessary updates to be fetched asynchronously from 68 // then requests neccessary updates to be fetched asynchronously from
67 // libcros (RequestNetworkServiceInfo). 69 // libcros (RequestNetworkServiceInfo).
(...skipping 1090 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 bool res = info->GetWithoutPathExpansion(key, &value); 1160 bool res = info->GetWithoutPathExpansion(key, &value);
1159 DCHECK(res); 1161 DCHECK(res);
1160 if (res) { 1162 if (res) {
1161 int index = property_index_parser().Get(key); 1163 int index = property_index_parser().Get(key);
1162 if (!ParseValue(index, value)) // virtual. 1164 if (!ParseValue(index, value)) // virtual.
1163 VLOG(1) << "Network: " << name() 1165 VLOG(1) << "Network: " << name()
1164 << " Type: " << ConnectionTypeToString(type()) 1166 << " Type: " << ConnectionTypeToString(type())
1165 << " Unhandled key: " << key; 1167 << " Unhandled key: " << key;
1166 } 1168 }
1167 } 1169 }
1170 CalculateUniqueId();
1168 } 1171 }
1169 1172
1170 void Network::EraseCredentials() { 1173 void Network::EraseCredentials() {
1171 } 1174 }
1172 1175
1176 void Network::CalculateUniqueId() {
1177 unique_id_ = name_;
1178 }
1179
1173 bool Network::RequiresUserProfile() const { 1180 bool Network::RequiresUserProfile() const {
1174 return false; 1181 return false;
1175 } 1182 }
1176 1183
1184 void Network::CopyCredentials(Network* other) {
1185 }
1186
1177 void Network::SetValueProperty(const char* prop, Value* val) { 1187 void Network::SetValueProperty(const char* prop, Value* val) {
1178 DCHECK(prop); 1188 DCHECK(prop);
1179 DCHECK(val); 1189 DCHECK(val);
1180 if (!EnsureCrosLoaded()) 1190 if (!EnsureCrosLoaded())
1181 return; 1191 return;
1182 chromeos::SetNetworkServiceProperty(service_path_.c_str(), prop, val); 1192 chromeos::SetNetworkServiceProperty(service_path_.c_str(), prop, val);
1183 } 1193 }
1184 1194
1185 void Network::ClearProperty(const char* prop) { 1195 void Network::ClearProperty(const char* prop) {
1186 DCHECK(prop); 1196 DCHECK(prop);
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
1397 default: 1407 default:
1398 return Network::ParseValue(index, value); 1408 return Network::ParseValue(index, value);
1399 break; 1409 break;
1400 } 1410 }
1401 return false; 1411 return false;
1402 } 1412 }
1403 1413
1404 void VirtualNetwork::ParseInfo(const DictionaryValue* info) { 1414 void VirtualNetwork::ParseInfo(const DictionaryValue* info) {
1405 Network::ParseInfo(info); 1415 Network::ParseInfo(info);
1406 VLOG(1) << "VPN: " << name() 1416 VLOG(1) << "VPN: " << name()
1417 << " Server: " << server_hostname()
1407 << " Type: " << ProviderTypeToString(provider_type()); 1418 << " Type: " << ProviderTypeToString(provider_type());
1408 if (provider_type_ == PROVIDER_TYPE_L2TP_IPSEC_PSK) { 1419 if (provider_type_ == PROVIDER_TYPE_L2TP_IPSEC_PSK) {
1409 if (!client_cert_id_.empty()) 1420 if (!client_cert_id_.empty())
1410 provider_type_ = PROVIDER_TYPE_L2TP_IPSEC_USER_CERT; 1421 provider_type_ = PROVIDER_TYPE_L2TP_IPSEC_USER_CERT;
1411 } 1422 }
1412 } 1423 }
1413 1424
1414 void VirtualNetwork::EraseCredentials() { 1425 void VirtualNetwork::EraseCredentials() {
1415 WipeString(&ca_cert_nss_); 1426 WipeString(&ca_cert_nss_);
1416 WipeString(&psk_passphrase_); 1427 WipeString(&psk_passphrase_);
1417 WipeString(&client_cert_id_); 1428 WipeString(&client_cert_id_);
1418 WipeString(&user_passphrase_); 1429 WipeString(&user_passphrase_);
1419 } 1430 }
1420 1431
1432 void VirtualNetwork::CalculateUniqueId() {
1433 std::string provider_type(ProviderTypeToString(provider_type_));
1434 unique_id_ = provider_type + "|" + server_hostname_;
1435 }
1436
1421 bool VirtualNetwork::RequiresUserProfile() const { 1437 bool VirtualNetwork::RequiresUserProfile() const {
1422 return true; 1438 return true;
1423 } 1439 }
1424 1440
1441 void VirtualNetwork::CopyCredentials(Network* other) {
1442 DCHECK(other->type() == TYPE_VPN);
1443 VirtualNetwork* other_vpn = static_cast<VirtualNetwork*>(other);
1444 VLOG(1) << "Copy VPN credentials: " << name()
1445 << " username: " << other_vpn->username();
1446 if (ca_cert_nss_.empty())
James Cook 2011/06/23 22:22:46 Why do we only overwrite fields that aren't empty?
stevenjb 2011/06/23 23:51:18 If an existing network has a value set, it might h
1447 ca_cert_nss_ = other_vpn->ca_cert_nss();
1448 if (psk_passphrase_.empty())
1449 psk_passphrase_ = other_vpn->psk_passphrase();
1450 if (client_cert_id_.empty())
1451 client_cert_id_ = other_vpn->client_cert_id();
1452 if (username_.empty())
1453 username_ = other_vpn->username();
1454 if (user_passphrase_.empty())
1455 user_passphrase_ = other_vpn->user_passphrase();
1456 }
1457
1425 bool VirtualNetwork::NeedMoreInfoToConnect() const { 1458 bool VirtualNetwork::NeedMoreInfoToConnect() const {
1426 if (server_hostname_.empty() || username_.empty() || user_passphrase_.empty()) 1459 if (server_hostname_.empty() || username_.empty() || user_passphrase_.empty())
1427 return true; 1460 return true;
1428 switch (provider_type_) { 1461 switch (provider_type_) {
1429 case PROVIDER_TYPE_L2TP_IPSEC_PSK: 1462 case PROVIDER_TYPE_L2TP_IPSEC_PSK:
1430 if (psk_passphrase_.empty()) 1463 if (psk_passphrase_.empty())
1431 return true; 1464 return true;
1432 break; 1465 break;
1433 case PROVIDER_TYPE_L2TP_IPSEC_USER_CERT: 1466 case PROVIDER_TYPE_L2TP_IPSEC_USER_CERT:
1434 case PROVIDER_TYPE_OPEN_VPN: 1467 case PROVIDER_TYPE_OPEN_VPN:
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
1957 : WirelessNetwork(service_path, TYPE_WIFI), 1990 : WirelessNetwork(service_path, TYPE_WIFI),
1958 encryption_(SECURITY_NONE), 1991 encryption_(SECURITY_NONE),
1959 passphrase_required_(false), 1992 passphrase_required_(false),
1960 eap_method_(EAP_METHOD_UNKNOWN), 1993 eap_method_(EAP_METHOD_UNKNOWN),
1961 eap_phase_2_auth_(EAP_PHASE_2_AUTH_AUTO), 1994 eap_phase_2_auth_(EAP_PHASE_2_AUTH_AUTO),
1962 eap_use_system_cas_(true) { 1995 eap_use_system_cas_(true) {
1963 } 1996 }
1964 1997
1965 WifiNetwork::~WifiNetwork() {} 1998 WifiNetwork::~WifiNetwork() {}
1966 1999
1967 // Called from ParseNetwork after calling ParseInfo.
1968 void WifiNetwork::CalculateUniqueId() { 2000 void WifiNetwork::CalculateUniqueId() {
1969 ConnectionSecurity encryption = encryption_; 2001 ConnectionSecurity encryption = encryption_;
1970 // Flimflam treats wpa and rsn as psk internally, so convert those types 2002 // Flimflam treats wpa and rsn as psk internally, so convert those types
1971 // to psk for unique naming. 2003 // to psk for unique naming.
1972 if (encryption == SECURITY_WPA || encryption == SECURITY_RSN) 2004 if (encryption == SECURITY_WPA || encryption == SECURITY_RSN)
1973 encryption = SECURITY_PSK; 2005 encryption = SECURITY_PSK;
1974 std::string security = std::string(SecurityToString(encryption)); 2006 std::string security = std::string(SecurityToString(encryption));
1975 unique_id_ = security + "|" + name_; 2007 unique_id_ = security + "|" + name_;
1976 } 2008 }
1977 2009
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
2091 case PROPERTY_INDEX_EAP_PIN: 2123 case PROPERTY_INDEX_EAP_PIN:
2092 case PROPERTY_INDEX_EAP_KEY_MGMT: 2124 case PROPERTY_INDEX_EAP_KEY_MGMT:
2093 // These properties are currently not used in the UI. 2125 // These properties are currently not used in the UI.
2094 return true; 2126 return true;
2095 default: 2127 default:
2096 return WirelessNetwork::ParseValue(index, value); 2128 return WirelessNetwork::ParseValue(index, value);
2097 } 2129 }
2098 return false; 2130 return false;
2099 } 2131 }
2100 2132
2101 void WifiNetwork::ParseInfo(const DictionaryValue* info) {
2102 Network::ParseInfo(info);
2103 CalculateUniqueId();
2104 }
2105
2106 const std::string& WifiNetwork::GetPassphrase() const { 2133 const std::string& WifiNetwork::GetPassphrase() const {
2107 if (!user_passphrase_.empty()) 2134 if (!user_passphrase_.empty())
2108 return user_passphrase_; 2135 return user_passphrase_;
2109 return passphrase_; 2136 return passphrase_;
2110 } 2137 }
2111 2138
2112 void WifiNetwork::SetPassphrase(const std::string& passphrase) { 2139 void WifiNetwork::SetPassphrase(const std::string& passphrase) {
2113 // Set the user_passphrase_ only; passphrase_ stores the flimflam value. 2140 // Set the user_passphrase_ only; passphrase_ stores the flimflam value.
2114 // If the user sets an empty passphrase, restore it to the passphrase 2141 // If the user sets an empty passphrase, restore it to the passphrase
2115 // remembered by flimflam. 2142 // remembered by flimflam.
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
2529 } 2556 }
2530 2557
2531 virtual const CellularNetworkVector& cellular_networks() const { 2558 virtual const CellularNetworkVector& cellular_networks() const {
2532 return cellular_networks_; 2559 return cellular_networks_;
2533 } 2560 }
2534 2561
2535 virtual const VirtualNetworkVector& virtual_networks() const { 2562 virtual const VirtualNetworkVector& virtual_networks() const {
2536 return virtual_networks_; 2563 return virtual_networks_;
2537 } 2564 }
2538 2565
2566 virtual const VirtualNetworkVector& remembered_virtual_networks() const {
2567 return remembered_virtual_networks_;
2568 }
2569
2539 ///////////////////////////////////////////////////////////////////////////// 2570 /////////////////////////////////////////////////////////////////////////////
2540 2571
2541 virtual const NetworkDevice* FindNetworkDeviceByPath( 2572 virtual const NetworkDevice* FindNetworkDeviceByPath(
2542 const std::string& path) const { 2573 const std::string& path) const {
2543 NetworkDeviceMap::const_iterator iter = device_map_.find(path); 2574 NetworkDeviceMap::const_iterator iter = device_map_.find(path);
2544 if (iter != device_map_.end()) 2575 if (iter != device_map_.end())
2545 return iter->second; 2576 return iter->second;
2546 LOG(WARNING) << "Device path not found: " << path; 2577 LOG(WARNING) << "Device path not found: " << path;
2547 return NULL; 2578 return NULL;
2548 } 2579 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
2614 2645
2615 virtual Network* FindNetworkFromRemembered( 2646 virtual Network* FindNetworkFromRemembered(
2616 const Network* remembered) const { 2647 const Network* remembered) const {
2617 NetworkMap::const_iterator found = 2648 NetworkMap::const_iterator found =
2618 network_unique_id_map_.find(remembered->unique_id()); 2649 network_unique_id_map_.find(remembered->unique_id());
2619 if (found != network_unique_id_map_.end()) 2650 if (found != network_unique_id_map_.end())
2620 return found->second; 2651 return found->second;
2621 return NULL; 2652 return NULL;
2622 } 2653 }
2623 2654
2655 Network* FindRememberedFromNetwork(const Network* network) const {
2656 for (NetworkMap::const_iterator iter = remembered_network_map_.begin();
2657 iter != remembered_network_map_.end(); ++iter) {
2658 if (iter->second->unique_id() == network->unique_id())
2659 return iter->second;
2660 }
2661 return NULL;
2662 }
2663
2624 virtual Network* FindRememberedNetworkByPath(const std::string& path) const { 2664 virtual Network* FindRememberedNetworkByPath(const std::string& path) const {
2625 NetworkMap::const_iterator iter = remembered_network_map_.find(path); 2665 NetworkMap::const_iterator iter = remembered_network_map_.find(path);
2626 if (iter != remembered_network_map_.end()) 2666 if (iter != remembered_network_map_.end())
2627 return iter->second; 2667 return iter->second;
2628 return NULL; 2668 return NULL;
2629 } 2669 }
2630 2670
2631 virtual const CellularDataPlanVector* GetDataPlans( 2671 virtual const CellularDataPlanVector* GetDataPlans(
2632 const std::string& path) const { 2672 const std::string& path) const {
2633 CellularDataPlanMap::const_iterator iter = data_plan_map_.find(path); 2673 CellularDataPlanMap::const_iterator iter = data_plan_map_.find(path);
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
3157 active_wifi_ = NULL; 3197 active_wifi_ = NULL;
3158 else if (found_network == active_cellular_) 3198 else if (found_network == active_cellular_)
3159 active_cellular_ = NULL; 3199 active_cellular_ = NULL;
3160 else if (found_network == active_virtual_) 3200 else if (found_network == active_virtual_)
3161 active_virtual_ = NULL; 3201 active_virtual_ = NULL;
3162 } 3202 }
3163 NotifyNetworkManagerChanged(true); // Forced update. 3203 NotifyNetworkManagerChanged(true); // Forced update.
3164 } 3204 }
3165 } 3205 }
3166 3206
3167 virtual void ForgetWifiNetwork(const std::string& service_path) { 3207 virtual void ForgetNetwork(const std::string& service_path) {
3168 if (!EnsureCrosLoaded()) 3208 if (!EnsureCrosLoaded())
3169 return; 3209 return;
3170 // Remove network from remembered list and notify observers. 3210 // Remove network from remembered list and notify observers.
3171 DeleteRememberedWifiNetwork(service_path); 3211 DeleteRememberedNetwork(service_path);
3172 NotifyNetworkManagerChanged(true); // Forced update. 3212 NotifyNetworkManagerChanged(true); // Forced update.
3173 } 3213 }
3174 3214
3175 // Note: currently there is no way to change the profile of a network 3215 // Note: currently there is no way to change the profile of a network
3176 // unless it is visible (i.e. in network_map_). We change the profile by 3216 // unless it is visible (i.e. in network_map_). We change the profile by
3177 // setting the Profile property of the visible network. 3217 // setting the Profile property of the visible network.
3178 // See chromium-os:15523. 3218 // See chromium-os:15523.
3179 virtual void SetNetworkProfile(const std::string& service_path, 3219 virtual void SetNetworkProfile(const std::string& service_path,
3180 NetworkProfileType type) { 3220 NetworkProfileType type) {
3181 Network* network = FindNetworkByPath(service_path); 3221 Network* network = FindNetworkByPath(service_path);
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
3664 } 3704 }
3665 3705
3666 static void RememberedNetworkServiceUpdate(void* object, 3706 static void RememberedNetworkServiceUpdate(void* object,
3667 const char* service_path, 3707 const char* service_path,
3668 const Value* info) { 3708 const Value* info) {
3669 NetworkLibraryImpl* networklib = static_cast<NetworkLibraryImpl*>(object); 3709 NetworkLibraryImpl* networklib = static_cast<NetworkLibraryImpl*>(object);
3670 DCHECK(networklib); 3710 DCHECK(networklib);
3671 if (service_path) { 3711 if (service_path) {
3672 if (!info) { 3712 if (!info) {
3673 // Remembered network no longer exists. 3713 // Remembered network no longer exists.
3674 networklib->DeleteRememberedWifiNetwork(std::string(service_path)); 3714 networklib->DeleteRememberedNetwork(std::string(service_path));
3675 } else { 3715 } else {
3676 DCHECK_EQ(info->GetType(), Value::TYPE_DICTIONARY); 3716 DCHECK_EQ(info->GetType(), Value::TYPE_DICTIONARY);
3677 const DictionaryValue* dict = static_cast<const DictionaryValue*>(info); 3717 const DictionaryValue* dict = static_cast<const DictionaryValue*>(info);
3678 networklib->ParseRememberedNetwork(std::string(service_path), dict); 3718 networklib->ParseRememberedNetwork(std::string(service_path), dict);
3679 } 3719 }
3680 } 3720 }
3681 } 3721 }
3682 3722
3683 static void NetworkDeviceUpdate(void* object, 3723 static void NetworkDeviceUpdate(void* object,
3684 const char* device_path, 3724 const char* device_path,
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
3818 data_plan_map_.find(network->service_path()); 3858 data_plan_map_.find(network->service_path());
3819 if (found != data_plan_map_.end()) { 3859 if (found != data_plan_map_.end()) {
3820 CellularDataPlanVector* data_plans = found->second; 3860 CellularDataPlanVector* data_plans = found->second;
3821 delete data_plans; 3861 delete data_plans;
3822 data_plan_map_.erase(found); 3862 data_plan_map_.erase(found);
3823 } 3863 }
3824 } 3864 }
3825 delete network; 3865 delete network;
3826 } 3866 }
3827 3867
3828 void AddRememberedWifiNetwork(WifiNetwork* wifi) { 3868 void AddRememberedNetwork(Network* network) {
3829 std::pair<NetworkMap::iterator,bool> result = 3869 std::pair<NetworkMap::iterator,bool> result =
3830 remembered_network_map_.insert( 3870 remembered_network_map_.insert(
3831 std::make_pair(wifi->service_path(), wifi)); 3871 std::make_pair(network->service_path(), network));
3832 DCHECK(result.second); // Should only get called with new network. 3872 DCHECK(result.second); // Should only get called with new network.
3833 remembered_wifi_networks_.push_back(wifi); 3873 if (network->type() == TYPE_WIFI) {
3874 remembered_wifi_networks_.push_back(
3875 static_cast<WifiNetwork*>(network));
3876 } else if (network->type() == TYPE_VPN) {
3877 remembered_virtual_networks_.push_back(
3878 static_cast<VirtualNetwork*>(network));
3879 } else {
3880 NOTREACHED();
3881 }
3834 // Find service path in profiles. Flimflam does not set the Profile 3882 // Find service path in profiles. Flimflam does not set the Profile
3835 // property for remembered networks, only active networks. 3883 // property for remembered networks, only active networks.
3836 for (NetworkProfileList::iterator iter = profile_list_.begin(); 3884 for (NetworkProfileList::iterator iter = profile_list_.begin();
3837 iter != profile_list_.end(); ++iter) { 3885 iter != profile_list_.end(); ++iter) {
3838 NetworkProfile& profile = *iter; 3886 NetworkProfile& profile = *iter;
3839 if (profile.services.find(wifi->service_path()) != 3887 if (profile.services.find(network->service_path()) !=
3840 profile.services.end()) { 3888 profile.services.end()) {
3841 wifi->set_profile_path(profile.path); 3889 network->set_profile_path(profile.path);
3842 wifi->set_profile_type(profile.type); 3890 network->set_profile_type(profile.type);
3843 VLOG(1) << "AddRememberedWifiNetwork: " << wifi->service_path() 3891 VLOG(1) << "AddRememberedNetwork: " << network->service_path()
3844 << " Profile: " << profile.path; 3892 << " Profile: " << profile.path;
3845 break; 3893 break;
3846 } 3894 }
3847 } 3895 }
3848 DCHECK(!wifi->profile_path().empty()) 3896 DCHECK(!network->profile_path().empty())
3849 << "Wifi service path not in any profile: " << wifi->service_path(); 3897 << "Service path not in any profile: " << network->service_path();
3850 } 3898 }
3851 3899
3852 void DeleteRememberedWifiNetwork(const std::string& service_path) { 3900 void DeleteRememberedNetwork(const std::string& service_path) {
3853 NetworkMap::iterator found = remembered_network_map_.find(service_path); 3901 NetworkMap::iterator found = remembered_network_map_.find(service_path);
3854 if (found == remembered_network_map_.end()) { 3902 if (found == remembered_network_map_.end()) {
3855 LOG(WARNING) << "Attempt to delete non-existant remembered network: " 3903 LOG(WARNING) << "Attempt to delete non-existant remembered network: "
3856 << service_path; 3904 << service_path;
3857 return; 3905 return;
3858 } 3906 }
3859 3907
3860 // Delete remembered network from lists. 3908 // Delete remembered network from lists.
3861 Network* remembered_network = found->second; 3909 Network* remembered_network = found->second;
3862 remembered_network_map_.erase(found); 3910 remembered_network_map_.erase(found);
3863 WifiNetworkVector::iterator iter = std::find(
3864 remembered_wifi_networks_.begin(), remembered_wifi_networks_.end(),
3865 remembered_network);
3866 if (iter != remembered_wifi_networks_.end())
3867 remembered_wifi_networks_.erase(iter);
3868 3911
3912 if (remembered_network->type() == TYPE_WIFI) {
3913 WifiNetworkVector::iterator iter = std::find(
3914 remembered_wifi_networks_.begin(),
3915 remembered_wifi_networks_.end(),
3916 remembered_network);
3917 if (iter != remembered_wifi_networks_.end())
3918 remembered_wifi_networks_.erase(iter);
3919 } else if (remembered_network->type() == TYPE_VPN) {
3920 VirtualNetworkVector::iterator iter = std::find(
3921 remembered_virtual_networks_.begin(),
3922 remembered_virtual_networks_.end(),
3923 remembered_network);
3924 if (iter != remembered_virtual_networks_.end())
3925 remembered_virtual_networks_.erase(iter);
3926 }
3869 // Delete remembered network from all profiles it is in. 3927 // Delete remembered network from all profiles it is in.
3870 for (NetworkProfileList::iterator iter = profile_list_.begin(); 3928 for (NetworkProfileList::iterator iter = profile_list_.begin();
3871 iter != profile_list_.end(); ++iter) { 3929 iter != profile_list_.end(); ++iter) {
3872 NetworkProfile& profile = *iter; 3930 NetworkProfile& profile = *iter;
3873 NetworkProfile::ServiceList::iterator found = 3931 NetworkProfile::ServiceList::iterator found =
3874 profile.services.find(remembered_network->service_path()); 3932 profile.services.find(remembered_network->service_path());
3875 if (found != profile.services.end()) { 3933 if (found != profile.services.end()) {
3876 VLOG(1) << "Deleting: " << remembered_network->service_path() 3934 VLOG(1) << "Deleting: " << remembered_network->service_path()
3877 << " From: " << profile.path; 3935 << " From: " << profile.path;
3878 chromeos::DeleteServiceFromProfile( 3936 chromeos::DeleteServiceFromProfile(
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
4087 4145
4088 network->ParseInfo(info); // virtual. 4146 network->ParseInfo(info); // virtual.
4089 4147
4090 if (!network->unique_id().empty()) 4148 if (!network->unique_id().empty())
4091 network_unique_id_map_[network->unique_id()] = network; 4149 network_unique_id_map_[network->unique_id()] = network;
4092 4150
4093 SetProfileTypeFromPath(network); 4151 SetProfileTypeFromPath(network);
4094 4152
4095 UpdateActiveNetwork(network); 4153 UpdateActiveNetwork(network);
4096 4154
4155 // Copy remembered credentials if required.
4156 Network* remembered = FindRememberedFromNetwork(network);
4157 if (remembered)
4158 network->CopyCredentials(remembered);
4159
4097 // Find and erase entry in update_requests, and set network priority. 4160 // Find and erase entry in update_requests, and set network priority.
4098 PriorityMap::iterator found2 = network_update_requests_.find(service_path); 4161 PriorityMap::iterator found2 = network_update_requests_.find(service_path);
4099 if (found2 != network_update_requests_.end()) { 4162 if (found2 != network_update_requests_.end()) {
4100 network->priority_order_ = found2->second; 4163 network->priority_order_ = found2->second;
4101 network_update_requests_.erase(found2); 4164 network_update_requests_.erase(found2);
4102 if (network_update_requests_.empty()) { 4165 if (network_update_requests_.empty()) {
4103 // Clear wifi_scanning_ when we have no pending requests. 4166 // Clear wifi_scanning_ when we have no pending requests.
4104 wifi_scanning_ = false; 4167 wifi_scanning_ = false;
4105 } 4168 }
4106 } else { 4169 } else {
4107 // TODO(stevenjb): Enable warning once UpdateNetworkServiceList is fixed. 4170 // TODO(stevenjb): Enable warning once UpdateNetworkServiceList is fixed.
4108 // LOG(WARNING) << "ParseNetwork called with no update request entry: " 4171 // LOG(WARNING) << "ParseNetwork called with no update request entry: "
4109 // << service_path; 4172 // << service_path;
4110 } 4173 }
4111 4174
4112 VLOG(1) << "ParseNetwork: " << network->name() 4175 VLOG(1) << "ParseNetwork: " << network->name()
4113 << " Path: " << network->service_path() 4176 << " Path: " << network->service_path()
4114 << " Profile: " << network->profile_path_; 4177 << " Profile: " << network->profile_path_;
4115 NotifyNetworkManagerChanged(false); // Not forced. 4178 NotifyNetworkManagerChanged(false); // Not forced.
4116 return network; 4179 return network;
4117 } 4180 }
4118 4181
4119 // Returns NULL if |service_path| refers to a network that is not a 4182 // Returns NULL if |service_path| refers to a network that is not a
4120 // remembered type. Called from RememberedNetworkServiceUpdate. 4183 // remembered type. Called from RememberedNetworkServiceUpdate.
4121 Network* ParseRememberedNetwork(const std::string& service_path, 4184 Network* ParseRememberedNetwork(const std::string& service_path,
4122 const DictionaryValue* info) { 4185 const DictionaryValue* info) {
4123 Network* network; 4186 Network* remembered;
4124 NetworkMap::iterator found = remembered_network_map_.find(service_path); 4187 NetworkMap::iterator found = remembered_network_map_.find(service_path);
4125 if (found != remembered_network_map_.end()) { 4188 if (found != remembered_network_map_.end()) {
4126 network = found->second; 4189 remembered = found->second;
4127 } else { 4190 } else {
4128 ConnectionType type = ParseTypeFromDictionary(info); 4191 ConnectionType type = ParseTypeFromDictionary(info);
4129 if (type == TYPE_WIFI) { 4192 if (type == TYPE_WIFI || type == TYPE_VPN) {
4130 network = CreateNewNetwork(type, service_path); 4193 remembered = CreateNewNetwork(type, service_path);
4131 WifiNetwork* wifi = static_cast<WifiNetwork*>(network); 4194 AddRememberedNetwork(remembered);
4132 AddRememberedWifiNetwork(wifi);
4133 } else { 4195 } else {
4134 VLOG(1) << "Ignoring remembered network: " << service_path 4196 VLOG(1) << "Ignoring remembered network: " << service_path
4135 << " Type: " << ConnectionTypeToString(type); 4197 << " Type: " << ConnectionTypeToString(type);
4136 return NULL; 4198 return NULL;
4137 } 4199 }
4138 } 4200 }
4139 network->ParseInfo(info); // virtual. 4201 remembered->ParseInfo(info); // virtual.
4140 4202
4141 SetProfileTypeFromPath(network); 4203 SetProfileTypeFromPath(remembered);
4142 4204
4143 VLOG(1) << "ParseRememberedNetwork: " << network->name() 4205 VLOG(1) << "ParseRememberedNetwork: " << remembered->name()
4144 << " Path: " << network->service_path() 4206 << " Path: " << remembered->service_path()
4145 << " Profile: " << network->profile_path_; 4207 << " Profile: " << remembered->profile_path_;
4146 NotifyNetworkManagerChanged(false); // Not forced. 4208 NotifyNetworkManagerChanged(false); // Not forced.
4147 return network; 4209
4210 if (remembered->type() == TYPE_VPN) {
4211 // VPNs are only stored in profiles. If we don't have a network for it,
4212 // request one.
4213 if (!FindNetworkFromRemembered(remembered)) {
4214 VirtualNetwork* vpn = static_cast<VirtualNetwork*>(remembered);
4215 std::string provider_type = ProviderTypeToString(vpn->provider_type());
4216 VLOG(1) << "Requesting VPN: " << vpn->name()
4217 << " Server: " << vpn->server_hostname()
4218 << " Type: " << provider_type;
4219 RequestVirtualNetwork(
4220 vpn->name().c_str(),
4221 vpn->server_hostname().c_str(),
4222 provider_type.c_str(),
4223 NetworkServiceUpdate,
4224 this);
4225 }
4226 }
4227
4228 return remembered;
4148 } 4229 }
4149 4230
4150 void SetProfileType(Network* network, NetworkProfileType type) { 4231 void SetProfileType(Network* network, NetworkProfileType type) {
4151 if (type == PROFILE_NONE) { 4232 if (type == PROFILE_NONE) {
4152 network->SetProfilePath(std::string()); 4233 network->SetProfilePath(std::string());
4153 network->set_profile_type(PROFILE_NONE); 4234 network->set_profile_type(PROFILE_NONE);
4154 } else { 4235 } else {
4155 std::string profile_path = GetProfilePath(type); 4236 std::string profile_path = GetProfilePath(type);
4156 if (!profile_path.empty()) { 4237 if (!profile_path.empty()) {
4157 network->SetProfilePath(profile_path); 4238 network->SetProfilePath(profile_path);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
4199 active_cellular_ = NULL; 4280 active_cellular_ = NULL;
4200 active_virtual_ = NULL; 4281 active_virtual_ = NULL;
4201 wifi_networks_.clear(); 4282 wifi_networks_.clear();
4202 cellular_networks_.clear(); 4283 cellular_networks_.clear();
4203 virtual_networks_.clear(); 4284 virtual_networks_.clear();
4204 } 4285 }
4205 4286
4206 void ClearRememberedNetworks() { 4287 void ClearRememberedNetworks() {
4207 remembered_network_map_.clear(); 4288 remembered_network_map_.clear();
4208 remembered_wifi_networks_.clear(); 4289 remembered_wifi_networks_.clear();
4290 remembered_virtual_networks_.clear();
4209 } 4291 }
4210 4292
4211 void DeleteNetworks() { 4293 void DeleteNetworks() {
4212 STLDeleteValues(&network_map_); 4294 STLDeleteValues(&network_map_);
4213 ClearNetworks(); 4295 ClearNetworks();
4214 } 4296 }
4215 4297
4216 void DeleteRememberedNetworks() { 4298 void DeleteRememberedNetworks() {
4217 STLDeleteValues(&remembered_network_map_); 4299 STLDeleteValues(&remembered_network_map_);
4218 ClearRememberedNetworks(); 4300 ClearRememberedNetworks();
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
4691 active_cellular_ = cellular1; 4773 active_cellular_ = cellular1;
4692 4774
4693 CellularNetwork* cellular2 = new CellularNetwork("fc2"); 4775 CellularNetwork* cellular2 = new CellularNetwork("fc2");
4694 cellular2->set_name("Fake Cellular 2"); 4776 cellular2->set_name("Fake Cellular 2");
4695 cellular2->set_strength(70); 4777 cellular2->set_strength(70);
4696 cellular2->set_connected(true); 4778 cellular2->set_connected(true);
4697 cellular2->set_activation_state(ACTIVATION_STATE_ACTIVATED); 4779 cellular2->set_activation_state(ACTIVATION_STATE_ACTIVATED);
4698 cellular2->set_network_technology(NETWORK_TECHNOLOGY_UMTS); 4780 cellular2->set_network_technology(NETWORK_TECHNOLOGY_UMTS);
4699 AddNetwork(cellular2); 4781 AddNetwork(cellular2);
4700 4782
4701 // Remembered Networks
4702 DeleteRememberedNetworks();
4703 NetworkProfile profile("default", PROFILE_SHARED);
4704 profile.services.insert("fw2");
4705 profile_list_.push_back(profile);
4706 WifiNetwork* remembered_wifi2 = new WifiNetwork("fw2");
4707 remembered_wifi2->set_name("Fake Wifi 2");
4708 remembered_wifi2->set_strength(70);
4709 remembered_wifi2->set_connected(true);
4710 remembered_wifi2->set_encryption(SECURITY_WEP);
4711 AddRememberedWifiNetwork(remembered_wifi2);
4712
4713 // VPNs. 4783 // VPNs.
4714 VirtualNetwork* vpn1 = new VirtualNetwork("fv1"); 4784 VirtualNetwork* vpn1 = new VirtualNetwork("fv1");
4715 vpn1->set_name("Fake VPN Provider 1"); 4785 vpn1->set_name("Fake VPN Provider 1");
4716 vpn1->set_server_hostname("vpn1server.fake.com"); 4786 vpn1->set_server_hostname("vpn1server.fake.com");
4717 vpn1->set_provider_type(VirtualNetwork::PROVIDER_TYPE_L2TP_IPSEC_PSK); 4787 vpn1->set_provider_type(VirtualNetwork::PROVIDER_TYPE_L2TP_IPSEC_PSK);
4718 vpn1->set_username("VPN User 1"); 4788 vpn1->set_username("VPN User 1");
4719 vpn1->set_connected(false); 4789 vpn1->set_connected(false);
4720 AddNetwork(vpn1); 4790 AddNetwork(vpn1);
4721 4791
4722 VirtualNetwork* vpn2 = new VirtualNetwork("fv2"); 4792 VirtualNetwork* vpn2 = new VirtualNetwork("fv2");
4723 vpn2->set_name("Fake VPN Provider 2"); 4793 vpn2->set_name("Fake VPN Provider 2");
4724 vpn2->set_server_hostname("vpn2server.fake.com"); 4794 vpn2->set_server_hostname("vpn2server.fake.com");
4725 vpn2->set_provider_type(VirtualNetwork::PROVIDER_TYPE_L2TP_IPSEC_USER_CERT); 4795 vpn2->set_provider_type(VirtualNetwork::PROVIDER_TYPE_L2TP_IPSEC_USER_CERT);
4726 vpn2->set_username("VPN User 2"); 4796 vpn2->set_username("VPN User 2");
4727 vpn2->set_connected(true); 4797 vpn2->set_connected(true);
4728 AddNetwork(vpn2); 4798 AddNetwork(vpn2);
4729 4799
4730 VirtualNetwork* vpn3 = new VirtualNetwork("fv3"); 4800 VirtualNetwork* vpn3 = new VirtualNetwork("fv3");
4731 vpn3->set_name("Fake VPN Provider 3"); 4801 vpn3->set_name("Fake VPN Provider 3");
4732 vpn3->set_server_hostname("vpn3server.fake.com"); 4802 vpn3->set_server_hostname("vpn3server.fake.com");
4733 vpn3->set_provider_type(VirtualNetwork::PROVIDER_TYPE_OPEN_VPN); 4803 vpn3->set_provider_type(VirtualNetwork::PROVIDER_TYPE_OPEN_VPN);
4734 vpn3->set_connected(false); 4804 vpn3->set_connected(false);
4735 AddNetwork(vpn3); 4805 AddNetwork(vpn3);
4736 4806
4737 active_virtual_ = vpn2; 4807 active_virtual_ = vpn2;
4738 4808
4809 // Remembered Networks
4810 DeleteRememberedNetworks();
4811 NetworkProfile profile("default", PROFILE_SHARED);
4812 profile.services.insert("fw2");
4813 profile.services.insert("fv2");
4814 profile_list_.push_back(profile);
4815 WifiNetwork* remembered_wifi2 = new WifiNetwork("fw2");
4816 remembered_wifi2->set_name("Fake Wifi 2");
4817 remembered_wifi2->set_encryption(SECURITY_WEP);
4818 AddRememberedNetwork(remembered_wifi2);
4819 VirtualNetwork* remembered_vpn2 = new VirtualNetwork("fv2");
James Cook 2011/06/23 22:22:46 Hooray for more stubs!
stevenjb 2011/06/23 23:51:18 :)
4820 remembered_vpn2->set_name("Fake VPN Provider 2");
4821 remembered_vpn2->set_server_hostname("vpn2server.fake.com");
4822 remembered_vpn2->set_provider_type(
4823 VirtualNetwork::PROVIDER_TYPE_L2TP_IPSEC_USER_CERT);
4824 remembered_vpn2->set_connected(true);
4825 AddRememberedNetwork(remembered_vpn2);
4826
4739 wifi_scanning_ = false; 4827 wifi_scanning_ = false;
4740 offline_mode_ = false; 4828 offline_mode_ = false;
4741 } 4829 }
4742 4830
4743 // Network manager observer list 4831 // Network manager observer list
4744 ObserverList<NetworkManagerObserver> network_manager_observers_; 4832 ObserverList<NetworkManagerObserver> network_manager_observers_;
4745 4833
4746 // Cellular data plan observer list 4834 // Cellular data plan observer list
4747 ObserverList<CellularDataPlanObserver> data_plan_observers_; 4835 ObserverList<CellularDataPlanObserver> data_plan_observers_;
4748 4836
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
4805 4893
4806 // The current connected (or connecting) cellular network. 4894 // The current connected (or connecting) cellular network.
4807 CellularNetwork* active_cellular_; 4895 CellularNetwork* active_cellular_;
4808 4896
4809 // The list of available virtual networks. 4897 // The list of available virtual networks.
4810 VirtualNetworkVector virtual_networks_; 4898 VirtualNetworkVector virtual_networks_;
4811 4899
4812 // The current connected (or connecting) virtual network. 4900 // The current connected (or connecting) virtual network.
4813 VirtualNetwork* active_virtual_; 4901 VirtualNetwork* active_virtual_;
4814 4902
4903 // The remembered virtual networks.
4904 VirtualNetworkVector remembered_virtual_networks_;
4905
4815 // The path of the active profile (for retrieving remembered services). 4906 // The path of the active profile (for retrieving remembered services).
4816 std::string active_profile_path_; 4907 std::string active_profile_path_;
4817 4908
4818 // The current available network devices. Bitwise flag of ConnectionTypes. 4909 // The current available network devices. Bitwise flag of ConnectionTypes.
4819 int available_devices_; 4910 int available_devices_;
4820 4911
4821 // The current enabled network devices. Bitwise flag of ConnectionTypes. 4912 // The current enabled network devices. Bitwise flag of ConnectionTypes.
4822 int enabled_devices_; 4913 int enabled_devices_;
4823 4914
4824 // The current connected network devices. Bitwise flag of ConnectionTypes. 4915 // The current connected network devices. Bitwise flag of ConnectionTypes.
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
4931 } 5022 }
4932 virtual const WifiNetworkVector& remembered_wifi_networks() const { 5023 virtual const WifiNetworkVector& remembered_wifi_networks() const {
4933 return wifi_networks_; 5024 return wifi_networks_;
4934 } 5025 }
4935 virtual const CellularNetworkVector& cellular_networks() const { 5026 virtual const CellularNetworkVector& cellular_networks() const {
4936 return cellular_networks_; 5027 return cellular_networks_;
4937 } 5028 }
4938 virtual const VirtualNetworkVector& virtual_networks() const { 5029 virtual const VirtualNetworkVector& virtual_networks() const {
4939 return virtual_networks_; 5030 return virtual_networks_;
4940 } 5031 }
5032 virtual const VirtualNetworkVector& remembered_virtual_networks() const {
5033 return virtual_networks_;
5034 }
4941 virtual bool has_cellular_networks() const { 5035 virtual bool has_cellular_networks() const {
4942 return cellular_networks_.begin() != cellular_networks_.end(); 5036 return cellular_networks_.begin() != cellular_networks_.end();
4943 } 5037 }
4944 ///////////////////////////////////////////////////////////////////////////// 5038 /////////////////////////////////////////////////////////////////////////////
4945 5039
4946 virtual const NetworkDevice* FindNetworkDeviceByPath( 5040 virtual const NetworkDevice* FindNetworkDeviceByPath(
4947 const std::string& path) const { return NULL; } 5041 const std::string& path) const { return NULL; }
4948 virtual const NetworkDevice* FindCellularDevice() const { 5042 virtual const NetworkDevice* FindCellularDevice() const {
4949 return NULL; 5043 return NULL;
4950 } 5044 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
5013 virtual void ConnectToVirtualNetworkCert( 5107 virtual void ConnectToVirtualNetworkCert(
5014 const std::string& service_name, 5108 const std::string& service_name,
5015 const std::string& server_hostname, 5109 const std::string& server_hostname,
5016 const std::string& server_ca_cert_nss_nickname, 5110 const std::string& server_ca_cert_nss_nickname,
5017 const std::string& client_cert_pkcs11_id, 5111 const std::string& client_cert_pkcs11_id,
5018 const std::string& username, 5112 const std::string& username,
5019 const std::string& user_passphrase) {} 5113 const std::string& user_passphrase) {}
5020 virtual void SignalCellularPlanPayment() {} 5114 virtual void SignalCellularPlanPayment() {}
5021 virtual bool HasRecentCellularPlanPayment() { return false; } 5115 virtual bool HasRecentCellularPlanPayment() { return false; }
5022 virtual void DisconnectFromNetwork(const Network* network) {} 5116 virtual void DisconnectFromNetwork(const Network* network) {}
5023 virtual void ForgetWifiNetwork(const std::string& service_path) {} 5117 virtual void ForgetNetwork(const std::string& service_path) {}
5024 virtual void SetNetworkProfile(const std::string& service_path, 5118 virtual void SetNetworkProfile(const std::string& service_path,
5025 NetworkProfileType type) {} 5119 NetworkProfileType type) {}
5026 virtual std::string GetCellularHomeCarrierId() const { return std::string(); } 5120 virtual std::string GetCellularHomeCarrierId() const { return std::string(); }
5027 virtual bool ethernet_available() const { return true; } 5121 virtual bool ethernet_available() const { return true; }
5028 virtual bool wifi_available() const { return false; } 5122 virtual bool wifi_available() const { return false; }
5029 virtual bool cellular_available() const { return false; } 5123 virtual bool cellular_available() const { return false; }
5030 virtual bool ethernet_enabled() const { return true; } 5124 virtual bool ethernet_enabled() const { return true; }
5031 virtual bool wifi_enabled() const { return false; } 5125 virtual bool wifi_enabled() const { return false; }
5032 virtual bool cellular_enabled() const { return false; } 5126 virtual bool cellular_enabled() const { return false; }
5033 virtual bool wifi_scanning() const { return false; } 5127 virtual bool wifi_scanning() const { return false; }
(...skipping 29 matching lines...) Expand all
5063 return new NetworkLibraryStubImpl(); 5157 return new NetworkLibraryStubImpl();
5064 else 5158 else
5065 return new NetworkLibraryImpl(); 5159 return new NetworkLibraryImpl();
5066 } 5160 }
5067 5161
5068 } // namespace chromeos 5162 } // namespace chromeos
5069 5163
5070 // Allows InvokeLater without adding refcounting. This class is a Singleton and 5164 // Allows InvokeLater without adding refcounting. This class is a Singleton and
5071 // won't be deleted until it's last InvokeLater is run. 5165 // won't be deleted until it's last InvokeLater is run.
5072 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImpl); 5166 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImpl);
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/cros/network_library.h ('k') | chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698