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

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

Issue 11192024: Add chromeos::NetworkStateManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clang fixes Created 8 years, 1 month 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_IMPL_H_
6 #define CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_IMPL_H_
7
8 #include <list>
9 #include <map>
10 #include <set>
11 #include <string>
12
13 #include "base/memory/weak_ptr.h"
14 #include "chromeos/dbus/dbus_method_call_status.h"
15 #include "chromeos/dbus/shill_property_changed_observer.h"
16 #include "chromeos/network/managed_state.h"
17
18 namespace base {
19 class DictionaryValue;
20 class ListValue;
21 class Value;
22 }
23
24 namespace chromeos {
25
26 class ShillServiceObserver;
27 class ShillManagerClient;
28
29 namespace internal {
30
31 // This class handles all Shill calls and observers for a Delegate (e.g.
32 // NetworkStateHandler). It observes Shill.Manager and requests properties
33 // for new devices/networks, calling Delegate methods to track them. It also
34 // observes Shill.Service for all services in Shill.Manager.ServiceWatchList
35 // and calls Delegate methods with updates.
36 // This class must not outlive the ShillManagerClient instance.
37 class CHROMEOS_EXPORT ShillPropertyHandler
pneubeck (no reviews) 2012/11/02 09:20:53 It looks odd to me that classes of the internal na
stevenjb 2012/11/02 17:17:14 Tests require it. 'internal' really just indicate
38 : public ShillPropertyChangedObserver {
39 public:
40 typedef std::map<std::string, ShillServiceObserver*> ShillServiceObserverMap;
41
42 class CHROMEOS_EXPORT Delegate {
pneubeck (no reviews) 2012/11/02 09:20:53 Wasn't ShillPropertyHandler the Delegate of Networ
stevenjb 2012/11/02 17:17:14 ShillPropertyHandler is wholly owned and exposed t
43 public:
44 // Called when the entries in a managed list have changed.
45 virtual void UpdateManagedList(ManagedState::ManagedType type,
46 const base::ListValue& entries) = 0;
47
48 // Called when the available technologies are set or have changed.
49 virtual void UpdateAvailableTechnologies(
50 const base::ListValue& technologies) = 0;
51
52 // Called when the enabled technologies are set or have changed.
53 virtual void UpdateEnabledTechnologies(
54 const base::ListValue& technologies) = 0;
55
56 // Called when the properties for a managed state have changed.
57 virtual void UpdateManagedStateProperties(
58 ManagedState::ManagedType type,
59 const std::string& path,
60 const base::DictionaryValue& properties) = 0;
61
62 // Called when a property for a watched network service has changed.
63 virtual void UpdateNetworkServiceProperty(
64 const std::string& service_path,
65 const std::string& key,
66 const base::Value& value) = 0;
67
68 // Called after updating a technology list.
69 virtual void ManagerPropertyChanged() = 0;
70
71 // Called whent the IP address of a service has been updated. Occurs after
72 // UpdateManagedStateProperties is called for the service.
73 virtual void UpdateNetworkServiceIPAddress(
74 const std::string& service_path,
75 const std::string& ip_address) = 0;
76
77 // Called when a managed state list has changed, after properties for any
78 // new entries in the list have been received and
79 // UpdateManagedStateProperties has been called for each new entry.
80 virtual void ManagedStateListChanged(ManagedState::ManagedType type) = 0;
81
82 protected:
83 virtual ~Delegate() {}
84 };
85
86 explicit ShillPropertyHandler(Delegate* delegate);
87 virtual ~ShillPropertyHandler();
88
89 // Sends an initial property request and sets up the observer.
90 void Init();
91
92 // Asynchronously sets the enabled state for |technology|.
93 // Note: Modifes Manager state. TODO(stevenjb): Add a completion callback.
94 void SetTechnologyEnabled(const std::string& technology, bool enabled);
95
96 // Requests an immediate network scan.
97 void RequestScan() const;
98
99 // Requests all properties for the service or device (called for new items).
100 void RequestProperties(ManagedState::ManagedType type,
101 const std::string& path);
102
103 // Requests the IP config specified by |ip_config_path| for |service_path|.
104 void RequestIPConfig(const std::string& service_path,
105 const std::string& ip_config_path);
106
107 bool IsObservingNetwork(const std::string& service_path) {
108 return observed_networks_.count(service_path) != 0;
109 }
110
111 // ShillPropertyChangedObserver overrides
112 virtual void OnPropertyChanged(const std::string& key,
113 const base::Value& value) OVERRIDE;
114
115 private:
116 // Callback for dbus method fetching properties.
117 void ManagerPropertiesCallback(DBusMethodCallStatus call_status,
118 const base::DictionaryValue& properties);
119 // Called form OnPropertyChanged() and ManagerPropertiesCallback().
120 // Returns true if observers should be notified.
121 bool ManagerPropertyChanged(const std::string& key, const base::Value& value);
122
123 // Calls delegate_->UpdateManagedList and triggers ManagedStateListChanged if
124 // no new property requests have been made.
125 void UpdateManagedList(ManagedState::ManagedType type,
126 const base::ListValue& entries);
127
128 // Updates the Shill service property observers to observe any entries
129 // in the service watch list.
130 void UpdateObservedNetworkServices(const base::ListValue& entries);
131
132 // Called when Shill returns the properties for a service or device.
133 void GetPropertiesCallback(ManagedState::ManagedType type,
134 const std::string& path,
135 DBusMethodCallStatus call_status,
136 const base::DictionaryValue& properties);
137
138 // Callback invoked when a watched service property changes. Calls
139 // network->PropertyChanged(key, value) and signals observers.
140 void NetworkServicePropertyChangedCallback(const std::string& path,
141 const std::string& key,
142 const base::Value& value);
143
144 // Callback for getting the IPConfig property of a Network. Handled here
145 // instead of in NetworkState so that all asynchronous requests are done
146 // in a single place (also simplifies NetworkState considerably).
147 void GetIPConfigCallback(const std::string& service_path,
148 DBusMethodCallStatus call_status,
149 const base::DictionaryValue& properties);
150
151 // Pointer to containing class (owns this)
152 Delegate* delegate_;
153
154 // Convenience pointer for ShillManagerClient
155 ShillManagerClient* shill_manager_;
156
157 // Pending update count for each managed state type
158 std::map<ManagedState::ManagedType, int> pending_updates_;
159
160 // List of network services with Shill property changed observers
161 ShillServiceObserverMap observed_networks_;
162
163 // For Shill client callbacks
164 base::WeakPtrFactory<ShillPropertyHandler> weak_ptr_factory_;
165
166 DISALLOW_COPY_AND_ASSIGN(ShillPropertyHandler);
167 };
168
169 } // namespace internal
170 } // namespace chromeos
171
172 #endif // CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_IMPL_H_
OLDNEW
« no previous file with comments | « chromeos/network/network_state_handler_unittest.cc ('k') | chromeos/network/shill_property_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698