blob: b45ebfdeb1386feec4ac5d3a20824b74529a85ff [file] [log] [blame]
[email protected]1b6888ad2013-11-22 12:44:411// 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]4f9264c2013-11-22 20:25:5415#include "base/threading/sequenced_worker_pool.h"
[email protected]1b6888ad2013-11-22 12:44:4116#include "base/values.h"
17#include "components/wifi/wifi_export.h"
18
19namespace 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.
25class 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]4f9264c2013-11-22 20:25:5433 // 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]1b6888ad2013-11-22 12:44:4140 // 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,
[email protected]85ecd7e2013-12-23 21:58:4548 base::DictionaryValue* properties,
[email protected]1b6888ad2013-11-22 12:44:4149 std::string* error) = 0;
50
[email protected]4adfc3b2013-12-05 00:50:3751 // 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]85ecd7e2013-12-23 21:58:4556 base::DictionaryValue* managed_properties,
[email protected]4adfc3b2013-12-05 00:50:3757 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]85ecd7e2013-12-23 21:58:4565 base::DictionaryValue* properties,
[email protected]4adfc3b2013-12-05 00:50:3766 std::string* error) = 0;
67
[email protected]1b6888ad2013-11-22 12:44:4168 // 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]4adfc3b2013-12-05 00:50:3774 // 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]a57ffbd52013-11-27 01:06:4783 // 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]85ecd7e2013-12-23 21:58:4586 base::ListValue* network_list) = 0;
[email protected]1b6888ad2013-11-22 12:44:4187
88 // Request network scan. Send |NetworkListChanged| event on completion.
89 virtual void RequestNetworkScan() = 0;
90
91 // Start connect to network identified by |network_guid|. Populates |error|
92 // on failure.
93 virtual void StartConnect(const std::string& network_guid,
94 std::string* error) = 0;
95
96 // Start disconnect from network identified by |network_guid|. Populates
97 // |error| on failure.
98 virtual void StartDisconnect(const std::string& network_guid,
99 std::string* error) = 0;
100
101 // Set observers to run when |NetworksChanged| and |NetworksListChanged|
102 // events needs to be sent. Notifications are posted on |message_loop_proxy|.
103 virtual void SetEventObservers(
104 scoped_refptr<base::MessageLoopProxy> message_loop_proxy,
105 const NetworkGuidListCallback& networks_changed_observer,
106 const NetworkGuidListCallback& network_list_changed_observer) = 0;
107
108 protected:
109 WiFiService() {}
110
111 typedef int32 Frequency;
112 enum FrequencyEnum {
[email protected]4f9264c2013-11-22 20:25:54113 kFrequencyAny = 0,
[email protected]1b6888ad2013-11-22 12:44:41114 kFrequencyUnknown = 0,
115 kFrequency2400 = 2400,
116 kFrequency5000 = 5000
117 };
118
119 typedef std::list<Frequency> FrequencyList;
120 // Network Properties, used as result of |GetProperties| and
121 // |GetVisibleNetworks|.
122 struct WIFI_EXPORT NetworkProperties {
123 NetworkProperties();
124 ~NetworkProperties();
125
126 std::string connection_state;
127 std::string guid;
128 std::string name;
129 std::string ssid;
130 std::string bssid;
131 std::string type;
132 std::string security;
[email protected]e425d0362013-12-13 18:25:17133 // |password| field is used to pass wifi password for network creation via
134 // |CreateNetwork| or connection via |StartConnect|. It does not persist
135 // once operation is completed.
136 std::string password;
[email protected]1b6888ad2013-11-22 12:44:41137 // WiFi Signal Strength. 0..100
138 uint32 signal_strength;
139 bool auto_connect;
140 Frequency frequency;
141 FrequencyList frequency_list;
142
143 std::string json_extra; // Extra JSON properties for unit tests
144
145 scoped_ptr<base::DictionaryValue> ToValue(bool network_list) const;
[email protected]e425d0362013-12-13 18:25:17146 // Updates only properties set in |value|.
[email protected]1b6888ad2013-11-22 12:44:41147 bool UpdateFromValue(const base::DictionaryValue& value);
148 static std::string MacAddressAsString(const uint8 mac_as_int[6]);
149 static bool OrderByType(const NetworkProperties& l,
150 const NetworkProperties& r);
151 };
152
153 typedef std::list<NetworkProperties> NetworkList;
154
155 private:
156 DISALLOW_COPY_AND_ASSIGN(WiFiService);
157};
158
159} // namespace wifi
160
161#endif // CHROME_UTILITY_WIFI_WIFI_SERVICE_H_