OLD | NEW |
(Empty) | |
| 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/cryptohome_op.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 10 #include "chrome/browser/chromeos/cros/cryptohome_library.h" |
| 11 #include "chrome/browser/chromeos/login/auth_attempt_state.h" |
| 12 #include "chrome/browser/chromeos/login/auth_attempt_state_resolver.h" |
| 13 |
| 14 namespace chromeos { |
| 15 |
| 16 CryptohomeOp::CryptohomeOp(AuthAttemptState* current_attempt, |
| 17 AuthAttemptStateResolver* callback) |
| 18 : attempt_(current_attempt), |
| 19 resolver_(callback) { |
| 20 CHECK(chromeos::CrosLibrary::Get()->EnsureLoaded()); |
| 21 } |
| 22 |
| 23 CryptohomeOp::~CryptohomeOp() {} |
| 24 |
| 25 void CryptohomeOp::OnComplete(bool success, int return_code) { |
| 26 ChromeThread::PostTask( |
| 27 ChromeThread::IO, FROM_HERE, |
| 28 NewRunnableMethod(this, |
| 29 &CryptohomeOp::TriggerResolve, |
| 30 success, return_code)); |
| 31 } |
| 32 |
| 33 void CryptohomeOp::TriggerResolve(bool success, int return_code) { |
| 34 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
| 35 attempt_->RecordOfflineLoginStatus(success, return_code); |
| 36 resolver_->Resolve(); |
| 37 } |
| 38 |
| 39 MountAttempt::MountAttempt(AuthAttemptState* current_attempt, |
| 40 AuthAttemptStateResolver* callback) |
| 41 : CryptohomeOp(current_attempt, callback) { |
| 42 } |
| 43 |
| 44 MountAttempt::~MountAttempt() {} |
| 45 |
| 46 bool MountAttempt::Initiate() { |
| 47 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 48 CryptohomeLibrary* lib = CrosLibrary::Get()->GetCryptohomeLibrary(); |
| 49 return lib->AsyncMount(attempt_->username, attempt_->ascii_hash, this); |
| 50 } |
| 51 |
| 52 MountGuestAttempt::MountGuestAttempt(AuthAttemptState* current_attempt, |
| 53 AuthAttemptStateResolver* callback) |
| 54 : CryptohomeOp(current_attempt, callback) { |
| 55 } |
| 56 |
| 57 MountGuestAttempt::~MountGuestAttempt() {} |
| 58 |
| 59 bool MountGuestAttempt::Initiate() { |
| 60 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 61 CryptohomeLibrary* lib = CrosLibrary::Get()->GetCryptohomeLibrary(); |
| 62 return lib->AsyncMountForBwsi(this); |
| 63 } |
| 64 |
| 65 MigrateAttempt::MigrateAttempt(AuthAttemptState* current_attempt, |
| 66 AuthAttemptStateResolver* callback, |
| 67 bool passing_old_hash, |
| 68 const std::string& hash) |
| 69 : CryptohomeOp(current_attempt, callback), |
| 70 is_old_hash_(passing_old_hash), |
| 71 hash_(hash) { |
| 72 } |
| 73 |
| 74 MigrateAttempt::~MigrateAttempt() {} |
| 75 |
| 76 bool MigrateAttempt::Initiate() { |
| 77 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 78 CryptohomeLibrary* lib = CrosLibrary::Get()->GetCryptohomeLibrary(); |
| 79 if (is_old_hash_) { |
| 80 return lib->AsyncMigrateKey(attempt_->username, |
| 81 hash_, |
| 82 attempt_->ascii_hash, |
| 83 this); |
| 84 } else { |
| 85 return lib->AsyncMigrateKey(attempt_->username, |
| 86 attempt_->ascii_hash, |
| 87 hash_, |
| 88 this); |
| 89 } |
| 90 } |
| 91 |
| 92 void MigrateAttempt::TriggerResolve(bool success, int return_code) { |
| 93 if (success) |
| 94 attempt_->ResetOfflineLoginStatus(); |
| 95 else |
| 96 attempt_->RecordOfflineLoginStatus(success, return_code); |
| 97 resolver_->Resolve(); |
| 98 } |
| 99 |
| 100 RemoveAttempt::RemoveAttempt(AuthAttemptState* current_attempt, |
| 101 AuthAttemptStateResolver* callback) |
| 102 : CryptohomeOp(current_attempt, callback) { |
| 103 } |
| 104 |
| 105 RemoveAttempt::~RemoveAttempt() {} |
| 106 |
| 107 bool RemoveAttempt::Initiate() { |
| 108 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 109 CryptohomeLibrary* lib = CrosLibrary::Get()->GetCryptohomeLibrary(); |
| 110 return lib->AsyncRemove(attempt_->username, this); |
| 111 } |
| 112 |
| 113 void RemoveAttempt::TriggerResolve(bool success, int return_code) { |
| 114 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
| 115 if (success) |
| 116 attempt_->ResetOfflineLoginStatus(); |
| 117 else |
| 118 attempt_->RecordOfflineLoginStatus(success, return_code); |
| 119 resolver_->Resolve(); |
| 120 } |
| 121 |
| 122 } // namespace chromeos |
OLD | NEW |