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