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

Side by Side Diff: chromeos/network/network_state_handler.h

Issue 289383004: Merge FavoriteState into NetworkState (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase + Fix tests Created 6 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) 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // 52 //
53 // Some notes about NetworkState, FavoriteState, and GUIDs: 53 // Some notes about NetworkState and GUIDs:
54 // * A FavoriteState exists for all network services stored in a profile, and 54 // * A NetworkState exists for all network services stored in a profile, and
55 // all "visible" networks (physically connected networks like ethernet 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, 56 // cellular or in-range wifi networks). If the network is stored in a profile,
57 // FavoriteState.IsInProfile() will return true. 57 // NetworkState.IsInProfile() will return true.
58 // * A NetworkState exists for "visible" networks only. There will always be a 58 // * "Visible" networks return true for NetworkState.IsVisible().
59 // corresponding FavoriteState with the same service_path() property.
60 // * All networks saved to a profile will have a saved GUID that is persistent 59 // * All networks saved to a profile will have a saved GUID that is persistent
61 // across sessions. 60 // across sessions.
62 // * Networks that are not saved to a profile will have a GUID assigned when 61 // * 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 62 // 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. 63 // 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()).
67 64
68 class CHROMEOS_EXPORT NetworkStateHandler 65 class CHROMEOS_EXPORT NetworkStateHandler
69 : public internal::ShillPropertyHandler::Listener { 66 : public internal::ShillPropertyHandler::Listener {
70 public: 67 public:
71 typedef std::vector<ManagedState*> ManagedStateList; 68 typedef std::vector<ManagedState*> ManagedStateList;
72 typedef std::vector<const NetworkState*> NetworkStateList; 69 typedef std::vector<const NetworkState*> NetworkStateList;
73 typedef std::vector<const DeviceState*> DeviceStateList; 70 typedef std::vector<const DeviceState*> DeviceStateList;
74 typedef std::vector<const FavoriteState*> FavoriteStateList;
75 71
76 enum TechnologyState { 72 enum TechnologyState {
77 TECHNOLOGY_UNAVAILABLE, 73 TECHNOLOGY_UNAVAILABLE,
78 TECHNOLOGY_AVAILABLE, 74 TECHNOLOGY_AVAILABLE,
79 TECHNOLOGY_UNINITIALIZED, 75 TECHNOLOGY_UNINITIALIZED,
80 TECHNOLOGY_ENABLING, 76 TECHNOLOGY_ENABLING,
81 TECHNOLOGY_ENABLED 77 TECHNOLOGY_ENABLED
82 }; 78 };
83 79
84 virtual ~NetworkStateHandler(); 80 virtual ~NetworkStateHandler();
85 81
86 // Add/remove observers. 82 // Add/remove observers.
87 void AddObserver(NetworkStateHandlerObserver* observer, 83 void AddObserver(NetworkStateHandlerObserver* observer,
88 const tracked_objects::Location& from_here); 84 const tracked_objects::Location& from_here);
89 void RemoveObserver(NetworkStateHandlerObserver* observer, 85 void RemoveObserver(NetworkStateHandlerObserver* observer,
90 const tracked_objects::Location& from_here); 86 const tracked_objects::Location& from_here);
91 87
92 // Requests all Manager properties, specifically to update the complete 88 // Requests all Manager properties, specifically to update the complete
93 // list of services which determines the list of Favorites. This should be 89 // list of services which determines the list of Networks. This should be
pneubeck (no reviews) 2014/06/10 10:51:37 Isn't this usually unnecessary to call, since we h
stevenjb 2014/06/10 16:17:28 It's mostly unused now, but I will do an audit and
94 // called any time a new service is configured or a Profile is loaded. 90 // called any time a new service is configured or a Profile is loaded.
95 void UpdateManagerProperties(); 91 void UpdateManagerProperties();
96 92
97 // Returns the state for technology |type|. Only 93 // Returns the state for technology |type|. Only
98 // NetworkTypePattern::Primitive, ::Mobile and ::Ethernet are supported. 94 // NetworkTypePattern::Primitive, ::Mobile and ::Ethernet are supported.
99 TechnologyState GetTechnologyState(const NetworkTypePattern& type) const; 95 TechnologyState GetTechnologyState(const NetworkTypePattern& type) const;
100 bool IsTechnologyAvailable(const NetworkTypePattern& type) const { 96 bool IsTechnologyAvailable(const NetworkTypePattern& type) const {
101 return GetTechnologyState(type) != TECHNOLOGY_UNAVAILABLE; 97 return GetTechnologyState(type) != TECHNOLOGY_UNAVAILABLE;
102 } 98 }
103 bool IsTechnologyEnabled(const NetworkTypePattern& type) const { 99 bool IsTechnologyEnabled(const NetworkTypePattern& type) const {
(...skipping 23 matching lines...) Expand all
127 // value for each property. To receive notifications when a property changes, 123 // value for each property. To receive notifications when a property changes,
128 // observe this class and implement NetworkPropertyChanged(). 124 // observe this class and implement NetworkPropertyChanged().
129 const NetworkState* GetNetworkState(const std::string& service_path) const; 125 const NetworkState* GetNetworkState(const std::string& service_path) const;
130 126
131 // Returns the default network (which includes VPNs) based on the Shill 127 // Returns the default network (which includes VPNs) based on the Shill
132 // Manager.DefaultNetwork property. Normally this is the same as 128 // Manager.DefaultNetwork property. Normally this is the same as
133 // ConnectedNetworkByType(NetworkTypePattern::Default()), but the timing might 129 // ConnectedNetworkByType(NetworkTypePattern::Default()), but the timing might
134 // differ. 130 // differ.
135 const NetworkState* DefaultNetwork() const; 131 const NetworkState* DefaultNetwork() const;
136 132
137 // Returns the FavoriteState associated to DefaultNetwork. Returns NULL if,
138 // and only if, DefaultNetwork returns NULL.
139 const FavoriteState* DefaultFavoriteNetwork() const;
140
141 // Returns the primary connected network of matching |type|, otherwise NULL. 133 // Returns the primary connected network of matching |type|, otherwise NULL.
142 const NetworkState* ConnectedNetworkByType( 134 const NetworkState* ConnectedNetworkByType(
143 const NetworkTypePattern& type) const; 135 const NetworkTypePattern& type) const;
144 136
145 // Like ConnectedNetworkByType() but returns a connecting network or NULL. 137 // Like ConnectedNetworkByType() but returns a connecting network or NULL.
146 const NetworkState* ConnectingNetworkByType( 138 const NetworkState* ConnectingNetworkByType(
147 const NetworkTypePattern& type) const; 139 const NetworkTypePattern& type) const;
148 140
149 // Like ConnectedNetworkByType() but returns any matching network or NULL. 141 // Like ConnectedNetworkByType() but returns any matching network or NULL.
150 // Mostly useful for mobile networks where there is generally only one 142 // Mostly useful for mobile networks where there is generally only one
151 // network. Note: O(N). 143 // network. Note: O(N).
152 const NetworkState* FirstNetworkByType(const NetworkTypePattern& type) const; 144 const NetworkState* FirstNetworkByType(const NetworkTypePattern& type) const;
153 145
154 // Returns the aa:bb formatted hardware (MAC) address for the first connected 146 // Returns the aa:bb formatted hardware (MAC) address for the first connected
155 // network matching |type|, or an empty string if none is connected. 147 // network matching |type|, or an empty string if none is connected.
156 std::string FormattedHardwareAddressForType( 148 std::string FormattedHardwareAddressForType(
157 const NetworkTypePattern& type) const; 149 const NetworkTypePattern& type) const;
158 150
159 // Sets |list| to contain the list of networks. The returned list contains 151 // Sets |list| to contain the list of visible networks matching |type|. The
pneubeck (no reviews) 2014/06/10 10:51:37 both functions GetVisibleNetworkList* should be ex
stevenjb 2014/06/10 16:17:28 Will do.
160 // a copy of NetworkState pointers which should not be stored or used beyond 152 // returned list contains a copy of NetworkState pointers which should not be
161 // the scope of the calling function (i.e. they may later become invalid, but 153 // stored or used beyond the scope of the calling function (i.e. they may
162 // only on the UI thread). 154 // later become invalid, but only on the UI thread).
163 void GetNetworkList(NetworkStateList* list) const; 155 void GetVisibleNetworkListByType(const NetworkTypePattern& type,
156 NetworkStateList* list) const;
164 157
165 // Like GetNetworkList() but only returns networks with matching |type|. 158 // Convenience method for GetVisibleNetworkListByType(All).
159 void GetVisibleNetworkList(NetworkStateList* list) const;
160
161 // Sets |list| to contain the list of networks with matching |type| and the
162 // following properties:
163 // |configured_only| - if true only include networks where IsInProfile is true
164 // |visible_only| - if true only include networks in the visible Services list
165 // |limit| - if > 0 limits the number of results.
166 void GetNetworkListByType(const NetworkTypePattern& type, 166 void GetNetworkListByType(const NetworkTypePattern& type,
167 bool configured_only,
168 bool visible_only,
169 int limit,
167 NetworkStateList* list) const; 170 NetworkStateList* list) const;
168 171
172 // Finds and returns the NetworkState associated with |service_path| or NULL
173 // if not found. If |configured_only| is true, only returns saved entries
174 // (IsInProfile is true).
175 const NetworkState* GetNetworkStateFromServicePath(
176 const std::string& service_path,
177 bool configured_only) const;
178
179 // Finds and returns the NetworkState associated with |guid| or NULL if not
180 // found. This returns all entries (IsInProfile() may be true or false).
181 const NetworkState* GetNetworkStateFromGuid(const std::string& guid) const;
182
169 // Sets |list| to contain the list of devices. The returned list contains 183 // Sets |list| to contain the list of devices. The returned list contains
170 // a copy of DeviceState pointers which should not be stored or used beyond 184 // a copy of DeviceState pointers which should not be stored or used beyond
171 // the scope of the calling function (i.e. they may later become invalid, but 185 // the scope of the calling function (i.e. they may later become invalid, but
172 // only on the UI thread). 186 // only on the UI thread).
173 void GetDeviceList(DeviceStateList* list) const; 187 void GetDeviceList(DeviceStateList* list) const;
174 188
175 // Like GetDeviceList() but only returns networks with matching |type|. 189 // Like GetDeviceList() but only returns networks with matching |type|.
176 void GetDeviceListByType(const NetworkTypePattern& type, 190 void GetDeviceListByType(const NetworkTypePattern& type,
177 DeviceStateList* list) const; 191 DeviceStateList* list) const;
178 192
179 // Sets |list| to contain the list of favorite (aka "preferred") networks.
180 // See GetNetworkList() for usage, and notes for |favorite_list_|.
181 // Favorites that are visible have the same path() as the entries in
182 // GetNetworkList(), so GetNetworkState() can be used to determine if a
183 // favorite is visible and retrieve the complete properties (and vice-versa).
184 void GetFavoriteList(FavoriteStateList* list) const;
185
186 // Like GetFavoriteList() but only returns favorites with matching |type| and
187 // the following properties:
188 // |configured_only| - if true only include networks where IsInProfile is true
189 // |visible_only| - if true only include networks in the visible Services list
190 // |limit| - if > 0 limits the number of results.
191 void GetFavoriteListByType(const NetworkTypePattern& type,
192 bool configured_only,
193 bool visible_only,
194 int limit,
195 FavoriteStateList* list) const;
196
197 // Finds and returns the FavoriteState associated with |service_path| or NULL
198 // if not found. If |configured_only| is true, only returns saved entries
199 // (IsInProfile is true).
200 const FavoriteState* GetFavoriteStateFromServicePath(
201 const std::string& service_path,
202 bool configured_only) const;
203
204 // Finds and returns the FavoriteState associated with |guid| or NULL if not
205 // found. This returns all entries (IsInProfile() may be true or false).
206 const FavoriteState* GetFavoriteStateFromGuid(const std::string& guid) const;
207
208 // Requests a network scan. This may trigger updates to the network 193 // Requests a network scan. This may trigger updates to the network
209 // list, which will trigger the appropriate observer calls. 194 // list, which will trigger the appropriate observer calls.
210 void RequestScan() const; 195 void RequestScan() const;
211 196
212 // Request a scan if not scanning and run |callback| when the Scanning state 197 // Request a scan if not scanning and run |callback| when the Scanning state
213 // for any Device of network type |type| completes. 198 // for any Device of network type |type| completes.
214 void WaitForScan(const std::string& type, const base::Closure& callback); 199 void WaitForScan(const std::string& type, const base::Closure& callback);
215 200
216 // Request a network scan then signal Shill to connect to the best available 201 // Request a network scan then signal Shill to connect to the best available
217 // networks when completed. 202 // networks when completed.
(...skipping 11 matching lines...) Expand all
229 // Clear the last_error value for the NetworkState for |service_path|. 214 // Clear the last_error value for the NetworkState for |service_path|.
230 void ClearLastErrorForNetwork(const std::string& service_path); 215 void ClearLastErrorForNetwork(const std::string& service_path);
231 216
232 // Set the list of devices on which portal check is enabled. 217 // Set the list of devices on which portal check is enabled.
233 void SetCheckPortalList(const std::string& check_portal_list); 218 void SetCheckPortalList(const std::string& check_portal_list);
234 219
235 const std::string& GetCheckPortalListForTest() const { 220 const std::string& GetCheckPortalListForTest() const {
236 return check_portal_list_; 221 return check_portal_list_;
237 } 222 }
238 223
239 // Returns the FavoriteState of the EthernetEAP service, which contains the 224 // Returns the NetworkState of the EthernetEAP service, which contains the
240 // EAP parameters used by the ethernet with |service_path|. If |service_path| 225 // EAP parameters used by the ethernet with |service_path|. If |service_path|
241 // doesn't refer to an ethernet service or if the ethernet service is not 226 // doesn't refer to an ethernet service or if the ethernet service is not
242 // connected using EAP, returns NULL. 227 // connected using EAP, returns NULL.
243 const FavoriteState* GetEAPForEthernet(const std::string& service_path) const; 228 const NetworkState* GetEAPForEthernet(const std::string& service_path) const;
244 229
245 const std::string& default_network_path() const { 230 const std::string& default_network_path() const {
246 return default_network_path_; 231 return default_network_path_;
247 } 232 }
248 233
249 // Construct and initialize an instance for testing. 234 // Construct and initialize an instance for testing.
250 static NetworkStateHandler* InitializeForTest(); 235 static NetworkStateHandler* InitializeForTest();
251 236
252 // Default set of comma separated interfaces on which to enable 237 // Default set of comma separated interfaces on which to enable
253 // portal checking. 238 // portal checking.
254 static const char kDefaultCheckPortalList[]; 239 static const char kDefaultCheckPortalList[];
255 240
256 protected: 241 protected:
257 friend class NetworkHandler; 242 friend class NetworkHandler;
258 NetworkStateHandler(); 243 NetworkStateHandler();
259 244
260 // ShillPropertyHandler::Listener overrides. 245 // ShillPropertyHandler::Listener overrides.
261 246
262 // This adds new entries to the managed list specified by |type| and deletes 247 // This adds new entries to |network_list_| or |device_list_| and deletes any
263 // any entries that are no longer in the list. 248 // entries that are no longer in the list.
264 virtual void UpdateManagedList(ManagedState::ManagedType type, 249 virtual void UpdateManagedList(ManagedState::ManagedType type,
265 const base::ListValue& entries) OVERRIDE; 250 const base::ListValue& entries) OVERRIDE;
266 251
252 // Updates the visibility if entries in |network_list_|. This should not
253 // contain entries that are not in |network_list_|. Any such entries will be
254 // ignored with an error message.
255 virtual void UpdateVisibleNetworks(const base::ListValue& entries) OVERRIDE;
256
267 // The list of profiles changed (i.e. a user has logged in). Re-request 257 // The list of profiles changed (i.e. a user has logged in). Re-request
268 // properties for all services since they may have changed. 258 // properties for all services since they may have changed.
269 virtual void ProfileListChanged() OVERRIDE; 259 virtual void ProfileListChanged() OVERRIDE;
270 260
271 // Parses the properties for the network service or device. Mostly calls 261 // Parses the properties for the network service or device. Mostly calls
272 // managed->PropertyChanged(key, value) for each dictionary entry. 262 // managed->PropertyChanged(key, value) for each dictionary entry.
273 virtual void UpdateManagedStateProperties( 263 virtual void UpdateManagedStateProperties(
274 ManagedState::ManagedType type, 264 ManagedState::ManagedType type,
275 const std::string& path, 265 const std::string& path,
276 const base::DictionaryValue& properties) OVERRIDE; 266 const base::DictionaryValue& properties) OVERRIDE;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 typedef std::map<std::string, ScanCallbackList> ScanCompleteCallbackMap; 314 typedef std::map<std::string, ScanCallbackList> ScanCompleteCallbackMap;
325 typedef std::map<std::string, std::string> SpecifierGuidMap; 315 typedef std::map<std::string, std::string> SpecifierGuidMap;
326 friend class NetworkStateHandlerTest; 316 friend class NetworkStateHandlerTest;
327 FRIEND_TEST_ALL_PREFIXES(NetworkStateHandlerTest, NetworkStateHandlerStub); 317 FRIEND_TEST_ALL_PREFIXES(NetworkStateHandlerTest, NetworkStateHandlerStub);
328 318
329 // NetworkState specific method for UpdateManagedStateProperties which 319 // NetworkState specific method for UpdateManagedStateProperties which
330 // notifies observers. 320 // notifies observers.
331 void UpdateNetworkStateProperties(NetworkState* network, 321 void UpdateNetworkStateProperties(NetworkState* network,
332 const base::DictionaryValue& properties); 322 const base::DictionaryValue& properties);
333 323
334 // Ensure a valid GUID for FavoriteState and update the NetworkState GUID from 324 // Ensure a valid GUID for NetworkState.
335 // the corresponding FavoriteState if necessary. 325 void UpdateGuid(NetworkState* network);
336 void UpdateGuid(ManagedState* managed);
337 326
338 // Sends DeviceListChanged() to observers and logs an event. 327 // Sends DeviceListChanged() to observers and logs an event.
339 void NotifyDeviceListChanged(); 328 void NotifyDeviceListChanged();
340 329
341 // 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
342 // 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
343 // pointers. 332 // pointers.
344 DeviceState* GetModifiableDeviceState(const std::string& device_path) const; 333 DeviceState* GetModifiableDeviceState(const std::string& device_path) const;
345 NetworkState* GetModifiableNetworkState( 334 NetworkState* GetModifiableNetworkState(
346 const std::string& service_path) const; 335 const std::string& service_path) const;
347 FavoriteState* GetModifiableFavoriteState(
348 const std::string& service_path) const;
349 ManagedState* GetModifiableManagedState(const ManagedStateList* managed_list, 336 ManagedState* GetModifiableManagedState(const ManagedStateList* managed_list,
350 const std::string& path) const; 337 const std::string& path) const;
351 338
352 // Gets the list specified by |type|. 339 // Gets the list specified by |type|.
353 ManagedStateList* GetManagedList(ManagedState::ManagedType type); 340 ManagedStateList* GetManagedList(ManagedState::ManagedType type);
354 341
355 // Helper function to notify observers. Calls CheckDefaultNetworkChanged(). 342 // Helper function to notify observers. Calls CheckDefaultNetworkChanged().
356 void OnNetworkConnectionStateChanged(NetworkState* network); 343 void OnNetworkConnectionStateChanged(NetworkState* network);
357 344
358 // Notifies observers when the default network or its properties change. 345 // Notifies observers when the default network or its properties change.
(...skipping 15 matching lines...) Expand all
374 361
375 // Shill property handler instance, owned by this class. 362 // Shill property handler instance, owned by this class.
376 scoped_ptr<internal::ShillPropertyHandler> shill_property_handler_; 363 scoped_ptr<internal::ShillPropertyHandler> shill_property_handler_;
377 364
378 // Observer list 365 // Observer list
379 ObserverList<NetworkStateHandlerObserver> observers_; 366 ObserverList<NetworkStateHandlerObserver> observers_;
380 367
381 // List of managed network states 368 // List of managed network states
382 ManagedStateList network_list_; 369 ManagedStateList network_list_;
383 370
384 // List of managed favorite states; this list includes all entries in
385 // Manager.ServiceCompleteList, but only entries with a non-empty Profile
386 // property are returned in GetFavoriteList().
387 ManagedStateList favorite_list_;
388
389 // List of managed device states 371 // List of managed device states
390 ManagedStateList device_list_; 372 ManagedStateList device_list_;
391 373
392 // Keeps track of the default network for notifying observers when it changes. 374 // Keeps track of the default network for notifying observers when it changes.
393 std::string default_network_path_; 375 std::string default_network_path_;
394 376
395 // List of interfaces on which portal check is enabled. 377 // List of interfaces on which portal check is enabled.
396 std::string check_portal_list_; 378 std::string check_portal_list_;
397 379
398 // Callbacks to run when a scan for the technology type completes. 380 // Callbacks to run when a scan for the technology type completes.
399 ScanCompleteCallbackMap scan_complete_callbacks_; 381 ScanCompleteCallbackMap scan_complete_callbacks_;
400 382
401 // Map of network specifiers to guids. Contains an entry for each 383 // Map of network specifiers to guids. Contains an entry for each
402 // FavoriteState that is not saved in a profile. 384 // NetworkState that is not saved in a profile.
403 SpecifierGuidMap specifier_guid_map_; 385 SpecifierGuidMap specifier_guid_map_;
404 386
405 DISALLOW_COPY_AND_ASSIGN(NetworkStateHandler); 387 DISALLOW_COPY_AND_ASSIGN(NetworkStateHandler);
406 }; 388 };
407 389
408 } // namespace chromeos 390 } // namespace chromeos
409 391
410 #endif // CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_H_ 392 #endif // CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698