• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <set>
10 #include <string>
11 #include <vector>
12 
13 #include "base/callback.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/message_loop/message_loop_proxy.h"
16 #include "base/threading/sequenced_worker_pool.h"
17 #include "base/values.h"
18 #include "components/wifi/wifi_export.h"
19 
20 namespace wifi {
21 
22 // WiFiService interface used by implementation of chrome.networkingPrivate
23 // JavaScript extension API. All methods should be called on worker thread.
24 // It could be created on any (including UI) thread, so nothing expensive should
25 // be done in the constructor. See |NetworkingPrivateService| for wrapper
26 // accessible on UI thread.
27 class WIFI_EXPORT WiFiService {
28  public:
29   typedef std::vector<std::string> NetworkGuidList;
30   typedef base::Callback<
31       void(const NetworkGuidList& network_guid_list)> NetworkGuidListCallback;
32 
~WiFiService()33   virtual ~WiFiService() {}
34 
35   // Initialize WiFiService, store |task_runner| for posting worker tasks.
36   virtual void Initialize(
37       scoped_refptr<base::SequencedTaskRunner> task_runner) = 0;
38 
39   // UnInitialize WiFiService.
40   virtual void UnInitialize() = 0;
41 
42   // Create instance of |WiFiService| for normal use.
43   static WiFiService* Create();
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                              base::DictionaryValue* properties,
49                              std::string* error) = 0;
50 
51   // 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,
56                                     base::DictionaryValue* managed_properties,
57                                     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,
65                         base::DictionaryValue* properties,
66                         std::string* error) = 0;
67 
68   // 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 
74   // 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 
83   // 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,
86                                   base::ListValue* network_list,
87                                   bool include_details) = 0;
88 
89   // Request network scan. Send |NetworkListChanged| event on completion.
90   virtual void RequestNetworkScan() = 0;
91 
92   // Start connect to network identified by |network_guid|. Populates |error|
93   // on failure.
94   virtual void StartConnect(const std::string& network_guid,
95                             std::string* error) = 0;
96 
97   // Start disconnect from network identified by |network_guid|. Populates
98   // |error| on failure.
99   virtual void StartDisconnect(const std::string& network_guid,
100                                std::string* error) = 0;
101 
102   // Get WiFi Key for network identified by |network_guid| from the
103   // system (if it has one) and store it in |key_data|. User privilege elevation
104   // may be required, and function will fail if user privileges are not
105   // sufficient. Populates |error| on failure.
106   virtual void GetKeyFromSystem(const std::string& network_guid,
107                                 std::string* key_data,
108                                 std::string* error) = 0;
109 
110   // Set observers to run when |NetworksChanged| and |NetworksListChanged|
111   // events needs to be sent. Notifications are posted on |message_loop_proxy|.
112   virtual void SetEventObservers(
113       scoped_refptr<base::MessageLoopProxy> message_loop_proxy,
114       const NetworkGuidListCallback& networks_changed_observer,
115       const NetworkGuidListCallback& network_list_changed_observer) = 0;
116 
117   // Request update of Connected Network information. Send |NetworksChanged|
118   // event on completion.
119   virtual void RequestConnectedNetworkUpdate() = 0;
120 
121  protected:
WiFiService()122   WiFiService() {}
123 
124   // Error constants.
125   static const char kErrorAssociateToNetwork[];
126   static const char kErrorInvalidData[];
127   static const char kErrorNotConfigured[];
128   static const char kErrorNotConnected[];
129   static const char kErrorNotFound[];
130   static const char kErrorNotImplemented[];
131   static const char kErrorScanForNetworksWithName[];
132   static const char kErrorWiFiService[];
133 
134  private:
135   DISALLOW_COPY_AND_ASSIGN(WiFiService);
136 };
137 
138 }  // namespace wifi
139 
140 #endif  // CHROME_UTILITY_WIFI_WIFI_SERVICE_H_
141