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_
10 #include "base/callback.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/values.h"
13 #include "components/keyed_service/core/keyed_service.h"
19 namespace extensions
{
21 class NetworkingPrivateDelegateObserver
;
24 namespace networking_private
{
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.json for descriptions of the expected inputs and results.
32 class NetworkingPrivateDelegate
: public KeyedService
{
34 typedef base::Callback
<void(scoped_ptr
<base::DictionaryValue
>)>
36 typedef base::Callback
<void()> VoidCallback
;
37 typedef base::Callback
<void(bool)> BoolCallback
;
38 typedef base::Callback
<void(const std::string
&)> StringCallback
;
39 typedef base::Callback
<void(scoped_ptr
<base::ListValue
>)> NetworkListCallback
;
40 typedef base::Callback
<void(const std::string
&)> FailureCallback
;
41 typedef core_api::networking_private::VerificationProperties
42 VerificationProperties
;
44 // The Verify* methods will be forwarded to a delegate implementation if
45 // provided, otherwise they will fail. A separate delegate it used so that the
46 // current Verify* implementations are not exposed outside of src/chrome.
47 class VerifyDelegate
{
49 typedef NetworkingPrivateDelegate::VerificationProperties
50 VerificationProperties
;
51 typedef NetworkingPrivateDelegate::BoolCallback BoolCallback
;
52 typedef NetworkingPrivateDelegate::StringCallback StringCallback
;
53 typedef NetworkingPrivateDelegate::FailureCallback FailureCallback
;
56 virtual ~VerifyDelegate();
58 virtual void VerifyDestination(
59 const VerificationProperties
& verification_properties
,
60 const BoolCallback
& success_callback
,
61 const FailureCallback
& failure_callback
) = 0;
62 virtual void VerifyAndEncryptCredentials(
63 const std::string
& guid
,
64 const VerificationProperties
& verification_properties
,
65 const StringCallback
& success_callback
,
66 const FailureCallback
& failure_callback
) = 0;
67 virtual void VerifyAndEncryptData(
68 const VerificationProperties
& verification_properties
,
69 const std::string
& data
,
70 const StringCallback
& success_callback
,
71 const FailureCallback
& failure_callback
) = 0;
74 DISALLOW_COPY_AND_ASSIGN(VerifyDelegate
);
77 // If |verify_delegate| is not NULL, the Verify* methods will be forwarded
78 // to the delegate. Otherwise they will fail with a NotSupported error.
79 explicit NetworkingPrivateDelegate(
80 scoped_ptr
<VerifyDelegate
> verify_delegate
);
81 ~NetworkingPrivateDelegate() override
;
83 // Asynchronous methods
84 virtual void GetProperties(const std::string
& guid
,
85 const DictionaryCallback
& success_callback
,
86 const FailureCallback
& failure_callback
) = 0;
87 virtual void GetManagedProperties(
88 const std::string
& guid
,
89 const DictionaryCallback
& success_callback
,
90 const FailureCallback
& failure_callback
) = 0;
91 virtual void GetState(const std::string
& guid
,
92 const DictionaryCallback
& success_callback
,
93 const FailureCallback
& failure_callback
) = 0;
94 virtual void SetProperties(const std::string
& guid
,
95 scoped_ptr
<base::DictionaryValue
> properties
,
96 const VoidCallback
& success_callback
,
97 const FailureCallback
& failure_callback
) = 0;
98 virtual void CreateNetwork(bool shared
,
99 scoped_ptr
<base::DictionaryValue
> properties
,
100 const StringCallback
& success_callback
,
101 const FailureCallback
& failure_callback
) = 0;
102 virtual void ForgetNetwork(const std::string
& guid
,
103 const VoidCallback
& success_callback
,
104 const FailureCallback
& failure_callback
) = 0;
105 virtual void GetNetworks(const std::string
& network_type
,
106 bool configured_only
,
109 const NetworkListCallback
& success_callback
,
110 const FailureCallback
& failure_callback
) = 0;
111 virtual void StartConnect(const std::string
& guid
,
112 const VoidCallback
& success_callback
,
113 const FailureCallback
& failure_callback
) = 0;
114 virtual void StartDisconnect(const std::string
& guid
,
115 const VoidCallback
& success_callback
,
116 const FailureCallback
& failure_callback
) = 0;
117 virtual void StartActivate(const std::string
& guid
,
118 const std::string
& carrier
,
119 const VoidCallback
& success_callback
,
120 const FailureCallback
& failure_callback
);
121 virtual void SetWifiTDLSEnabledState(
122 const std::string
& ip_or_mac_address
,
124 const StringCallback
& success_callback
,
125 const FailureCallback
& failure_callback
) = 0;
126 virtual void GetWifiTDLSStatus(const std::string
& ip_or_mac_address
,
127 const StringCallback
& success_callback
,
128 const FailureCallback
& failure_callback
) = 0;
129 virtual void GetCaptivePortalStatus(
130 const std::string
& guid
,
131 const StringCallback
& success_callback
,
132 const FailureCallback
& failure_callback
) = 0;
134 // Synchronous methods
136 // Returns a list of ONC type strings.
137 virtual scoped_ptr
<base::ListValue
> GetEnabledNetworkTypes() = 0;
139 // Returns true if the ONC network type |type| is enabled.
140 virtual bool EnableNetworkType(const std::string
& type
) = 0;
142 // Returns true if the ONC network type |type| is disabled.
143 virtual bool DisableNetworkType(const std::string
& type
) = 0;
145 // Returns true if a scan was requested. It may take many seconds for a scan
146 // to complete. The scan may or may not trigger API events when complete.
147 virtual bool RequestScan() = 0;
149 // Optional methods for adding a NetworkingPrivateDelegateObserver for
150 // implementations that require it (non-chromeos).
151 virtual void AddObserver(NetworkingPrivateDelegateObserver
* observer
);
152 virtual void RemoveObserver(NetworkingPrivateDelegateObserver
* observer
);
154 // Verify* methods are forwarded to |verify_delegate_| if not NULL.
155 void VerifyDestination(const VerificationProperties
& verification_properties
,
156 const BoolCallback
& success_callback
,
157 const FailureCallback
& failure_callback
);
158 void VerifyAndEncryptCredentials(
159 const std::string
& guid
,
160 const VerificationProperties
& verification_properties
,
161 const StringCallback
& success_callback
,
162 const FailureCallback
& failure_callback
);
163 void VerifyAndEncryptData(
164 const VerificationProperties
& verification_properties
,
165 const std::string
& data
,
166 const StringCallback
& success_callback
,
167 const FailureCallback
& failure_callback
);
170 // Interface for Verify* methods. May be NULL.
171 scoped_ptr
<VerifyDelegate
> verify_delegate_
;
173 DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateDelegate
);
176 } // namespace extensions
178 #endif // EXTENSIONS_BROWSER_API_NETWORKING_PRIVATE_NETWORKING_PRIVATE_DELEGATE_H_