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

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

Issue 14729017: Add NetworkHandler to own network handlers in src/chromeos/network (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 7 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>
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
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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
170 static const char kMatchTypeDefault[]; 159 static const char kMatchTypeDefault[];
171 static const char kMatchTypeWireless[]; 160 static const char kMatchTypeWireless[];
172 static const char kMatchTypeMobile[]; 161 static const char kMatchTypeMobile[];
173 static const char kMatchTypeNonVirtual[]; 162 static const char kMatchTypeNonVirtual[];
174 163
175 protected: 164 protected:
165 friend class NetworkHandler;
176 NetworkStateHandler(); 166 NetworkStateHandler();
177 167
178 // ShillPropertyHandler::Listener overrides. 168 // ShillPropertyHandler::Listener overrides.
179 169
180 // This adds new entries to the managed list specified by |type| and deletes 170 // This adds new entries to the managed list specified by |type| and deletes
181 // any entries that are no longer in the list. 171 // any entries that are no longer in the list.
182 virtual void UpdateManagedList(ManagedState::ManagedType type, 172 virtual void UpdateManagedList(ManagedState::ManagedType type,
183 const base::ListValue& entries) OVERRIDE; 173 const base::ListValue& entries) OVERRIDE;
184 174
185 // The list of profiles changed (i.e. a user has logged in). Re-request 175 // The list of profiles changed (i.e. a user has logged in). Re-request
(...skipping 22 matching lines...) Expand all
208 // Sends NetworkManagerChanged() to observers. 198 // Sends NetworkManagerChanged() to observers.
209 virtual void ManagerPropertyChanged() OVERRIDE; 199 virtual void ManagerPropertyChanged() OVERRIDE;
210 200
211 // Called by |shill_property_handler_| when the service or device list has 201 // 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 202 // changed and all entries have been updated. This updates the list and
213 // notifies observers. If |type| == TYPE_NETWORK this also calls 203 // notifies observers. If |type| == TYPE_NETWORK this also calls
214 // CheckDefaultNetworkChanged(). 204 // CheckDefaultNetworkChanged().
215 virtual void ManagedStateListChanged( 205 virtual void ManagedStateListChanged(
216 ManagedState::ManagedType type) OVERRIDE; 206 ManagedState::ManagedType type) OVERRIDE;
217 207
218 // Called in Initialize(). Called explicitly by tests after adding 208 // Called after construction. Called explicitly by tests after adding
219 // test observers. 209 // test observers.
220 void InitShillPropertyHandler(); 210 void InitShillPropertyHandler();
221 211
222 private: 212 private:
223 typedef std::list<base::Closure> ScanCallbackList; 213 typedef std::list<base::Closure> ScanCallbackList;
224 typedef std::map<std::string, ScanCallbackList> ScanCompleteCallbackMap; 214 typedef std::map<std::string, ScanCallbackList> ScanCompleteCallbackMap;
225 friend class NetworkStateHandlerTest; 215 friend class NetworkStateHandlerTest;
226 FRIEND_TEST_ALL_PREFIXES(NetworkStateHandlerTest, NetworkStateHandlerStub); 216 FRIEND_TEST_ALL_PREFIXES(NetworkStateHandlerTest, NetworkStateHandlerStub);
227 217
228 // Non-const getters for managed entries. These are const so that they can 218 // 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
277 267
278 // Callbacks to run when a scan for the technology type completes. 268 // Callbacks to run when a scan for the technology type completes.
279 ScanCompleteCallbackMap scan_complete_callbacks_; 269 ScanCompleteCallbackMap scan_complete_callbacks_;
280 270
281 DISALLOW_COPY_AND_ASSIGN(NetworkStateHandler); 271 DISALLOW_COPY_AND_ASSIGN(NetworkStateHandler);
282 }; 272 };
283 273
284 } // namespace chromeos 274 } // namespace chromeos
285 275
286 #endif // CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_H_ 276 #endif // CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698