Home | History | Annotate | Download | only in login
      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.
      4 
      5 #ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_ENROLLMENT_SCREEN_HANDLER_H_
      6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_ENROLLMENT_SCREEN_HANDLER_H_
      7 
      8 #include <string>
      9 #include <vector>
     10 
     11 #include "base/basictypes.h"
     12 #include "base/callback_forward.h"
     13 #include "base/memory/scoped_ptr.h"
     14 #include "base/memory/scoped_vector.h"
     15 #include "chrome/browser/browsing_data/browsing_data_remover.h"
     16 #include "chrome/browser/chromeos/login/enrollment/enrollment_screen_actor.h"
     17 #include "chrome/browser/ui/webui/chromeos/login/base_screen_handler.h"
     18 
     19 namespace policy {
     20 class PolicyOAuth2TokenFetcher;
     21 }
     22 
     23 namespace chromeos {
     24 
     25 // WebUIMessageHandler implementation which handles events occurring on the
     26 // page, such as the user pressing the signin button.
     27 class EnrollmentScreenHandler
     28     : public BaseScreenHandler,
     29       public EnrollmentScreenActor,
     30       public BrowsingDataRemover::Observer {
     31  public:
     32   EnrollmentScreenHandler();
     33   virtual ~EnrollmentScreenHandler();
     34 
     35   // Implements WebUIMessageHandler:
     36   virtual void RegisterMessages() OVERRIDE;
     37 
     38   // Implements EnrollmentScreenActor:
     39   virtual void SetParameters(Controller* controller,
     40                              bool is_auto_enrollment,
     41                              bool can_exit_enrollment,
     42                              const std::string& user) OVERRIDE;
     43   virtual void PrepareToShow() OVERRIDE;
     44   virtual void Show() OVERRIDE;
     45   virtual void Hide() OVERRIDE;
     46   virtual void FetchOAuthToken() OVERRIDE;
     47   virtual void ResetAuth(const base::Closure& callback) OVERRIDE;
     48   virtual void ShowSigninScreen() OVERRIDE;
     49   virtual void ShowEnrollmentSpinnerScreen() OVERRIDE;
     50   virtual void ShowLoginSpinnerScreen() OVERRIDE;
     51   virtual void ShowAuthError(const GoogleServiceAuthError& error) OVERRIDE;
     52   virtual void ShowEnrollmentStatus(policy::EnrollmentStatus status) OVERRIDE;
     53   virtual void ShowUIError(UIError error_code) OVERRIDE;
     54 
     55   // Implements BaseScreenHandler:
     56   virtual void Initialize() OVERRIDE;
     57   virtual void DeclareLocalizedValues(LocalizedValuesBuilder* builder) OVERRIDE;
     58 
     59   // Implements BrowsingDataRemover::Observer:
     60   virtual void OnBrowsingDataRemoverDone() OVERRIDE;
     61 
     62  private:
     63   class TokenRevoker;
     64 
     65   // Handlers for WebUI messages.
     66   void HandleClose(const std::string& reason);
     67   void HandleCompleteLogin(const std::string& user);
     68   void HandleRetry();
     69 
     70   // Shows a given enrollment step.
     71   void ShowStep(const char* step);
     72 
     73   // Display the given i18n resource as error message.
     74   void ShowError(int message_id, bool retry);
     75 
     76   // Display the given string as error message.
     77   void ShowErrorMessage(const std::string& message, bool retry);
     78 
     79   // Display the given i18n string as a progress message.
     80   void ShowWorking(int message_id);
     81 
     82   // Handles completion of the OAuth2 token fetch attempt.
     83   void OnTokenFetched(const std::string& token,
     84                       const GoogleServiceAuthError& error);
     85 
     86   // Callback for TokenRevokers that have completed.
     87   void OnTokenRevokerDone(TokenRevoker* revoker);
     88 
     89   // Checks whether a pending auth reset is complete. If so, invokes callbacks.
     90   void CheckAuthResetDone();
     91 
     92   // Shows the screen.
     93   void DoShow();
     94 
     95   // Keeps the controller for this actor.
     96   Controller* controller_;
     97 
     98   bool show_on_init_;
     99 
    100   // Whether this is an auto-enrollment screen.
    101   bool is_auto_enrollment_;
    102 
    103   // True of we can exit enrollment and return back to the regular login flow.
    104   bool can_exit_enrollment_;
    105 
    106   // Whether an enrollment attempt has failed.
    107   bool enrollment_failed_once_;
    108 
    109   // Username of the user signing in.
    110   std::string user_;
    111 
    112   // This intentionally lives here and not in the controller, since it needs to
    113   // execute requests in the context of the profile that displays the webui.
    114   scoped_ptr<policy::PolicyOAuth2TokenFetcher> oauth_fetcher_;
    115 
    116   // The browsing data remover instance currently active, if any.
    117   BrowsingDataRemover* browsing_data_remover_;
    118   scoped_ptr<TokenRevoker> access_token_revoker_;
    119   scoped_ptr<TokenRevoker> refresh_token_revoker_;
    120 
    121   // The callbacks to invoke after browsing data has been cleared.
    122   std::vector<base::Closure> auth_reset_callbacks_;
    123 
    124   DISALLOW_COPY_AND_ASSIGN(EnrollmentScreenHandler);
    125 };
    126 
    127 }  // namespace chromeos
    128 
    129 #endif  // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_ENROLLMENT_SCREEN_HANDLER_H_
    130