[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> |
| 9 | #include <string> |
| 10 | #include <vector> |
| 11 | |
| 12 | #include "base/callback.h" |
| 13 | #include "base/memory/ref_counted.h" |
| 14 | #include "base/message_loop/message_loop_proxy.h" |
[email protected] | 4f9264c | 2013-11-22 20:25:54 | [diff] [blame^] | 15 | #include "base/threading/sequenced_worker_pool.h" |
[email protected] | 1b6888ad | 2013-11-22 12:44:41 | [diff] [blame] | 16 | #include "base/values.h" |
| 17 | #include "components/wifi/wifi_export.h" |
| 18 | |
| 19 | namespace wifi { |
| 20 | |
| 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. |
| 25 | class WIFI_EXPORT WiFiService { |
| 26 | public: |
| 27 | typedef std::vector<std::string> NetworkGuidList; |
| 28 | typedef base::Callback< |
| 29 | void(const NetworkGuidList& network_guid_list)> NetworkGuidListCallback; |
| 30 | |
| 31 | virtual ~WiFiService() {} |
| 32 | |
[email protected] | 4f9264c | 2013-11-22 20:25:54 | [diff] [blame^] | 33 | // Initialize WiFiService, store |task_runner| for posting worker tasks. |
| 34 | virtual void Initialize( |
| 35 | scoped_refptr<base::SequencedTaskRunner> task_runner) = 0; |
| 36 | |
| 37 | // UnInitialize WiFiService. |
| 38 | virtual void UnInitialize() = 0; |
| 39 | |
[email protected] | 1b6888ad | 2013-11-22 12:44:41 | [diff] [blame] | 40 | // Create instance of |WiFiService| for normal use. |
| 41 | static WiFiService* Create(); |
| 42 | // Create instance of |WiFiService| for unit test use. |
| 43 | static WiFiService* CreateForTest(); |
| 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, |
| 48 | DictionaryValue* properties, |
| 49 | std::string* error) = 0; |
| 50 | |
| 51 | // Set Properties of network identified by |network_guid|. Populates |error| |
| 52 | // on failure. |
| 53 | virtual void SetProperties(const std::string& network_guid, |
| 54 | scoped_ptr<base::DictionaryValue> properties, |
| 55 | std::string* error) = 0; |
| 56 | |
| 57 | // Get list of visible networks. Populates |network_list| on success. |
| 58 | virtual void GetVisibleNetworks(ListValue* network_list) = 0; |
| 59 | |
| 60 | // Request network scan. Send |NetworkListChanged| event on completion. |
| 61 | virtual void RequestNetworkScan() = 0; |
| 62 | |
| 63 | // Start connect to network identified by |network_guid|. Populates |error| |
| 64 | // on failure. |
| 65 | virtual void StartConnect(const std::string& network_guid, |
| 66 | std::string* error) = 0; |
| 67 | |
| 68 | // Start disconnect from network identified by |network_guid|. Populates |
| 69 | // |error| on failure. |
| 70 | virtual void StartDisconnect(const std::string& network_guid, |
| 71 | std::string* error) = 0; |
| 72 | |
| 73 | // Set observers to run when |NetworksChanged| and |NetworksListChanged| |
| 74 | // events needs to be sent. Notifications are posted on |message_loop_proxy|. |
| 75 | virtual void SetEventObservers( |
| 76 | scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
| 77 | const NetworkGuidListCallback& networks_changed_observer, |
| 78 | const NetworkGuidListCallback& network_list_changed_observer) = 0; |
| 79 | |
| 80 | protected: |
| 81 | WiFiService() {} |
| 82 | |
| 83 | typedef int32 Frequency; |
| 84 | enum FrequencyEnum { |
[email protected] | 4f9264c | 2013-11-22 20:25:54 | [diff] [blame^] | 85 | kFrequencyAny = 0, |
[email protected] | 1b6888ad | 2013-11-22 12:44:41 | [diff] [blame] | 86 | kFrequencyUnknown = 0, |
| 87 | kFrequency2400 = 2400, |
| 88 | kFrequency5000 = 5000 |
| 89 | }; |
| 90 | |
| 91 | typedef std::list<Frequency> FrequencyList; |
| 92 | // Network Properties, used as result of |GetProperties| and |
| 93 | // |GetVisibleNetworks|. |
| 94 | struct WIFI_EXPORT NetworkProperties { |
| 95 | NetworkProperties(); |
| 96 | ~NetworkProperties(); |
| 97 | |
| 98 | std::string connection_state; |
| 99 | std::string guid; |
| 100 | std::string name; |
| 101 | std::string ssid; |
| 102 | std::string bssid; |
| 103 | std::string type; |
| 104 | std::string security; |
| 105 | // WiFi Signal Strength. 0..100 |
| 106 | uint32 signal_strength; |
| 107 | bool auto_connect; |
| 108 | Frequency frequency; |
| 109 | FrequencyList frequency_list; |
| 110 | |
| 111 | std::string json_extra; // Extra JSON properties for unit tests |
| 112 | |
| 113 | scoped_ptr<base::DictionaryValue> ToValue(bool network_list) const; |
| 114 | bool UpdateFromValue(const base::DictionaryValue& value); |
| 115 | static std::string MacAddressAsString(const uint8 mac_as_int[6]); |
| 116 | static bool OrderByType(const NetworkProperties& l, |
| 117 | const NetworkProperties& r); |
| 118 | }; |
| 119 | |
| 120 | typedef std::list<NetworkProperties> NetworkList; |
| 121 | |
| 122 | private: |
| 123 | DISALLOW_COPY_AND_ASSIGN(WiFiService); |
| 124 | }; |
| 125 | |
| 126 | } // namespace wifi |
| 127 | |
| 128 | #endif // CHROME_UTILITY_WIFI_WIFI_SERVICE_H_ |