OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_PROFILE_HANDLER_H_ | 5 #ifndef CHROMEOS_NETWORK_NETWORK_PROFILE_HANDLER_H_ |
6 #define CHROMEOS_NETWORK_NETWORK_PROFILE_HANDLER_H_ | 6 #define CHROMEOS_NETWORK_NETWORK_PROFILE_HANDLER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
15 #include "chromeos/chromeos_export.h" | 15 #include "chromeos/chromeos_export.h" |
16 #include "chromeos/dbus/dbus_method_call_status.h" | 16 #include "chromeos/dbus/dbus_method_call_status.h" |
17 #include "chromeos/dbus/shill_property_changed_observer.h" | 17 #include "chromeos/dbus/shill_property_changed_observer.h" |
| 18 #include "chromeos/network/network_handler.h" |
18 #include "chromeos/network/network_profile.h" | 19 #include "chromeos/network/network_profile.h" |
19 | 20 |
20 namespace base { | 21 namespace base { |
21 class DictionaryValue; | 22 class DictionaryValue; |
22 } | 23 } |
23 | 24 |
24 namespace chromeos { | 25 namespace chromeos { |
25 | 26 |
26 class NetworkProfileObserver; | 27 class NetworkProfileObserver; |
27 | 28 |
28 class CHROMEOS_EXPORT NetworkProfileHandler | 29 class CHROMEOS_EXPORT NetworkProfileHandler |
29 : public ShillPropertyChangedObserver { | 30 : public ShillPropertyChangedObserver { |
30 public: | 31 public: |
31 typedef std::vector<NetworkProfile> ProfileList; | 32 typedef std::vector<NetworkProfile> ProfileList; |
32 | 33 |
33 // Initializes the singleton and registers it for DBus events. | 34 virtual ~NetworkProfileHandler(); |
34 static NetworkProfileHandler* Initialize(); | |
35 | |
36 // Returns if the singleton is initialized. | |
37 static bool IsInitialized(); | |
38 | |
39 // Unregisters the singleton from DBus events and destroys it. | |
40 static void Shutdown(); | |
41 | |
42 // Initialize() must be called before this. | |
43 static NetworkProfileHandler* Get(); | |
44 | 35 |
45 void AddObserver(NetworkProfileObserver* observer); | 36 void AddObserver(NetworkProfileObserver* observer); |
46 void RemoveObserver(NetworkProfileObserver* observer); | 37 void RemoveObserver(NetworkProfileObserver* observer); |
47 | 38 |
48 void RequestInitialProfileList(); | |
49 void GetManagerPropertiesCallback(DBusMethodCallStatus call_status, | 39 void GetManagerPropertiesCallback(DBusMethodCallStatus call_status, |
50 const base::DictionaryValue& properties); | 40 const base::DictionaryValue& properties); |
51 | 41 |
52 // ShillPropertyChangedObserver overrides | 42 // ShillPropertyChangedObserver overrides |
53 virtual void OnPropertyChanged(const std::string& name, | 43 virtual void OnPropertyChanged(const std::string& name, |
54 const base::Value& value) OVERRIDE; | 44 const base::Value& value) OVERRIDE; |
55 | 45 |
56 void GetProfilePropertiesCallback(const std::string& profile_path, | 46 void GetProfilePropertiesCallback(const std::string& profile_path, |
57 const base::DictionaryValue& properties); | 47 const base::DictionaryValue& properties); |
58 | 48 |
59 const NetworkProfile* GetProfileForPath( | 49 const NetworkProfile* GetProfileForPath( |
60 const std::string& profile_path) const; | 50 const std::string& profile_path) const; |
61 const NetworkProfile* GetProfileForUserhash( | 51 const NetworkProfile* GetProfileForUserhash( |
62 const std::string& userhash) const; | 52 const std::string& userhash) const; |
63 | 53 |
| 54 void AddProfileForTest(const NetworkProfile& profile); |
| 55 |
64 protected: | 56 protected: |
65 // We make the de-/constructor protected to prevent their usage except in | 57 friend class NetworkHandler; |
66 // tests by deriving a stub (see NetworkProfileHandlerStub). Outside of tests, | |
67 // the singleton should be retrieved with the static Get() function. | |
68 NetworkProfileHandler(); | 58 NetworkProfileHandler(); |
69 virtual ~NetworkProfileHandler(); | |
70 | 59 |
71 void AddProfile(const NetworkProfile& profile); | 60 void AddProfile(const NetworkProfile& profile); |
72 void RemoveProfile(const std::string& profile_path); | 61 void RemoveProfile(const std::string& profile_path); |
73 | 62 |
74 private: | 63 private: |
75 ProfileList profiles_; | 64 ProfileList profiles_; |
76 ObserverList<NetworkProfileObserver> observers_; | 65 ObserverList<NetworkProfileObserver> observers_; |
77 | 66 |
78 protected: | 67 protected: |
79 // For Shill client callbacks | 68 // For Shill client callbacks |
80 base::WeakPtrFactory<NetworkProfileHandler> weak_ptr_factory_; | 69 base::WeakPtrFactory<NetworkProfileHandler> weak_ptr_factory_; |
81 | 70 |
82 private: | 71 private: |
83 DISALLOW_COPY_AND_ASSIGN(NetworkProfileHandler); | 72 DISALLOW_COPY_AND_ASSIGN(NetworkProfileHandler); |
84 }; | 73 }; |
85 | 74 |
86 } // namespace chromeos | 75 } // namespace chromeos |
87 | 76 |
88 #endif // CHROMEOS_NETWORK_NETWORK_PROFILE_HANDLER_H_ | 77 #endif // CHROMEOS_NETWORK_NETWORK_PROFILE_HANDLER_H_ |
OLD | NEW |