[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 | |
| 5 | #ifndef CHROME_UTILITY_WIFI_WIFI_SERVICE_H_ |
| 6 | #define CHROME_UTILITY_WIFI_WIFI_SERVICE_H_ |
| 7 | |
| 8 | #include <list> |
[email protected] | 333db22 | 2014-01-29 07:34:37 | [diff] [blame] | 9 | #include <set> |
[email protected] | 1b6888ad | 2013-11-22 12:44:41 | [diff] [blame] | 10 | #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] | 4f9264c | 2013-11-22 20:25:54 | [diff] [blame] | 16 | #include "base/threading/sequenced_worker_pool.h" |
[email protected] | 1b6888ad | 2013-11-22 12:44:41 | [diff] [blame] | 17 | #include "base/values.h" |
| 18 | #include "components/wifi/wifi_export.h" |
| 19 | |
| 20 | namespace 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] | 333db22 | 2014-01-29 07:34:37 | [diff] [blame] | 25 | // be done in the constructor. See |NetworkingPrivateService| for wrapper |
| 26 | // accessible on UI thread. |
[email protected] | 1b6888ad | 2013-11-22 12:44:41 | [diff] [blame] | 27 | class 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] | 4f9264c | 2013-11-22 20:25:54 | [diff] [blame] | 35 | // 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] | 1b6888ad | 2013-11-22 12:44:41 | [diff] [blame] | 42 | // Create instance of |WiFiService| for normal use. |
| 43 | static WiFiService* Create(); |
[email protected] | 1b6888ad | 2013-11-22 12:44:41 | [diff] [blame] | 44 | |
| 45 | // Get Properties of network identified by |network_guid|. Populates |
| 46 | // |properties| on success, |error| on failure. |
| 47 | virtual void GetProperties(const std::string& network_guid, |
[email protected] | 85ecd7e | 2013-12-23 21:58:45 | [diff] [blame] | 48 | base::DictionaryValue* properties, |
[email protected] | 1b6888ad | 2013-11-22 12:44:41 | [diff] [blame] | 49 | std::string* error) = 0; |
| 50 | |
[email protected] | 4adfc3b | 2013-12-05 00:50:37 | [diff] [blame] | 51 | // Gets the merged properties of the network with id |network_guid| from the |
| 52 | // sources: User settings, shared settings, user policy, device policy and |
| 53 | // the currently active settings. Populates |managed_properties| on success, |
| 54 | // |error| on failure. |
| 55 | virtual void GetManagedProperties(const std::string& network_guid, |
[email protected] | 85ecd7e | 2013-12-23 21:58:45 | [diff] [blame] | 56 | base::DictionaryValue* managed_properties, |
[email protected] | 4adfc3b | 2013-12-05 00:50:37 | [diff] [blame] | 57 | std::string* error) = 0; |
| 58 | |
| 59 | // Get the cached read-only properties of the network with id |network_guid|. |
| 60 | // This is meant to be a higher performance function than |GetProperties|, |
| 61 | // which requires a round trip to query the networking subsystem. It only |
| 62 | // returns a subset of the properties returned by |GetProperties|. Populates |
| 63 | // |properties| on success, |error| on failure. |
| 64 | virtual void GetState(const std::string& network_guid, |
[email protected] | 85ecd7e | 2013-12-23 21:58:45 | [diff] [blame] | 65 | base::DictionaryValue* properties, |
[email protected] | 4adfc3b | 2013-12-05 00:50:37 | [diff] [blame] | 66 | std::string* error) = 0; |
| 67 | |
[email protected] | 1b6888ad | 2013-11-22 12:44:41 | [diff] [blame] | 68 | // Set Properties of network identified by |network_guid|. Populates |error| |
| 69 | // on failure. |
| 70 | virtual void SetProperties(const std::string& network_guid, |
| 71 | scoped_ptr<base::DictionaryValue> properties, |
| 72 | std::string* error) = 0; |
| 73 | |
[email protected] | 4adfc3b | 2013-12-05 00:50:37 | [diff] [blame] | 74 | // Creates a new network configuration from |properties|. If |shared| is true, |
| 75 | // share this network configuration with other users. If a matching configured |
| 76 | // network already exists, this will fail and populate |error|. On success |
| 77 | // populates the |network_guid| of the new network. |
| 78 | virtual void CreateNetwork(bool shared, |
| 79 | scoped_ptr<base::DictionaryValue> properties, |
| 80 | std::string* network_guid, |
| 81 | std::string* error) = 0; |
| 82 | |
[email protected] | a57ffbd5 | 2013-11-27 01:06:47 | [diff] [blame] | 83 | // Get list of visible networks of |network_type| (one of onc::network_type). |
| 84 | // Populates |network_list| on success. |
| 85 | virtual void GetVisibleNetworks(const std::string& network_type, |
[email protected] | ca11059e | 2014-06-04 08:41:22 | [diff] [blame^] | 86 | base::ListValue* network_list, |
| 87 | bool include_details) = 0; |
[email protected] | 1b6888ad | 2013-11-22 12:44:41 | [diff] [blame] | 88 | |
| 89 | // Request network scan. Send |NetworkListChanged| event on completion. |
| 90 | virtual void RequestNetworkScan() = 0; |
| 91 | |
| 92 | // Start connect to network identified by |network_guid|. Populates |error| |
| 93 | // on failure. |
| 94 | virtual void StartConnect(const std::string& network_guid, |
| 95 | std::string* error) = 0; |
| 96 | |
| 97 | // Start disconnect from network identified by |network_guid|. Populates |
| 98 | // |error| on failure. |
| 99 | virtual void StartDisconnect(const std::string& network_guid, |
| 100 | std::string* error) = 0; |
| 101 | |
[email protected] | c552755 | 2014-02-13 21:37:32 | [diff] [blame] | 102 | // Get WiFi Key for network identified by |network_guid| from the |
| 103 | // system (if it has one) and store it in |key_data|. User privilege elevation |
| 104 | // may be required, and function will fail if user privileges are not |
| 105 | // sufficient. Populates |error| on failure. |
| 106 | virtual void GetKeyFromSystem(const std::string& network_guid, |
| 107 | std::string* key_data, |
| 108 | std::string* error) = 0; |
| 109 | |
[email protected] | 1b6888ad | 2013-11-22 12:44:41 | [diff] [blame] | 110 | // Set observers to run when |NetworksChanged| and |NetworksListChanged| |
| 111 | // events needs to be sent. Notifications are posted on |message_loop_proxy|. |
| 112 | virtual void SetEventObservers( |
| 113 | scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
| 114 | const NetworkGuidListCallback& networks_changed_observer, |
| 115 | const NetworkGuidListCallback& network_list_changed_observer) = 0; |
| 116 | |
[email protected] | 333db22 | 2014-01-29 07:34:37 | [diff] [blame] | 117 | // Request update of Connected Network information. Send |NetworksChanged| |
| 118 | // event on completion. |
| 119 | virtual void RequestConnectedNetworkUpdate() = 0; |
| 120 | |
[email protected] | 1b6888ad | 2013-11-22 12:44:41 | [diff] [blame] | 121 | protected: |
| 122 | WiFiService() {} |
| 123 | |
[email protected] | 85445f7 | 2014-05-06 14:45:26 | [diff] [blame] | 124 | // Error constants. |
| 125 | static const char kErrorAssociateToNetwork[]; |
| 126 | static const char kErrorInvalidData[]; |
| 127 | static const char kErrorNotConfigured[]; |
| 128 | static const char kErrorNotConnected[]; |
| 129 | static const char kErrorNotFound[]; |
| 130 | static const char kErrorNotImplemented[]; |
| 131 | static const char kErrorScanForNetworksWithName[]; |
| 132 | static const char kErrorWiFiService[]; |
| 133 | |
[email protected] | 1b6888ad | 2013-11-22 12:44:41 | [diff] [blame] | 134 | private: |
| 135 | DISALLOW_COPY_AND_ASSIGN(WiFiService); |
| 136 | }; |
| 137 | |
| 138 | } // namespace wifi |
| 139 | |
| 140 | #endif // CHROME_UTILITY_WIFI_WIFI_SERVICE_H_ |