| 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 #ifndef CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_H_ | 5 #ifndef CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_H_ |
| 6 #define CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_H_ | 6 #define CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/callback_forward.h" |
| 13 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
| 16 #include "chromeos/chromeos_export.h" | 17 #include "chromeos/chromeos_export.h" |
| 17 #include "chromeos/network/managed_state.h" | 18 #include "chromeos/network/managed_state.h" |
| 18 #include "chromeos/network/network_handler_callbacks.h" | 19 #include "chromeos/network/network_handler_callbacks.h" |
| 19 #include "chromeos/network/shill_property_handler.h" | 20 #include "chromeos/network/shill_property_handler.h" |
| 20 | 21 |
| 21 namespace base { | 22 namespace base { |
| 22 class DictionaryValue; | 23 class DictionaryValue; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 // Sets |list| to contain the list of networks. The returned list contains | 133 // Sets |list| to contain the list of networks. The returned list contains |
| 133 // a copy of NetworkState pointers which should not be stored or used beyond | 134 // a copy of NetworkState pointers which should not be stored or used beyond |
| 134 // the scope of the calling function (i.e. they may later become invalid, but | 135 // the scope of the calling function (i.e. they may later become invalid, but |
| 135 // only on the UI thread). | 136 // only on the UI thread). |
| 136 void GetNetworkList(NetworkStateList* list) const; | 137 void GetNetworkList(NetworkStateList* list) const; |
| 137 | 138 |
| 138 // Requests a network scan. This may trigger updates to the network | 139 // Requests a network scan. This may trigger updates to the network |
| 139 // list, which will trigger the appropriate observer calls. | 140 // list, which will trigger the appropriate observer calls. |
| 140 void RequestScan() const; | 141 void RequestScan() const; |
| 141 | 142 |
| 143 // Request a scan if not scanning and run |callback| when the Scanning state |
| 144 // for Device type |type| completes. |
| 145 void WaitForScan(const std::string& type, const base::Closure& callback); |
| 146 |
| 147 // Request a network scan then signal Shill to connect to the best available |
| 148 // networks when completed. |
| 149 void ConnectToBestWifiNetwork(); |
| 150 |
| 142 static const char kMatchTypeDefault[]; | 151 static const char kMatchTypeDefault[]; |
| 143 static const char kMatchTypeWireless[]; | 152 static const char kMatchTypeWireless[]; |
| 144 static const char kMatchTypeMobile[]; | 153 static const char kMatchTypeMobile[]; |
| 145 static const char kMatchTypeNonVirtual[]; | 154 static const char kMatchTypeNonVirtual[]; |
| 146 | 155 |
| 147 const std::string& connecting_network() const { return connecting_network_; } | 156 const std::string& connecting_network() const { return connecting_network_; } |
| 148 void set_connecting_network(const std::string& service_path) { | 157 void set_connecting_network(const std::string& service_path) { |
| 149 connecting_network_ = service_path; | 158 connecting_network_ = service_path; |
| 150 } | 159 } |
| 151 | 160 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 // notifies observers. If |type| == TYPE_NETWORK this also calls | 200 // notifies observers. If |type| == TYPE_NETWORK this also calls |
| 192 // CheckDefaultNetworkChanged(). | 201 // CheckDefaultNetworkChanged(). |
| 193 virtual void ManagedStateListChanged( | 202 virtual void ManagedStateListChanged( |
| 194 ManagedState::ManagedType type) OVERRIDE; | 203 ManagedState::ManagedType type) OVERRIDE; |
| 195 | 204 |
| 196 // Called in Initialize(). Called explicitly by tests after adding | 205 // Called in Initialize(). Called explicitly by tests after adding |
| 197 // test observers. | 206 // test observers. |
| 198 void InitShillPropertyHandler(); | 207 void InitShillPropertyHandler(); |
| 199 | 208 |
| 200 private: | 209 private: |
| 210 typedef std::list<base::Closure> ScanCallbackList; |
| 211 typedef std::map<std::string, ScanCallbackList> ScanCompleteCallbackMap; |
| 201 friend class NetworkStateHandlerTest; | 212 friend class NetworkStateHandlerTest; |
| 202 FRIEND_TEST_ALL_PREFIXES(NetworkStateHandlerTest, NetworkStateHandlerStub); | 213 FRIEND_TEST_ALL_PREFIXES(NetworkStateHandlerTest, NetworkStateHandlerStub); |
| 203 | 214 |
| 204 // Non-const getters for managed entries. These are const so that they can | 215 // Non-const getters for managed entries. These are const so that they can |
| 205 // be called by Get[Network|Device]State, even though they return non-const | 216 // be called by Get[Network|Device]State, even though they return non-const |
| 206 // pointers. | 217 // pointers. |
| 207 DeviceState* GetModifiableDeviceState(const std::string& device_path) const; | 218 DeviceState* GetModifiableDeviceState(const std::string& device_path) const; |
| 208 NetworkState* GetModifiableNetworkState( | 219 NetworkState* GetModifiableNetworkState( |
| 209 const std::string& service_path) const; | 220 const std::string& service_path) const; |
| 210 ManagedState* GetModifiableManagedState(const ManagedStateList* managed_list, | 221 ManagedState* GetModifiableManagedState(const ManagedStateList* managed_list, |
| 211 const std::string& path) const; | 222 const std::string& path) const; |
| 212 | 223 |
| 213 // Gets the list specified by |type|. | 224 // Gets the list specified by |type|. |
| 214 ManagedStateList* GetManagedList(ManagedState::ManagedType type); | 225 ManagedStateList* GetManagedList(ManagedState::ManagedType type); |
| 215 | 226 |
| 216 // Helper function to notify observers. Calls CheckDefaultNetworkChanged(). | 227 // Helper function to notify observers. Calls CheckDefaultNetworkChanged(). |
| 217 void OnNetworkConnectionStateChanged(NetworkState* network); | 228 void OnNetworkConnectionStateChanged(NetworkState* network); |
| 218 | 229 |
| 219 // If the default network changed returns true and sets | 230 // If the default network changed returns true and sets |
| 220 // |default_network_path_|. | 231 // |default_network_path_|. |
| 221 bool CheckDefaultNetworkChanged(); | 232 bool CheckDefaultNetworkChanged(); |
| 222 | 233 |
| 223 // Logs an event and notifies observers. | 234 // Logs an event and notifies observers. |
| 224 void OnDefaultNetworkChanged(); | 235 void OnDefaultNetworkChanged(); |
| 225 | 236 |
| 226 // Notifies observers and updates connecting_network_. | 237 // Notifies observers and updates connecting_network_. |
| 227 void NetworkPropertiesUpdated(const NetworkState* network); | 238 void NetworkPropertiesUpdated(const NetworkState* network); |
| 228 | 239 |
| 240 // Called whenever Device.Scanning state transitions to false. |
| 241 void ScanCompleted(const std::string& type); |
| 242 |
| 229 // Shill property handler instance, owned by this class. | 243 // Shill property handler instance, owned by this class. |
| 230 scoped_ptr<internal::ShillPropertyHandler> shill_property_handler_; | 244 scoped_ptr<internal::ShillPropertyHandler> shill_property_handler_; |
| 231 | 245 |
| 232 // Observer list | 246 // Observer list |
| 233 ObserverList<NetworkStateHandlerObserver> observers_; | 247 ObserverList<NetworkStateHandlerObserver> observers_; |
| 234 | 248 |
| 235 // Lists of managed states | 249 // Lists of managed states |
| 236 ManagedStateList network_list_; | 250 ManagedStateList network_list_; |
| 237 ManagedStateList device_list_; | 251 ManagedStateList device_list_; |
| 238 | 252 |
| 239 // Keeps track of the default network for notifying observers when it changes. | 253 // Keeps track of the default network for notifying observers when it changes. |
| 240 std::string default_network_path_; | 254 std::string default_network_path_; |
| 241 | 255 |
| 242 // Convenience member to track the user initiated connecting network. Set | 256 // Convenience member to track the user initiated connecting network. Set |
| 243 // externally when a connection is requested and cleared here when the state | 257 // externally when a connection is requested and cleared here when the state |
| 244 // changes to something other than Connecting (after observers are notified). | 258 // changes to something other than Connecting (after observers are notified). |
| 245 // TODO(stevenjb): Move this to NetworkConfigurationHandler. | 259 // TODO(stevenjb): Move this to NetworkConfigurationHandler. |
| 246 std::string connecting_network_; | 260 std::string connecting_network_; |
| 247 | 261 |
| 262 // Callbacks to run when a scan for the technology type completes. |
| 263 ScanCompleteCallbackMap scan_complete_callbacks_; |
| 264 |
| 248 DISALLOW_COPY_AND_ASSIGN(NetworkStateHandler); | 265 DISALLOW_COPY_AND_ASSIGN(NetworkStateHandler); |
| 249 }; | 266 }; |
| 250 | 267 |
| 251 } // namespace chromeos | 268 } // namespace chromeos |
| 252 | 269 |
| 253 #endif // CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_H_ | 270 #endif // CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_H_ |
| OLD | NEW |