OLD | NEW |
(Empty) | |
| 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 |
| 11 #include "base/callback.h" |
| 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/values.h" |
| 14 |
| 15 // WiFiService interface used by implementation of chrome.networkingPrivate |
| 16 // JavaScript extension API. |
| 17 class WiFiService { |
| 18 public: |
| 19 enum ConnectionState { |
| 20 kConnectionStateConnected, |
| 21 kConnectionStateNotConnected |
| 22 }; |
| 23 |
| 24 enum NetworkType { |
| 25 kNetworkTypeAll, |
| 26 kNetworkTypeNone, |
| 27 kNetworkTypeEthernet, |
| 28 kNetworkTypeWiFi, |
| 29 kNetworkTypeVPN, |
| 30 kNetworkTypeCellular |
| 31 }; |
| 32 |
| 33 typedef int32 Frequency; |
| 34 enum FrequencyEnum { |
| 35 kFrequencyUnknown = 0, |
| 36 kFrequency2400 = 2400, |
| 37 kFrequency5000 = 5000 |
| 38 }; |
| 39 |
| 40 typedef std::list<Frequency> FrequencyList; |
| 41 |
| 42 enum Security { |
| 43 kSecurityNone, |
| 44 kSecurityUnknown, |
| 45 kSecurityWPA, |
| 46 kSecurityWPA_PSK, |
| 47 kSecurityWEP_PSK |
| 48 }; |
| 49 |
| 50 // Network Properties, used as result of |GetProperties| and |
| 51 // |GetVisibleNetworks|. |
| 52 // TODO(mef): Replace with |DictionaryValue| once onc_constants are moved into |
| 53 // src/components. |
| 54 struct NetworkProperties { |
| 55 NetworkProperties(); |
| 56 ~NetworkProperties(); |
| 57 |
| 58 ConnectionState connection_state; |
| 59 std::string guid; |
| 60 std::string name; |
| 61 std::string ssid; |
| 62 std::string bssid; |
| 63 NetworkType type; |
| 64 Frequency frequency; |
| 65 Security security; |
| 66 // WiFi Signal Strength. 0..100 |
| 67 int32 signal_strength; |
| 68 bool auto_connect; |
| 69 FrequencyList frequency_list; |
| 70 |
| 71 std::string json_extra; // Extra JSON properties for unit tests |
| 72 |
| 73 scoped_ptr<base::DictionaryValue> ToValue(bool network_list) const; |
| 74 bool UpdateFromValue(const base::DictionaryValue& value); |
| 75 static std::string MacAddressAsString(const uint8 mac_as_int[6]); |
| 76 static bool OrderByType(const NetworkProperties& l, |
| 77 const NetworkProperties& r); |
| 78 }; |
| 79 |
| 80 typedef std::list<NetworkProperties> NetworkList; |
| 81 typedef std::list<std::string> NetworkGuidList; |
| 82 |
| 83 // An error callback used by both the configuration handler and the state |
| 84 // handler to receive error results from the API. |
| 85 typedef base::Callback<void(const std::string& error_name, |
| 86 scoped_ptr<base::DictionaryValue> error_data)> |
| 87 ErrorCallback; |
| 88 |
| 89 typedef base::Callback<void(const std::string& network_guid, |
| 90 const base::DictionaryValue& dictionary)> |
| 91 DictionaryResultCallback; |
| 92 |
| 93 typedef base::Callback<void(const std::string& network_guid, |
| 94 const NetworkProperties& properties)> |
| 95 NetworkPropertiesCallback; |
| 96 |
| 97 typedef base::Callback<void(const NetworkList& network_list)> |
| 98 NetworkListCallback; |
| 99 |
| 100 typedef base::Callback<void(const std::string& service_path)> |
| 101 StringResultCallback; |
| 102 |
| 103 typedef base::Callback<void(const NetworkGuidList& network_guid_list)> |
| 104 NetworkGuidListCallback; |
| 105 |
| 106 virtual ~WiFiService() {} |
| 107 |
| 108 // Get Properties of network identified by |network_guid|. Run |callback| on |
| 109 // success, |error_callback| on failure. |
| 110 virtual void GetProperties(const std::string& network_guid, |
| 111 const NetworkPropertiesCallback& callback, |
| 112 const ErrorCallback& error_callback) = 0; |
| 113 |
| 114 // Get State of network identified by |network_guid|. Run |callback| on |
| 115 // success, |error_callback| on failure. Not implemented except unit tests. |
| 116 virtual void GetState(const std::string& network_guid, |
| 117 const NetworkPropertiesCallback& callback, |
| 118 const ErrorCallback& error_callback) = 0; |
| 119 |
| 120 // Get Managed Properties of network identified by |network_guid|. |
| 121 // Run |callback| on success, |error_callback| on failure. Not implemented |
| 122 // except unit tests. |
| 123 virtual void GetManagedProperties(const std::string& network_guid, |
| 124 const DictionaryResultCallback& callback, |
| 125 const ErrorCallback& error_callback) = 0; |
| 126 |
| 127 // Set Properties of network identified by |network_guid|. Run |callback| on |
| 128 // success, |error_callback| on failure. Not implemented except unit tests. |
| 129 virtual void SetProperties(const std::string& network_guid, |
| 130 const base::DictionaryValue& properties, |
| 131 const StringResultCallback& callback, |
| 132 const ErrorCallback& error_callback) = 0; |
| 133 |
| 134 // Get list of visible networks. Run |callback| on success, |error_callback| |
| 135 // on failure. |
| 136 virtual void GetVisibleNetworks(const NetworkListCallback& callback, |
| 137 const ErrorCallback& error_callback) = 0; |
| 138 |
| 139 // Request network scan. Send |NetworkListChanged| event on completion. |
| 140 virtual void RequestNetworkScan() = 0; |
| 141 |
| 142 // Start connect to network identified by |network_guid|. Run |callback| on |
| 143 // success, |error_callback| on failure. Send |NetworksChanged| event |
| 144 // on completion. |
| 145 virtual void StartConnect(const std::string& network_guid, |
| 146 const StringResultCallback& callback, |
| 147 const ErrorCallback& error_callback) = 0; |
| 148 |
| 149 // Start disconnect from network identified by |network_guid|. Run |callback| |
| 150 // on success, |error_callback| on failure. Send |NetworksChanged| event on |
| 151 // completion. |
| 152 virtual void StartDisconnect(const std::string& network_guid, |
| 153 const StringResultCallback& callback, |
| 154 const ErrorCallback& error_callback) = 0; |
| 155 |
| 156 // Set |observer| to run when |NetworksChanged| event needs to be sent. |
| 157 virtual void SetNetworksChangedObserver( |
| 158 const NetworkGuidListCallback& observer) = 0; |
| 159 |
| 160 // Set |observer| to run when |NetworkListChanged| event needs to be sent. |
| 161 virtual void SetNetworkListChangedObserver( |
| 162 const NetworkGuidListCallback& observer) = 0; |
| 163 |
| 164 // Create instance of |WiFiService| for normal use. Creates mock service on |
| 165 // non-Windows system. |
| 166 static WiFiService* CreateService(); |
| 167 // Create instance of |WiFiService| for unit test use. |
| 168 static WiFiService* CreateServiceMock(); |
| 169 |
| 170 protected: |
| 171 WiFiService() {} |
| 172 |
| 173 private: |
| 174 DISALLOW_COPY_AND_ASSIGN(WiFiService); |
| 175 }; |
| 176 |
| 177 #endif // CHROME_UTILITY_WIFI_WIFI_SERVICE_H_ |
OLD | NEW |