| 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> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
| 14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
| 17 #include "chromeos/chromeos_export.h" | 17 #include "chromeos/chromeos_export.h" |
| 18 #include "chromeos/network/managed_state.h" | 18 #include "chromeos/network/managed_state.h" |
| 19 #include "chromeos/network/network_handler.h" |
| 19 #include "chromeos/network/network_handler_callbacks.h" | 20 #include "chromeos/network/network_handler_callbacks.h" |
| 20 #include "chromeos/network/shill_property_handler.h" | 21 #include "chromeos/network/shill_property_handler.h" |
| 21 | 22 |
| 22 namespace base { | 23 namespace base { |
| 23 class DictionaryValue; | 24 class DictionaryValue; |
| 24 class ListValue; | 25 class ListValue; |
| 25 class Value; | 26 class Value; |
| 26 } | 27 } |
| 27 | 28 |
| 28 namespace chromeos { | 29 namespace chromeos { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 enum TechnologyState { | 61 enum TechnologyState { |
| 61 TECHNOLOGY_UNAVAILABLE, | 62 TECHNOLOGY_UNAVAILABLE, |
| 62 TECHNOLOGY_AVAILABLE, | 63 TECHNOLOGY_AVAILABLE, |
| 63 TECHNOLOGY_UNINITIALIZED, | 64 TECHNOLOGY_UNINITIALIZED, |
| 64 TECHNOLOGY_ENABLING, | 65 TECHNOLOGY_ENABLING, |
| 65 TECHNOLOGY_ENABLED | 66 TECHNOLOGY_ENABLED |
| 66 }; | 67 }; |
| 67 | 68 |
| 68 virtual ~NetworkStateHandler(); | 69 virtual ~NetworkStateHandler(); |
| 69 | 70 |
| 70 // Sets the global instance. Must be called before any calls to Get(). | |
| 71 static void Initialize(); | |
| 72 | |
| 73 // Returns true if the global instance has been initialized. | |
| 74 static bool IsInitialized(); | |
| 75 | |
| 76 // Destroys the global instance. | |
| 77 static void Shutdown(); | |
| 78 | |
| 79 // Gets the global instance. Initialize() must be called first. | |
| 80 static NetworkStateHandler* Get(); | |
| 81 | |
| 82 // Add/remove observers. | 71 // Add/remove observers. |
| 83 void AddObserver(NetworkStateHandlerObserver* observer); | 72 void AddObserver(NetworkStateHandlerObserver* observer); |
| 84 void RemoveObserver(NetworkStateHandlerObserver* observer); | 73 void RemoveObserver(NetworkStateHandlerObserver* observer); |
| 85 | 74 |
| 86 // Returns the state for technology |type|. kMatchTypeMobile (only) is | 75 // Returns the state for technology |type|. kMatchTypeMobile (only) is |
| 87 // also supported. | 76 // also supported. |
| 88 TechnologyState GetTechnologyState(const std::string& type) const; | 77 TechnologyState GetTechnologyState(const std::string& type) const; |
| 89 bool IsTechnologyEnabled(const std::string& type) const { | 78 bool IsTechnologyEnabled(const std::string& type) const { |
| 90 return GetTechnologyState(type) == TECHNOLOGY_ENABLED; | 79 return GetTechnologyState(type) == TECHNOLOGY_ENABLED; |
| 91 } | 80 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 // Set the user initiated connecting network. | 149 // Set the user initiated connecting network. |
| 161 void SetConnectingNetwork(const std::string& service_path); | 150 void SetConnectingNetwork(const std::string& service_path); |
| 162 | 151 |
| 163 const std::string& connecting_network() const { return connecting_network_; } | 152 const std::string& connecting_network() const { return connecting_network_; } |
| 164 | 153 |
| 165 // Generates a DictionaryValue of all NetworkState properties. Currently | 154 // Generates a DictionaryValue of all NetworkState properties. Currently |
| 166 // provided for debugging purposes only. | 155 // provided for debugging purposes only. |
| 167 void GetNetworkStatePropertiesForTest( | 156 void GetNetworkStatePropertiesForTest( |
| 168 base::DictionaryValue* dictionary) const; | 157 base::DictionaryValue* dictionary) const; |
| 169 | 158 |
| 159 // Construct and initialize an instance for testing. |
| 160 static NetworkStateHandler* InitializeForTest(); |
| 161 |
| 170 static const char kMatchTypeDefault[]; | 162 static const char kMatchTypeDefault[]; |
| 171 static const char kMatchTypeWireless[]; | 163 static const char kMatchTypeWireless[]; |
| 172 static const char kMatchTypeMobile[]; | 164 static const char kMatchTypeMobile[]; |
| 173 static const char kMatchTypeNonVirtual[]; | 165 static const char kMatchTypeNonVirtual[]; |
| 174 | 166 |
| 175 protected: | 167 protected: |
| 168 friend class NetworkHandler; |
| 176 NetworkStateHandler(); | 169 NetworkStateHandler(); |
| 177 | 170 |
| 178 // ShillPropertyHandler::Listener overrides. | 171 // ShillPropertyHandler::Listener overrides. |
| 179 | 172 |
| 180 // This adds new entries to the managed list specified by |type| and deletes | 173 // This adds new entries to the managed list specified by |type| and deletes |
| 181 // any entries that are no longer in the list. | 174 // any entries that are no longer in the list. |
| 182 virtual void UpdateManagedList(ManagedState::ManagedType type, | 175 virtual void UpdateManagedList(ManagedState::ManagedType type, |
| 183 const base::ListValue& entries) OVERRIDE; | 176 const base::ListValue& entries) OVERRIDE; |
| 184 | 177 |
| 185 // The list of profiles changed (i.e. a user has logged in). Re-request | 178 // The list of profiles changed (i.e. a user has logged in). Re-request |
| (...skipping 22 matching lines...) Expand all Loading... |
| 208 // Sends NetworkManagerChanged() to observers and logs an event. | 201 // Sends NetworkManagerChanged() to observers and logs an event. |
| 209 virtual void NotifyManagerPropertyChanged() OVERRIDE; | 202 virtual void NotifyManagerPropertyChanged() OVERRIDE; |
| 210 | 203 |
| 211 // Called by |shill_property_handler_| when the service or device list has | 204 // Called by |shill_property_handler_| when the service or device list has |
| 212 // changed and all entries have been updated. This updates the list and | 205 // changed and all entries have been updated. This updates the list and |
| 213 // notifies observers. If |type| == TYPE_NETWORK this also calls | 206 // notifies observers. If |type| == TYPE_NETWORK this also calls |
| 214 // CheckDefaultNetworkChanged(). | 207 // CheckDefaultNetworkChanged(). |
| 215 virtual void ManagedStateListChanged( | 208 virtual void ManagedStateListChanged( |
| 216 ManagedState::ManagedType type) OVERRIDE; | 209 ManagedState::ManagedType type) OVERRIDE; |
| 217 | 210 |
| 218 // Called in Initialize(). Called explicitly by tests after adding | 211 // Called after construction. Called explicitly by tests after adding |
| 219 // test observers. | 212 // test observers. |
| 220 void InitShillPropertyHandler(); | 213 void InitShillPropertyHandler(); |
| 221 | 214 |
| 222 private: | 215 private: |
| 223 typedef std::list<base::Closure> ScanCallbackList; | 216 typedef std::list<base::Closure> ScanCallbackList; |
| 224 typedef std::map<std::string, ScanCallbackList> ScanCompleteCallbackMap; | 217 typedef std::map<std::string, ScanCallbackList> ScanCompleteCallbackMap; |
| 225 friend class NetworkStateHandlerTest; | 218 friend class NetworkStateHandlerTest; |
| 226 FRIEND_TEST_ALL_PREFIXES(NetworkStateHandlerTest, NetworkStateHandlerStub); | 219 FRIEND_TEST_ALL_PREFIXES(NetworkStateHandlerTest, NetworkStateHandlerStub); |
| 227 | 220 |
| 228 // Non-const getters for managed entries. These are const so that they can | 221 // Non-const getters for managed entries. These are const so that they can |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 | 270 |
| 278 // Callbacks to run when a scan for the technology type completes. | 271 // Callbacks to run when a scan for the technology type completes. |
| 279 ScanCompleteCallbackMap scan_complete_callbacks_; | 272 ScanCompleteCallbackMap scan_complete_callbacks_; |
| 280 | 273 |
| 281 DISALLOW_COPY_AND_ASSIGN(NetworkStateHandler); | 274 DISALLOW_COPY_AND_ASSIGN(NetworkStateHandler); |
| 282 }; | 275 }; |
| 283 | 276 |
| 284 } // namespace chromeos | 277 } // namespace chromeos |
| 285 | 278 |
| 286 #endif // CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_H_ | 279 #endif // CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_H_ |
| OLD | NEW |