blob: fd299b533185b3c12942225a5c9f05f949eed045 [file] [log] [blame]
[email protected]3c8bd112012-11-07 10:14:591// 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
[email protected]b7c377e2013-01-15 10:00:395#ifndef CHROMEOS_NETWORK_SHILL_PROPERTY_HANDLER_H_
6#define CHROMEOS_NETWORK_SHILL_PROPERTY_HANDLER_H_
[email protected]3c8bd112012-11-07 10:14:597
8#include <list>
9#include <map>
10#include <set>
11#include <string>
fqjfee5067a2015-11-13 20:12:5912#include <vector>
[email protected]3c8bd112012-11-07 10:14:5913
avi6e1a22d2015-12-21 03:43:2014#include "base/macros.h"
[email protected]3c8bd112012-11-07 10:14:5915#include "base/memory/weak_ptr.h"
16#include "chromeos/dbus/dbus_method_call_status.h"
17#include "chromeos/dbus/shill_property_changed_observer.h"
18#include "chromeos/network/managed_state.h"
[email protected]eb052c92012-11-26 20:12:2119#include "chromeos/network/network_handler_callbacks.h"
[email protected]3c8bd112012-11-07 10:14:5920
21namespace base {
22class DictionaryValue;
23class ListValue;
24class Value;
25}
26
27namespace chromeos {
28
29class ShillManagerClient;
30
31namespace internal {
32
[email protected]b16d79d72013-02-07 08:14:4633class ShillPropertyObserver;
[email protected]3c8bd112012-11-07 10:14:5934
35// This class handles Shill calls and observers to reflect the state of the
36// Shill Manager and its services and devices. It observes Shill.Manager and
37// requests properties for new devices/networks. It takes a Listener in its
38// constructor (e.g. NetworkStateHandler) that it calls when properties change
39// (including once to set their initial state after Init() gets called).
40// It also observes Shill.Service for all services in Manager.ServiceWatchList.
41// This class must not outlive the ShillManagerClient instance.
42class CHROMEOS_EXPORT ShillPropertyHandler
[email protected]8617f982013-04-01 21:50:2243 : public ShillPropertyChangedObserver,
44 public base::SupportsWeakPtr<ShillPropertyHandler> {
[email protected]3c8bd112012-11-07 10:14:5945 public:
avi8194ad62016-09-20 16:58:3646 typedef std::map<std::string, std::unique_ptr<ShillPropertyObserver>>
[email protected]b16d79d72013-02-07 08:14:4647 ShillPropertyObserverMap;
[email protected]3c8bd112012-11-07 10:14:5948
49 class CHROMEOS_EXPORT Listener {
50 public:
51 // Called when the entries in a managed list have changed.
52 virtual void UpdateManagedList(ManagedState::ManagedType type,
53 const base::ListValue& entries) = 0;
54
[email protected]3c8bd112012-11-07 10:14:5955 // Called when the properties for a managed state have changed.
56 virtual void UpdateManagedStateProperties(
57 ManagedState::ManagedType type,
58 const std::string& path,
59 const base::DictionaryValue& properties) = 0;
60
[email protected]4a3ed972013-04-11 22:03:2361 // Called when the list of profiles changes.
62 virtual void ProfileListChanged() = 0;
63
[email protected]3c8bd112012-11-07 10:14:5964 // Called when a property for a watched network service has changed.
65 virtual void UpdateNetworkServiceProperty(
66 const std::string& service_path,
67 const std::string& key,
68 const base::Value& value) = 0;
69
[email protected]b16d79d72013-02-07 08:14:4670 // Called when a property for a watched device has changed.
71 virtual void UpdateDeviceProperty(
72 const std::string& device_path,
73 const std::string& key,
74 const base::Value& value) = 0;
75
[email protected]0e7085a2014-05-09 16:45:4676 // Called when a watched network or device IPConfig property changes.
77 virtual void UpdateIPConfigProperties(
78 ManagedState::ManagedType type,
79 const std::string& path,
80 const std::string& ip_config_path,
81 const base::DictionaryValue& properties) = 0;
82
[email protected]68196e452013-05-31 01:16:3883 // Called when the list of devices with portal check enabled changes.
84 virtual void CheckPortalListChanged(
85 const std::string& check_portal_list) = 0;
86
[email protected]e925cfd2013-09-13 18:38:3787 // Called when a technology list changes.
88 virtual void TechnologyListChanged() = 0;
[email protected]3c8bd112012-11-07 10:14:5989
[email protected]3c8bd112012-11-07 10:14:5990 // Called when a managed state list has changed, after properties for any
91 // new entries in the list have been received and
92 // UpdateManagedStateProperties has been called for each new entry.
93 virtual void ManagedStateListChanged(ManagedState::ManagedType type) = 0;
94
[email protected]4d201ec2014-03-05 19:54:4095 // Called when the default network service changes.
96 virtual void DefaultNetworkServiceChanged(
97 const std::string& service_path) = 0;
98
[email protected]3c8bd112012-11-07 10:14:5999 protected:
100 virtual ~Listener() {}
101 };
102
103 explicit ShillPropertyHandler(Listener* listener);
dchengaeb064e2015-01-20 20:56:38104 ~ShillPropertyHandler() override;
[email protected]3c8bd112012-11-07 10:14:59105
[email protected]ce21fc62013-07-03 10:45:58106 // Sets up the observer and calls UpdateManagerProperties().
[email protected]3c8bd112012-11-07 10:14:59107 void Init();
108
[email protected]ce21fc62013-07-03 10:45:58109 // Requests all Manager properties. Called from Init() and any time
110 // properties that do not signal changes might have been updated (e.g.
111 // ServiceCompleteList).
112 void UpdateManagerProperties();
113
[email protected]b15f4932013-04-15 21:09:25114 // Returns true if |technology| is available, enabled, etc.
115 bool IsTechnologyAvailable(const std::string& technology) const;
116 bool IsTechnologyEnabled(const std::string& technology) const;
117 bool IsTechnologyEnabling(const std::string& technology) const;
fqj9bbb6b3f2015-11-17 22:41:53118 bool IsTechnologyProhibited(const std::string& technology) const;
[email protected]b15f4932013-04-15 21:09:25119 bool IsTechnologyUninitialized(const std::string& technology) const;
[email protected]b16d79d72013-02-07 08:14:46120
[email protected]3c8bd112012-11-07 10:14:59121 // Asynchronously sets the enabled state for |technology|.
[email protected]ce21fc62013-07-03 10:45:58122 // Note: Modifies Manager state. Calls |error_callback| on failure.
[email protected]eb052c92012-11-26 20:12:21123 void SetTechnologyEnabled(
124 const std::string& technology,
125 bool enabled,
126 const network_handler::ErrorCallback& error_callback);
[email protected]3c8bd112012-11-07 10:14:59127
fqjfee5067a2015-11-13 20:12:59128 // Asynchronously sets the prohibited state for every network technology
129 // listed in |technologies|. Note: Modifies Manager state. Calls
130 // |error_callback| on failure.
131 void SetProhibitedTechnologies(
132 const std::vector<std::string>& technologies,
133 const network_handler::ErrorCallback& error_callback);
134
[email protected]68196e452013-05-31 01:16:38135 // Sets the list of devices on which portal check is enabled.
136 void SetCheckPortalList(const std::string& check_portal_list);
137
stevenjb19d23372014-10-31 20:27:21138 // Sets the Manager.WakeOnLan property. Note: we do not track this state, we
139 // only set it.
140 void SetWakeOnLanEnabled(bool enabled);
141
[email protected]3c8bd112012-11-07 10:14:59142 // Requests an immediate network scan.
143 void RequestScan() const;
144
145 // Requests all properties for the service or device (called for new items).
146 void RequestProperties(ManagedState::ManagedType type,
147 const std::string& path);
148
[email protected]3c8bd112012-11-07 10:14:59149 // ShillPropertyChangedObserver overrides
dchengaeb064e2015-01-20 20:56:38150 void OnPropertyChanged(const std::string& key,
151 const base::Value& value) override;
[email protected]3c8bd112012-11-07 10:14:59152
153 private:
[email protected]ce21fc62013-07-03 10:45:58154 typedef std::map<ManagedState::ManagedType, std::set<std::string> >
155 TypeRequestMap;
156
[email protected]3c8bd112012-11-07 10:14:59157 // Callback for dbus method fetching properties.
158 void ManagerPropertiesCallback(DBusMethodCallStatus call_status,
159 const base::DictionaryValue& properties);
[email protected]ce21fc62013-07-03 10:45:58160
161 // Notifies the listener when a ManagedStateList has changed and all pending
162 // updates have been received. |key| can either identify the list that
163 // has changed or an empty string if multiple lists may have changed.
164 void CheckPendingStateListUpdates(const std::string& key);
165
[email protected]3c8bd112012-11-07 10:14:59166 // Called form OnPropertyChanged() and ManagerPropertiesCallback().
[email protected]e925cfd2013-09-13 18:38:37167 void ManagerPropertyChanged(const std::string& key,
[email protected]5092ea872013-05-16 21:56:08168 const base::Value& value);
[email protected]3c8bd112012-11-07 10:14:59169
[email protected]fa0336f2014-06-12 22:08:38170 // Requests properties for new entries in the list for |type|.
[email protected]ce21fc62013-07-03 10:45:58171 void UpdateProperties(ManagedState::ManagedType type,
172 const base::ListValue& entries);
173
[email protected]b16d79d72013-02-07 08:14:46174 // Updates the Shill property observers to observe any entries for |type|.
175 void UpdateObserved(ManagedState::ManagedType type,
176 const base::ListValue& entries);
[email protected]3c8bd112012-11-07 10:14:59177
[email protected]b16d79d72013-02-07 08:14:46178
179 // Sets |*_technologies_| to contain only entries in |technologies|.
180 void UpdateAvailableTechnologies(const base::ListValue& technologies);
181 void UpdateEnabledTechnologies(const base::ListValue& technologies);
182 void UpdateUninitializedTechnologies(const base::ListValue& technologies);
[email protected]3c8bd112012-11-07 10:14:59183
[email protected]b15f4932013-04-15 21:09:25184 void EnableTechnologyFailed(
185 const std::string& technology,
186 const network_handler::ErrorCallback& error_callback,
[email protected]77ac5402013-07-09 21:41:42187 const std::string& dbus_error_name,
188 const std::string& dbus_error_message);
[email protected]b15f4932013-04-15 21:09:25189
[email protected]3c8bd112012-11-07 10:14:59190 // Called when Shill returns the properties for a service or device.
191 void GetPropertiesCallback(ManagedState::ManagedType type,
192 const std::string& path,
193 DBusMethodCallStatus call_status,
194 const base::DictionaryValue& properties);
195
[email protected]b16d79d72013-02-07 08:14:46196 // Callback invoked when a watched property changes. Calls appropriate
197 // handlers and signals observers.
198 void PropertyChangedCallback(ManagedState::ManagedType type,
199 const std::string& path,
200 const std::string& key,
201 const base::Value& value);
[email protected]3c8bd112012-11-07 10:14:59202
[email protected]0e7085a2014-05-09 16:45:46203 // Request a single IPConfig object corresponding to |ip_config_path_value|
204 // from Shill.IPConfigClient and trigger a call to UpdateIPConfigProperties
205 // for the network or device corresponding to |type| and |path|.
206 void RequestIPConfig(ManagedState::ManagedType type,
207 const std::string& path,
208 const base::Value& ip_config_path_value);
209
210 // Request the IPConfig objects corresponding to entries in
211 // |ip_config_list_value| from Shill.IPConfigClient and trigger a call to
212 // UpdateIPConfigProperties with each object for the network or device
213 // corresponding to |type| and |path|.
214 void RequestIPConfigsList(ManagedState::ManagedType type,
215 const std::string& path,
216 const base::Value& ip_config_list_value);
217
218 // Callback for getting the IPConfig property of a network or device. Handled
219 // here instead of in NetworkState so that all asynchronous requests are done
[email protected]3c8bd112012-11-07 10:14:59220 // in a single place (also simplifies NetworkState considerably).
[email protected]0e7085a2014-05-09 16:45:46221 void GetIPConfigCallback(ManagedState::ManagedType type,
222 const std::string& path,
223 const std::string& ip_config_path,
[email protected]3c8bd112012-11-07 10:14:59224 DBusMethodCallStatus call_status,
225 const base::DictionaryValue& properties);
[email protected]ce21fc62013-07-03 10:45:58226
fqjfee5067a2015-11-13 20:12:59227 void SetProhibitedTechnologiesEnforced(bool enforced);
228
[email protected]3c8bd112012-11-07 10:14:59229 // Pointer to containing class (owns this)
230 Listener* listener_;
231
232 // Convenience pointer for ShillManagerClient
233 ShillManagerClient* shill_manager_;
234
[email protected]fa6797e2012-11-28 15:15:44235 // Pending update list for each managed state type
[email protected]ce21fc62013-07-03 10:45:58236 TypeRequestMap pending_updates_;
237
238 // List of states for which properties have been requested, for each managed
239 // state type
240 TypeRequestMap requested_updates_;
[email protected]3c8bd112012-11-07 10:14:59241
242 // List of network services with Shill property changed observers
[email protected]b16d79d72013-02-07 08:14:46243 ShillPropertyObserverMap observed_networks_;
244
245 // List of network devices with Shill property changed observers
246 ShillPropertyObserverMap observed_devices_;
247
248 // Lists of available / enabled / uninitialized technologies
249 std::set<std::string> available_technologies_;
250 std::set<std::string> enabled_technologies_;
[email protected]b15f4932013-04-15 21:09:25251 std::set<std::string> enabling_technologies_;
fqjfee5067a2015-11-13 20:12:59252 std::set<std::string> prohibited_technologies_;
[email protected]b16d79d72013-02-07 08:14:46253 std::set<std::string> uninitialized_technologies_;
[email protected]3c8bd112012-11-07 10:14:59254
[email protected]3c8bd112012-11-07 10:14:59255 DISALLOW_COPY_AND_ASSIGN(ShillPropertyHandler);
256};
257
258} // namespace internal
259} // namespace chromeos
260
[email protected]b7c377e2013-01-15 10:00:39261#endif // CHROMEOS_NETWORK_SHILL_PROPERTY_HANDLER_H_