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"
22 namespace extensions
{
24 class NetworkingPrivateDelegateObserver
;
27 namespace networking_private
{
28 struct DeviceStateProperties
;
29 struct VerificationProperties
;
30 } // networking_private
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
{
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
<core_api::networking_private::DeviceStateProperties
>;
47 using VerificationProperties
=
48 core_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
{
55 typedef NetworkingPrivateDelegate::VerificationProperties
56 VerificationProperties
;
57 typedef NetworkingPrivateDelegate::BoolCallback BoolCallback
;
58 typedef NetworkingPrivateDelegate::StringCallback StringCallback
;
59 typedef NetworkingPrivateDelegate::FailureCallback FailureCallback
;
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;
80 DISALLOW_COPY_AND_ASSIGN(VerifyDelegate
);
83 // If |verify_delegate| is not NULL, the Verify* methods will be forwarded
84 // to the delegate. Otherwise they will fail with a NotSupported error.
85 explicit NetworkingPrivateDelegate(
86 scoped_ptr
<VerifyDelegate
> verify_delegate
);
87 ~NetworkingPrivateDelegate() override
;
89 // Asynchronous methods
90 virtual void GetProperties(const std::string
& guid
,
91 const DictionaryCallback
& success_callback
,
92 const FailureCallback
& failure_callback
) = 0;
93 virtual void GetManagedProperties(
94 const std::string
& guid
,
95 const DictionaryCallback
& success_callback
,
96 const FailureCallback
& failure_callback
) = 0;
97 virtual void GetState(const std::string
& guid
,
98 const DictionaryCallback
& success_callback
,
99 const FailureCallback
& failure_callback
) = 0;
100 virtual void SetProperties(const std::string
& guid
,
101 scoped_ptr
<base::DictionaryValue
> properties
,
102 const VoidCallback
& success_callback
,
103 const FailureCallback
& failure_callback
) = 0;
104 virtual void CreateNetwork(bool shared
,
105 scoped_ptr
<base::DictionaryValue
> properties
,
106 const StringCallback
& success_callback
,
107 const FailureCallback
& failure_callback
) = 0;
108 virtual void ForgetNetwork(const std::string
& guid
,
109 const VoidCallback
& success_callback
,
110 const FailureCallback
& failure_callback
) = 0;
111 virtual void GetNetworks(const std::string
& network_type
,
112 bool configured_only
,
115 const NetworkListCallback
& success_callback
,
116 const FailureCallback
& failure_callback
) = 0;
117 virtual void StartConnect(const std::string
& guid
,
118 const VoidCallback
& success_callback
,
119 const FailureCallback
& failure_callback
) = 0;
120 virtual void StartDisconnect(const std::string
& guid
,
121 const VoidCallback
& success_callback
,
122 const FailureCallback
& failure_callback
) = 0;
123 virtual void StartActivate(const std::string
& guid
,
124 const std::string
& carrier
,
125 const VoidCallback
& success_callback
,
126 const FailureCallback
& failure_callback
);
127 virtual void SetWifiTDLSEnabledState(
128 const std::string
& ip_or_mac_address
,
130 const StringCallback
& success_callback
,
131 const FailureCallback
& failure_callback
) = 0;
132 virtual void GetWifiTDLSStatus(const std::string
& ip_or_mac_address
,
133 const StringCallback
& success_callback
,
134 const FailureCallback
& failure_callback
) = 0;
135 virtual void GetCaptivePortalStatus(
136 const std::string
& guid
,
137 const StringCallback
& success_callback
,
138 const FailureCallback
& failure_callback
) = 0;
140 // Synchronous methods
142 // Returns a list of ONC type strings.
143 virtual scoped_ptr
<base::ListValue
> GetEnabledNetworkTypes() = 0;
145 // Returns a list of DeviceStateProperties.
146 virtual scoped_ptr
<DeviceStateList
> GetDeviceStateList() = 0;
148 // Returns true if the ONC network type |type| is enabled.
149 virtual bool EnableNetworkType(const std::string
& type
) = 0;
151 // Returns true if the ONC network type |type| is disabled.
152 virtual bool DisableNetworkType(const std::string
& type
) = 0;
154 // Returns true if a scan was requested. It may take many seconds for a scan
155 // to complete. The scan may or may not trigger API events when complete.
156 virtual bool RequestScan() = 0;
158 // Optional methods for adding a NetworkingPrivateDelegateObserver for
159 // implementations that require it (non-chromeos).
160 virtual void AddObserver(NetworkingPrivateDelegateObserver
* observer
);
161 virtual void RemoveObserver(NetworkingPrivateDelegateObserver
* observer
);
163 // Verify* methods are forwarded to |verify_delegate_| if not NULL.
164 void VerifyDestination(const VerificationProperties
& verification_properties
,
165 const BoolCallback
& success_callback
,
166 const FailureCallback
& failure_callback
);
167 void VerifyAndEncryptCredentials(
168 const std::string
& guid
,
169 const VerificationProperties
& verification_properties
,
170 const StringCallback
& success_callback
,
171 const FailureCallback
& failure_callback
);
172 void VerifyAndEncryptData(
173 const VerificationProperties
& verification_properties
,
174 const std::string
& data
,
175 const StringCallback
& success_callback
,
176 const FailureCallback
& failure_callback
);
179 // Interface for Verify* methods. May be NULL.
180 scoped_ptr
<VerifyDelegate
> verify_delegate_
;
182 DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateDelegate
);
185 } // namespace extensions
187 #endif // EXTENSIONS_BROWSER_API_NETWORKING_PRIVATE_NETWORKING_PRIVATE_DELEGATE_H_