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