1 // 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.
5 #ifndef CHROME_UTILITY_WIFI_WIFI_SERVICE_H_
6 #define CHROME_UTILITY_WIFI_WIFI_SERVICE_H_
13 #include "base/callback.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/threading/sequenced_worker_pool.h"
16 #include "base/values.h"
17 #include "components/wifi/wifi_export.h"
21 // WiFiService interface used by implementation of chrome.networkingPrivate
22 // JavaScript extension API. All methods should be called on worker thread.
23 // It could be created on any (including UI) thread, so nothing expensive should
24 // be done in the constructor. See |NetworkingPrivateService| for wrapper
25 // accessible on UI thread.
26 class WIFI_EXPORT WiFiService
{
28 typedef std::vector
<std::string
> NetworkGuidList
;
29 typedef base::Callback
<
30 void(const NetworkGuidList
& network_guid_list
)> NetworkGuidListCallback
;
32 virtual ~WiFiService() {}
34 // Initialize WiFiService, store |task_runner| for posting worker tasks.
35 virtual void Initialize(
36 scoped_refptr
<base::SequencedTaskRunner
> task_runner
) = 0;
38 // UnInitialize WiFiService.
39 virtual void UnInitialize() = 0;
41 // Create instance of |WiFiService| for normal use.
42 static WiFiService
* Create();
44 // Get Properties of network identified by |network_guid|. Populates
45 // |properties| on success, |error| on failure.
46 virtual void GetProperties(const std::string
& network_guid
,
47 base::DictionaryValue
* properties
,
48 std::string
* error
) = 0;
50 // Gets the merged properties of the network with id |network_guid| from the
51 // sources: User settings, shared settings, user policy, device policy and
52 // the currently active settings. Populates |managed_properties| on success,
53 // |error| on failure.
54 virtual void GetManagedProperties(const std::string
& network_guid
,
55 base::DictionaryValue
* managed_properties
,
56 std::string
* error
) = 0;
58 // Get the cached read-only properties of the network with id |network_guid|.
59 // This is meant to be a higher performance function than |GetProperties|,
60 // which requires a round trip to query the networking subsystem. It only
61 // returns a subset of the properties returned by |GetProperties|. Populates
62 // |properties| on success, |error| on failure.
63 virtual void GetState(const std::string
& network_guid
,
64 base::DictionaryValue
* properties
,
65 std::string
* error
) = 0;
67 // Set Properties of network identified by |network_guid|. Populates |error|
69 virtual void SetProperties(const std::string
& network_guid
,
70 scoped_ptr
<base::DictionaryValue
> properties
,
71 std::string
* error
) = 0;
73 // Creates a new network configuration from |properties|. If |shared| is true,
74 // share this network configuration with other users. If a matching configured
75 // network already exists, this will fail and populate |error|. On success
76 // populates the |network_guid| of the new network.
77 virtual void CreateNetwork(bool shared
,
78 scoped_ptr
<base::DictionaryValue
> properties
,
79 std::string
* network_guid
,
80 std::string
* error
) = 0;
82 // Get list of visible networks of |network_type| (one of onc::network_type).
83 // Populates |network_list| on success.
84 virtual void GetVisibleNetworks(const std::string
& network_type
,
85 base::ListValue
* network_list
,
86 bool include_details
) = 0;
88 // Request network scan. Send |NetworkListChanged| event on completion.
89 virtual void RequestNetworkScan() = 0;
91 // Start connect to network identified by |network_guid|. Populates |error|
93 virtual void StartConnect(const std::string
& network_guid
,
94 std::string
* error
) = 0;
96 // Start disconnect from network identified by |network_guid|. Populates
97 // |error| on failure.
98 virtual void StartDisconnect(const std::string
& network_guid
,
99 std::string
* error
) = 0;
101 // Get WiFi Key for network identified by |network_guid| from the
102 // system (if it has one) and store it in |key_data|. User privilege elevation
103 // may be required, and function will fail if user privileges are not
104 // sufficient. Populates |error| on failure.
105 virtual void GetKeyFromSystem(const std::string
& network_guid
,
106 std::string
* key_data
,
107 std::string
* error
) = 0;
109 // Set observers to run when |NetworksChanged| and |NetworksListChanged|
110 // events needs to be sent. Notifications are posted on |task_runner|.
111 virtual void SetEventObservers(
112 scoped_refptr
<base::SingleThreadTaskRunner
> task_runner
,
113 const NetworkGuidListCallback
& networks_changed_observer
,
114 const NetworkGuidListCallback
& network_list_changed_observer
) = 0;
116 // Request update of Connected Network information. Send |NetworksChanged|
117 // event on completion.
118 virtual void RequestConnectedNetworkUpdate() = 0;
120 // Get the SSID of the currently connected network, if any.
121 virtual void GetConnectedNetworkSSID(std::string
* ssid
,
122 std::string
* error
) = 0;
128 static const char kErrorAssociateToNetwork
[];
129 static const char kErrorInvalidData
[];
130 static const char kErrorNotConfigured
[];
131 static const char kErrorNotConnected
[];
132 static const char kErrorNotFound
[];
133 static const char kErrorNotImplemented
[];
134 static const char kErrorScanForNetworksWithName
[];
135 static const char kErrorWiFiService
[];
138 DISALLOW_COPY_AND_ASSIGN(WiFiService
);
143 #endif // CHROME_UTILITY_WIFI_WIFI_SERVICE_H_