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

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

Issue 330833003: Rely on Service.Visible instead of Manager.Services (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sort on demand if necessary 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 const NetworkState* ConnectedNetworkByType( 129 const NetworkState* ConnectedNetworkByType(
130 const NetworkTypePattern& type) const; 130 const NetworkTypePattern& type) const;
131 131
132 // Like ConnectedNetworkByType() but returns a connecting network or NULL. 132 // Like ConnectedNetworkByType() but returns a connecting network or NULL.
133 const NetworkState* ConnectingNetworkByType( 133 const NetworkState* ConnectingNetworkByType(
134 const NetworkTypePattern& type) const; 134 const NetworkTypePattern& type) const;
135 135
136 // Like ConnectedNetworkByType() but returns any matching visible network or 136 // Like ConnectedNetworkByType() but returns any matching visible network or
137 // NULL. Mostly useful for mobile networks where there is generally only one 137 // NULL. Mostly useful for mobile networks where there is generally only one
138 // network. Note: O(N). 138 // network. Note: O(N).
139 const NetworkState* FirstNetworkByType(const NetworkTypePattern& type) const; 139 const NetworkState* FirstNetworkByType(const NetworkTypePattern& type);
140 140
141 // Returns the aa:bb formatted hardware (MAC) address for the first connected 141 // Returns the aa:bb formatted hardware (MAC) address for the first connected
142 // network matching |type|, or an empty string if none is connected. 142 // network matching |type|, or an empty string if none is connected.
143 std::string FormattedHardwareAddressForType( 143 std::string FormattedHardwareAddressForType(
144 const NetworkTypePattern& type) const; 144 const NetworkTypePattern& type) const;
145 145
146 // Convenience method to call GetNetworkListByType(visible=true). 146 // Convenience method to call GetNetworkListByType(visible=true).
147 void GetVisibleNetworkListByType(const NetworkTypePattern& type, 147 void GetVisibleNetworkListByType(const NetworkTypePattern& type,
148 NetworkStateList* list) const; 148 NetworkStateList* list);
149 149
150 // Convenience method for GetVisibleNetworkListByType(Default). 150 // Convenience method for GetVisibleNetworkListByType(Default).
151 void GetVisibleNetworkList(NetworkStateList* list) const; 151 void GetVisibleNetworkList(NetworkStateList* list);
152 152
153 // Sets |list| to contain the list of networks with matching |type| and the 153 // Sets |list| to contain the list of networks with matching |type| and the
154 // following properties: 154 // following properties:
155 // |configured_only| - if true only include networks where IsInProfile is true 155 // |configured_only| - if true only include networks where IsInProfile is true
156 // |visible_only| - if true only include networks in the visible Services list 156 // |visible_only| - if true only include networks in the visible Services list
157 // |limit| - if > 0 limits the number of results. 157 // |limit| - if > 0 limits the number of results.
158 // The returned list contains a copy of NetworkState pointers which should not 158 // The returned list contains a copy of NetworkState pointers which should not
159 // be stored or used beyond the scope of the calling function (i.e. they may 159 // be stored or used beyond the scope of the calling function (i.e. they may
160 // later become invalid, but only on the UI thread). 160 // later become invalid, but only on the UI thread). SortNetworkList() will be
161 // called if necessary to prove the states in the a convenient order (see
pneubeck (no reviews) 2014/06/18 09:45:49 prove? or should it be 'provide'? 'the a' -> 'a'
stevenjb 2014/06/18 22:33:26 Done.
162 // SortNetworkList for details).
161 void GetNetworkListByType(const NetworkTypePattern& type, 163 void GetNetworkListByType(const NetworkTypePattern& type,
162 bool configured_only, 164 bool configured_only,
163 bool visible_only, 165 bool visible_only,
164 int limit, 166 int limit,
165 NetworkStateList* list) const; 167 NetworkStateList* list);
166 168
167 // Finds and returns the NetworkState associated with |service_path| or NULL 169 // Finds and returns the NetworkState associated with |service_path| or NULL
168 // if not found. If |configured_only| is true, only returns saved entries 170 // if not found. If |configured_only| is true, only returns saved entries
169 // (IsInProfile is true). 171 // (IsInProfile is true).
170 const NetworkState* GetNetworkStateFromServicePath( 172 const NetworkState* GetNetworkStateFromServicePath(
171 const std::string& service_path, 173 const std::string& service_path,
172 bool configured_only) const; 174 bool configured_only) const;
173 175
174 // Finds and returns the NetworkState associated with |guid| or NULL if not 176 // Finds and returns the NetworkState associated with |guid| or NULL if not
175 // found. This returns all entries (IsInProfile() may be true or false). 177 // found. This returns all entries (IsInProfile() may be true or false).
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 void SetCheckPortalList(const std::string& check_portal_list); 215 void SetCheckPortalList(const std::string& check_portal_list);
214 216
215 const std::string& GetCheckPortalListForTest() const { 217 const std::string& GetCheckPortalListForTest() const {
216 return check_portal_list_; 218 return check_portal_list_;
217 } 219 }
218 220
219 // Returns the NetworkState of the EthernetEAP service, which contains the 221 // Returns the NetworkState of the EthernetEAP service, which contains the
220 // EAP parameters used by the ethernet with |service_path|. If |service_path| 222 // EAP parameters used by the ethernet with |service_path|. If |service_path|
221 // doesn't refer to an ethernet service or if the ethernet service is not 223 // doesn't refer to an ethernet service or if the ethernet service is not
222 // connected using EAP, returns NULL. 224 // connected using EAP, returns NULL.
223 const NetworkState* GetEAPForEthernet(const std::string& service_path) const; 225 const NetworkState* GetEAPForEthernet(const std::string& service_path);
224 226
225 const std::string& default_network_path() const { 227 const std::string& default_network_path() const {
226 return default_network_path_; 228 return default_network_path_;
227 } 229 }
228 230
229 // Construct and initialize an instance for testing. 231 // Construct and initialize an instance for testing.
230 static NetworkStateHandler* InitializeForTest(); 232 static NetworkStateHandler* InitializeForTest();
231 233
232 // Default set of comma separated interfaces on which to enable 234 // Default set of comma separated interfaces on which to enable
233 // portal checking. 235 // portal checking.
234 static const char kDefaultCheckPortalList[]; 236 static const char kDefaultCheckPortalList[];
235 237
236 protected: 238 protected:
237 friend class NetworkHandler; 239 friend class NetworkHandler;
238 NetworkStateHandler(); 240 NetworkStateHandler();
239 241
240 // ShillPropertyHandler::Listener overrides. 242 // ShillPropertyHandler::Listener overrides.
241 243
242 // This adds new entries to |network_list_| or |device_list_| and deletes any 244 // This adds new entries to |network_list_| or |device_list_| and deletes any
243 // entries that are no longer in the list. 245 // entries that are no longer in the list.
244 virtual void UpdateManagedList(ManagedState::ManagedType type, 246 virtual void UpdateManagedList(ManagedState::ManagedType type,
245 const base::ListValue& entries) OVERRIDE; 247 const base::ListValue& entries) OVERRIDE;
246 248
247 // Updates the visibility of entries in |network_list_|. This should not
248 // contain entries that are not in |network_list_|. Any such entries will be
249 // ignored with an error message.
250 virtual void UpdateVisibleNetworks(const base::ListValue& entries) OVERRIDE;
251
252 // The list of profiles changed (i.e. a user has logged in). Re-request 249 // The list of profiles changed (i.e. a user has logged in). Re-request
253 // properties for all services since they may have changed. 250 // properties for all services since they may have changed.
254 virtual void ProfileListChanged() OVERRIDE; 251 virtual void ProfileListChanged() OVERRIDE;
255 252
256 // Parses the properties for the network service or device. Mostly calls 253 // Parses the properties for the network service or device. Mostly calls
257 // managed->PropertyChanged(key, value) for each dictionary entry. 254 // managed->PropertyChanged(key, value) for each dictionary entry.
258 virtual void UpdateManagedStateProperties( 255 virtual void UpdateManagedStateProperties(
259 ManagedState::ManagedType type, 256 ManagedState::ManagedType type,
260 const std::string& path, 257 const std::string& path,
261 const base::DictionaryValue& properties) OVERRIDE; 258 const base::DictionaryValue& properties) OVERRIDE;
(...skipping 21 matching lines...) Expand all
283 // Called by ShillPropertyHandler when the portal check list manager property 280 // Called by ShillPropertyHandler when the portal check list manager property
284 // changes. 281 // changes.
285 virtual void CheckPortalListChanged( 282 virtual void CheckPortalListChanged(
286 const std::string& check_portal_list) OVERRIDE; 283 const std::string& check_portal_list) OVERRIDE;
287 284
288 // Called by ShillPropertyHandler when a technology list changes. 285 // Called by ShillPropertyHandler when a technology list changes.
289 virtual void TechnologyListChanged() OVERRIDE; 286 virtual void TechnologyListChanged() OVERRIDE;
290 287
291 // Called by |shill_property_handler_| when the service or device list has 288 // Called by |shill_property_handler_| when the service or device list has
292 // changed and all entries have been updated. This updates the list and 289 // changed and all entries have been updated. This updates the list and
293 // notifies observers. If |type| == TYPE_NETWORK this also calls 290 // notifies observers.
294 // CheckDefaultNetworkChanged().
295 virtual void ManagedStateListChanged( 291 virtual void ManagedStateListChanged(
296 ManagedState::ManagedType type) OVERRIDE; 292 ManagedState::ManagedType type) OVERRIDE;
297 293
298 // Called when the default network service changes. Sets default_network_path_ 294 // Called when the default network service changes. Sets default_network_path_
299 // and notifies listeners. 295 // and notifies listeners.
300 virtual void DefaultNetworkServiceChanged( 296 virtual void DefaultNetworkServiceChanged(
301 const std::string& service_path) OVERRIDE; 297 const std::string& service_path) OVERRIDE;
302 298
303 // Called after construction. Called explicitly by tests after adding 299 // Called after construction. Called explicitly by tests after adding
304 // test observers. 300 // test observers.
305 void InitShillPropertyHandler(); 301 void InitShillPropertyHandler();
306 302
307 private: 303 private:
308 typedef std::list<base::Closure> ScanCallbackList; 304 typedef std::list<base::Closure> ScanCallbackList;
309 typedef std::map<std::string, ScanCallbackList> ScanCompleteCallbackMap; 305 typedef std::map<std::string, ScanCallbackList> ScanCompleteCallbackMap;
310 typedef std::map<std::string, std::string> SpecifierGuidMap; 306 typedef std::map<std::string, std::string> SpecifierGuidMap;
311 friend class NetworkStateHandlerTest; 307 friend class NetworkStateHandlerTest;
312 FRIEND_TEST_ALL_PREFIXES(NetworkStateHandlerTest, NetworkStateHandlerStub); 308 FRIEND_TEST_ALL_PREFIXES(NetworkStateHandlerTest, NetworkStateHandlerStub);
313 309
310 // Sorts the network list. Called when all network updates have been received,
311 // or when the network list is requested but the list is in an unsorted state.
312 // Networks are sorted as follows, maintaining the existing relative ordering:
313 // * Connected or connecting networks (should be listed first by Shill)
314 // * Visible non-wifi networks
315 // * Visible wifi networks
316 // * Hidden (wifi) networks
317 void SortNetworkList();
318
319 // Updates UMA stats. Called once after all requested networks are updated.
320 void UpdateNetworkStats();
321
314 // NetworkState specific method for UpdateManagedStateProperties which 322 // NetworkState specific method for UpdateManagedStateProperties which
315 // notifies observers. 323 // notifies observers.
316 void UpdateNetworkStateProperties(NetworkState* network, 324 void UpdateNetworkStateProperties(NetworkState* network,
317 const base::DictionaryValue& properties); 325 const base::DictionaryValue& properties);
318 326
319 // Ensure a valid GUID for NetworkState. 327 // Ensure a valid GUID for NetworkState.
320 void UpdateGuid(NetworkState* network); 328 void UpdateGuid(NetworkState* network);
321 329
322 // Sends DeviceListChanged() to observers and logs an event. 330 // Sends DeviceListChanged() to observers and logs an event.
323 void NotifyDeviceListChanged(); 331 void NotifyDeviceListChanged();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 364
357 // Shill property handler instance, owned by this class. 365 // Shill property handler instance, owned by this class.
358 scoped_ptr<internal::ShillPropertyHandler> shill_property_handler_; 366 scoped_ptr<internal::ShillPropertyHandler> shill_property_handler_;
359 367
360 // Observer list 368 // Observer list
361 ObserverList<NetworkStateHandlerObserver> observers_; 369 ObserverList<NetworkStateHandlerObserver> observers_;
362 370
363 // List of managed network states 371 // List of managed network states
364 ManagedStateList network_list_; 372 ManagedStateList network_list_;
365 373
374 // Set to true when the network list is sorted, cleared when network updates
375 // arrive. Used to trigger sorting when needed.
376 bool network_list_sorted_;
377
366 // List of managed device states 378 // List of managed device states
367 ManagedStateList device_list_; 379 ManagedStateList device_list_;
368 380
369 // 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.
370 std::string default_network_path_; 382 std::string default_network_path_;
371 383
372 // List of interfaces on which portal check is enabled. 384 // List of interfaces on which portal check is enabled.
373 std::string check_portal_list_; 385 std::string check_portal_list_;
374 386
375 // Callbacks to run when a scan for the technology type completes. 387 // Callbacks to run when a scan for the technology type completes.
376 ScanCompleteCallbackMap scan_complete_callbacks_; 388 ScanCompleteCallbackMap scan_complete_callbacks_;
377 389
378 // Map of network specifiers to guids. Contains an entry for each 390 // Map of network specifiers to guids. Contains an entry for each
379 // NetworkState that is not saved in a profile. 391 // NetworkState that is not saved in a profile.
380 SpecifierGuidMap specifier_guid_map_; 392 SpecifierGuidMap specifier_guid_map_;
381 393
382 DISALLOW_COPY_AND_ASSIGN(NetworkStateHandler); 394 DISALLOW_COPY_AND_ASSIGN(NetworkStateHandler);
383 }; 395 };
384 396
385 } // namespace chromeos 397 } // namespace chromeos
386 398
387 #endif // CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_H_ 399 #endif // CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698