Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include <set> | 9 #include <set> |
| 10 | 10 |
| (...skipping 2658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2669 const std::string& user_passphrase) OVERRIDE; | 2669 const std::string& user_passphrase) OVERRIDE; |
| 2670 | 2670 |
| 2671 // virtual DisconnectFromNetwork implemented in derived classes. | 2671 // virtual DisconnectFromNetwork implemented in derived classes. |
| 2672 virtual void ForgetNetwork(const std::string& service_path) OVERRIDE; | 2672 virtual void ForgetNetwork(const std::string& service_path) OVERRIDE; |
| 2673 virtual void EnableEthernetNetworkDevice(bool enable) OVERRIDE; | 2673 virtual void EnableEthernetNetworkDevice(bool enable) OVERRIDE; |
| 2674 virtual void EnableWifiNetworkDevice(bool enable) OVERRIDE; | 2674 virtual void EnableWifiNetworkDevice(bool enable) OVERRIDE; |
| 2675 virtual void EnableCellularNetworkDevice(bool enable) OVERRIDE; | 2675 virtual void EnableCellularNetworkDevice(bool enable) OVERRIDE; |
| 2676 // virtual EnableOfflineMode implemented in derived classes. | 2676 // virtual EnableOfflineMode implemented in derived classes. |
| 2677 // virtual GetIPConfigs implemented in derived classes. | 2677 // virtual GetIPConfigs implemented in derived classes. |
| 2678 // virtual SetIPConfig implemented in derived classes. | 2678 // virtual SetIPConfig implemented in derived classes. |
| 2679 virtual void SwitchToPreferredNetwork() OVERRIDE; | |
| 2679 | 2680 |
| 2680 protected: | 2681 protected: |
| 2681 typedef ObserverList<NetworkObserver> NetworkObserverList; | 2682 typedef ObserverList<NetworkObserver> NetworkObserverList; |
| 2682 typedef std::map<std::string, NetworkObserverList*> NetworkObserverMap; | 2683 typedef std::map<std::string, NetworkObserverList*> NetworkObserverMap; |
| 2683 | 2684 |
| 2684 typedef ObserverList<NetworkDeviceObserver> NetworkDeviceObserverList; | 2685 typedef ObserverList<NetworkDeviceObserver> NetworkDeviceObserverList; |
| 2685 typedef std::map<std::string, NetworkDeviceObserverList*> | 2686 typedef std::map<std::string, NetworkDeviceObserverList*> |
| 2686 NetworkDeviceObserverMap; | 2687 NetworkDeviceObserverMap; |
| 2687 | 2688 |
| 2688 typedef std::map<std::string, Network*> NetworkMap; | 2689 typedef std::map<std::string, Network*> NetworkMap; |
| (...skipping 1048 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3737 return; | 3738 return; |
| 3738 CallEnableNetworkDeviceType(TYPE_WIFI, enable); | 3739 CallEnableNetworkDeviceType(TYPE_WIFI, enable); |
| 3739 } | 3740 } |
| 3740 | 3741 |
| 3741 void NetworkLibraryImplBase::EnableCellularNetworkDevice(bool enable) { | 3742 void NetworkLibraryImplBase::EnableCellularNetworkDevice(bool enable) { |
| 3742 if (is_locked_) | 3743 if (is_locked_) |
| 3743 return; | 3744 return; |
| 3744 CallEnableNetworkDeviceType(TYPE_CELLULAR, enable); | 3745 CallEnableNetworkDeviceType(TYPE_CELLULAR, enable); |
| 3745 } | 3746 } |
| 3746 | 3747 |
| 3748 void NetworkLibraryImplBase::SwitchToPreferredNetwork() { | |
| 3749 // If current network (if any) is not preferred, check network service list to | |
| 3750 // see if the first not connected network is preferred and set to autoconnect. | |
| 3751 // If so, connect to it. | |
| 3752 if (!wifi_enabled() || (active_wifi_ && active_wifi_->preferred())) | |
| 3753 return; | |
| 3754 for (WifiNetworkVector::const_iterator it = wifi_networks_.begin(); | |
| 3755 it != wifi_networks_.end(); ++it) { | |
| 3756 WifiNetwork* wifi = *it; | |
| 3757 if (wifi->connected() || wifi->connecting()) // Skip connected/connecting. | |
| 3758 continue; | |
| 3759 if (!wifi->preferred()) // All preferred networks are sorted in front. | |
| 3760 break; | |
| 3761 if (wifi->auto_connect()) { | |
| 3762 ConnectToWifiNetwork(wifi); | |
| 3763 break; | |
| 3764 } | |
| 3765 } | |
| 3766 } | |
| 3767 | |
| 3768 | |
| 3747 //////////////////////////////////////////////////////////////////////////// | 3769 //////////////////////////////////////////////////////////////////////////// |
| 3748 // Network list management functions. | 3770 // Network list management functions. |
| 3749 | 3771 |
| 3750 // Note: sometimes flimflam still returns networks when the device type is | 3772 // Note: sometimes flimflam still returns networks when the device type is |
| 3751 // disabled. Always check the appropriate enabled() state before adding | 3773 // disabled. Always check the appropriate enabled() state before adding |
| 3752 // networks to a list or setting an active network so that we do not show them | 3774 // networks to a list or setting an active network so that we do not show them |
| 3753 // in the UI. | 3775 // in the UI. |
| 3754 | 3776 |
| 3755 // This relies on services being requested from flimflam in priority order, | 3777 // This relies on services being requested from flimflam in priority order, |
| 3756 // and the updates getting processed and received in order. | 3778 // and the updates getting processed and received in order. |
| (...skipping 1200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4957 case PROPERTY_INDEX_OFFLINE_MODE: { | 4979 case PROPERTY_INDEX_OFFLINE_MODE: { |
| 4958 DCHECK_EQ(value->GetType(), Value::TYPE_BOOLEAN); | 4980 DCHECK_EQ(value->GetType(), Value::TYPE_BOOLEAN); |
| 4959 value->GetAsBoolean(&offline_mode_); | 4981 value->GetAsBoolean(&offline_mode_); |
| 4960 NotifyNetworkManagerChanged(false); // Not forced. | 4982 NotifyNetworkManagerChanged(false); // Not forced. |
| 4961 break; | 4983 break; |
| 4962 } | 4984 } |
| 4963 case PROPERTY_INDEX_ACTIVE_PROFILE: { | 4985 case PROPERTY_INDEX_ACTIVE_PROFILE: { |
| 4964 DCHECK_EQ(value->GetType(), Value::TYPE_STRING); | 4986 DCHECK_EQ(value->GetType(), Value::TYPE_STRING); |
| 4965 value->GetAsString(&active_profile_path_); | 4987 value->GetAsString(&active_profile_path_); |
| 4966 VLOG(1) << "Active Profile: " << active_profile_path_; | 4988 VLOG(1) << "Active Profile: " << active_profile_path_; |
| 4989 if (active_profile_path_ != kSharedProfilePath) | |
| 4990 SwitchToPreferredNetwork(); | |
|
stevenjb
2011/08/03 22:58:26
We should probably only call this when active_prof
Charlie Lee
2011/08/04 20:43:02
What's the format of the user profile? It seems li
stevenjb
2011/08/04 21:01:15
Ah, I see, I didn't add a kUserProfilePath[]. We s
| |
| 4967 break; | 4991 break; |
| 4968 } | 4992 } |
| 4969 case PROPERTY_INDEX_PROFILES: { | 4993 case PROPERTY_INDEX_PROFILES: { |
| 4970 DCHECK_EQ(value->GetType(), Value::TYPE_LIST); | 4994 DCHECK_EQ(value->GetType(), Value::TYPE_LIST); |
| 4971 const ListValue* vlist = static_cast<const ListValue*>(value); | 4995 const ListValue* vlist = static_cast<const ListValue*>(value); |
| 4972 UpdateRememberedNetworks(vlist); | 4996 UpdateRememberedNetworks(vlist); |
| 4973 RequestRememberedNetworksUpdate(); | 4997 RequestRememberedNetworksUpdate(); |
| 4974 break; | 4998 break; |
| 4975 } | 4999 } |
| 4976 case PROPERTY_INDEX_SERVICES: { | 5000 case PROPERTY_INDEX_SERVICES: { |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5251 // Update the list of profiles. | 5275 // Update the list of profiles. |
| 5252 profile_list_.clear(); | 5276 profile_list_.clear(); |
| 5253 for (ListValue::const_iterator iter = profiles->begin(); | 5277 for (ListValue::const_iterator iter = profiles->begin(); |
| 5254 iter != profiles->end(); ++iter) { | 5278 iter != profiles->end(); ++iter) { |
| 5255 std::string profile_path; | 5279 std::string profile_path; |
| 5256 (*iter)->GetAsString(&profile_path); | 5280 (*iter)->GetAsString(&profile_path); |
| 5257 if (profile_path.empty()) { | 5281 if (profile_path.empty()) { |
| 5258 LOG(WARNING) << "Bad or empty profile path."; | 5282 LOG(WARNING) << "Bad or empty profile path."; |
| 5259 continue; | 5283 continue; |
| 5260 } | 5284 } |
| 5261 NetworkProfileType profile_type; | 5285 NetworkProfileType profile_type; |
|
Charlie Lee
2011/08/04 20:43:02
See this code. I assume user profile is something
| |
| 5262 if (profile_path == kSharedProfilePath) | 5286 if (profile_path == kSharedProfilePath) |
| 5263 profile_type = PROFILE_SHARED; | 5287 profile_type = PROFILE_SHARED; |
| 5264 else | 5288 else |
| 5265 profile_type = PROFILE_USER; | 5289 profile_type = PROFILE_USER; |
| 5266 profile_list_.push_back(NetworkProfile(profile_path, profile_type)); | 5290 profile_list_.push_back(NetworkProfile(profile_path, profile_type)); |
| 5267 // Check to see if we connected to any networks before a user profile was | 5291 // Check to see if we connected to any networks before a user profile was |
| 5268 // available (i.e. before login), but unchecked the "Share" option (i.e. | 5292 // available (i.e. before login), but unchecked the "Share" option (i.e. |
| 5269 // the desired pofile is the user profile). Move these networks to the | 5293 // the desired pofile is the user profile). Move these networks to the |
| 5270 // user profile when it becomes available. | 5294 // user profile when it becomes available. |
| 5271 if (profile_type == PROFILE_USER && !user_networks_.empty()) { | 5295 if (profile_type == PROFILE_USER && !user_networks_.empty()) { |
| (...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5847 return network_library; | 5871 return network_library; |
| 5848 } | 5872 } |
| 5849 | 5873 |
| 5850 ///////////////////////////////////////////////////////////////////////////// | 5874 ///////////////////////////////////////////////////////////////////////////// |
| 5851 | 5875 |
| 5852 } // namespace chromeos | 5876 } // namespace chromeos |
| 5853 | 5877 |
| 5854 // Allows InvokeLater without adding refcounting. This class is a Singleton and | 5878 // Allows InvokeLater without adding refcounting. This class is a Singleton and |
| 5855 // won't be deleted until it's last InvokeLater is run. | 5879 // won't be deleted until it's last InvokeLater is run. |
| 5856 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImplBase); | 5880 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImplBase); |
| OLD | NEW |