Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / extensions / browser / api / networking_private / networking_private_service_client.h
blobdfa87c02570c0ba9d1ccd65b278709b92ed8a92a
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.
5 #ifndef EXTENSIONS_BROWSER_API_NETWORKING_PRIVATE_NETWORKING_PRIVATE_SERVICE_CLIENT_H_
6 #define EXTENSIONS_BROWSER_API_NETWORKING_PRIVATE_NETWORKING_PRIVATE_SERVICE_CLIENT_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/id_map.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/observer_list.h"
16 #include "base/strings/string16.h"
17 #include "base/supports_user_data.h"
18 #include "base/threading/sequenced_worker_pool.h"
19 #include "base/values.h"
20 #include "components/keyed_service/core/keyed_service.h"
21 #include "components/wifi/wifi_service.h"
22 #include "content/public/browser/utility_process_host.h"
23 #include "content/public/browser/utility_process_host_client.h"
24 #include "extensions/browser/api/networking_private/networking_private_delegate.h"
25 #include "net/base/network_change_notifier.h"
27 namespace base {
28 class SequencedTaskRunner;
31 namespace extensions {
33 // Windows / Mac NetworkingPrivateApi implementation. This implements
34 // NetworkingPrivateDelegate, making WiFiService calls on the worker thead.
35 // It also observes |OnNetworkChanged| notifications and posts them to
36 // WiFiService on the worker thread. Created and called from the UI thread.
37 class NetworkingPrivateServiceClient
38 : public NetworkingPrivateDelegate,
39 net::NetworkChangeNotifier::NetworkChangeObserver {
40 public:
41 // Takes ownership of |wifi_service| which is accessed and deleted on the
42 // worker thread. The deletion task is posted from the destructor.
43 // |verify_delegate| is passed to NetworkingPrivateDelegate and may be NULL.
44 NetworkingPrivateServiceClient(scoped_ptr<wifi::WiFiService> wifi_service,
45 scoped_ptr<VerifyDelegate> verify_delegate);
47 // KeyedService
48 void Shutdown() override;
50 // NetworkingPrivateDelegate
51 void GetProperties(const std::string& guid,
52 const DictionaryCallback& success_callback,
53 const FailureCallback& failure_callback) override;
54 void GetManagedProperties(const std::string& guid,
55 const DictionaryCallback& success_callback,
56 const FailureCallback& failure_callback) override;
57 void GetState(const std::string& guid,
58 const DictionaryCallback& success_callback,
59 const FailureCallback& failure_callback) override;
60 void SetProperties(const std::string& guid,
61 scoped_ptr<base::DictionaryValue> properties_dict,
62 const VoidCallback& success_callback,
63 const FailureCallback& failure_callback) override;
64 void CreateNetwork(bool shared,
65 scoped_ptr<base::DictionaryValue> properties_dict,
66 const StringCallback& success_callback,
67 const FailureCallback& failure_callback) override;
68 void ForgetNetwork(const std::string& guid,
69 const VoidCallback& success_callback,
70 const FailureCallback& failure_callback) override;
71 void GetNetworks(const std::string& network_type,
72 bool configured_only,
73 bool visible_only,
74 int limit,
75 const NetworkListCallback& success_callback,
76 const FailureCallback& failure_callback) override;
77 void StartConnect(const std::string& guid,
78 const VoidCallback& success_callback,
79 const FailureCallback& failure_callback) override;
80 void StartDisconnect(const std::string& guid,
81 const VoidCallback& success_callback,
82 const FailureCallback& failure_callback) override;
83 void SetWifiTDLSEnabledState(
84 const std::string& ip_or_mac_address,
85 bool enabled,
86 const StringCallback& success_callback,
87 const FailureCallback& failure_callback) override;
88 void GetWifiTDLSStatus(const std::string& ip_or_mac_address,
89 const StringCallback& success_callback,
90 const FailureCallback& failure_callback) override;
91 void GetCaptivePortalStatus(const std::string& guid,
92 const StringCallback& success_callback,
93 const FailureCallback& failure_callback) override;
94 scoped_ptr<base::ListValue> GetEnabledNetworkTypes() override;
95 scoped_ptr<DeviceStateList> GetDeviceStateList() override;
96 bool EnableNetworkType(const std::string& type) override;
97 bool DisableNetworkType(const std::string& type) override;
98 bool RequestScan() override;
99 void AddObserver(NetworkingPrivateDelegateObserver* observer) override;
100 void RemoveObserver(NetworkingPrivateDelegateObserver* observer) override;
102 // NetworkChangeNotifier::NetworkChangeObserver implementation.
103 void OnNetworkChanged(
104 net::NetworkChangeNotifier::ConnectionType type) override;
106 private:
107 // Callbacks to extension api function objects. Keep reference to API object
108 // and are released in ShutdownOnUIThread. Run when WiFiService calls back
109 // into NetworkingPrivateServiceClient's callback wrappers.
110 typedef int32 ServiceCallbacksID;
111 struct ServiceCallbacks {
112 ServiceCallbacks();
113 ~ServiceCallbacks();
115 DictionaryCallback get_properties_callback;
116 VoidCallback start_connect_callback;
117 VoidCallback start_disconnect_callback;
118 VoidCallback set_properties_callback;
119 StringCallback create_network_callback;
120 NetworkListCallback get_visible_networks_callback;
121 FailureCallback failure_callback;
123 ServiceCallbacksID id;
125 typedef IDMap<ServiceCallbacks, IDMapOwnPointer> ServiceCallbacksMap;
127 ~NetworkingPrivateServiceClient() override;
129 // Callback wrappers.
130 void AfterGetProperties(ServiceCallbacksID callback_id,
131 const std::string& network_guid,
132 scoped_ptr<base::DictionaryValue> properties,
133 const std::string* error);
134 void AfterSetProperties(ServiceCallbacksID callback_id,
135 const std::string* error);
136 void AfterCreateNetwork(ServiceCallbacksID callback_id,
137 const std::string* network_guid,
138 const std::string* error);
139 void AfterGetVisibleNetworks(ServiceCallbacksID callback_id,
140 scoped_ptr<base::ListValue> networks);
141 void AfterStartConnect(ServiceCallbacksID callback_id,
142 const std::string* error);
143 void AfterStartDisconnect(ServiceCallbacksID callback_id,
144 const std::string* error);
146 void OnNetworksChangedEventOnUIThread(
147 const wifi::WiFiService::NetworkGuidList& network_guid_list);
148 void OnNetworkListChangedEventOnUIThread(
149 const wifi::WiFiService::NetworkGuidList& network_guid_list);
151 // Add new |ServiceCallbacks| to |callbacks_map_|.
152 ServiceCallbacks* AddServiceCallbacks();
153 // Removes ServiceCallbacks for |callback_id| from |callbacks_map_|.
154 void RemoveServiceCallbacks(ServiceCallbacksID callback_id);
156 // Callbacks to run when callback is called from WiFiService.
157 ServiceCallbacksMap callbacks_map_;
158 // Observers to Network Events.
159 ObserverList<NetworkingPrivateDelegateObserver> network_events_observers_;
160 // Interface to WiFiService. Used and deleted on the worker thread.
161 scoped_ptr<wifi::WiFiService> wifi_service_;
162 // Sequence token associated with wifi tasks.
163 base::SequencedWorkerPool::SequenceToken sequence_token_;
164 // Task runner for worker tasks.
165 scoped_refptr<base::SequencedTaskRunner> task_runner_;
166 // Use WeakPtrs for callbacks from |wifi_service_|.
167 base::WeakPtrFactory<NetworkingPrivateServiceClient> weak_factory_;
169 DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateServiceClient);
172 } // namespace extensions
174 #endif // EXTENSIONS_BROWSER_API_NETWORKING_PRIVATE_NETWORKING_PRIVATE_SERVICE_CLIENT_H_