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

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

Issue 11887008: Deprecate ShillNetworkClient and add GeolocationHandler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unittest Created 7 years, 11 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_DEVICE_HANDLER_H_ 5 #ifndef CHROMEOS_NETWORK_NETWORK_DEVICE_HANDLER_H_
6 #define CHROMEOS_NETWORK_NETWORK_DEVICE_HANDLER_H_ 6 #define CHROMEOS_NETWORK_NETWORK_DEVICE_HANDLER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 11
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/observer_list.h" 13 #include "base/observer_list.h"
14 #include "chromeos/chromeos_export.h" 14 #include "chromeos/chromeos_export.h"
15 #include "chromeos/dbus/dbus_method_call_status.h" 15 #include "chromeos/dbus/dbus_method_call_status.h"
16 #include "chromeos/dbus/shill_property_changed_observer.h" 16 #include "chromeos/dbus/shill_property_changed_observer.h"
17 #include "chromeos/network/network_util.h" // WifiAccessPoint
18 17
19 namespace base { 18 namespace base {
20 class DictionaryValue; 19 class DictionaryValue;
21 class ListValue; 20 class ListValue;
22 class Value; 21 class Value;
23 } 22 }
24 23
25 namespace chromeos { 24 namespace chromeos {
26 25
27 class CHROMEOS_EXPORT NetworkDeviceHandler 26 class CHROMEOS_EXPORT NetworkDeviceHandler
28 : public ShillPropertyChangedObserver { 27 : public ShillPropertyChangedObserver {
29 public: 28 public:
30 struct Device { 29 struct Device {
31 Device(); 30 Device();
32 ~Device(); 31 ~Device();
33 std::string type; 32 std::string type;
34 bool powered; 33 bool powered;
35 bool scanning; 34 bool scanning;
36 int scan_interval; 35 int scan_interval;
37 std::map<std::string, WifiAccessPoint> wifi_access_points;
38 }; 36 };
39 typedef std::map<std::string, Device> DeviceMap; 37 typedef std::map<std::string, Device> DeviceMap;
40 38
41 class Observer { 39 class Observer {
42 public: 40 public:
43 typedef NetworkDeviceHandler::DeviceMap DeviceMap; 41 typedef NetworkDeviceHandler::DeviceMap DeviceMap;
44 42
45 // Called when devices are updated. Passes the updated map of devices. 43 // Called when devices are updated. Passes the updated map of devices.
46 virtual void NetworkDevicesUpdated(const DeviceMap& devices) = 0; 44 virtual void NetworkDevicesUpdated(const DeviceMap& devices) = 0;
47 45
48 protected: 46 protected:
49 virtual ~Observer() {} 47 virtual ~Observer() {}
50 }; 48 };
51 49
52 NetworkDeviceHandler();
53 virtual ~NetworkDeviceHandler(); 50 virtual ~NetworkDeviceHandler();
54 void Init(); 51
52 // Manage the global instance. Must be initialized before any calls to Get().
53 static void Initialize();
54 static void Shutdown();
55 static NetworkDeviceHandler* Get();
55 56
56 // Add/remove observers. 57 // Add/remove observers.
57 void AddObserver(Observer* observer); 58 void AddObserver(Observer* observer);
58 void RemoveObserver(Observer* observer); 59 void RemoveObserver(Observer* observer);
59 60
60 bool devices_ready() const { return devices_ready_; } 61 bool devices_ready() const { return devices_ready_; }
61 const DeviceMap& devices() const { return devices_; } 62 const DeviceMap& devices() const { return devices_; }
62 63
63 // ShillPropertyChangedObserver overrides 64 // ShillPropertyChangedObserver overrides
64 virtual void OnPropertyChanged(const std::string& key, 65 virtual void OnPropertyChanged(const std::string& key,
65 const base::Value& value) OVERRIDE; 66 const base::Value& value) OVERRIDE;
66 67
67 private: 68 private:
69 friend class NetworkDeviceHandlerTest;
70 NetworkDeviceHandler();
71 void Init();
72
68 void ManagerPropertiesCallback(DBusMethodCallStatus call_status, 73 void ManagerPropertiesCallback(DBusMethodCallStatus call_status,
69 const base::DictionaryValue& properties); 74 const base::DictionaryValue& properties);
70 void DevicePropertyChanged(const base::ListValue* devices); 75 void DevicePropertyChanged(const base::ListValue* devices);
71 void DevicePropertiesCallback(const std::string& device_path, 76 void DevicePropertiesCallback(const std::string& device_path,
72 DBusMethodCallStatus call_status, 77 DBusMethodCallStatus call_status,
73 const base::DictionaryValue& properties); 78 const base::DictionaryValue& properties);
74 void NetworkPropertiesCallback(const std::string& device_path, 79 void NetworkPropertiesCallback(const std::string& device_path,
75 const std::string& network_path, 80 const std::string& network_path,
76 DBusMethodCallStatus call_status, 81 DBusMethodCallStatus call_status,
77 const base::DictionaryValue& properties); 82 const base::DictionaryValue& properties);
78 void DeviceNetworkReady(const std::string& device_path, 83 void GetDeviceProperties(const std::string& device_path,
79 const std::string& network_path); 84 const base::DictionaryValue& properties);
80 void DeviceReady(const std::string& device_path);
81 85
82 // True when the device list is up to date. 86 // True when the device list is up to date.
83 bool devices_ready_; 87 bool devices_ready_;
84 88
85 // Map of Device structs, valid when |devices_ready_| is true. 89 // Map of Device structs, valid when |devices_ready_| is true.
86 DeviceMap devices_; 90 DeviceMap devices_;
87 91
88 // Map of pending devices. 92 // Map of pending devices.
89 std::set<std::string> pending_device_paths_; 93 std::set<std::string> pending_device_paths_;
90 94
91 // Map of pending networks per device path.
92 std::map<std::string, std::set<std::string> > pending_network_paths_;
93
94 // Observer list 95 // Observer list
95 ObserverList<Observer> observers_; 96 ObserverList<Observer> observers_;
96 97
97 // For Shill client callbacks 98 // For Shill client callbacks
98 base::WeakPtrFactory<NetworkDeviceHandler> weak_ptr_factory_; 99 base::WeakPtrFactory<NetworkDeviceHandler> weak_ptr_factory_;
100
101 DISALLOW_COPY_AND_ASSIGN(NetworkDeviceHandler);
99 }; 102 };
100 103
101 } // namespace chromeos 104 } // namespace chromeos
102 105
103 #endif // CHROMEOS_NETWORK_NETWORK_DEVICE_HANDLER_H_ 106 #endif // CHROMEOS_NETWORK_NETWORK_DEVICE_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698