Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / extensions / browser / api / networking_private / networking_private_delegate.h
blobc08ff651a9576ff7aad9432613a0bfdedc75d94c
1 // Copyright 2014 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_DELEGATE_H_
6 #define EXTENSIONS_BROWSER_API_NETWORKING_PRIVATE_NETWORKING_PRIVATE_DELEGATE_H_
8 #include <string>
9 #include <vector>
11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/scoped_vector.h"
14 #include "base/values.h"
15 #include "components/keyed_service/core/keyed_service.h"
16 #include "extensions/common/api/networking_private.h"
18 namespace content {
19 class BrowserContext;
22 namespace extensions {
24 class NetworkingPrivateDelegateObserver;
26 namespace api {
27 namespace networking_private {
28 struct DeviceStateProperties;
29 struct VerificationProperties;
30 } // networking_private
31 } // api
33 // Base class for platform dependent networkingPrivate API implementations.
34 // All inputs and results for this class use ONC values. See
35 // networking_private.idl for descriptions of the expected inputs and results.
36 class NetworkingPrivateDelegate : public KeyedService {
37 public:
38 using DictionaryCallback =
39 base::Callback<void(scoped_ptr<base::DictionaryValue>)>;
40 using VoidCallback = base::Callback<void()>;
41 using BoolCallback = base::Callback<void(bool)>;
42 using StringCallback = base::Callback<void(const std::string&)>;
43 using NetworkListCallback = base::Callback<void(scoped_ptr<base::ListValue>)>;
44 using FailureCallback = base::Callback<void(const std::string&)>;
45 using DeviceStateList =
46 ScopedVector<api::networking_private::DeviceStateProperties>;
47 using VerificationProperties =
48 api::networking_private::VerificationProperties;
50 // The Verify* methods will be forwarded to a delegate implementation if
51 // provided, otherwise they will fail. A separate delegate it used so that the
52 // current Verify* implementations are not exposed outside of src/chrome.
53 class VerifyDelegate {
54 public:
55 typedef NetworkingPrivateDelegate::VerificationProperties
56 VerificationProperties;
57 typedef NetworkingPrivateDelegate::BoolCallback BoolCallback;
58 typedef NetworkingPrivateDelegate::StringCallback StringCallback;
59 typedef NetworkingPrivateDelegate::FailureCallback FailureCallback;
61 VerifyDelegate();
62 virtual ~VerifyDelegate();
64 virtual void VerifyDestination(
65 const VerificationProperties& verification_properties,
66 const BoolCallback& success_callback,
67 const FailureCallback& failure_callback) = 0;
68 virtual void VerifyAndEncryptCredentials(
69 const std::string& guid,
70 const VerificationProperties& verification_properties,
71 const StringCallback& success_callback,
72 const FailureCallback& failure_callback) = 0;
73 virtual void VerifyAndEncryptData(
74 const VerificationProperties& verification_properties,
75 const std::string& data,
76 const StringCallback& success_callback,
77 const FailureCallback& failure_callback) = 0;
79 private:
80 DISALLOW_COPY_AND_ASSIGN(VerifyDelegate);
83 // Delegate for forwarding UI requests, e.g. for showing the account UI.
84 class UIDelegate {
85 public:
86 UIDelegate();
87 virtual ~UIDelegate();
89 // Navigate to the acoount details page for the cellular network associated
90 // with |guid|.
91 virtual void ShowAccountDetails(const std::string& guid) const = 0;
93 // Possibly handle a connection failure, e.g. by showing the configuration
94 // UI. Returns true if the error was handled, i.e. the UI was shown.
95 virtual bool HandleConnectFailed(const std::string& guid,
96 const std::string error) const = 0;
98 private:
99 DISALLOW_COPY_AND_ASSIGN(UIDelegate);
102 // If |verify_delegate| is not NULL, the Verify* methods will be forwarded
103 // to the delegate. Otherwise they will fail with a NotSupported error.
104 explicit NetworkingPrivateDelegate(
105 scoped_ptr<VerifyDelegate> verify_delegate);
106 ~NetworkingPrivateDelegate() override;
108 void set_ui_delegate(scoped_ptr<UIDelegate> ui_delegate) {
109 ui_delegate_.reset(ui_delegate.release());
112 const UIDelegate* ui_delegate() { return ui_delegate_.get(); }
114 // Asynchronous methods
115 virtual void GetProperties(const std::string& guid,
116 const DictionaryCallback& success_callback,
117 const FailureCallback& failure_callback) = 0;
118 virtual void GetManagedProperties(
119 const std::string& guid,
120 const DictionaryCallback& success_callback,
121 const FailureCallback& failure_callback) = 0;
122 virtual void GetState(const std::string& guid,
123 const DictionaryCallback& success_callback,
124 const FailureCallback& failure_callback) = 0;
125 virtual void SetProperties(const std::string& guid,
126 scoped_ptr<base::DictionaryValue> properties,
127 const VoidCallback& success_callback,
128 const FailureCallback& failure_callback) = 0;
129 virtual void CreateNetwork(bool shared,
130 scoped_ptr<base::DictionaryValue> properties,
131 const StringCallback& success_callback,
132 const FailureCallback& failure_callback) = 0;
133 virtual void ForgetNetwork(const std::string& guid,
134 const VoidCallback& success_callback,
135 const FailureCallback& failure_callback) = 0;
136 virtual void GetNetworks(const std::string& network_type,
137 bool configured_only,
138 bool visible_only,
139 int limit,
140 const NetworkListCallback& success_callback,
141 const FailureCallback& failure_callback) = 0;
142 virtual void StartConnect(const std::string& guid,
143 const VoidCallback& success_callback,
144 const FailureCallback& failure_callback) = 0;
145 virtual void StartDisconnect(const std::string& guid,
146 const VoidCallback& success_callback,
147 const FailureCallback& failure_callback) = 0;
148 virtual void StartActivate(const std::string& guid,
149 const std::string& carrier,
150 const VoidCallback& success_callback,
151 const FailureCallback& failure_callback);
152 virtual void SetWifiTDLSEnabledState(
153 const std::string& ip_or_mac_address,
154 bool enabled,
155 const StringCallback& success_callback,
156 const FailureCallback& failure_callback) = 0;
157 virtual void GetWifiTDLSStatus(const std::string& ip_or_mac_address,
158 const StringCallback& success_callback,
159 const FailureCallback& failure_callback) = 0;
160 virtual void GetCaptivePortalStatus(
161 const std::string& guid,
162 const StringCallback& success_callback,
163 const FailureCallback& failure_callback) = 0;
164 virtual void UnlockCellularSim(const std::string& guid,
165 const std::string& pin,
166 const std::string& puk,
167 const VoidCallback& success_callback,
168 const FailureCallback& failure_callback) = 0;
170 virtual void SetCellularSimState(const std::string& guid,
171 bool require_pin,
172 const std::string& current_pin,
173 const std::string& new_pin,
174 const VoidCallback& success_callback,
175 const FailureCallback& failure_callback) = 0;
177 // Synchronous methods
179 // Returns a list of ONC type strings.
180 virtual scoped_ptr<base::ListValue> GetEnabledNetworkTypes() = 0;
182 // Returns a list of DeviceStateProperties.
183 virtual scoped_ptr<DeviceStateList> GetDeviceStateList() = 0;
185 // Returns true if the ONC network type |type| is enabled.
186 virtual bool EnableNetworkType(const std::string& type) = 0;
188 // Returns true if the ONC network type |type| is disabled.
189 virtual bool DisableNetworkType(const std::string& type) = 0;
191 // Returns true if a scan was requested. It may take many seconds for a scan
192 // to complete. The scan may or may not trigger API events when complete.
193 virtual bool RequestScan() = 0;
195 // Optional methods for adding a NetworkingPrivateDelegateObserver for
196 // implementations that require it (non-chromeos).
197 virtual void AddObserver(NetworkingPrivateDelegateObserver* observer);
198 virtual void RemoveObserver(NetworkingPrivateDelegateObserver* observer);
200 // Verify* methods are forwarded to |verify_delegate_| if not NULL.
201 void VerifyDestination(const VerificationProperties& verification_properties,
202 const BoolCallback& success_callback,
203 const FailureCallback& failure_callback);
204 void VerifyAndEncryptCredentials(
205 const std::string& guid,
206 const VerificationProperties& verification_properties,
207 const StringCallback& success_callback,
208 const FailureCallback& failure_callback);
209 void VerifyAndEncryptData(
210 const VerificationProperties& verification_properties,
211 const std::string& data,
212 const StringCallback& success_callback,
213 const FailureCallback& failure_callback);
215 private:
216 // Interface for Verify* methods. May be null.
217 scoped_ptr<VerifyDelegate> verify_delegate_;
219 // Interface for UI methods. May be null.
220 scoped_ptr<UIDelegate> ui_delegate_;
222 DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateDelegate);
225 } // namespace extensions
227 #endif // EXTENSIONS_BROWSER_API_NETWORKING_PRIVATE_NETWORKING_PRIVATE_DELEGATE_H_