Chromium Code Reviews| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 // * kMatchTypeNonVirtual returns the primary non virtual network | 50 // * kMatchTypeNonVirtual returns the primary non virtual network |
| 51 // * kMatchTypeWireless returns the primary wireless network | 51 // * kMatchTypeWireless returns the primary wireless network |
| 52 // * kMatchTypeMobile returns the primary cellular or wimax network | 52 // * kMatchTypeMobile returns the primary cellular or wimax network |
| 53 | 53 |
| 54 class CHROMEOS_EXPORT NetworkStateHandler | 54 class CHROMEOS_EXPORT NetworkStateHandler |
| 55 : public internal::ShillPropertyHandler::Listener { | 55 : public internal::ShillPropertyHandler::Listener { |
| 56 public: | 56 public: |
| 57 typedef std::vector<ManagedState*> ManagedStateList; | 57 typedef std::vector<ManagedState*> ManagedStateList; |
| 58 typedef std::vector<const NetworkState*> NetworkStateList; | 58 typedef std::vector<const NetworkState*> NetworkStateList; |
| 59 | 59 |
| 60 enum TechnologyState { | |
| 61 TECHNOLOGY_UNAVAILABLE, | |
| 62 TECHNOLOGY_AVAILABLE, | |
| 63 TECHNOLOGY_UNINITIALIZED, | |
| 64 TECHNOLOGY_ENABLING, | |
| 65 TECHNOLOGY_ENABLED | |
| 66 }; | |
| 67 | |
| 60 virtual ~NetworkStateHandler(); | 68 virtual ~NetworkStateHandler(); |
| 61 | 69 |
| 62 // Sets the global instance. Must be called before any calls to Get(). | 70 // Sets the global instance. Must be called before any calls to Get(). |
| 63 static void Initialize(); | 71 static void Initialize(); |
| 64 | 72 |
| 65 // Returns true if the global instance has been initialized. | 73 // Returns true if the global instance has been initialized. |
| 66 static bool IsInitialized(); | 74 static bool IsInitialized(); |
| 67 | 75 |
| 68 // Destroys the global instance. | 76 // Destroys the global instance. |
| 69 static void Shutdown(); | 77 static void Shutdown(); |
| 70 | 78 |
| 71 // Gets the global instance. Initialize() must be called first. | 79 // Gets the global instance. Initialize() must be called first. |
| 72 static NetworkStateHandler* Get(); | 80 static NetworkStateHandler* Get(); |
| 73 | 81 |
| 74 // Add/remove observers. | 82 // Add/remove observers. |
| 75 void AddObserver(NetworkStateHandlerObserver* observer); | 83 void AddObserver(NetworkStateHandlerObserver* observer); |
| 76 void RemoveObserver(NetworkStateHandlerObserver* observer); | 84 void RemoveObserver(NetworkStateHandlerObserver* observer); |
| 77 | 85 |
| 78 // Returns true if technology for |type| is available/ enabled/uninitialized. | 86 // Returns the state for technology |type|. kMatchTypeMobile (only) is |
| 79 // kMatchTypeMobile (only) is also supported. | 87 // also supported. |
| 80 bool TechnologyAvailable(const std::string& type) const; | 88 TechnologyState GetTechnologyState(const std::string& type) const; |
| 81 bool TechnologyEnabled(const std::string& type) const; | 89 bool TechnologyEnabled(const std::string& type) const { |
|
Greg Spencer (Chromium)
2013/04/11 21:35:12
Shouldn't this be named something like "IsTechnolo
stevenjb
2013/04/15 18:49:33
Done.
| |
| 82 bool TechnologyUninitialized(const std::string& type) const; | 90 return GetTechnologyState(type) == TECHNOLOGY_ENABLED; |
| 91 } | |
| 83 | 92 |
| 84 // Asynchronously sets the technology enabled property for |type|. | 93 // Asynchronously sets the technology enabled property for |type|. |
| 85 // kMatchTypeMobile (only) is also supported. | 94 // kMatchTypeMobile (only) is also supported. |
| 86 // Note: Modifies Manager state. Calls |error_callback| on failure. | 95 // Note: Modifies Manager state. Calls |error_callback| on failure. |
| 87 void SetTechnologyEnabled( | 96 void SetTechnologyEnabled( |
| 88 const std::string& type, | 97 const std::string& type, |
| 89 bool enabled, | 98 bool enabled, |
| 90 const network_handler::ErrorCallback& error_callback); | 99 const network_handler::ErrorCallback& error_callback); |
| 91 | 100 |
| 92 // Finds and returns a device state by |device_path| or NULL if not found. | 101 // Finds and returns a device state by |device_path| or NULL if not found. |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 | 242 |
| 234 // Logs an event and notifies observers. | 243 // Logs an event and notifies observers. |
| 235 void OnDefaultNetworkChanged(); | 244 void OnDefaultNetworkChanged(); |
| 236 | 245 |
| 237 // Notifies observers and updates connecting_network_. | 246 // Notifies observers and updates connecting_network_. |
| 238 void NetworkPropertiesUpdated(const NetworkState* network); | 247 void NetworkPropertiesUpdated(const NetworkState* network); |
| 239 | 248 |
| 240 // Called whenever Device.Scanning state transitions to false. | 249 // Called whenever Device.Scanning state transitions to false. |
| 241 void ScanCompleted(const std::string& type); | 250 void ScanCompleted(const std::string& type); |
| 242 | 251 |
| 252 // Returns the technology type for |type|. | |
| 253 std::string TechnologyForType(const std::string& type) const; | |
|
Greg Spencer (Chromium)
2013/04/11 21:35:12
Maybe GetTechnologyForType? I think usually only
stevenjb
2013/04/15 18:49:33
Done.
| |
| 254 | |
| 243 // Shill property handler instance, owned by this class. | 255 // Shill property handler instance, owned by this class. |
| 244 scoped_ptr<internal::ShillPropertyHandler> shill_property_handler_; | 256 scoped_ptr<internal::ShillPropertyHandler> shill_property_handler_; |
| 245 | 257 |
| 246 // Observer list | 258 // Observer list |
| 247 ObserverList<NetworkStateHandlerObserver> observers_; | 259 ObserverList<NetworkStateHandlerObserver> observers_; |
| 248 | 260 |
| 249 // Lists of managed states | 261 // Lists of managed states |
| 250 ManagedStateList network_list_; | 262 ManagedStateList network_list_; |
| 251 ManagedStateList device_list_; | 263 ManagedStateList device_list_; |
| 252 | 264 |
| 253 // Keeps track of the default network for notifying observers when it changes. | 265 // Keeps track of the default network for notifying observers when it changes. |
| 254 std::string default_network_path_; | 266 std::string default_network_path_; |
| 255 | 267 |
| 256 // Convenience member to track the user initiated connecting network. Set | 268 // Convenience member to track the user initiated connecting network. Set |
| 257 // externally when a connection is requested and cleared here when the state | 269 // externally when a connection is requested and cleared here when the state |
| 258 // changes to something other than Connecting (after observers are notified). | 270 // changes to something other than Connecting (after observers are notified). |
| 259 // TODO(stevenjb): Move this to NetworkConfigurationHandler. | 271 // TODO(stevenjb): Move this to NetworkConfigurationHandler. |
| 260 std::string connecting_network_; | 272 std::string connecting_network_; |
| 261 | 273 |
| 262 // Callbacks to run when a scan for the technology type completes. | 274 // Callbacks to run when a scan for the technology type completes. |
| 263 ScanCompleteCallbackMap scan_complete_callbacks_; | 275 ScanCompleteCallbackMap scan_complete_callbacks_; |
| 264 | 276 |
| 265 DISALLOW_COPY_AND_ASSIGN(NetworkStateHandler); | 277 DISALLOW_COPY_AND_ASSIGN(NetworkStateHandler); |
| 266 }; | 278 }; |
| 267 | 279 |
| 268 } // namespace chromeos | 280 } // namespace chromeos |
| 269 | 281 |
| 270 #endif // CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_H_ | 282 #endif // CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_H_ |
| OLD | NEW |