blob: 8bf600109391cb58269d0fc6f4cdceff969ce489 [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
thestiga11cbfb72015-09-15 08:44:495#ifndef COMPONENTS_WIFI_WIFI_SERVICE_H_
6#define COMPONENTS_WIFI_WIFI_SERVICE_H_
[email protected]1b6888ad2013-11-22 12:44:417
8#include <list>
dcheng3f767dc32016-04-25 22:54:229#include <memory>
[email protected]333db222014-01-29 07:34:3710#include <set>
[email protected]1b6888ad2013-11-22 12:44:4111#include <string>
12#include <vector>
13
14#include "base/callback.h"
avi5dd91f82015-12-25 22:30:4615#include "base/macros.h"
[email protected]1b6888ad2013-11-22 12:44:4116#include "base/memory/ref_counted.h"
gab10ae4362016-11-02 23:34:5317#include "base/sequenced_task_runner.h"
18#include "base/single_thread_task_runner.h"
[email protected]1b6888ad2013-11-22 12:44:4119#include "base/values.h"
20#include "components/wifi/wifi_export.h"
21
22namespace wifi {
23
24// WiFiService interface used by implementation of chrome.networkingPrivate
25// JavaScript extension API. All methods should be called on worker thread.
26// It could be created on any (including UI) thread, so nothing expensive should
[email protected]333db222014-01-29 07:34:3727// be done in the constructor. See |NetworkingPrivateService| for wrapper
28// accessible on UI thread.
[email protected]1b6888ad2013-11-22 12:44:4129class WIFI_EXPORT WiFiService {
30 public:
31 typedef std::vector<std::string> NetworkGuidList;
32 typedef base::Callback<
33 void(const NetworkGuidList& network_guid_list)> NetworkGuidListCallback;
34
35 virtual ~WiFiService() {}
36
[email protected]4f9264c2013-11-22 20:25:5437 // Initialize WiFiService, store |task_runner| for posting worker tasks.
38 virtual void Initialize(
39 scoped_refptr<base::SequencedTaskRunner> task_runner) = 0;
40
41 // UnInitialize WiFiService.
42 virtual void UnInitialize() = 0;
43
[email protected]1b6888ad2013-11-22 12:44:4144 // Create instance of |WiFiService| for normal use.
45 static WiFiService* Create();
[email protected]1b6888ad2013-11-22 12:44:4146
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,
dcheng3f767dc32016-04-25 22:54:2273 std::unique_ptr<base::DictionaryValue> properties,
[email protected]1b6888ad2013-11-22 12:44:4174 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,
dcheng3f767dc32016-04-25 22:54:2281 std::unique_ptr<base::DictionaryValue> properties,
[email protected]4adfc3b2013-12-05 00:50:3782 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]ca11059e2014-06-04 08:41:2288 base::ListValue* network_list,
89 bool include_details) = 0;
[email protected]1b6888ad2013-11-22 12:44:4190
91 // Request network scan. Send |NetworkListChanged| event on completion.
92 virtual void RequestNetworkScan() = 0;
93
94 // Start connect to network identified by |network_guid|. Populates |error|
95 // on failure.
96 virtual void StartConnect(const std::string& network_guid,
97 std::string* error) = 0;
98
99 // Start disconnect from network identified by |network_guid|. Populates
100 // |error| on failure.
101 virtual void StartDisconnect(const std::string& network_guid,
102 std::string* error) = 0;
103
[email protected]c5527552014-02-13 21:37:32104 // Get WiFi Key for network identified by |network_guid| from the
105 // system (if it has one) and store it in |key_data|. User privilege elevation
106 // may be required, and function will fail if user privileges are not
107 // sufficient. Populates |error| on failure.
108 virtual void GetKeyFromSystem(const std::string& network_guid,
109 std::string* key_data,
110 std::string* error) = 0;
111
[email protected]1b6888ad2013-11-22 12:44:41112 // Set observers to run when |NetworksChanged| and |NetworksListChanged|
skyostilb0daa012015-06-02 19:03:48113 // events needs to be sent. Notifications are posted on |task_runner|.
[email protected]1b6888ad2013-11-22 12:44:41114 virtual void SetEventObservers(
skyostilb0daa012015-06-02 19:03:48115 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
[email protected]1b6888ad2013-11-22 12:44:41116 const NetworkGuidListCallback& networks_changed_observer,
117 const NetworkGuidListCallback& network_list_changed_observer) = 0;
118
[email protected]333db222014-01-29 07:34:37119 // Request update of Connected Network information. Send |NetworksChanged|
120 // event on completion.
121 virtual void RequestConnectedNetworkUpdate() = 0;
122
meacer4770e8a2015-01-30 21:15:44123 // Get the SSID of the currently connected network, if any.
124 virtual void GetConnectedNetworkSSID(std::string* ssid,
125 std::string* error) = 0;
126
[email protected]1b6888ad2013-11-22 12:44:41127 protected:
128 WiFiService() {}
129
[email protected]85445f72014-05-06 14:45:26130 // Error constants.
131 static const char kErrorAssociateToNetwork[];
132 static const char kErrorInvalidData[];
133 static const char kErrorNotConfigured[];
134 static const char kErrorNotConnected[];
135 static const char kErrorNotFound[];
136 static const char kErrorNotImplemented[];
137 static const char kErrorScanForNetworksWithName[];
138 static const char kErrorWiFiService[];
139
[email protected]1b6888ad2013-11-22 12:44:41140 private:
141 DISALLOW_COPY_AND_ASSIGN(WiFiService);
142};
143
144} // namespace wifi
145
thestiga11cbfb72015-09-15 08:44:49146#endif // COMPONENTS_WIFI_WIFI_SERVICE_H_