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.
5 #ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_ENROLLMENT_SCREEN_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_ENROLLMENT_SCREEN_HANDLER_H_
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"
20 class PolicyOAuth2TokenFetcher;
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 {
32 EnrollmentScreenHandler();
33 virtual ~EnrollmentScreenHandler();
35 // Implements WebUIMessageHandler:
36 virtual void RegisterMessages() OVERRIDE;
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;
55 // Implements BaseScreenHandler:
56 virtual void Initialize() OVERRIDE;
57 virtual void DeclareLocalizedValues(LocalizedValuesBuilder* builder) OVERRIDE;
59 // Implements BrowsingDataRemover::Observer:
60 virtual void OnBrowsingDataRemoverDone() OVERRIDE;
63 // Handlers for WebUI messages.
64 void HandleClose(const std::string& reason);
65 void HandleCompleteLogin(const std::string& user);
68 // Shows a given enrollment step.
69 void ShowStep(const char* step);
71 // Display the given i18n resource as error message.
72 void ShowError(int message_id, bool retry);
74 // Display the given string as error message.
75 void ShowErrorMessage(const std::string& message, bool retry);
77 // Display the given i18n string as a progress message.
78 void ShowWorking(int message_id);
80 // Handles completion of the OAuth2 token fetch attempt.
81 void OnTokenFetched(const std::string& token,
82 const GoogleServiceAuthError& error);
87 // Keeps the controller for this actor.
88 Controller* controller_;
92 // Whether this is an auto-enrollment screen.
93 bool is_auto_enrollment_;
95 // True of we can exit enrollment and return back to the regular login flow.
96 bool can_exit_enrollment_;
98 // Whether an enrollment attempt has failed.
99 bool enrollment_failed_once_;
101 // Username of the user signing in.
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_;
108 // The browsing data remover instance currently active, if any.
109 BrowsingDataRemover* browsing_data_remover_;
111 // The callbacks to invoke after browsing data has been cleared.
112 std::vector<base::Closure> auth_reset_callbacks_;
114 DISALLOW_COPY_AND_ASSIGN(EnrollmentScreenHandler);
117 } // namespace chromeos
119 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_ENROLLMENT_SCREEN_HANDLER_H_