15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_ECHO_PRIVATE_API_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_BROWSER_CHROMEOS_EXTENSIONS_ECHO_PRIVATE_API_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/compiler_specific.h" 9c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/chromeos/ui/echo_dialog_listener.h" 101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/extensions/chrome_extension_function.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 12424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)class PrefRegistrySimple; 13424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 14c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)namespace chromeos { 15424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 16c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class EchoDialogView; 17424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 18424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// Namespace to register the EchoCheckedOffers field in Local State. 19424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)namespace echo_offer { 20424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 21424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)void RegisterPrefs(PrefRegistrySimple* registry); 22424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 23424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} // namespace echo_offer 24424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 25424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} // namespace chromeos 26c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class EchoPrivateGetRegistrationCodeFunction 281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) : public ChromeSyncExtensionFunction { 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EchoPrivateGetRegistrationCodeFunction(); 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~EchoPrivateGetRegistrationCodeFunction(); 345c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu virtual bool RunSync() OVERRIDE; 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void GetRegistrationCode(const std::string& type); 382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("echoPrivate.getRegistrationCode", 392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ECHOPRIVATE_GETREGISTRATIONCODE) 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class EchoPrivateGetOobeTimestampFunction 431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) : public ChromeAsyncExtensionFunction { 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EchoPrivateGetOobeTimestampFunction(); 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected: 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~EchoPrivateGetOobeTimestampFunction(); 49010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) virtual bool RunAsync() OVERRIDE; 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool GetOobeTimestampOnFileThread(); 532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("echoPrivate.getOobeTimestamp", 542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ECHOPRIVATE_GETOOBETIMESTAMP) 552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class EchoPrivateSetOfferInfoFunction : public ChromeSyncExtensionFunction { 58424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) public: 59424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) EchoPrivateSetOfferInfoFunction(); 60424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 61424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) protected: 62424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) virtual ~EchoPrivateSetOfferInfoFunction(); 635c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu virtual bool RunSync() OVERRIDE; 64424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 65424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) private: 66424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) DECLARE_EXTENSION_FUNCTION("echoPrivate.setOfferInfo", 67424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) ECHOPRIVATE_SETOFFERINFO) 68424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)}; 69424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class EchoPrivateGetOfferInfoFunction : public ChromeSyncExtensionFunction { 71424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) public: 72424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) EchoPrivateGetOfferInfoFunction(); 73424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 74424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) protected: 75424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) virtual ~EchoPrivateGetOfferInfoFunction(); 765c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu virtual bool RunSync() OVERRIDE; 77424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 78424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) private: 79424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) DECLARE_EXTENSION_FUNCTION("echoPrivate.getOfferInfo", 80424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) ECHOPRIVATE_GETOFFERINFO) 81424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)}; 82424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// The function first checks if offers redeeming is allowed by the device 842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// policy. It should then show a dialog that, depending on the check result, 852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// either asks user's consent to verify the device's eligibility for the offer, 862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// or informs the user that the offers redeeming is disabled. 872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// It returns whether the user consent was given. 881e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class EchoPrivateGetUserConsentFunction : public ChromeAsyncExtensionFunction, 891e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) public chromeos::EchoDialogListener { 902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 91c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Type for the dialog shown callback used in tests. 92c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) typedef base::Callback<void(chromeos::EchoDialogView* dialog)> 93c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DialogShownTestCallback; 94c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EchoPrivateGetUserConsentFunction(); 962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 97c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Creates the function with non-null dialog_shown_callback_. 98c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // To be used in tests. 99c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) static scoped_refptr<EchoPrivateGetUserConsentFunction> CreateForTest( 100c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const DialogShownTestCallback& dialog_shown_callback); 1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected: 1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~EchoPrivateGetUserConsentFunction(); 1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 105010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) virtual bool RunAsync() OVERRIDE; 1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 108c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // chromeos::EchoDialogListener overrides. 109c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void OnAccept() OVERRIDE; 110c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void OnCancel() OVERRIDE; 111c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void OnMoreInfoLinkClicked() OVERRIDE; 112c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Checks whether "allow redeem ChromeOS registration offers" setting is 1142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // disabled in cros settings. It may be asynchronous if the needed settings 1152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // provider is not yet trusted. 1162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Upon completion |OnRedeemOffersAllowed| is called. 1172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void CheckRedeemOffersAllowed(); 1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void OnRedeemOffersAllowedChecked(bool is_allowed); 1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 120c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Sets result and calls SendResponse. 121c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void Finalize(bool consent); 122c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 123c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Result of |CheckRedeemOffersAllowed()|. 1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool redeem_offers_allowed_; 125c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Callback used in tests. Called after an echo dialog is shown. 126c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DialogShownTestCallback dialog_shown_callback_; 1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("echoPrivate.getUserConsent", 1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ECHOPRIVATE_GETUSERCONSENT) 1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_ECHO_PRIVATE_API_H_ 133