blob: 49f8af454df351dee1f53908aa57c652a63b34c1 [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,
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
[email protected]a57ffbd52013-11-27 01:06:4757 // Get list of visible networks of |network_type| (one of onc::network_type).
58 // Populates |network_list| on success.
59 virtual void GetVisibleNetworks(const std::string& network_type,
60 ListValue* network_list) = 0;
[email protected]1b6888ad2013-11-22 12:44:4161
62 // Request network scan. Send |NetworkListChanged| event on completion.
63 virtual void RequestNetworkScan() = 0;
64
65 // Start connect to network identified by |network_guid|. Populates |error|
66 // on failure.
67 virtual void StartConnect(const std::string& network_guid,
68 std::string* error) = 0;
69
70 // Start disconnect from network identified by |network_guid|. Populates
71 // |error| on failure.
72 virtual void StartDisconnect(const std::string& network_guid,
73 std::string* error) = 0;
74
75 // Set observers to run when |NetworksChanged| and |NetworksListChanged|
76 // events needs to be sent. Notifications are posted on |message_loop_proxy|.
77 virtual void SetEventObservers(
78 scoped_refptr<base::MessageLoopProxy> message_loop_proxy,
79 const NetworkGuidListCallback& networks_changed_observer,
80 const NetworkGuidListCallback& network_list_changed_observer) = 0;
81
82 protected:
83 WiFiService() {}
84
85 typedef int32 Frequency;
86 enum FrequencyEnum {
[email protected]4f9264c2013-11-22 20:25:5487 kFrequencyAny = 0,
[email protected]1b6888ad2013-11-22 12:44:4188 kFrequencyUnknown = 0,
89 kFrequency2400 = 2400,
90 kFrequency5000 = 5000
91 };
92
93 typedef std::list<Frequency> FrequencyList;
94 // Network Properties, used as result of |GetProperties| and
95 // |GetVisibleNetworks|.
96 struct WIFI_EXPORT NetworkProperties {
97 NetworkProperties();
98 ~NetworkProperties();
99
100 std::string connection_state;
101 std::string guid;
102 std::string name;
103 std::string ssid;
104 std::string bssid;
105 std::string type;
106 std::string security;
107 // WiFi Signal Strength. 0..100
108 uint32 signal_strength;
109 bool auto_connect;
110 Frequency frequency;
111 FrequencyList frequency_list;
112
113 std::string json_extra; // Extra JSON properties for unit tests
114
115 scoped_ptr<base::DictionaryValue> ToValue(bool network_list) const;
116 bool UpdateFromValue(const base::DictionaryValue& value);
117 static std::string MacAddressAsString(const uint8 mac_as_int[6]);
118 static bool OrderByType(const NetworkProperties& l,
119 const NetworkProperties& r);
120 };
121
122 typedef std::list<NetworkProperties> NetworkList;
123
124 private:
125 DISALLOW_COPY_AND_ASSIGN(WiFiService);
126};
127
128} // namespace wifi
129
130#endif // CHROME_UTILITY_WIFI_WIFI_SERVICE_H_