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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 | 60 |
| 61 // Add/remove observers. | 61 // Add/remove observers. |
| 62 void AddObserver(NetworkStateHandlerObserver* observer); | 62 void AddObserver(NetworkStateHandlerObserver* observer); |
| 63 void RemoveObserver(NetworkStateHandlerObserver* observer); | 63 void RemoveObserver(NetworkStateHandlerObserver* observer); |
| 64 | 64 |
| 65 // Returns true if |technology| is enabled / available. | 65 // Returns true if |technology| is enabled / available. |
| 66 bool TechnologyAvailable(const std::string& technology) const; | 66 bool TechnologyAvailable(const std::string& technology) const; |
| 67 bool TechnologyEnabled(const std::string& technology) const; | 67 bool TechnologyEnabled(const std::string& technology) const; |
| 68 | 68 |
| 69 // Asynchronously sets the enabled state for |technology|. | 69 // Asynchronously sets the enabled state for |technology|. |
| 70 // Note: Modifes Manager state. Calls |error_callback| on failure. | 70 // Note: Modifies Manager state. Calls |error_callback| on failure. |
| 71 void SetTechnologyEnabled( | 71 void SetTechnologyEnabled( |
| 72 const std::string& technology, | 72 const std::string& technology, |
| 73 bool enabled, | 73 bool enabled, |
| 74 const network_handler::ErrorCallback& error_callback); | 74 const network_handler::ErrorCallback& error_callback); |
| 75 | 75 |
| 76 // Finds and returns a device state by |device_path| or NULL if not found. | 76 // Finds and returns a device state by |device_path| or NULL if not found. |
| 77 const DeviceState* GetDeviceState(const std::string& device_path) const; | 77 const DeviceState* GetDeviceState(const std::string& device_path) const; |
| 78 | 78 |
| 79 // Finds and returns a device state by |type|. Returns NULL if not found. | 79 // Finds and returns a device state by |type|. Returns NULL if not found. |
| 80 const DeviceState* GetDeviceStateByType(const std::string& type) const; | 80 const DeviceState* GetDeviceStateByType(const std::string& type) const; |
| 81 | 81 |
| 82 // Finds and returns a network state by |service_path| or NULL if not found. | 82 // Finds and returns a network state by |service_path| or NULL if not found. |
| 83 // Note: NetworkState is frequently updated asynchronously, i.e. properties | 83 // Note: NetworkState is frequently updated asynchronously, i.e. properties |
| 84 // are not always updated all at once. This will contain the most recent | 84 // are not always updated all at once. This will contain the most recent |
| 85 // value for each state. To receive notifications when the state changes, | 85 // value for each state. To receive notifications when the state changes, |
| 86 // observer this class and implement NetworkServiceChanged(). | 86 // observer this class and implement NetworkServiceChanged(). |
| 87 const NetworkState* GetNetworkState(const std::string& service_path) const; | 87 const NetworkState* GetNetworkState(const std::string& service_path) const; |
| 88 | 88 |
| 89 // Returns the "active" network (first network in the list if connected), | 89 // Returns the default connected network (which includes VPNs) or NULL. |
| 90 // NULL if none. | 90 // This is equivalent to ConnectedNetworkByType(kMatchTypeDefault). |
| 91 const NetworkState* ActiveNetwork() const; | 91 const NetworkState* DefaultNetwork() const; |
| 92 | 92 |
| 93 // Returns the first connected network of type |type|, otherwise NULL. | 93 // Returns the first connected network of type |type|, otherwise NULL. |
|
pneubeck (no reviews)
2012/12/19 15:22:38
Do we assume that the first connected network has
stevenjb
2012/12/19 18:01:07
Yes.
pneubeck (no reviews)
2012/12/19 19:40:06
As there are several users (uses in the code) of "
| |
| 94 // |type| can be a type defined in service_constants.h, or the additional | |
| 95 // match types defined in NetworkState; see NetworkState::MatchesType(). | |
| 94 const NetworkState* ConnectedNetworkByType(const std::string& type) const; | 96 const NetworkState* ConnectedNetworkByType(const std::string& type) const; |
| 95 | 97 |
| 96 // Returns the first connecting network of type |type|, otherwise NULL. | 98 // Like ConnectedNetworkByType() but returns the connecting network or NULL. |
| 97 // An empty type will return any connecting non-ethernet network. | |
| 98 const NetworkState* ConnectingNetworkByType(const std::string& type) const; | 99 const NetworkState* ConnectingNetworkByType(const std::string& type) const; |
| 99 | 100 |
| 100 // Returns the hardware (MAC) address for the first connected network | 101 // Returns the hardware (MAC) address for the first connected network |
| 101 // matching |type|, or an empty string if none. | 102 // matching |type|, or an empty string if none. |
| 102 std::string HardwareAddressForType(const std::string& type) const; | 103 std::string HardwareAddressForType(const std::string& type) const; |
| 103 // Same as above but in aa:bb format. | 104 // Same as above but in aa:bb format. |
| 104 std::string FormattedHardwareAddressForType(const std::string& type) const; | 105 std::string FormattedHardwareAddressForType(const std::string& type) const; |
| 105 | 106 |
| 106 // Sets |list| to contain the list of networks. The returned list contains | 107 // Sets |list| to contain the list of networks. The returned list contains |
| 107 // a copy of NetworkState pointers which should not be stored or used beyond | 108 // a copy of NetworkState pointers which should not be stored or used beyond |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 174 // pointers. | 175 // pointers. |
| 175 DeviceState* GetModifiableDeviceState(const std::string& device_path) const; | 176 DeviceState* GetModifiableDeviceState(const std::string& device_path) const; |
| 176 NetworkState* GetModifiableNetworkState( | 177 NetworkState* GetModifiableNetworkState( |
| 177 const std::string& service_path) const; | 178 const std::string& service_path) const; |
| 178 ManagedState* GetModifiableManagedState(const ManagedStateList* managed_list, | 179 ManagedState* GetModifiableManagedState(const ManagedStateList* managed_list, |
| 179 const std::string& path) const; | 180 const std::string& path) const; |
| 180 | 181 |
| 181 // Gets the list specified by |type|. | 182 // Gets the list specified by |type|. |
| 182 ManagedStateList* GetManagedList(ManagedState::ManagedType type); | 183 ManagedStateList* GetManagedList(ManagedState::ManagedType type); |
| 183 | 184 |
| 184 // Helper function called to parse |network| properties. | 185 // Helper function called to parse |network| properties. |
|
pneubeck (no reviews)
2012/12/19 15:22:38
Please document this function more clearly.
Somet
stevenjb
2012/12/19 18:01:07
I separated out the observer notification code. I
| |
| 185 bool ParseNetworkServiceProperty(NetworkState* network, | 186 bool ParseNetworkServiceProperty(NetworkState* network, |
| 186 const std::string& key, | 187 const std::string& key, |
| 187 const base::Value& value); | 188 const base::Value& value); |
| 188 | 189 |
| 190 // Checks to see if the default network changed. Signals observers and | |
| 191 // returns true if it has. | |
| 192 bool CheckDefaultNetworkChanged(); | |
| 193 | |
| 189 // Shill property handler instance, owned by this class. | 194 // Shill property handler instance, owned by this class. |
| 190 scoped_ptr<internal::ShillPropertyHandler> shill_property_handler_; | 195 scoped_ptr<internal::ShillPropertyHandler> shill_property_handler_; |
| 191 | 196 |
| 192 // Observer list | 197 // Observer list |
| 193 ObserverList<NetworkStateHandlerObserver> observers_; | 198 ObserverList<NetworkStateHandlerObserver> observers_; |
| 194 | 199 |
| 195 // Lists of managed states | 200 // Lists of managed states |
| 196 ManagedStateList network_list_; | 201 ManagedStateList network_list_; |
| 197 ManagedStateList device_list_; | 202 ManagedStateList device_list_; |
| 198 | 203 |
| 199 // Lists of available / enabled technologies | 204 // Lists of available / enabled technologies |
| 200 std::set<std::string> available_technologies_; | 205 std::set<std::string> available_technologies_; |
| 201 std::set<std::string> enabled_technologies_; | 206 std::set<std::string> enabled_technologies_; |
| 202 | 207 |
| 203 // Keeps track of the active network for notifying observers when it changes. | 208 // Keeps track of the default network for notifying observers when it changes. |
| 204 std::string active_network_path_; | 209 std::string default_network_path_; |
| 205 | 210 |
| 206 DISALLOW_COPY_AND_ASSIGN(NetworkStateHandler); | 211 DISALLOW_COPY_AND_ASSIGN(NetworkStateHandler); |
| 207 }; | 212 }; |
| 208 | 213 |
| 209 } // namespace chromeos | 214 } // namespace chromeos |
| 210 | 215 |
| 211 #endif // CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_H_ | 216 #endif // CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_H_ |
| OLD | NEW |