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_
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 extensions
{
20 class NetworkingPrivateDelegateObserver
;
23 namespace networking_private
{
24 struct DeviceStateProperties
;
25 struct VerificationProperties
;
26 } // networking_private
29 // Base class for platform dependent networkingPrivate API implementations.
30 // All inputs and results for this class use ONC values. See
31 // networking_private.idl for descriptions of the expected inputs and results.
32 class NetworkingPrivateDelegate
: public KeyedService
{
34 using DictionaryCallback
=
35 base::Callback
<void(scoped_ptr
<base::DictionaryValue
>)>;
36 using VoidCallback
= base::Callback
<void()>;
37 using BoolCallback
= base::Callback
<void(bool)>;
38 using StringCallback
= base::Callback
<void(const std::string
&)>;
39 using NetworkListCallback
= base::Callback
<void(scoped_ptr
<base::ListValue
>)>;
40 using FailureCallback
= base::Callback
<void(const std::string
&)>;
41 using DeviceStateList
=
42 ScopedVector
<api::networking_private::DeviceStateProperties
>;
43 using VerificationProperties
=
44 api::networking_private::VerificationProperties
;
46 // The Verify* methods will be forwarded to a delegate implementation if
47 // provided, otherwise they will fail. A separate delegate it used so that the
48 // current Verify* implementations are not exposed outside of src/chrome.
49 class VerifyDelegate
{
51 typedef NetworkingPrivateDelegate::VerificationProperties
52 VerificationProperties
;
53 typedef NetworkingPrivateDelegate::BoolCallback BoolCallback
;
54 typedef NetworkingPrivateDelegate::StringCallback StringCallback
;
55 typedef NetworkingPrivateDelegate::FailureCallback FailureCallback
;
58 virtual ~VerifyDelegate();
60 virtual void VerifyDestination(
61 const VerificationProperties
& verification_properties
,
62 const BoolCallback
& success_callback
,
63 const FailureCallback
& failure_callback
) = 0;
64 virtual void VerifyAndEncryptCredentials(
65 const std::string
& guid
,
66 const VerificationProperties
& verification_properties
,
67 const StringCallback
& success_callback
,
68 const FailureCallback
& failure_callback
) = 0;
69 virtual void VerifyAndEncryptData(
70 const VerificationProperties
& verification_properties
,
71 const std::string
& data
,
72 const StringCallback
& success_callback
,
73 const FailureCallback
& failure_callback
) = 0;
76 DISALLOW_COPY_AND_ASSIGN(VerifyDelegate
);
79 // Delegate for forwarding UI requests, e.g. for showing the account UI.
83 virtual ~UIDelegate();
85 // Navigate to the acoount details page for the cellular network associated
87 virtual void ShowAccountDetails(const std::string
& guid
) const = 0;
89 // Possibly handle a connection failure, e.g. by showing the configuration
90 // UI. Returns true if the error was handled, i.e. the UI was shown.
91 virtual bool HandleConnectFailed(const std::string
& guid
,
92 const std::string error
) const = 0;
95 DISALLOW_COPY_AND_ASSIGN(UIDelegate
);
98 // If |verify_delegate| is not NULL, the Verify* methods will be forwarded
99 // to the delegate. Otherwise they will fail with a NotSupported error.
100 explicit NetworkingPrivateDelegate(
101 scoped_ptr
<VerifyDelegate
> verify_delegate
);
102 ~NetworkingPrivateDelegate() override
;
104 void set_ui_delegate(scoped_ptr
<UIDelegate
> ui_delegate
) {
105 ui_delegate_
.reset(ui_delegate
.release());
108 const UIDelegate
* ui_delegate() { return ui_delegate_
.get(); }
110 // Asynchronous methods
111 virtual void GetProperties(const std::string
& guid
,
112 const DictionaryCallback
& success_callback
,
113 const FailureCallback
& failure_callback
) = 0;
114 virtual void GetManagedProperties(
115 const std::string
& guid
,
116 const DictionaryCallback
& success_callback
,
117 const FailureCallback
& failure_callback
) = 0;
118 virtual void GetState(const std::string
& guid
,
119 const DictionaryCallback
& success_callback
,
120 const FailureCallback
& failure_callback
) = 0;
121 virtual void SetProperties(const std::string
& guid
,
122 scoped_ptr
<base::DictionaryValue
> properties
,
123 const VoidCallback
& success_callback
,
124 const FailureCallback
& failure_callback
) = 0;
125 virtual void CreateNetwork(bool shared
,
126 scoped_ptr
<base::DictionaryValue
> properties
,
127 const StringCallback
& success_callback
,
128 const FailureCallback
& failure_callback
) = 0;
129 virtual void ForgetNetwork(const std::string
& guid
,
130 const VoidCallback
& success_callback
,
131 const FailureCallback
& failure_callback
) = 0;
132 virtual void GetNetworks(const std::string
& network_type
,
133 bool configured_only
,
136 const NetworkListCallback
& success_callback
,
137 const FailureCallback
& failure_callback
) = 0;
138 virtual void StartConnect(const std::string
& guid
,
139 const VoidCallback
& success_callback
,
140 const FailureCallback
& failure_callback
) = 0;
141 virtual void StartDisconnect(const std::string
& guid
,
142 const VoidCallback
& success_callback
,
143 const FailureCallback
& failure_callback
) = 0;
144 virtual void StartActivate(const std::string
& guid
,
145 const std::string
& carrier
,
146 const VoidCallback
& success_callback
,
147 const FailureCallback
& failure_callback
);
148 virtual void SetWifiTDLSEnabledState(
149 const std::string
& ip_or_mac_address
,
151 const StringCallback
& success_callback
,
152 const FailureCallback
& failure_callback
) = 0;
153 virtual void GetWifiTDLSStatus(const std::string
& ip_or_mac_address
,
154 const StringCallback
& success_callback
,
155 const FailureCallback
& failure_callback
) = 0;
156 virtual void GetCaptivePortalStatus(
157 const std::string
& guid
,
158 const StringCallback
& success_callback
,
159 const FailureCallback
& failure_callback
) = 0;
160 virtual void UnlockCellularSim(const std::string
& guid
,
161 const std::string
& pin
,
162 const std::string
& puk
,
163 const VoidCallback
& success_callback
,
164 const FailureCallback
& failure_callback
) = 0;
166 virtual void SetCellularSimState(const std::string
& guid
,
168 const std::string
& current_pin
,
169 const std::string
& new_pin
,
170 const VoidCallback
& success_callback
,
171 const FailureCallback
& failure_callback
) = 0;
173 // Synchronous methods
175 // Returns a list of ONC type strings.
176 virtual scoped_ptr
<base::ListValue
> GetEnabledNetworkTypes() = 0;
178 // Returns a list of DeviceStateProperties.
179 virtual scoped_ptr
<DeviceStateList
> GetDeviceStateList() = 0;
181 // Returns true if the ONC network type |type| is enabled.
182 virtual bool EnableNetworkType(const std::string
& type
) = 0;
184 // Returns true if the ONC network type |type| is disabled.
185 virtual bool DisableNetworkType(const std::string
& type
) = 0;
187 // Returns true if a scan was requested. It may take many seconds for a scan
188 // to complete. The scan may or may not trigger API events when complete.
189 virtual bool RequestScan() = 0;
191 // Optional methods for adding a NetworkingPrivateDelegateObserver for
192 // implementations that require it (non-chromeos).
193 virtual void AddObserver(NetworkingPrivateDelegateObserver
* observer
);
194 virtual void RemoveObserver(NetworkingPrivateDelegateObserver
* observer
);
196 // Verify* methods are forwarded to |verify_delegate_| if not NULL.
197 void VerifyDestination(const VerificationProperties
& verification_properties
,
198 const BoolCallback
& success_callback
,
199 const FailureCallback
& failure_callback
);
200 void VerifyAndEncryptCredentials(
201 const std::string
& guid
,
202 const VerificationProperties
& verification_properties
,
203 const StringCallback
& success_callback
,
204 const FailureCallback
& failure_callback
);
205 void VerifyAndEncryptData(
206 const VerificationProperties
& verification_properties
,
207 const std::string
& data
,
208 const StringCallback
& success_callback
,
209 const FailureCallback
& failure_callback
);
212 // Interface for Verify* methods. May be null.
213 scoped_ptr
<VerifyDelegate
> verify_delegate_
;
215 // Interface for UI methods. May be null.
216 scoped_ptr
<UIDelegate
> ui_delegate_
;
218 DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateDelegate
);
221 } // namespace extensions
223 #endif // EXTENSIONS_BROWSER_API_NETWORKING_PRIVATE_NETWORKING_PRIVATE_DELEGATE_H_