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 18 matching lines...) Expand all Loading... |
29 namespace tracked_objects { | 29 namespace tracked_objects { |
30 class Location; | 30 class Location; |
31 } | 31 } |
32 | 32 |
33 namespace chromeos { | 33 namespace chromeos { |
34 | 34 |
35 class DeviceState; | 35 class DeviceState; |
36 class NetworkState; | 36 class NetworkState; |
37 class NetworkStateHandlerObserver; | 37 class NetworkStateHandlerObserver; |
38 class NetworkStateHandlerTest; | 38 class NetworkStateHandlerTest; |
| 39 class NetworkTypePattern; |
39 | 40 |
40 // Class for tracking the list of visible networks and their properties. | 41 // Class for tracking the list of visible networks and their properties. |
41 // | 42 // |
42 // This class maps essential properties from the connection manager (Shill) for | 43 // This class maps essential properties from the connection manager (Shill) for |
43 // each visible network. It is not used to change the properties of services or | 44 // each visible network. It is not used to change the properties of services or |
44 // devices, only global (manager) properties. | 45 // devices, only global (manager) properties. |
45 // | 46 // |
46 // All getters return the currently cached properties. This class is expected to | 47 // All getters return the currently cached properties. This class is expected to |
47 // keep properties up to date by managing the appropriate Shill observers. | 48 // keep properties up to date by managing the appropriate Shill observers. |
48 // It will invoke its own more specific observer methods when the specified | 49 // It will invoke its own more specific observer methods when the specified |
49 // changes occur. | 50 // changes occur. |
50 // | 51 // |
51 // Most *ByType or *ForType methods will accept any of the following for | 52 // Most *ByType or *ForType methods will accept any of the following for |type|. |
52 // |type|. See individual methods for specific notes. | 53 // See individual methods for specific notes. |
53 // * Any type defined in service_constants.h (e.g. flimflam::kTypeWifi) | 54 // * Any type defined in service_constants.h (e.g. flimflam::kTypeWifi) |
54 // * kMatchTypeDefault returns the default (active) network | 55 // * kMatchTypeDefault returns the default (active) network |
55 // * kMatchTypeNonVirtual returns the primary non virtual network | 56 // * kMatchTypeNonVirtual returns the primary non virtual network |
| 57 // * kMatchTypeWired returns the primary wired network |
56 // * kMatchTypeWireless returns the primary wireless network | 58 // * kMatchTypeWireless returns the primary wireless network |
57 // * kMatchTypeMobile returns the primary cellular or wimax network | 59 // * kMatchTypeMobile returns the primary cellular or wimax network |
58 | 60 |
59 class CHROMEOS_EXPORT NetworkStateHandler | 61 class CHROMEOS_EXPORT NetworkStateHandler |
60 : public internal::ShillPropertyHandler::Listener { | 62 : public internal::ShillPropertyHandler::Listener { |
61 public: | 63 public: |
62 typedef std::vector<ManagedState*> ManagedStateList; | 64 typedef std::vector<ManagedState*> ManagedStateList; |
63 typedef std::vector<const NetworkState*> NetworkStateList; | 65 typedef std::vector<const NetworkState*> NetworkStateList; |
64 typedef std::vector<const DeviceState*> DeviceStateList; | 66 typedef std::vector<const DeviceState*> DeviceStateList; |
65 typedef std::vector<const FavoriteState*> FavoriteStateList; | 67 typedef std::vector<const FavoriteState*> FavoriteStateList; |
(...skipping 12 matching lines...) Expand all Loading... |
78 void AddObserver(NetworkStateHandlerObserver* observer, | 80 void AddObserver(NetworkStateHandlerObserver* observer, |
79 const tracked_objects::Location& from_here); | 81 const tracked_objects::Location& from_here); |
80 void RemoveObserver(NetworkStateHandlerObserver* observer, | 82 void RemoveObserver(NetworkStateHandlerObserver* observer, |
81 const tracked_objects::Location& from_here); | 83 const tracked_objects::Location& from_here); |
82 | 84 |
83 // Requests all Manager properties, specifically to update the complete | 85 // Requests all Manager properties, specifically to update the complete |
84 // list of services which determines the list of Favorites. This should be | 86 // list of services which determines the list of Favorites. This should be |
85 // called any time a new service is configured or a Profile is loaded. | 87 // called any time a new service is configured or a Profile is loaded. |
86 void UpdateManagerProperties(); | 88 void UpdateManagerProperties(); |
87 | 89 |
88 // Returns the state for technology |type|. kMatchTypeMobile (only) is | 90 // Returns the state for technology |type|. Only |
89 // also supported. | 91 // NetworkTypePattern::Primitive, ::Mobile and ::Ethernet are supported. |
90 TechnologyState GetTechnologyState(const std::string& type) const; | 92 TechnologyState GetTechnologyState(const NetworkTypePattern& type) const; |
91 bool IsTechnologyAvailable(const std::string& type) const { | 93 bool IsTechnologyAvailable(const NetworkTypePattern& type) const { |
92 return GetTechnologyState(type) != TECHNOLOGY_UNAVAILABLE; | 94 return GetTechnologyState(type) != TECHNOLOGY_UNAVAILABLE; |
93 } | 95 } |
94 bool IsTechnologyEnabled(const std::string& type) const { | 96 bool IsTechnologyEnabled(const NetworkTypePattern& type) const { |
95 return GetTechnologyState(type) == TECHNOLOGY_ENABLED; | 97 return GetTechnologyState(type) == TECHNOLOGY_ENABLED; |
96 } | 98 } |
97 | 99 |
98 // Asynchronously sets the technology enabled property for |type|. | 100 // Asynchronously sets the technology enabled property for |type|. Only |
99 // kMatchTypeMobile (only) is also supported. | 101 // NetworkTypePattern::Primitive, ::Mobile and ::Ethernet are supported. |
100 // Note: Modifies Manager state. Calls |error_callback| on failure. | 102 // Note: Modifies Manager state. Calls |error_callback| on failure. |
101 void SetTechnologyEnabled( | 103 void SetTechnologyEnabled( |
102 const std::string& type, | 104 const NetworkTypePattern& type, |
103 bool enabled, | 105 bool enabled, |
104 const network_handler::ErrorCallback& error_callback); | 106 const network_handler::ErrorCallback& error_callback); |
105 | 107 |
106 // Finds and returns a device state by |device_path| or NULL if not found. | 108 // Finds and returns a device state by |device_path| or NULL if not found. |
107 const DeviceState* GetDeviceState(const std::string& device_path) const; | 109 const DeviceState* GetDeviceState(const std::string& device_path) const; |
108 | 110 |
109 // Finds and returns a device state by |type|. Returns NULL if not found. | 111 // Finds and returns a device state by |type|. Returns NULL if not found. |
110 // See note above for valid types. | 112 const DeviceState* GetDeviceStateByType(const NetworkTypePattern& type) const; |
111 const DeviceState* GetDeviceStateByType(const std::string& type) const; | |
112 | 113 |
113 // Returns true if any device of |type| is scanning. | 114 // Returns true if any device of |type| is scanning. |
114 // See note above for valid types. | 115 bool GetScanningByType(const NetworkTypePattern& type) const; |
115 bool GetScanningByType(const std::string& type) const; | |
116 | 116 |
117 // Finds and returns a network state by |service_path| or NULL if not found. | 117 // Finds and returns a network state by |service_path| or NULL if not found. |
118 // Note: NetworkState is frequently updated asynchronously, i.e. properties | 118 // Note: NetworkState is frequently updated asynchronously, i.e. properties |
119 // are not always updated all at once. This will contain the most recent | 119 // are not always updated all at once. This will contain the most recent |
120 // value for each property. To receive notifications when a property changes, | 120 // value for each property. To receive notifications when a property changes, |
121 // observe this class and implement NetworkPropertyChanged(). | 121 // observe this class and implement NetworkPropertyChanged(). |
122 const NetworkState* GetNetworkState(const std::string& service_path) const; | 122 const NetworkState* GetNetworkState(const std::string& service_path) const; |
123 | 123 |
124 // Returns the default connected network (which includes VPNs) or NULL. | 124 // Returns the default connected network (which includes VPNs) or NULL. |
125 // This is equivalent to ConnectedNetworkByType(kMatchTypeDefault). | 125 // This is equivalent to ConnectedNetworkByType(kMatchTypeDefault). |
126 const NetworkState* DefaultNetwork() const; | 126 const NetworkState* DefaultNetwork() const; |
127 | 127 |
128 // Returns the primary connected network of matching |type|, otherwise NULL. | 128 // Returns the primary connected network of matching |type|, otherwise NULL. |
129 // See note above for valid types. | 129 const NetworkState* ConnectedNetworkByType( |
130 const NetworkState* ConnectedNetworkByType(const std::string& 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(const std::string& type) const; | 133 const NetworkState* ConnectingNetworkByType( |
| 134 const NetworkTypePattern& type) const; |
134 | 135 |
135 // Like ConnectedNetworkByType() but returns any matching network or NULL. | 136 // Like ConnectedNetworkByType() but returns any matching network or NULL. |
136 // Mostly useful for mobile networks where there is generally only one | 137 // Mostly useful for mobile networks where there is generally only one |
137 // network. Note: O(N). | 138 // network. Note: O(N). |
138 const NetworkState* FirstNetworkByType(const std::string& type) const; | 139 const NetworkState* FirstNetworkByType(const NetworkTypePattern& type) const; |
139 | 140 |
140 // Returns the hardware (MAC) address for the first connected network | 141 // Returns the hardware (MAC) address for the first connected network |
141 // matching |type|, or an empty string if none. | 142 // matching |type|, or an empty string if none is connected. |
142 // See note above for valid types. | 143 std::string HardwareAddressForType(const NetworkTypePattern& type) const; |
143 std::string HardwareAddressForType(const std::string& type) const; | |
144 // Same as above but in aa:bb format. | 144 // Same as above but in aa:bb format. |
145 std::string FormattedHardwareAddressForType(const std::string& type) const; | 145 std::string FormattedHardwareAddressForType( |
| 146 const NetworkTypePattern& type) const; |
146 | 147 |
147 // Sets |list| to contain the list of networks. The returned list contains | 148 // Sets |list| to contain the list of networks. The returned list contains |
148 // a copy of NetworkState pointers which should not be stored or used beyond | 149 // a copy of NetworkState pointers which should not be stored or used beyond |
149 // the scope of the calling function (i.e. they may later become invalid, but | 150 // the scope of the calling function (i.e. they may later become invalid, but |
150 // only on the UI thread). | 151 // only on the UI thread). |
151 void GetNetworkList(NetworkStateList* list) const; | 152 void GetNetworkList(NetworkStateList* list) const; |
152 | 153 |
153 // Like GetNetworkList() but only returns networks with matching |type|. | 154 // Like GetNetworkList() but only returns networks with matching |type|. |
154 void GetNetworkListByType(const std::string& type, | 155 void GetNetworkListByType(const NetworkTypePattern& type, |
155 NetworkStateList* list) const; | 156 NetworkStateList* list) const; |
156 | 157 |
157 // Sets |list| to contain the list of devices. The returned list contains | 158 // Sets |list| to contain the list of devices. The returned list contains |
158 // a copy of DeviceState pointers which should not be stored or used beyond | 159 // a copy of DeviceState pointers which should not be stored or used beyond |
159 // the scope of the calling function (i.e. they may later become invalid, but | 160 // the scope of the calling function (i.e. they may later become invalid, but |
160 // only on the UI thread). | 161 // only on the UI thread). |
161 void GetDeviceList(DeviceStateList* list) const; | 162 void GetDeviceList(DeviceStateList* list) const; |
162 | 163 |
163 // Sets |list| to contain the list of favorite (aka "preferred") networks. | 164 // Sets |list| to contain the list of favorite (aka "preferred") networks. |
164 // See GetNetworkList() for usage, and notes for |favorite_list_|. | 165 // See GetNetworkList() for usage, and notes for |favorite_list_|. |
165 // Favorites that are visible have the same path() as the entries in | 166 // Favorites that are visible have the same path() as the entries in |
166 // GetNetworkList(), so GetNetworkState() can be used to determine if a | 167 // GetNetworkList(), so GetNetworkState() can be used to determine if a |
167 // favorite is visible and retrieve the complete properties (and vice-versa). | 168 // favorite is visible and retrieve the complete properties (and vice-versa). |
168 void GetFavoriteList(FavoriteStateList* list) const; | 169 void GetFavoriteList(FavoriteStateList* list) const; |
169 | 170 |
170 // Finds and returns a favorite state by |service_path| or NULL if not found. | 171 // Finds and returns a favorite state by |service_path| or NULL if not found. |
171 const FavoriteState* GetFavoriteState(const std::string& service_path) const; | 172 const FavoriteState* GetFavoriteState(const std::string& service_path) const; |
172 | 173 |
173 // Requests a network scan. This may trigger updates to the network | 174 // Requests a network scan. This may trigger updates to the network |
174 // list, which will trigger the appropriate observer calls. | 175 // list, which will trigger the appropriate observer calls. |
175 void RequestScan() const; | 176 void RequestScan() const; |
176 | 177 |
177 // Request a scan if not scanning and run |callback| when the Scanning state | 178 // Request a scan if not scanning and run |callback| when the Scanning state |
178 // for any Device matching |type| completes. | 179 // for any Device of network type |type| completes. |
179 void WaitForScan(const std::string& type, const base::Closure& callback); | 180 void WaitForScan(const std::string& type, const base::Closure& callback); |
180 | 181 |
181 // Request a network scan then signal Shill to connect to the best available | 182 // Request a network scan then signal Shill to connect to the best available |
182 // networks when completed. | 183 // networks when completed. |
183 void ConnectToBestWifiNetwork(); | 184 void ConnectToBestWifiNetwork(); |
184 | 185 |
185 // Request an update for an existing NetworkState, e.g. after configuring | 186 // Request an update for an existing NetworkState, e.g. after configuring |
186 // a network. This is a no-op if an update request is already pending. To | 187 // a network. This is a no-op if an update request is already pending. To |
187 // ensure that a change is picked up, this must be called after Shill | 188 // ensure that a change is picked up, this must be called after Shill |
188 // acknowledged it (e.g. in the callback of a SetProperties). | 189 // acknowledged it (e.g. in the callback of a SetProperties). |
(...skipping 13 matching lines...) Expand all Loading... |
202 const std::string& check_portal_list() const { return check_portal_list_; } | 203 const std::string& check_portal_list() const { return check_portal_list_; } |
203 | 204 |
204 // Generates a DictionaryValue of all NetworkState properties. Currently | 205 // Generates a DictionaryValue of all NetworkState properties. Currently |
205 // provided for debugging purposes only. | 206 // provided for debugging purposes only. |
206 void GetNetworkStatePropertiesForTest( | 207 void GetNetworkStatePropertiesForTest( |
207 base::DictionaryValue* dictionary) const; | 208 base::DictionaryValue* dictionary) const; |
208 | 209 |
209 // Construct and initialize an instance for testing. | 210 // Construct and initialize an instance for testing. |
210 static NetworkStateHandler* InitializeForTest(); | 211 static NetworkStateHandler* InitializeForTest(); |
211 | 212 |
212 static const char kMatchTypeDefault[]; | |
213 static const char kMatchTypeWireless[]; | |
214 static const char kMatchTypeMobile[]; | |
215 static const char kMatchTypeNonVirtual[]; | |
216 | |
217 // Default set of comma separated interfaces on which to enable | 213 // Default set of comma separated interfaces on which to enable |
218 // portal checking. | 214 // portal checking. |
219 static const char kDefaultCheckPortalList[]; | 215 static const char kDefaultCheckPortalList[]; |
220 | 216 |
221 protected: | 217 protected: |
222 friend class NetworkHandler; | 218 friend class NetworkHandler; |
223 NetworkStateHandler(); | 219 NetworkStateHandler(); |
224 | 220 |
225 // ShillPropertyHandler::Listener overrides. | 221 // ShillPropertyHandler::Listener overrides. |
226 | 222 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 // Logs an event and notifies observers. | 300 // Logs an event and notifies observers. |
305 void OnDefaultNetworkChanged(); | 301 void OnDefaultNetworkChanged(); |
306 | 302 |
307 // Notifies observers and updates connecting_network_. | 303 // Notifies observers and updates connecting_network_. |
308 void NetworkPropertiesUpdated(const NetworkState* network); | 304 void NetworkPropertiesUpdated(const NetworkState* network); |
309 | 305 |
310 // Called whenever Device.Scanning state transitions to false. | 306 // Called whenever Device.Scanning state transitions to false. |
311 void ScanCompleted(const std::string& type); | 307 void ScanCompleted(const std::string& type); |
312 | 308 |
313 // Returns the technology type for |type|. | 309 // Returns the technology type for |type|. |
314 std::string GetTechnologyForType(const std::string& type) const; | 310 std::string GetTechnologyForType(const NetworkTypePattern& type) const; |
315 | 311 |
316 // Shill property handler instance, owned by this class. | 312 // Shill property handler instance, owned by this class. |
317 scoped_ptr<internal::ShillPropertyHandler> shill_property_handler_; | 313 scoped_ptr<internal::ShillPropertyHandler> shill_property_handler_; |
318 | 314 |
319 // Observer list | 315 // Observer list |
320 ObserverList<NetworkStateHandlerObserver> observers_; | 316 ObserverList<NetworkStateHandlerObserver> observers_; |
321 | 317 |
322 // List of managed network states | 318 // List of managed network states |
323 ManagedStateList network_list_; | 319 ManagedStateList network_list_; |
324 | 320 |
(...skipping 13 matching lines...) Expand all Loading... |
338 | 334 |
339 // Callbacks to run when a scan for the technology type completes. | 335 // Callbacks to run when a scan for the technology type completes. |
340 ScanCompleteCallbackMap scan_complete_callbacks_; | 336 ScanCompleteCallbackMap scan_complete_callbacks_; |
341 | 337 |
342 DISALLOW_COPY_AND_ASSIGN(NetworkStateHandler); | 338 DISALLOW_COPY_AND_ASSIGN(NetworkStateHandler); |
343 }; | 339 }; |
344 | 340 |
345 } // namespace chromeos | 341 } // namespace chromeos |
346 | 342 |
347 #endif // CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_H_ | 343 #endif // CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_H_ |
OLD | NEW |