• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   // Handlers for WebUI messages.
64   void HandleClose(const std::string& reason);
65   void HandleCompleteLogin(const std::string& user);
66   void HandleRetry();
67 
68   // Shows a given enrollment step.
69   void ShowStep(const char* step);
70 
71   // Display the given i18n resource as error message.
72   void ShowError(int message_id, bool retry);
73 
74   // Display the given string as error message.
75   void ShowErrorMessage(const std::string& message, bool retry);
76 
77   // Display the given i18n string as a progress message.
78   void ShowWorking(int message_id);
79 
80   // Handles completion of the OAuth2 token fetch attempt.
81   void OnTokenFetched(const std::string& token,
82                       const GoogleServiceAuthError& error);
83 
84   // Shows the screen.
85   void DoShow();
86 
87   // Keeps the controller for this actor.
88   Controller* controller_;
89 
90   bool show_on_init_;
91 
92   // Whether this is an auto-enrollment screen.
93   bool is_auto_enrollment_;
94 
95   // True of we can exit enrollment and return back to the regular login flow.
96   bool can_exit_enrollment_;
97 
98   // Whether an enrollment attempt has failed.
99   bool enrollment_failed_once_;
100 
101   // Username of the user signing in.
102   std::string user_;
103 
104   // This intentionally lives here and not in the controller, since it needs to
105   // execute requests in the context of the profile that displays the webui.
106   scoped_ptr<policy::PolicyOAuth2TokenFetcher> oauth_fetcher_;
107 
108   // The browsing data remover instance currently active, if any.
109   BrowsingDataRemover* browsing_data_remover_;
110 
111   // The callbacks to invoke after browsing data has been cleared.
112   std::vector<base::Closure> auth_reset_callbacks_;
113 
114   DISALLOW_COPY_AND_ASSIGN(EnrollmentScreenHandler);
115 };
116 
117 }  // namespace chromeos
118 
119 #endif  // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_ENROLLMENT_SCREEN_HANDLER_H_
120