blob: f7e7999fa8ac35ae37eeb2b6a391dca3f6831855 [file] [log] [blame]
[email protected]1b6888ad2013-11-22 12:44:411// Copyright 2013 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 CHROME_UTILITY_WIFI_WIFI_SERVICE_H_
6#define CHROME_UTILITY_WIFI_WIFI_SERVICE_H_
7
8#include <list>
[email protected]333db222014-01-29 07:34:379#include <set>
[email protected]1b6888ad2013-11-22 12:44:4110#include <string>
11#include <vector>
12
13#include "base/callback.h"
14#include "base/memory/ref_counted.h"
15#include "base/message_loop/message_loop_proxy.h"
[email protected]4f9264c2013-11-22 20:25:5416#include "base/threading/sequenced_worker_pool.h"
[email protected]1b6888ad2013-11-22 12:44:4117#include "base/values.h"
18#include "components/wifi/wifi_export.h"
19
20namespace wifi {
21
22// WiFiService interface used by implementation of chrome.networkingPrivate
23// JavaScript extension API. All methods should be called on worker thread.
24// It could be created on any (including UI) thread, so nothing expensive should
[email protected]333db222014-01-29 07:34:3725// be done in the constructor. See |NetworkingPrivateService| for wrapper
26// accessible on UI thread.
[email protected]1b6888ad2013-11-22 12:44:4127class WIFI_EXPORT WiFiService {
28 public:
29 typedef std::vector<std::string> NetworkGuidList;
30 typedef base::Callback<
31 void(const NetworkGuidList& network_guid_list)> NetworkGuidListCallback;
32
33 virtual ~WiFiService() {}
34
[email protected]4f9264c2013-11-22 20:25:5435 // Initialize WiFiService, store |task_runner| for posting worker tasks.
36 virtual void Initialize(
37 scoped_refptr<base::SequencedTaskRunner> task_runner) = 0;
38
39 // UnInitialize WiFiService.
40 virtual void UnInitialize() = 0;
41
[email protected]1b6888ad2013-11-22 12:44:4142 // Create instance of |WiFiService| for normal use.
43 static WiFiService* Create();
44 // Create instance of |WiFiService| for unit test use.
45 static WiFiService* CreateForTest();
46
47 // Get Properties of network identified by |network_guid|. Populates
48 // |properties| on success, |error| on failure.
49 virtual void GetProperties(const std::string& network_guid,
[email protected]85ecd7e2013-12-23 21:58:4550 base::DictionaryValue* properties,
[email protected]1b6888ad2013-11-22 12:44:4151 std::string* error) = 0;
52
[email protected]4adfc3b2013-12-05 00:50:3753 // Gets the merged properties of the network with id |network_guid| from the
54 // sources: User settings, shared settings, user policy, device policy and
55 // the currently active settings. Populates |managed_properties| on success,
56 // |error| on failure.
57 virtual void GetManagedProperties(const std::string& network_guid,
[email protected]85ecd7e2013-12-23 21:58:4558 base::DictionaryValue* managed_properties,
[email protected]4adfc3b2013-12-05 00:50:3759 std::string* error) = 0;
60
61 // Get the cached read-only properties of the network with id |network_guid|.
62 // This is meant to be a higher performance function than |GetProperties|,
63 // which requires a round trip to query the networking subsystem. It only
64 // returns a subset of the properties returned by |GetProperties|. Populates
65 // |properties| on success, |error| on failure.
66 virtual void GetState(const std::string& network_guid,
[email protected]85ecd7e2013-12-23 21:58:4567 base::DictionaryValue* properties,
[email protected]4adfc3b2013-12-05 00:50:3768 std::string* error) = 0;
69
[email protected]1b6888ad2013-11-22 12:44:4170 // Set Properties of network identified by |network_guid|. Populates |error|
71 // on failure.
72 virtual void SetProperties(const std::string& network_guid,
73 scoped_ptr<base::DictionaryValue> properties,
74 std::string* error) = 0;
75
[email protected]4adfc3b2013-12-05 00:50:3776 // Creates a new network configuration from |properties|. If |shared| is true,
77 // share this network configuration with other users. If a matching configured
78 // network already exists, this will fail and populate |error|. On success
79 // populates the |network_guid| of the new network.
80 virtual void CreateNetwork(bool shared,
81 scoped_ptr<base::DictionaryValue> properties,
82 std::string* network_guid,
83 std::string* error) = 0;
84
[email protected]a57ffbd52013-11-27 01:06:4785 // Get list of visible networks of |network_type| (one of onc::network_type).
86 // Populates |network_list| on success.
87 virtual void GetVisibleNetworks(const std::string& network_type,
[email protected]85ecd7e2013-12-23 21:58:4588 base::ListValue* network_list) = 0;
[email protected]1b6888ad2013-11-22 12:44:4189
90 // Request network scan. Send |NetworkListChanged| event on completion.
91 virtual void RequestNetworkScan() = 0;
92
93 // Start connect to network identified by |network_guid|. Populates |error|
94 // on failure.
95 virtual void StartConnect(const std::string& network_guid,
96 std::string* error) = 0;
97
98 // Start disconnect from network identified by |network_guid|. Populates
99 // |error| on failure.
100 virtual void StartDisconnect(const std::string& network_guid,
101 std::string* error) = 0;
102
103 // Set observers to run when |NetworksChanged| and |NetworksListChanged|
104 // events needs to be sent. Notifications are posted on |message_loop_proxy|.
105 virtual void SetEventObservers(
106 scoped_refptr<base::MessageLoopProxy> message_loop_proxy,
107 const NetworkGuidListCallback& networks_changed_observer,
108 const NetworkGuidListCallback& network_list_changed_observer) = 0;
109
[email protected]333db222014-01-29 07:34:37110 // Request update of Connected Network information. Send |NetworksChanged|
111 // event on completion.
112 virtual void RequestConnectedNetworkUpdate() = 0;
113
[email protected]1b6888ad2013-11-22 12:44:41114 protected:
115 WiFiService() {}
116
117 typedef int32 Frequency;
118 enum FrequencyEnum {
[email protected]4f9264c2013-11-22 20:25:54119 kFrequencyAny = 0,
[email protected]1b6888ad2013-11-22 12:44:41120 kFrequencyUnknown = 0,
121 kFrequency2400 = 2400,
122 kFrequency5000 = 5000
123 };
124
[email protected]333db222014-01-29 07:34:37125 typedef std::set<Frequency> FrequencySet;
[email protected]1b6888ad2013-11-22 12:44:41126 // Network Properties, used as result of |GetProperties| and
127 // |GetVisibleNetworks|.
128 struct WIFI_EXPORT NetworkProperties {
129 NetworkProperties();
130 ~NetworkProperties();
131
132 std::string connection_state;
133 std::string guid;
134 std::string name;
135 std::string ssid;
136 std::string bssid;
137 std::string type;
138 std::string security;
[email protected]e425d0362013-12-13 18:25:17139 // |password| field is used to pass wifi password for network creation via
140 // |CreateNetwork| or connection via |StartConnect|. It does not persist
141 // once operation is completed.
142 std::string password;
[email protected]1b6888ad2013-11-22 12:44:41143 // WiFi Signal Strength. 0..100
144 uint32 signal_strength;
145 bool auto_connect;
146 Frequency frequency;
[email protected]333db222014-01-29 07:34:37147 FrequencySet frequency_set;
[email protected]1b6888ad2013-11-22 12:44:41148
149 std::string json_extra; // Extra JSON properties for unit tests
150
151 scoped_ptr<base::DictionaryValue> ToValue(bool network_list) const;
[email protected]e425d0362013-12-13 18:25:17152 // Updates only properties set in |value|.
[email protected]1b6888ad2013-11-22 12:44:41153 bool UpdateFromValue(const base::DictionaryValue& value);
154 static std::string MacAddressAsString(const uint8 mac_as_int[6]);
155 static bool OrderByType(const NetworkProperties& l,
156 const NetworkProperties& r);
157 };
158
159 typedef std::list<NetworkProperties> NetworkList;
160
161 private:
162 DISALLOW_COPY_AND_ASSIGN(WiFiService);
163};
164
165} // namespace wifi
166
167#endif // CHROME_UTILITY_WIFI_WIFI_SERVICE_H_