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 any Device matching |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 // Set the user initiated connecting network. | 151 // Set the user initiated connecting network. |
143 void SetConnectingNetwork(const std::string& service_path); | 152 void SetConnectingNetwork(const std::string& service_path); |
144 | 153 |
145 const std::string& connecting_network() const { return connecting_network_; } | 154 const std::string& connecting_network() const { return connecting_network_; } |
146 | 155 |
147 // Generates a DictionaryValue of all NetworkState properties. Currently | 156 // Generates a DictionaryValue of all NetworkState properties. Currently |
148 // provided for debugging purposes only. | 157 // provided for debugging purposes only. |
149 void GetNetworkStatePropertiesForTest( | 158 void GetNetworkStatePropertiesForTest( |
150 base::DictionaryValue* dictionary) const; | 159 base::DictionaryValue* dictionary) const; |
151 | 160 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 // notifies observers. If |type| == TYPE_NETWORK this also calls | 205 // notifies observers. If |type| == TYPE_NETWORK this also calls |
197 // CheckDefaultNetworkChanged(). | 206 // CheckDefaultNetworkChanged(). |
198 virtual void ManagedStateListChanged( | 207 virtual void ManagedStateListChanged( |
199 ManagedState::ManagedType type) OVERRIDE; | 208 ManagedState::ManagedType type) OVERRIDE; |
200 | 209 |
201 // Called in Initialize(). Called explicitly by tests after adding | 210 // Called in Initialize(). Called explicitly by tests after adding |
202 // test observers. | 211 // test observers. |
203 void InitShillPropertyHandler(); | 212 void InitShillPropertyHandler(); |
204 | 213 |
205 private: | 214 private: |
| 215 typedef std::list<base::Closure> ScanCallbackList; |
| 216 typedef std::map<std::string, ScanCallbackList> ScanCompleteCallbackMap; |
206 friend class NetworkStateHandlerTest; | 217 friend class NetworkStateHandlerTest; |
207 FRIEND_TEST_ALL_PREFIXES(NetworkStateHandlerTest, NetworkStateHandlerStub); | 218 FRIEND_TEST_ALL_PREFIXES(NetworkStateHandlerTest, NetworkStateHandlerStub); |
208 | 219 |
209 // Non-const getters for managed entries. These are const so that they can | 220 // Non-const getters for managed entries. These are const so that they can |
210 // be called by Get[Network|Device]State, even though they return non-const | 221 // be called by Get[Network|Device]State, even though they return non-const |
211 // pointers. | 222 // pointers. |
212 DeviceState* GetModifiableDeviceState(const std::string& device_path) const; | 223 DeviceState* GetModifiableDeviceState(const std::string& device_path) const; |
213 NetworkState* GetModifiableNetworkState( | 224 NetworkState* GetModifiableNetworkState( |
214 const std::string& service_path) const; | 225 const std::string& service_path) const; |
215 ManagedState* GetModifiableManagedState(const ManagedStateList* managed_list, | 226 ManagedState* GetModifiableManagedState(const ManagedStateList* managed_list, |
216 const std::string& path) const; | 227 const std::string& path) const; |
217 | 228 |
218 // Gets the list specified by |type|. | 229 // Gets the list specified by |type|. |
219 ManagedStateList* GetManagedList(ManagedState::ManagedType type); | 230 ManagedStateList* GetManagedList(ManagedState::ManagedType type); |
220 | 231 |
221 // Helper function to notify observers. Calls CheckDefaultNetworkChanged(). | 232 // Helper function to notify observers. Calls CheckDefaultNetworkChanged(). |
222 void OnNetworkConnectionStateChanged(NetworkState* network); | 233 void OnNetworkConnectionStateChanged(NetworkState* network); |
223 | 234 |
224 // If the default network changed returns true and sets | 235 // If the default network changed returns true and sets |
225 // |default_network_path_|. | 236 // |default_network_path_|. |
226 bool CheckDefaultNetworkChanged(); | 237 bool CheckDefaultNetworkChanged(); |
227 | 238 |
228 // Logs an event and notifies observers. | 239 // Logs an event and notifies observers. |
229 void OnDefaultNetworkChanged(); | 240 void OnDefaultNetworkChanged(); |
230 | 241 |
231 // Notifies observers and updates connecting_network_. | 242 // Notifies observers and updates connecting_network_. |
232 void NetworkPropertiesUpdated(const NetworkState* network); | 243 void NetworkPropertiesUpdated(const NetworkState* network); |
233 | 244 |
| 245 // Called whenever Device.Scanning state transitions to false. |
| 246 void ScanCompleted(const std::string& type); |
| 247 |
234 // Shill property handler instance, owned by this class. | 248 // Shill property handler instance, owned by this class. |
235 scoped_ptr<internal::ShillPropertyHandler> shill_property_handler_; | 249 scoped_ptr<internal::ShillPropertyHandler> shill_property_handler_; |
236 | 250 |
237 // Observer list | 251 // Observer list |
238 ObserverList<NetworkStateHandlerObserver> observers_; | 252 ObserverList<NetworkStateHandlerObserver> observers_; |
239 | 253 |
240 // Lists of managed states | 254 // Lists of managed states |
241 ManagedStateList network_list_; | 255 ManagedStateList network_list_; |
242 ManagedStateList device_list_; | 256 ManagedStateList device_list_; |
243 | 257 |
244 // Keeps track of the default network for notifying observers when it changes. | 258 // Keeps track of the default network for notifying observers when it changes. |
245 std::string default_network_path_; | 259 std::string default_network_path_; |
246 | 260 |
247 // Convenience member to track the user initiated connecting network. Set | 261 // Convenience member to track the user initiated connecting network. Set |
248 // externally when a connection is requested and cleared here when the state | 262 // externally when a connection is requested and cleared here when the state |
249 // changes to something other than Connecting (after observers are notified). | 263 // changes to something other than Connecting (after observers are notified). |
250 // TODO(stevenjb): Move this to NetworkConfigurationHandler. | 264 // TODO(stevenjb): Move this to NetworkConfigurationHandler. |
251 std::string connecting_network_; | 265 std::string connecting_network_; |
252 | 266 |
| 267 // Callbacks to run when a scan for the technology type completes. |
| 268 ScanCompleteCallbackMap scan_complete_callbacks_; |
| 269 |
253 DISALLOW_COPY_AND_ASSIGN(NetworkStateHandler); | 270 DISALLOW_COPY_AND_ASSIGN(NetworkStateHandler); |
254 }; | 271 }; |
255 | 272 |
256 } // namespace chromeos | 273 } // namespace chromeos |
257 | 274 |
258 #endif // CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_H_ | 275 #endif // CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_H_ |
OLD | NEW |