1 // Copyright 2014 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 #include "chrome/browser/chromeos/login/supervised/supervised_user_creation_flow.h"
7 #include "base/logging.h"
8 #include "base/values.h"
9 #include "chrome/browser/chromeos/login/supervised/supervised_user_creation_screen.h"
10 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
11 #include "chrome/browser/chromeos/login/wizard_controller.h"
12 #include "chrome/browser/chromeos/profiles/profile_helper.h"
18 SupervisedUserCreationScreen
* GetScreen(LoginDisplayHost
* host
) {
20 DCHECK(host
->GetWizardController());
21 SupervisedUserCreationScreen
* result
=
22 SupervisedUserCreationScreen::Get(host
->GetWizardController());
29 SupervisedUserCreationFlow::SupervisedUserCreationFlow(
30 const std::string
& manager_id
)
31 : ExtendedUserFlow(manager_id
),
32 token_validated_(false),
34 session_started_(false),
35 manager_profile_(NULL
) {}
37 SupervisedUserCreationFlow::~SupervisedUserCreationFlow() {
38 LOG(ERROR
) << "Destroyed " << this;
41 bool SupervisedUserCreationFlow::CanLockScreen() {
45 bool SupervisedUserCreationFlow::ShouldShowSettings() {
49 bool SupervisedUserCreationFlow::ShouldLaunchBrowser() {
53 bool SupervisedUserCreationFlow::ShouldSkipPostLoginScreens() {
57 bool SupervisedUserCreationFlow::SupportsEarlyRestartToApplyFlags() {
61 void SupervisedUserCreationFlow::HandleOAuthTokenStatusChange(
62 user_manager::User::OAuthTokenStatus status
) {
63 if (status
== user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN
)
65 if (status
== user_manager::User::OAUTH2_TOKEN_STATUS_INVALID
) {
66 GetScreen(host())->ShowManagerInconsistentStateErrorScreen();
69 DCHECK(status
== user_manager::User::OAUTH2_TOKEN_STATUS_VALID
);
70 // We expect that LaunchExtraSteps is called by this time (local
71 // authentication happens before oauth token validation).
72 token_validated_
= true;
74 if (token_validated_
&& logged_in_
) {
75 if (!session_started_
)
76 GetScreen(host())->OnManagerFullyAuthenticated(manager_profile_
);
77 session_started_
= true;
81 bool SupervisedUserCreationFlow::HandleLoginFailure(
82 const AuthFailure
& failure
) {
83 if (failure
.reason() == AuthFailure::COULD_NOT_MOUNT_CRYPTOHOME
)
84 GetScreen(host())->OnManagerLoginFailure();
86 GetScreen(host())->ShowManagerInconsistentStateErrorScreen();
90 void SupervisedUserCreationFlow::HandleLoginSuccess(
91 const UserContext
& context
) {}
93 bool SupervisedUserCreationFlow::HandlePasswordChangeDetected() {
94 GetScreen(host())->ShowManagerInconsistentStateErrorScreen();
98 void SupervisedUserCreationFlow::LaunchExtraSteps(
100 // TODO(antrim): remove this output once crash is found.
101 LOG(ERROR
) << "LaunchExtraSteps for " << this << " host is " << host();
103 manager_profile_
= profile
;
104 ProfileHelper::Get()->ProfileStartup(profile
, true);
106 if (token_validated_
&& logged_in_
) {
107 if (!session_started_
)
108 GetScreen(host())->OnManagerFullyAuthenticated(manager_profile_
);
109 session_started_
= true;
111 GetScreen(host())->OnManagerCryptohomeAuthenticated();
115 } // namespace chromeos