auth_attempt_state.cc revision 731df977c0511bca2206b5f333555b1205ff1f43
1// Copyright (c) 2010 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/auth_attempt_state.h"
6
7#include <string>
8
9#include "chrome/browser/browser_thread.h"
10#include "chrome/common/net/gaia/gaia_auth_consumer.h"
11#include "cros/chromeos_cryptohome.h"
12
13namespace chromeos {
14
15AuthAttemptState::AuthAttemptState(const std::string& username,
16                                   const std::string& password,
17                                   const std::string& ascii_hash,
18                                   const std::string& login_token,
19                                   const std::string& login_captcha)
20    : username(username),
21      password(password),
22      ascii_hash(ascii_hash),
23      login_token(login_token),
24      login_captcha(login_captcha),
25      unlock(false),
26      online_complete_(false),
27      online_outcome_(LoginFailure::NONE),
28      cryptohome_complete_(false),
29      cryptohome_outcome_(false),
30      cryptohome_code_(kCryptohomeMountErrorNone) {
31}
32
33AuthAttemptState::AuthAttemptState(const std::string& username,
34                                   const std::string& ascii_hash)
35    : username(username),
36      ascii_hash(ascii_hash),
37      unlock(true),
38      online_complete_(true),
39      online_outcome_(LoginFailure::UNLOCK_FAILED),
40      credentials_(GaiaAuthConsumer::ClientLoginResult()),
41      cryptohome_complete_(false),
42      cryptohome_outcome_(false),
43      cryptohome_code_(kCryptohomeMountErrorNone) {
44}
45
46AuthAttemptState::~AuthAttemptState() {}
47
48void AuthAttemptState::RecordOnlineLoginStatus(
49    const GaiaAuthConsumer::ClientLoginResult& credentials,
50    const LoginFailure& outcome) {
51  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
52  online_complete_ = true;
53  online_outcome_ = outcome;
54  credentials_ = credentials;
55}
56
57void AuthAttemptState::RecordCryptohomeStatus(bool cryptohome_outcome,
58                                              int cryptohome_code) {
59  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
60  cryptohome_complete_ = true;
61  cryptohome_outcome_ = cryptohome_outcome;
62  cryptohome_code_ = cryptohome_code;
63}
64
65void AuthAttemptState::ResetCryptohomeStatus() {
66  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
67  cryptohome_complete_ = false;
68  cryptohome_outcome_ = false;
69  cryptohome_code_ = kCryptohomeMountErrorNone;
70}
71
72bool AuthAttemptState::online_complete() {
73  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
74  return online_complete_;
75}
76
77const LoginFailure& AuthAttemptState::online_outcome() {
78  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
79  return online_outcome_;
80}
81
82const GaiaAuthConsumer::ClientLoginResult& AuthAttemptState::credentials() {
83  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
84  return credentials_;
85}
86
87bool AuthAttemptState::cryptohome_complete() {
88  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
89  return cryptohome_complete_;
90}
91
92bool AuthAttemptState::cryptohome_outcome() {
93  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
94  return cryptohome_outcome_;
95}
96
97int AuthAttemptState::cryptohome_code() {
98  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
99  return cryptohome_code_;
100}
101
102}  // namespace chromeos
103