1 // Copyright (c) 2013 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. 4 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_TERMS_OF_SERVICE_SCREEN_H_ 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_TERMS_OF_SERVICE_SCREEN_H_ 7 8 #include <memory> 9 10 #include "base/callback.h" 11 #include "base/compiler_specific.h" 12 #include "base/macros.h" 13 #include "base/timer/timer.h" 14 #include "chrome/browser/chromeos/login/screens/base_screen.h" 15 16 namespace network { 17 class SimpleURLLoader; 18 } 19 20 namespace chromeos { 21 22 class TermsOfServiceScreenView; 23 24 // A screen that shows Terms of Service which have been configured through 25 // policy. The screen is shown during login and requires the user to accept the 26 // Terms of Service before proceeding. Currently, Terms of Service are available 27 // for public sessions only. 28 class TermsOfServiceScreen : public BaseScreen { 29 public: 30 enum class Result { ACCEPTED, DECLINED, NOT_APPLICABLE }; 31 32 static std::string GetResultString(Result result); 33 34 // The possible states that the screen may assume. 35 enum class ScreenState : int { LOADING = 0, LOADED = 1, ERROR = 2 }; 36 37 using ScreenExitCallback = base::RepeatingCallback<void(Result result)>; 38 TermsOfServiceScreen(TermsOfServiceScreenView* view, 39 const ScreenExitCallback& exit_callback); 40 ~TermsOfServiceScreen() override; 41 42 // Called when the user declines the Terms of Service. 43 void OnDecline(); 44 45 // Called when the user accepts the Terms of Service. 46 void OnAccept(); 47 48 // Called when the user retries to obtain the Terms of Service. 49 void OnRetry(); 50 51 // Called when view is destroyed so there is no dead reference to it. 52 void OnViewDestroyed(TermsOfServiceScreenView* view); 53 set_exit_callback_for_testing(const ScreenExitCallback & exit_callback)54 void set_exit_callback_for_testing(const ScreenExitCallback& exit_callback) { 55 exit_callback_ = exit_callback; 56 } 57 get_exit_callback_for_testing()58 const ScreenExitCallback& get_exit_callback_for_testing() { 59 return exit_callback_; 60 } 61 62 private: 63 // BaseScreen: 64 bool MaybeSkip(WizardContext* context) override; 65 void ShowImpl() override; 66 void HideImpl() override; 67 void OnUserAction(const std::string& action_id) override; 68 69 // Start downloading the Terms of Service. 70 void StartDownload(); 71 72 // Abort the attempt to download the Terms of Service if it takes too long. 73 void OnDownloadTimeout(); 74 75 // Callback function called when SimpleURLLoader completes. 76 void OnDownloaded(std::unique_ptr<std::string> response_body); 77 78 TermsOfServiceScreenView* view_; 79 ScreenExitCallback exit_callback_; 80 81 std::unique_ptr<network::SimpleURLLoader> terms_of_service_loader_; 82 83 // Timer that enforces a custom (shorter) timeout on the attempt to download 84 // the Terms of Service. 85 base::OneShotTimer download_timer_; 86 87 DISALLOW_COPY_AND_ASSIGN(TermsOfServiceScreen); 88 }; 89 90 } // namespace chromeos 91 92 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_TERMS_OF_SERVICE_SCREEN_H_ 93