File: networking_private_linux.h

package info (click to toggle)
chromium-browser 41.0.2272.118-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 2,189,132 kB
  • sloc: cpp: 9,691,462; ansic: 3,341,451; python: 712,689; asm: 518,779; xml: 208,926; java: 169,820; sh: 119,353; perl: 68,907; makefile: 28,311; yacc: 13,305; objc: 11,385; tcl: 3,186; cs: 2,225; sql: 2,217; lex: 2,215; lisp: 1,349; pascal: 1,256; awk: 407; ruby: 155; sed: 53; php: 14; exp: 11
file content (249 lines) | stat: -rw-r--r-- 11,088 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_EXTENSIONS_API_NETWORKING_PRIVATE_NETWORKING_PRIVATE_LINUX_H_
#define CHROME_BROWSER_EXTENSIONS_API_NETWORKING_PRIVATE_NETWORKING_PRIVATE_LINUX_H_

#include <string>
#include <vector>

#include "base/memory/linked_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/threading/thread.h"
#include "chrome/browser/extensions/api/networking_private/networking_private_delegate.h"
#include "components/keyed_service/core/keyed_service.h"

namespace context {
class BrowserContext;
}

namespace dbus {
class Bus;
class ObjectPath;
class ObjectProxy;
class Response;
};

namespace extensions {

// Linux NetworkingPrivateDelegate implementation.
class NetworkingPrivateLinux : public NetworkingPrivateDelegate {
 public:
  typedef std::map<base::string16, linked_ptr<base::DictionaryValue>>
      NetworkMap;

  typedef std::vector<std::string> GuidList;

  NetworkingPrivateLinux(content::BrowserContext* browser_context,
                         scoped_ptr<VerifyDelegate> verify_delegate);

  // NetworkingPrivateDelegate
  void GetProperties(const std::string& guid,
                     const DictionaryCallback& success_callback,
                     const FailureCallback& failure_callback) override;
  void GetManagedProperties(const std::string& guid,
                            const DictionaryCallback& success_callback,
                            const FailureCallback& failure_callback) override;
  void GetState(const std::string& guid,
                const DictionaryCallback& success_callback,
                const FailureCallback& failure_callback) override;
  void SetProperties(const std::string& guid,
                     scoped_ptr<base::DictionaryValue> properties,
                     const VoidCallback& success_callback,
                     const FailureCallback& failure_callback) override;
  void CreateNetwork(bool shared,
                     scoped_ptr<base::DictionaryValue> properties,
                     const StringCallback& success_callback,
                     const FailureCallback& failure_callback) override;
  void GetNetworks(const std::string& network_type,
                   bool configured_only,
                   bool visible_only,
                   int limit,
                   const NetworkListCallback& success_callback,
                   const FailureCallback& failure_callback) override;
  void StartConnect(const std::string& guid,
                    const VoidCallback& success_callback,
                    const FailureCallback& failure_callback) override;
  void StartDisconnect(const std::string& guid,
                       const VoidCallback& success_callback,
                       const FailureCallback& failure_callback) override;
  void SetWifiTDLSEnabledState(
      const std::string& ip_or_mac_address,
      bool enabled,
      const StringCallback& success_callback,
      const FailureCallback& failure_callback) override;
  void GetWifiTDLSStatus(const std::string& ip_or_mac_address,
                         const StringCallback& success_callback,
                         const FailureCallback& failure_callback) override;
  void GetCaptivePortalStatus(const std::string& guid,
                              const StringCallback& success_callback,
                              const FailureCallback& failure_callback) override;
  scoped_ptr<base::ListValue> GetEnabledNetworkTypes() override;
  bool EnableNetworkType(const std::string& type) override;
  bool DisableNetworkType(const std::string& type) override;
  bool RequestScan() override;
  void AddObserver(NetworkingPrivateDelegateObserver* observer) override;
  void RemoveObserver(NetworkingPrivateDelegateObserver* observer) override;

 private:
  ~NetworkingPrivateLinux() override;

  // https://developer.gnome.org/NetworkManager/unstable/spec.html#type-NM_DEVICE_TYPE
  enum DeviceType {
    NM_DEVICE_TYPE_UNKNOWN = 0,
    NM_DEVICE_TYPE_ETHERNET = 1,
    NM_DEVICE_TYPE_WIFI = 2
  };

  // https://developer.gnome.org/NetworkManager/unstable/spec.html#type-NM_802_11_AP_SEC
  enum WirelessSecurityFlags {
    NM_802_11_AP_SEC_NONE = 0x0,
    NM_802_11_AP_SEC_PAIR_WEP40 = 0x1,
    NM_802_11_AP_SEC_PAIR_WEP104 = 0x2,
    NM_802_11_AP_SEC_PAIR_TKIP = 0x4,
    NM_802_11_AP_SEC_PAIR_CCMP = 0x8,
    NM_802_11_AP_SEC_GROUP_WEP40 = 0x10,
    NM_802_11_AP_SEC_GROUP_WEP104 = 0x20,
    NM_802_11_AP_SEC_GROUP_TKIP = 0x40,
    NM_802_11_AP_SEC_GROUP_CCMP = 0x80,
    NM_802_11_AP_SEC_KEY_MGMT_PSK = 0x100,
    NM_802_11_AP_SEC_KEY_MGMT_802_1X = 0x200
  };

  // Initializes the DBus instance and the proxy object to the network manager.
  // Must be called on |dbus_thread_|.
  void Initialize();

  // Enumerates all WiFi adapters and scans for access points on each.
  // Results are appended into the provided |network_map|.
  // Must be called on |dbus_thread_|.
  void GetAllWiFiAccessPoints(bool configured_only,
                              bool visible_only,
                              int limit,
                              NetworkMap* network_map);

  // Initiates the connection to the network.
  // Must be called on |dbus_thread_|.
  void ConnectToNetwork(const std::string& guid, std::string* error);

  // Initiates disconnection from the specified network.
  // Must be called on |dbus_thread_|
  void DisconnectFromNetwork(const std::string& guid, std::string* error);

  // Checks whether the current thread is the DBus thread. If not, DCHECK will
  // fail.
  void AssertOnDBusThread();

  // Verifies that NetworkManager interfaces are initialized.
  // Returns true if NetworkManager is initialized, otherwise returns false
  // and the API call will fail with |kErrorNotSupported|.
  bool CheckNetworkManagerSupported(const FailureCallback& failure_callback);

  // Gets all network devices on the system.
  // Returns false if there is an error getting the device paths.
  bool GetNetworkDevices(std::vector<dbus::ObjectPath>* device_paths);

  // Returns the DeviceType (eg. WiFi, ethernet). corresponding to the
  // |device_path|.
  DeviceType GetDeviceType(const dbus::ObjectPath& device_path);

  // Helper function to enumerate WiFi networks. Takes a path to a Wireless
  // device, scans that device and appends networks to network_list.
  // Returns false if there is an error getting the access points visible
  // to the |device_path|.
  bool AddAccessPointsFromDevice(const dbus::ObjectPath& device_path,
                                 NetworkMap* network_map);

  // Reply callback accepts the map of networks and fires the callback.
  void OnAccessPointsFound(scoped_ptr<NetworkMap> network_map,
                           const NetworkListCallback& success_callback,
                           const FailureCallback& failure_callback);

  // Gets a dictionary of information about the access point.
  // Returns false if there is an error getting information about the
  // supplied |access_point_path|.
  bool GetAccessPointInfo(
      const dbus::ObjectPath& access_point_path,
      const scoped_ptr<base::DictionaryValue>& access_point_info);

  // Helper function to extract a property from a device.
  // Returns the dbus::Response object from calling Get on the supplied
  // |property_name|.
  scoped_ptr<dbus::Response> GetAccessPointProperty(
      dbus::ObjectProxy* access_point_proxy,
      const std::string& property_name);

  // If the access_point is not already in the map it is added. Otherwise
  // the access point is updated (eg. with the max of the signal
  // strength).
  void AddOrUpdateAccessPoint(NetworkMap* network_map,
                              const std::string& network_guid,
                              scoped_ptr<base::DictionaryValue>& access_point);

  // Maps the WPA security flags to a human readable string.
  void MapSecurityFlagsToString(uint32 securityFlags, std::string* security);

  // Gets the connected access point path on the given device. Internally gets
  // all active connections then checks if the device matches the requested
  // device, then gets the access point associated with the connection.
  // Returns false if there is an error getting the connected access point.
  bool GetConnectedAccessPoint(dbus::ObjectPath device_path,
                               dbus::ObjectPath* access_point_path);

  // Given a path to an active connection gets the path to the device
  // that the connection belongs to. Returns false if there is an error getting
  // the device corresponding to the supplied |connection_path|.
  bool GetDeviceOfConnection(dbus::ObjectPath connection_path,
                             dbus::ObjectPath* device_path);

  // Given a path to an active wireless connection gets the path to the
  // access point associated with that connection.
  // Returns false if there is an error getting the |access_point_path|
  // corresponding to the supplied |connection_path|.
  bool GetAccessPointForConnection(dbus::ObjectPath connection_path,
                                   dbus::ObjectPath* access_point_path);

  // Helper method to set the connection state in the |network_map_| and post
  // a change event.
  bool SetConnectionStateAndPostEvent(const std::string& guid,
                                      const std::string& ssid,
                                      const std::string& connection_state);

  // Helper method to post an OnNetworkChanged event to the UI thread from the
  // dbus thread. Used for connection status progress during |StartConnect|.
  void PostOnNetworksChangedToUIThread(scoped_ptr<GuidList> guid_list);

  // Helper method to be called from the UI thread and manage ownership of the
  // passed vector from the |dbus_thread_|.
  void OnNetworksChangedEventTask(scoped_ptr<GuidList> guid_list);

  void GetCachedNetworkProperties(const std::string& guid,
                                  base::DictionaryValue* properties,
                                  std::string* error);

  void OnNetworksChangedEventOnUIThread(const GuidList& network_guids);

  void OnNetworkListChangedEventOnUIThread(const GuidList& network_guids);

  // Browser context.
  content::BrowserContext* browser_context_;
  // Thread used for DBus actions.
  base::Thread dbus_thread_;
  // DBus instance. Only access on |dbus_thread_|.
  scoped_refptr<dbus::Bus> dbus_;
  // Task runner used by the |dbus_| object.
  scoped_refptr<base::SequencedTaskRunner> dbus_task_runner_;
  // This is owned by |dbus_| object. Only access on |dbus_thread_|.
  dbus::ObjectProxy* network_manager_proxy_;
  // Holds the current mapping of known networks. Only access on |dbus_thread_|.
  scoped_ptr<NetworkMap> network_map_;
  // Observers to Network Events.
  ObserverList<NetworkingPrivateDelegateObserver> network_events_observers_;

  DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateLinux);
};

}  // namespace extensions

#endif  // CHROME_BROWSER_EXTENSIONS_API_NETWORKING_PRIVATE_NETWORKING_PRIVATE_LINUX_H_