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 class AuthenticatedUserEmailRetriever
;
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
{
34 EnrollmentScreenHandler();
35 virtual ~EnrollmentScreenHandler();
37 // Implements WebUIMessageHandler:
38 virtual void RegisterMessages() OVERRIDE
;
40 // Implements EnrollmentScreenActor:
41 virtual void SetParameters(Controller
* controller
,
42 bool is_auto_enrollment
,
43 bool can_exit_enrollment
,
44 const std::string
& user
) OVERRIDE
;
45 virtual void PrepareToShow() OVERRIDE
;
46 virtual void Show() OVERRIDE
;
47 virtual void Hide() OVERRIDE
;
48 virtual void FetchOAuthToken() OVERRIDE
;
49 virtual void ResetAuth(const base::Closure
& callback
) OVERRIDE
;
50 virtual void ShowSigninScreen() OVERRIDE
;
51 virtual void ShowEnrollmentSpinnerScreen() OVERRIDE
;
52 virtual void ShowLoginSpinnerScreen() OVERRIDE
;
53 virtual void ShowAuthError(const GoogleServiceAuthError
& error
) OVERRIDE
;
54 virtual void ShowEnrollmentStatus(policy::EnrollmentStatus status
) OVERRIDE
;
55 virtual void ShowUIError(UIError error_code
) OVERRIDE
;
57 // Implements BaseScreenHandler:
58 virtual void Initialize() OVERRIDE
;
59 virtual void DeclareLocalizedValues(LocalizedValuesBuilder
* builder
) OVERRIDE
;
61 // Implements BrowsingDataRemover::Observer:
62 virtual void OnBrowsingDataRemoverDone() OVERRIDE
;
65 // Handlers for WebUI messages.
66 void HandleRetrieveAuthenticatedUserEmail(double attempt_token
);
67 void HandleClose(const std::string
& reason
);
68 void HandleCompleteLogin(const std::string
& user
);
71 // Shows a given enrollment step.
72 void ShowStep(const char* step
);
74 // Display the given i18n resource as error message.
75 void ShowError(int message_id
, bool retry
);
77 // Display the given string as error message.
78 void ShowErrorMessage(const std::string
& message
, bool retry
);
80 // Display the given i18n string as a progress message.
81 void ShowWorking(int message_id
);
83 // Handles completion of the OAuth2 token fetch attempt.
84 void OnTokenFetched(const std::string
& token
,
85 const GoogleServiceAuthError
& error
);
90 // Keeps the controller for this actor.
91 Controller
* controller_
;
95 // Whether this is an auto-enrollment screen.
96 bool is_auto_enrollment_
;
98 // True of we can exit enrollment and return back to the regular login flow.
99 bool can_exit_enrollment_
;
101 // Whether an enrollment attempt has failed.
102 bool enrollment_failed_once_
;
104 // Username of the user signing in.
107 // This intentionally lives here and not in the controller, since it needs to
108 // execute requests in the context of the profile that displays the webui.
109 scoped_ptr
<policy::PolicyOAuth2TokenFetcher
> oauth_fetcher_
;
111 // The browsing data remover instance currently active, if any.
112 BrowsingDataRemover
* browsing_data_remover_
;
114 // The callbacks to invoke after browsing data has been cleared.
115 std::vector
<base::Closure
> auth_reset_callbacks_
;
117 // Helper that retrieves the authenticated user's e-mail address.
118 scoped_ptr
<AuthenticatedUserEmailRetriever
> email_retriever_
;
120 DISALLOW_COPY_AND_ASSIGN(EnrollmentScreenHandler
);
123 } // namespace chromeos
125 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_ENROLLMENT_SCREEN_HANDLER_H_