• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "chromeos/login/auth/auth_attempt_state.h"
6 
7 #include <string>
8 
9 #include "google_apis/gaia/gaia_auth_consumer.h"
10 #include "google_apis/gaia/gaia_auth_fetcher.h"
11 
12 namespace chromeos {
13 
AuthAttemptState(const UserContext & user_context,user_manager::UserType user_type,bool unlock,bool online_complete,bool user_is_new)14 AuthAttemptState::AuthAttemptState(const UserContext& user_context,
15                                    user_manager::UserType user_type,
16                                    bool unlock,
17                                    bool online_complete,
18                                    bool user_is_new)
19     : user_context(user_context),
20       user_type(user_type),
21       unlock(unlock),
22       online_complete_(online_complete),
23       online_outcome_(online_complete ? AuthFailure::UNLOCK_FAILED
24                                       : AuthFailure::NONE),
25       hosted_policy_(GaiaAuthFetcher::HostedAccountsAllowed),
26       is_first_time_user_(user_is_new),
27       cryptohome_complete_(false),
28       cryptohome_outcome_(false),
29       cryptohome_code_(cryptohome::MOUNT_ERROR_NONE),
30       username_hash_obtained_(true),
31       username_hash_valid_(true) {
32 }
33 
~AuthAttemptState()34 AuthAttemptState::~AuthAttemptState() {
35 }
36 
RecordOnlineLoginStatus(const AuthFailure & outcome)37 void AuthAttemptState::RecordOnlineLoginStatus(const AuthFailure& outcome) {
38   online_complete_ = true;
39   online_outcome_ = outcome;
40   // We're either going to not try again, or try again with HOSTED
41   // accounts not allowed, so just set this here.
42   DisableHosted();
43 }
44 
DisableHosted()45 void AuthAttemptState::DisableHosted() {
46   hosted_policy_ = GaiaAuthFetcher::HostedAccountsNotAllowed;
47 }
48 
RecordCryptohomeStatus(bool cryptohome_outcome,cryptohome::MountError cryptohome_code)49 void AuthAttemptState::RecordCryptohomeStatus(
50     bool cryptohome_outcome,
51     cryptohome::MountError cryptohome_code) {
52   cryptohome_complete_ = true;
53   cryptohome_outcome_ = cryptohome_outcome;
54   cryptohome_code_ = cryptohome_code;
55 }
56 
RecordUsernameHash(const std::string & username_hash)57 void AuthAttemptState::RecordUsernameHash(const std::string& username_hash) {
58   user_context.SetUserIDHash(username_hash);
59   username_hash_obtained_ = true;
60   username_hash_valid_ = true;
61 }
62 
RecordUsernameHashFailed()63 void AuthAttemptState::RecordUsernameHashFailed() {
64   username_hash_obtained_ = true;
65   username_hash_valid_ = false;
66 }
67 
UsernameHashRequested()68 void AuthAttemptState::UsernameHashRequested() {
69   username_hash_obtained_ = false;
70 }
71 
ResetCryptohomeStatus()72 void AuthAttemptState::ResetCryptohomeStatus() {
73   cryptohome_complete_ = false;
74   cryptohome_outcome_ = false;
75   cryptohome_code_ = cryptohome::MOUNT_ERROR_NONE;
76 }
77 
online_complete()78 bool AuthAttemptState::online_complete() {
79   return online_complete_;
80 }
81 
online_outcome()82 const AuthFailure& AuthAttemptState::online_outcome() {
83   return online_outcome_;
84 }
85 
is_first_time_user()86 bool AuthAttemptState::is_first_time_user() {
87   return is_first_time_user_;
88 }
89 
hosted_policy()90 GaiaAuthFetcher::HostedAccountsSetting AuthAttemptState::hosted_policy() {
91   return hosted_policy_;
92 }
93 
cryptohome_complete()94 bool AuthAttemptState::cryptohome_complete() {
95   return cryptohome_complete_;
96 }
97 
cryptohome_outcome()98 bool AuthAttemptState::cryptohome_outcome() {
99   return cryptohome_outcome_;
100 }
101 
cryptohome_code()102 cryptohome::MountError AuthAttemptState::cryptohome_code() {
103   return cryptohome_code_;
104 }
105 
username_hash_obtained()106 bool AuthAttemptState::username_hash_obtained() {
107   return username_hash_obtained_;
108 }
109 
username_hash_valid()110 bool AuthAttemptState::username_hash_valid() {
111   return username_hash_obtained_;
112 }
113 
114 }  // namespace chromeos
115