1 // Copyright (c) 2012 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 CHROME_BROWSER_CHROMEOS_EXTENSIONS_ECHO_PRIVATE_API_H_
6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_ECHO_PRIVATE_API_H_
8 #include "base/compiler_specific.h"
9 #include "chrome/browser/chromeos/ui/echo_dialog_listener.h"
10 #include "chrome/browser/extensions/chrome_extension_function.h"
12 class PrefRegistrySimple
;
18 // Namespace to register the EchoCheckedOffers field in Local State.
19 namespace echo_offer
{
21 void RegisterPrefs(PrefRegistrySimple
* registry
);
23 } // namespace echo_offer
25 } // namespace chromeos
27 class EchoPrivateGetRegistrationCodeFunction
28 : public ChromeSyncExtensionFunction
{
30 EchoPrivateGetRegistrationCodeFunction();
33 ~EchoPrivateGetRegistrationCodeFunction() override
;
34 bool RunSync() override
;
37 void GetRegistrationCode(const std::string
& type
);
38 DECLARE_EXTENSION_FUNCTION("echoPrivate.getRegistrationCode",
39 ECHOPRIVATE_GETREGISTRATIONCODE
)
42 class EchoPrivateGetOobeTimestampFunction
43 : public ChromeAsyncExtensionFunction
{
45 EchoPrivateGetOobeTimestampFunction();
48 ~EchoPrivateGetOobeTimestampFunction() override
;
49 bool RunAsync() override
;
52 bool GetOobeTimestampOnFileThread();
53 DECLARE_EXTENSION_FUNCTION("echoPrivate.getOobeTimestamp",
54 ECHOPRIVATE_GETOOBETIMESTAMP
)
57 class EchoPrivateSetOfferInfoFunction
: public ChromeSyncExtensionFunction
{
59 EchoPrivateSetOfferInfoFunction();
62 ~EchoPrivateSetOfferInfoFunction() override
;
63 bool RunSync() override
;
66 DECLARE_EXTENSION_FUNCTION("echoPrivate.setOfferInfo",
67 ECHOPRIVATE_SETOFFERINFO
)
70 class EchoPrivateGetOfferInfoFunction
: public ChromeSyncExtensionFunction
{
72 EchoPrivateGetOfferInfoFunction();
75 ~EchoPrivateGetOfferInfoFunction() override
;
76 bool RunSync() override
;
79 DECLARE_EXTENSION_FUNCTION("echoPrivate.getOfferInfo",
80 ECHOPRIVATE_GETOFFERINFO
)
83 // The function first checks if offers redeeming is allowed by the device
84 // policy. It should then show a dialog that, depending on the check result,
85 // either asks user's consent to verify the device's eligibility for the offer,
86 // or informs the user that the offers redeeming is disabled.
87 // It returns whether the user consent was given.
88 class EchoPrivateGetUserConsentFunction
: public ChromeAsyncExtensionFunction
,
89 public chromeos::EchoDialogListener
{
91 // Type for the dialog shown callback used in tests.
92 typedef base::Callback
<void(chromeos::EchoDialogView
* dialog
)>
93 DialogShownTestCallback
;
95 EchoPrivateGetUserConsentFunction();
97 // Creates the function with non-null dialog_shown_callback_.
98 // To be used in tests.
99 static scoped_refptr
<EchoPrivateGetUserConsentFunction
> CreateForTest(
100 const DialogShownTestCallback
& dialog_shown_callback
);
103 ~EchoPrivateGetUserConsentFunction() override
;
105 bool RunAsync() override
;
108 // chromeos::EchoDialogListener overrides.
109 void OnAccept() override
;
110 void OnCancel() override
;
111 void OnMoreInfoLinkClicked() override
;
113 // Checks whether "allow redeem ChromeOS registration offers" setting is
114 // disabled in cros settings. It may be asynchronous if the needed settings
115 // provider is not yet trusted.
116 // Upon completion |OnRedeemOffersAllowed| is called.
117 void CheckRedeemOffersAllowed();
118 void OnRedeemOffersAllowedChecked(bool is_allowed
);
120 // Sets result and calls SendResponse.
121 void Finalize(bool consent
);
123 // Result of |CheckRedeemOffersAllowed()|.
124 bool redeem_offers_allowed_
;
125 // Callback used in tests. Called after an echo dialog is shown.
126 DialogShownTestCallback dialog_shown_callback_
;
128 DECLARE_EXTENSION_FUNCTION("echoPrivate.getUserConsent",
129 ECHOPRIVATE_GETUSERCONSENT
)
132 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_ECHO_PRIVATE_API_H_