Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / login / managed / locally_managed_user_creation_flow.cc
blobcff2c37fa55caa7d2911d194f2eea62299deaba8
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 #include "chrome/browser/chromeos/login/managed/locally_managed_user_creation_flow.h"
7 #include "base/logging.h"
8 #include "base/values.h"
9 #include "chrome/browser/chromeos/login/login_display_host_impl.h"
10 #include "chrome/browser/chromeos/login/managed/locally_managed_user_creation_screen.h"
11 #include "chrome/browser/chromeos/login/wizard_controller.h"
13 namespace chromeos {
15 namespace {
17 LocallyManagedUserCreationScreen* GetScreen(LoginDisplayHost* host) {
18 DCHECK(host);
19 DCHECK(host->GetWizardController());
20 DCHECK(host->GetWizardController()->GetLocallyManagedUserCreationScreen());
21 return host->GetWizardController()->GetLocallyManagedUserCreationScreen();
24 } // namespace
26 LocallyManagedUserCreationFlow::LocallyManagedUserCreationFlow(
27 const std::string& manager_id)
28 : ExtendedUserFlow(manager_id),
29 token_validated_(false),
30 logged_in_(false),
31 manager_profile_(NULL) {}
33 LocallyManagedUserCreationFlow::~LocallyManagedUserCreationFlow() {}
35 bool LocallyManagedUserCreationFlow::ShouldShowSettings() {
36 return false;
39 bool LocallyManagedUserCreationFlow::ShouldLaunchBrowser() {
40 return false;
43 bool LocallyManagedUserCreationFlow::ShouldSkipPostLoginScreens() {
44 return true;
47 void LocallyManagedUserCreationFlow::HandleOAuthTokenStatusChange(
48 User::OAuthTokenStatus status) {
49 if (status == User::OAUTH_TOKEN_STATUS_UNKNOWN)
50 return;
51 if (status == User::OAUTH2_TOKEN_STATUS_INVALID) {
52 GetScreen(host())->ShowManagerInconsistentStateErrorScreen();
53 return;
55 DCHECK(status == User::OAUTH2_TOKEN_STATUS_VALID);
56 // We expect that LaunchExtraSteps is called by this time (local
57 // authentication happens before oauth token validation).
58 token_validated_ = true;
60 if (token_validated_ && logged_in_)
61 GetScreen(host())->OnManagerFullyAuthenticated(manager_profile_);
65 bool LocallyManagedUserCreationFlow::HandleLoginFailure(
66 const LoginFailure& failure) {
67 if (failure.reason() == LoginFailure::COULD_NOT_MOUNT_CRYPTOHOME)
68 GetScreen(host())->OnManagerLoginFailure();
69 else
70 GetScreen(host())->ShowManagerInconsistentStateErrorScreen();
71 return true;
74 bool LocallyManagedUserCreationFlow::HandlePasswordChangeDetected() {
75 GetScreen(host())->ShowManagerInconsistentStateErrorScreen();
76 return true;
79 void LocallyManagedUserCreationFlow::LaunchExtraSteps(
80 Profile* profile) {
81 logged_in_ = true;
82 manager_profile_ = profile;
83 if (token_validated_ && logged_in_)
84 GetScreen(host())->OnManagerFullyAuthenticated(manager_profile_);
85 else
86 GetScreen(host())->OnManagerCryptohomeAuthenticated();
89 } // namespace chromeos