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> |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 // Class for tracking the list of visible networks and their properties. | 42 // Class for tracking the list of visible networks and their properties. |
43 // | 43 // |
44 // This class maps essential properties from the connection manager (Shill) for | 44 // This class maps essential properties from the connection manager (Shill) for |
45 // each visible network. It is not used to change the properties of services or | 45 // each visible network. It is not used to change the properties of services or |
46 // devices, only global (manager) properties. | 46 // devices, only global (manager) properties. |
47 // | 47 // |
48 // All getters return the currently cached properties. This class is expected to | 48 // All getters return the currently cached properties. This class is expected to |
49 // keep properties up to date by managing the appropriate Shill observers. | 49 // keep properties up to date by managing the appropriate Shill observers. |
50 // It will invoke its own more specific observer methods when the specified | 50 // It will invoke its own more specific observer methods when the specified |
51 // changes occur. | 51 // changes occur. |
52 // | |
53 // Some notes about NetworkState, FavoriteState, and GUIDs: | |
54 // * A FavoriteState exists for all network services stored in a profile, and | |
55 // all "visible" networks (physically connected networks like ethernet and | |
56 // cellular or in-range wifi networks). If the network is stored in a profile, | |
57 // FavoriteState.IsInProfile() will return true. | |
58 // * A NetworkState exists for "visible" networks only. There will always be a | |
59 // corresponding FavoriteState with the same service_path() property. | |
60 // * All networks saved to a profile will have a saved GUID that is persistent | |
61 // across sessions. | |
62 // * Networks that are not saved to a profile will have a GUID assigned when | |
63 // the initial properties are received. The GUID will be consistent for | |
64 // the duration of a session, even if the network drops out and returns. | |
65 // * Both FavoriteState and NetworkState store the GUID. It will always be the | |
66 // same for the same network (i.e. entries with the same service_path()). | |
52 | 67 |
53 class CHROMEOS_EXPORT NetworkStateHandler | 68 class CHROMEOS_EXPORT NetworkStateHandler |
54 : public internal::ShillPropertyHandler::Listener { | 69 : public internal::ShillPropertyHandler::Listener { |
55 public: | 70 public: |
56 typedef std::vector<ManagedState*> ManagedStateList; | 71 typedef std::vector<ManagedState*> ManagedStateList; |
57 typedef std::vector<const NetworkState*> NetworkStateList; | 72 typedef std::vector<const NetworkState*> NetworkStateList; |
58 typedef std::vector<const DeviceState*> DeviceStateList; | 73 typedef std::vector<const DeviceState*> DeviceStateList; |
59 typedef std::vector<const FavoriteState*> FavoriteStateList; | 74 typedef std::vector<const FavoriteState*> FavoriteStateList; |
60 | 75 |
61 enum TechnologyState { | 76 enum TechnologyState { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 // See GetNetworkList() for usage, and notes for |favorite_list_|. | 180 // See GetNetworkList() for usage, and notes for |favorite_list_|. |
166 // Favorites that are visible have the same path() as the entries in | 181 // Favorites that are visible have the same path() as the entries in |
167 // GetNetworkList(), so GetNetworkState() can be used to determine if a | 182 // GetNetworkList(), so GetNetworkState() can be used to determine if a |
168 // favorite is visible and retrieve the complete properties (and vice-versa). | 183 // favorite is visible and retrieve the complete properties (and vice-versa). |
169 void GetFavoriteList(FavoriteStateList* list) const; | 184 void GetFavoriteList(FavoriteStateList* list) const; |
170 | 185 |
171 // Like GetFavoriteList() but only returns favorites with matching |type|. | 186 // Like GetFavoriteList() but only returns favorites with matching |type|. |
172 void GetFavoriteListByType(const NetworkTypePattern& type, | 187 void GetFavoriteListByType(const NetworkTypePattern& type, |
173 FavoriteStateList* list) const; | 188 FavoriteStateList* list) const; |
174 | 189 |
175 // Finds and returns a favorite state by |service_path| or NULL if not found. | 190 // Finds and returns the FavoriteState associated with |service_path| or NULL |
176 const FavoriteState* GetFavoriteState(const std::string& service_path) const; | 191 // if not found. If |configured_only| is true, only returns saved entries |
192 // (IsInProfile is true). | |
193 const FavoriteState* GetFavoriteStateFromServicePath( | |
194 const std::string& service_path, | |
195 bool configured_only) const; | |
196 | |
197 // Finds and returns the FavoriteState associated with |guid| or NULL if not | |
198 // found. This returns all entries (IsInProfile() may be true or false). | |
199 const FavoriteState* GetFavoriteStateFromGuid(const std::string& guid) const; | |
177 | 200 |
178 // Requests a network scan. This may trigger updates to the network | 201 // Requests a network scan. This may trigger updates to the network |
179 // list, which will trigger the appropriate observer calls. | 202 // list, which will trigger the appropriate observer calls. |
180 void RequestScan() const; | 203 void RequestScan() const; |
181 | 204 |
182 // Request a scan if not scanning and run |callback| when the Scanning state | 205 // Request a scan if not scanning and run |callback| when the Scanning state |
183 // for any Device of network type |type| completes. | 206 // for any Device of network type |type| completes. |
184 void WaitForScan(const std::string& type, const base::Closure& callback); | 207 void WaitForScan(const std::string& type, const base::Closure& callback); |
185 | 208 |
186 // Request a network scan then signal Shill to connect to the best available | 209 // Request a network scan then signal Shill to connect to the best available |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 virtual void DefaultNetworkServiceChanged( | 304 virtual void DefaultNetworkServiceChanged( |
282 const std::string& service_path) OVERRIDE; | 305 const std::string& service_path) OVERRIDE; |
283 | 306 |
284 // Called after construction. Called explicitly by tests after adding | 307 // Called after construction. Called explicitly by tests after adding |
285 // test observers. | 308 // test observers. |
286 void InitShillPropertyHandler(); | 309 void InitShillPropertyHandler(); |
287 | 310 |
288 private: | 311 private: |
289 typedef std::list<base::Closure> ScanCallbackList; | 312 typedef std::list<base::Closure> ScanCallbackList; |
290 typedef std::map<std::string, ScanCallbackList> ScanCompleteCallbackMap; | 313 typedef std::map<std::string, ScanCallbackList> ScanCompleteCallbackMap; |
314 typedef std::map<std::string, std::string> SpecifierGuidMap; | |
291 friend class NetworkStateHandlerTest; | 315 friend class NetworkStateHandlerTest; |
292 FRIEND_TEST_ALL_PREFIXES(NetworkStateHandlerTest, NetworkStateHandlerStub); | 316 FRIEND_TEST_ALL_PREFIXES(NetworkStateHandlerTest, NetworkStateHandlerStub); |
293 | 317 |
294 // NetworkState specific method for UpdateManagedStateProperties which | 318 // NetworkState specific method for UpdateManagedStateProperties which |
295 // notifies observers. | 319 // notifies observers. |
296 void UpdateNetworkStateProperties(NetworkState* network, | 320 void UpdateNetworkStateProperties(NetworkState* network, |
297 const base::DictionaryValue& properties); | 321 const base::DictionaryValue& properties); |
298 | 322 |
323 // Ensure a valid GUID for FavoriteState and update the NetworkState GUID from | |
324 // the corresponding FavoriteState if necessary. | |
325 void UpdateGuid(ManagedState* managed); | |
326 | |
299 // Sends DeviceListChanged() to observers and logs an event. | 327 // Sends DeviceListChanged() to observers and logs an event. |
300 void NotifyDeviceListChanged(); | 328 void NotifyDeviceListChanged(); |
301 | 329 |
302 // Non-const getters for managed entries. These are const so that they can | 330 // Non-const getters for managed entries. These are const so that they can |
303 // be called by Get[Network|Device]State, even though they return non-const | 331 // be called by Get[Network|Device]State, even though they return non-const |
304 // pointers. | 332 // pointers. |
305 DeviceState* GetModifiableDeviceState(const std::string& device_path) const; | 333 DeviceState* GetModifiableDeviceState(const std::string& device_path) const; |
306 NetworkState* GetModifiableNetworkState( | 334 NetworkState* GetModifiableNetworkState( |
307 const std::string& service_path) const; | 335 const std::string& service_path) const; |
336 FavoriteState* GetModifiableFavoriteState( | |
337 const std::string& service_path) const; | |
308 ManagedState* GetModifiableManagedState(const ManagedStateList* managed_list, | 338 ManagedState* GetModifiableManagedState(const ManagedStateList* managed_list, |
309 const std::string& path) const; | 339 const std::string& path) const; |
310 | 340 |
311 // Gets the list specified by |type|. | 341 // Gets the list specified by |type|. |
312 ManagedStateList* GetManagedList(ManagedState::ManagedType type); | 342 ManagedStateList* GetManagedList(ManagedState::ManagedType type); |
313 | 343 |
314 // Helper function to notify observers. Calls CheckDefaultNetworkChanged(). | 344 // Helper function to notify observers. Calls CheckDefaultNetworkChanged(). |
315 void OnNetworkConnectionStateChanged(NetworkState* network); | 345 void OnNetworkConnectionStateChanged(NetworkState* network); |
316 | 346 |
317 // Notifies observers when the default network or its properties change. | 347 // Notifies observers when the default network or its properties change. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
350 | 380 |
351 // Keeps track of the default network for notifying observers when it changes. | 381 // Keeps track of the default network for notifying observers when it changes. |
352 std::string default_network_path_; | 382 std::string default_network_path_; |
353 | 383 |
354 // List of interfaces on which portal check is enabled. | 384 // List of interfaces on which portal check is enabled. |
355 std::string check_portal_list_; | 385 std::string check_portal_list_; |
356 | 386 |
357 // Callbacks to run when a scan for the technology type completes. | 387 // Callbacks to run when a scan for the technology type completes. |
358 ScanCompleteCallbackMap scan_complete_callbacks_; | 388 ScanCompleteCallbackMap scan_complete_callbacks_; |
359 | 389 |
390 // Map of network specifiers to guids. Contains an entry for each | |
391 // FavoriteState that is not saved in a profile, and only for unsaved entries. | |
pneubeck (no reviews)
2014/05/13 08:43:54
last 'entries' -> 'networks'/'FavoriteStates' ?
stevenjb
2014/05/13 18:25:07
Removed last clause, it was just confusing.
| |
392 SpecifierGuidMap specifier_guid_map_; | |
393 | |
360 DISALLOW_COPY_AND_ASSIGN(NetworkStateHandler); | 394 DISALLOW_COPY_AND_ASSIGN(NetworkStateHandler); |
361 }; | 395 }; |
362 | 396 |
363 } // namespace chromeos | 397 } // namespace chromeos |
364 | 398 |
365 #endif // CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_H_ | 399 #endif // CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_H_ |
OLD | NEW |