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 class AuthenticatedUserEmailRetriever;
     26 
     27 // WebUIMessageHandler implementation which handles events occurring on the
     28 // page, such as the user pressing the signin button.
     29 class EnrollmentScreenHandler
     30     : public BaseScreenHandler,
     31       public EnrollmentScreenActor,
     32       public BrowsingDataRemover::Observer {
     33  public:
     34   EnrollmentScreenHandler();
     35   virtual ~EnrollmentScreenHandler();
     36 
     37   // Implements WebUIMessageHandler:
     38   virtual void RegisterMessages() OVERRIDE;
     39 
     40   // Implements EnrollmentScreenActor:
     41   virtual void SetParameters(Controller* controller,
     42                              EnrollmentMode enrollment_mode,
     43                              const std::string& management_domain) OVERRIDE;
     44   virtual void PrepareToShow() OVERRIDE;
     45   virtual void Show() OVERRIDE;
     46   virtual void Hide() OVERRIDE;
     47   virtual void FetchOAuthToken() OVERRIDE;
     48   virtual void ResetAuth(const base::Closure& callback) OVERRIDE;
     49   virtual void ShowSigninScreen() OVERRIDE;
     50   virtual void ShowEnrollmentSpinnerScreen() OVERRIDE;
     51   virtual void ShowLoginSpinnerScreen() OVERRIDE;
     52   virtual void ShowAuthError(const GoogleServiceAuthError& error) OVERRIDE;
     53   virtual void ShowEnrollmentStatus(policy::EnrollmentStatus status) OVERRIDE;
     54   virtual void ShowUIError(UIError error_code) OVERRIDE;
     55 
     56   // Implements BaseScreenHandler:
     57   virtual void Initialize() OVERRIDE;
     58   virtual void DeclareLocalizedValues(LocalizedValuesBuilder* builder) OVERRIDE;
     59 
     60   // Implements BrowsingDataRemover::Observer:
     61   virtual void OnBrowsingDataRemoverDone() OVERRIDE;
     62 
     63  private:
     64   // Handlers for WebUI messages.
     65   void HandleRetrieveAuthenticatedUserEmail(double attempt_token);
     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   // Shows the screen.
     87   void DoShow();
     88 
     89   // Keeps the controller for this actor.
     90   Controller* controller_;
     91 
     92   bool show_on_init_;
     93 
     94   // The enrollment mode.
     95   EnrollmentMode enrollment_mode_;
     96 
     97   // The management domain, if applicable.
     98   std::string management_domain_;
     99 
    100   // Whether an enrollment attempt has failed.
    101   bool enrollment_failed_once_;
    102 
    103   // This intentionally lives here and not in the controller, since it needs to
    104   // execute requests in the context of the profile that displays the webui.
    105   scoped_ptr<policy::PolicyOAuth2TokenFetcher> oauth_fetcher_;
    106 
    107   // The browsing data remover instance currently active, if any.
    108   BrowsingDataRemover* browsing_data_remover_;
    109 
    110   // The callbacks to invoke after browsing data has been cleared.
    111   std::vector<base::Closure> auth_reset_callbacks_;
    112 
    113   // Helper that retrieves the authenticated user's e-mail address.
    114   scoped_ptr<AuthenticatedUserEmailRetriever> email_retriever_;
    115 
    116   DISALLOW_COPY_AND_ASSIGN(EnrollmentScreenHandler);
    117 };
    118 
    119 }  // namespace chromeos
    120 
    121 #endif  // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_ENROLLMENT_SCREEN_HANDLER_H_
    122