OLD | NEW |
---|---|
(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_DEVICE_HANDLER_H_ | |
6 #define CHROMEOS_NETWORK_NETWORK_DEVICE_HANDLER_H_ | |
7 | |
8 #include <map> | |
9 #include <set> | |
10 #include <string> | |
11 | |
12 #include "base/memory/weak_ptr.h" | |
13 #include "base/observer_list.h" | |
14 #include "chromeos/chromeos_export.h" | |
15 #include "chromeos/dbus/dbus_method_call_status.h" | |
16 #include "chromeos/dbus/shill_property_changed_observer.h" | |
17 #include "chromeos/network/network_util.h" // WifiAccessPoint | |
18 | |
19 namespace base { | |
20 class DictionaryValue; | |
21 class ListValue; | |
22 class Value; | |
23 } | |
24 | |
25 namespace chromeos { | |
26 | |
27 class CHROMEOS_EXPORT NetworkDeviceHandler | |
28 : public ShillPropertyChangedObserver { | |
29 public: | |
30 struct Device { | |
31 Device() : powered(false), scanning(false), scan_interval(0) {} | |
32 std::string type; | |
33 bool powered; | |
34 bool scanning; | |
35 int scan_interval; | |
36 std::map<std::string, WifiAccessPoint> wifi_access_points; | |
37 }; | |
38 typedef std::map<std::string, Device> DeviceMap; | |
39 | |
40 class Observer { | |
Greg Spencer (Chromium)
2013/01/04 23:57:26
This class should be in a separate header. There
stevenjb
2013/01/07 15:56:22
I don't recall the specifics of that discussion, b
Greg Spencer (Chromium)
2013/01/08 21:03:07
Well, Device could go in the same header file as t
stevenjb
2013/01/08 21:29:17
Yeah, but it wouldn't make sense to have Device in
| |
41 public: | |
42 typedef NetworkDeviceHandler::DeviceMap DeviceMap; | |
43 | |
44 // Called when |devices_| is updated, passes |devices_| as a convenience. | |
Greg Spencer (Chromium)
2013/01/04 23:57:26
Shouldn't one of those be "|devices|" without the
stevenjb
2013/01/07 15:56:22
Done.
| |
45 virtual void NetworkDevicesUpdated(const DeviceMap& devices) = 0; | |
46 | |
47 protected: | |
48 virtual ~Observer() {} | |
49 }; | |
50 | |
51 NetworkDeviceHandler(); | |
52 virtual ~NetworkDeviceHandler(); | |
53 void Init(); | |
54 | |
55 // Add/remove observers. | |
56 void AddObserver(Observer* observer); | |
57 void RemoveObserver(Observer* observer); | |
58 | |
59 bool devices_ready() const { return devices_ready_; } | |
60 const DeviceMap& devices() const { return devices_; } | |
61 | |
62 // ShillPropertyChangedObserver overrides | |
63 virtual void OnPropertyChanged(const std::string& key, | |
64 const base::Value& value) OVERRIDE; | |
65 | |
66 private: | |
67 void ManagerPropertiesCallback(DBusMethodCallStatus call_status, | |
68 const base::DictionaryValue& properties); | |
69 void DevicePropertyChanged(const base::ListValue* devices); | |
70 void DevicePropertiesCallback(const std::string& device_path, | |
71 DBusMethodCallStatus call_status, | |
72 const base::DictionaryValue& properties); | |
73 void NetworkPropertiesCallback(const std::string& device_path, | |
74 const std::string& network_path, | |
75 DBusMethodCallStatus call_status, | |
76 const base::DictionaryValue& properties); | |
77 void DeviceNetworkReady(const std::string& device_path, | |
78 const std::string& network_path); | |
79 void DeviceReady(const std::string& device_path); | |
80 | |
81 // True when the device list is up to date. | |
82 bool devices_ready_; | |
83 | |
84 // Map of Device structs, valid when |devices_ready_| is true. | |
85 DeviceMap devices_; | |
86 | |
87 // Map of pending devices. | |
88 std::set<std::string> pending_device_paths_; | |
89 | |
90 // Map of pending networks per device path. | |
91 std::map<std::string, std::set<std::string> > pending_network_paths_; | |
92 | |
93 // Observer list | |
94 ObserverList<Observer> observers_; | |
95 | |
96 // For Shill client callbacks | |
97 base::WeakPtrFactory<NetworkDeviceHandler> weak_ptr_factory_; | |
98 }; | |
99 | |
100 } // namespace chromeos | |
101 | |
102 #endif // CHROMEOS_NETWORK_NETWORK_DEVICE_HANDLER_H_ | |
OLD | NEW |