supervised_user_creation_flow.cc revision 1320f92c476a1ad9d19dba2a48c72b75566198e9
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. 4 5#include "chrome/browser/chromeos/login/supervised/supervised_user_creation_flow.h" 6 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" 13 14namespace chromeos { 15 16namespace { 17 18SupervisedUserCreationScreen* GetScreen(LoginDisplayHost* host) { 19 DCHECK(host); 20 DCHECK(host->GetWizardController()); 21 SupervisedUserCreationScreen* result = 22 SupervisedUserCreationScreen::Get(host->GetWizardController()); 23 DCHECK(result); 24 return result; 25} 26 27} // namespace 28 29SupervisedUserCreationFlow::SupervisedUserCreationFlow( 30 const std::string& manager_id) 31 : ExtendedUserFlow(manager_id), 32 token_validated_(false), 33 logged_in_(false), 34 session_started_(false), 35 manager_profile_(NULL) {} 36 37SupervisedUserCreationFlow::~SupervisedUserCreationFlow() {} 38 39bool SupervisedUserCreationFlow::CanLockScreen() { 40 return false; 41} 42 43bool SupervisedUserCreationFlow::ShouldShowSettings() { 44 return false; 45} 46 47bool SupervisedUserCreationFlow::ShouldLaunchBrowser() { 48 return false; 49} 50 51bool SupervisedUserCreationFlow::ShouldSkipPostLoginScreens() { 52 return true; 53} 54 55void SupervisedUserCreationFlow::HandleOAuthTokenStatusChange( 56 user_manager::User::OAuthTokenStatus status) { 57 if (status == user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN) 58 return; 59 if (status == user_manager::User::OAUTH2_TOKEN_STATUS_INVALID) { 60 GetScreen(host())->ShowManagerInconsistentStateErrorScreen(); 61 return; 62 } 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; 67 68 if (token_validated_ && logged_in_) { 69 if (!session_started_) 70 GetScreen(host())->OnManagerFullyAuthenticated(manager_profile_); 71 session_started_ = true; 72 } 73} 74 75bool SupervisedUserCreationFlow::HandleLoginFailure( 76 const AuthFailure& failure) { 77 if (failure.reason() == AuthFailure::COULD_NOT_MOUNT_CRYPTOHOME) 78 GetScreen(host())->OnManagerLoginFailure(); 79 else 80 GetScreen(host())->ShowManagerInconsistentStateErrorScreen(); 81 return true; 82} 83 84void SupervisedUserCreationFlow::HandleLoginSuccess( 85 const UserContext& context) {} 86 87bool SupervisedUserCreationFlow::HandlePasswordChangeDetected() { 88 GetScreen(host())->ShowManagerInconsistentStateErrorScreen(); 89 return true; 90} 91 92void SupervisedUserCreationFlow::LaunchExtraSteps( 93 Profile* profile) { 94 logged_in_ = true; 95 manager_profile_ = profile; 96 ProfileHelper::Get()->ProfileStartup(profile, true); 97 98 if (token_validated_ && logged_in_) { 99 if (!session_started_) 100 GetScreen(host())->OnManagerFullyAuthenticated(manager_profile_); 101 session_started_ = true; 102 } else { 103 GetScreen(host())->OnManagerCryptohomeAuthenticated(); 104 } 105} 106 107} // namespace chromeos 108