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() {}
39 bool SupervisedUserCreationFlow::CanLockScreen() {
43 bool SupervisedUserCreationFlow::ShouldShowSettings() {
47 bool SupervisedUserCreationFlow::ShouldLaunchBrowser() {
51 bool SupervisedUserCreationFlow::ShouldSkipPostLoginScreens() {
55 void SupervisedUserCreationFlow::HandleOAuthTokenStatusChange(
56 user_manager::User::OAuthTokenStatus status) {
57 if (status == user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN)
59 if (status == user_manager::User::OAUTH2_TOKEN_STATUS_INVALID) {
60 GetScreen(host())->ShowManagerInconsistentStateErrorScreen();
63 DCHECK(status == user_manager::User::OAUTH2_TOKEN_STATUS_VALID);
64 // We expect that LaunchExtraSteps is called by this time (local
65 // authentication happens before oauth token validation).
66 token_validated_ = true;
68 if (token_validated_ && logged_in_) {
69 if (!session_started_)
70 GetScreen(host())->OnManagerFullyAuthenticated(manager_profile_);
71 session_started_ = true;
75 bool SupervisedUserCreationFlow::HandleLoginFailure(
76 const AuthFailure& failure) {
77 if (failure.reason() == AuthFailure::COULD_NOT_MOUNT_CRYPTOHOME)
78 GetScreen(host())->OnManagerLoginFailure();
80 GetScreen(host())->ShowManagerInconsistentStateErrorScreen();
84 void SupervisedUserCreationFlow::HandleLoginSuccess(
85 const UserContext& context) {}
87 bool SupervisedUserCreationFlow::HandlePasswordChangeDetected() {
88 GetScreen(host())->ShowManagerInconsistentStateErrorScreen();
92 void SupervisedUserCreationFlow::LaunchExtraSteps(
95 manager_profile_ = profile;
96 ProfileHelper::Get()->ProfileStartup(profile, true);
98 if (token_validated_ && logged_in_) {
99 if (!session_started_)
100 GetScreen(host())->OnManagerFullyAuthenticated(manager_profile_);
101 session_started_ = true;
103 GetScreen(host())->OnManagerCryptohomeAuthenticated();
107 } // namespace chromeos