[email protected] | 1b6888ad | 2013-11-22 12:44:41 | [diff] [blame] | 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. |
| 4 | |
thestig | a11cbfb7 | 2015-09-15 08:44:49 | [diff] [blame] | 5 | #ifndef COMPONENTS_WIFI_WIFI_SERVICE_H_ |
| 6 | #define COMPONENTS_WIFI_WIFI_SERVICE_H_ |
[email protected] | 1b6888ad | 2013-11-22 12:44:41 | [diff] [blame] | 7 | |
| 8 | #include <list> |
dcheng | 3f767dc3 | 2016-04-25 22:54:22 | [diff] [blame] | 9 | #include <memory> |
[email protected] | 333db22 | 2014-01-29 07:34:37 | [diff] [blame] | 10 | #include <set> |
[email protected] | 1b6888ad | 2013-11-22 12:44:41 | [diff] [blame] | 11 | #include <string> |
| 12 | #include <vector> |
| 13 | |
| 14 | #include "base/callback.h" |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 15 | #include "base/macros.h" |
[email protected] | 1b6888ad | 2013-11-22 12:44:41 | [diff] [blame] | 16 | #include "base/memory/ref_counted.h" |
gab | 10ae436 | 2016-11-02 23:34:53 | [diff] [blame] | 17 | #include "base/sequenced_task_runner.h" |
| 18 | #include "base/single_thread_task_runner.h" |
[email protected] | 1b6888ad | 2013-11-22 12:44:41 | [diff] [blame] | 19 | #include "base/values.h" |
| 20 | #include "components/wifi/wifi_export.h" |
| 21 | |
| 22 | namespace 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] | 333db22 | 2014-01-29 07:34:37 | [diff] [blame] | 27 | // be done in the constructor. See |NetworkingPrivateService| for wrapper |
| 28 | // accessible on UI thread. |
[email protected] | 1b6888ad | 2013-11-22 12:44:41 | [diff] [blame] | 29 | class 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] | 4f9264c | 2013-11-22 20:25:54 | [diff] [blame] | 37 | // 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] | 1b6888ad | 2013-11-22 12:44:41 | [diff] [blame] | 44 | // Create instance of |WiFiService| for normal use. |
| 45 | static WiFiService* Create(); |
[email protected] | 1b6888ad | 2013-11-22 12:44:41 | [diff] [blame] | 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] | 85ecd7e | 2013-12-23 21:58:45 | [diff] [blame] | 50 | base::DictionaryValue* properties, |
[email protected] | 1b6888ad | 2013-11-22 12:44:41 | [diff] [blame] | 51 | std::string* error) = 0; |
| 52 | |
[email protected] | 4adfc3b | 2013-12-05 00:50:37 | [diff] [blame] | 53 | // 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] | 85ecd7e | 2013-12-23 21:58:45 | [diff] [blame] | 58 | base::DictionaryValue* managed_properties, |
[email protected] | 4adfc3b | 2013-12-05 00:50:37 | [diff] [blame] | 59 | 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] | 85ecd7e | 2013-12-23 21:58:45 | [diff] [blame] | 67 | base::DictionaryValue* properties, |
[email protected] | 4adfc3b | 2013-12-05 00:50:37 | [diff] [blame] | 68 | std::string* error) = 0; |
| 69 | |
[email protected] | 1b6888ad | 2013-11-22 12:44:41 | [diff] [blame] | 70 | // Set Properties of network identified by |network_guid|. Populates |error| |
| 71 | // on failure. |
| 72 | virtual void SetProperties(const std::string& network_guid, |
dcheng | 3f767dc3 | 2016-04-25 22:54:22 | [diff] [blame] | 73 | std::unique_ptr<base::DictionaryValue> properties, |
[email protected] | 1b6888ad | 2013-11-22 12:44:41 | [diff] [blame] | 74 | std::string* error) = 0; |
| 75 | |
[email protected] | 4adfc3b | 2013-12-05 00:50:37 | [diff] [blame] | 76 | // 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, |
dcheng | 3f767dc3 | 2016-04-25 22:54:22 | [diff] [blame] | 81 | std::unique_ptr<base::DictionaryValue> properties, |
[email protected] | 4adfc3b | 2013-12-05 00:50:37 | [diff] [blame] | 82 | std::string* network_guid, |
| 83 | std::string* error) = 0; |
| 84 | |
[email protected] | a57ffbd5 | 2013-11-27 01:06:47 | [diff] [blame] | 85 | // 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] | ca11059e | 2014-06-04 08:41:22 | [diff] [blame] | 88 | base::ListValue* network_list, |
| 89 | bool include_details) = 0; |
[email protected] | 1b6888ad | 2013-11-22 12:44:41 | [diff] [blame] | 90 | |
| 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] | c552755 | 2014-02-13 21:37:32 | [diff] [blame] | 104 | // 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] | 1b6888ad | 2013-11-22 12:44:41 | [diff] [blame] | 112 | // Set observers to run when |NetworksChanged| and |NetworksListChanged| |
skyostil | b0daa01 | 2015-06-02 19:03:48 | [diff] [blame] | 113 | // events needs to be sent. Notifications are posted on |task_runner|. |
[email protected] | 1b6888ad | 2013-11-22 12:44:41 | [diff] [blame] | 114 | virtual void SetEventObservers( |
skyostil | b0daa01 | 2015-06-02 19:03:48 | [diff] [blame] | 115 | scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
[email protected] | 1b6888ad | 2013-11-22 12:44:41 | [diff] [blame] | 116 | const NetworkGuidListCallback& networks_changed_observer, |
| 117 | const NetworkGuidListCallback& network_list_changed_observer) = 0; |
| 118 | |
[email protected] | 333db22 | 2014-01-29 07:34:37 | [diff] [blame] | 119 | // Request update of Connected Network information. Send |NetworksChanged| |
| 120 | // event on completion. |
| 121 | virtual void RequestConnectedNetworkUpdate() = 0; |
| 122 | |
meacer | 4770e8a | 2015-01-30 21:15:44 | [diff] [blame] | 123 | // 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] | 1b6888ad | 2013-11-22 12:44:41 | [diff] [blame] | 127 | protected: |
| 128 | WiFiService() {} |
| 129 | |
[email protected] | 85445f7 | 2014-05-06 14:45:26 | [diff] [blame] | 130 | // 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] | 1b6888ad | 2013-11-22 12:44:41 | [diff] [blame] | 140 | private: |
| 141 | DISALLOW_COPY_AND_ASSIGN(WiFiService); |
| 142 | }; |
| 143 | |
| 144 | } // namespace wifi |
| 145 | |
thestig | a11cbfb7 | 2015-09-15 08:44:49 | [diff] [blame] | 146 | #endif // COMPONENTS_WIFI_WIFI_SERVICE_H_ |