OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_get_keys_operati
on.h" | 5 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_get_keys_operati
on.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h" | 13 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h" |
| 14 #include "chromeos/dbus/cryptohome_client.h" |
| 15 #include "chromeos/dbus/dbus_thread_manager.h" |
14 #include "components/proximity_auth/logging/logging.h" | 16 #include "components/proximity_auth/logging/logging.h" |
15 #include "components/signin/core/account_id/account_id.h" | 17 #include "components/signin/core/account_id/account_id.h" |
16 #include "google_apis/gaia/gaia_auth_util.h" | 18 #include "google_apis/gaia/gaia_auth_util.h" |
17 | 19 |
18 namespace chromeos { | 20 namespace chromeos { |
19 | 21 |
20 EasyUnlockGetKeysOperation::EasyUnlockGetKeysOperation( | 22 EasyUnlockGetKeysOperation::EasyUnlockGetKeysOperation( |
21 const UserContext& user_context, | 23 const UserContext& user_context, |
22 const GetKeysCallback& callback) | 24 const GetKeysCallback& callback) |
23 : user_context_(user_context), | 25 : user_context_(user_context), |
24 callback_(callback), | 26 callback_(callback), |
25 key_index_(0), | 27 key_index_(0), |
26 weak_ptr_factory_(this) { | 28 weak_ptr_factory_(this) { |
27 } | 29 } |
28 | 30 |
29 EasyUnlockGetKeysOperation::~EasyUnlockGetKeysOperation() { | 31 EasyUnlockGetKeysOperation::~EasyUnlockGetKeysOperation() { |
30 } | 32 } |
31 | 33 |
32 void EasyUnlockGetKeysOperation::Start() { | 34 void EasyUnlockGetKeysOperation::Start() { |
| 35 // Register for asynchronous notification of cryptohome being ready. |
| 36 DBusThreadManager::Get()->GetCryptohomeClient()->WaitForServiceToBeAvailable( |
| 37 base::Bind(&EasyUnlockGetKeysOperation::OnCryptohomeAvailable, |
| 38 weak_ptr_factory_.GetWeakPtr())); |
| 39 } |
| 40 |
| 41 void EasyUnlockGetKeysOperation::OnCryptohomeAvailable(bool available) { |
| 42 if (!available) { |
| 43 PA_LOG(ERROR) << "Failed to wait for cryptohome to become available"; |
| 44 callback_.Run(false, EasyUnlockDeviceKeyDataList()); |
| 45 return; |
| 46 } |
| 47 |
| 48 // Start the asynchronous key fetch. |
33 // TODO(xiyuan): Use ListKeyEx. | 49 // TODO(xiyuan): Use ListKeyEx. |
34 key_index_ = 0; | 50 key_index_ = 0; |
35 GetKeyData(); | 51 GetKeyData(); |
36 } | 52 } |
37 | 53 |
38 void EasyUnlockGetKeysOperation::GetKeyData() { | 54 void EasyUnlockGetKeysOperation::GetKeyData() { |
39 const cryptohome::Identification id(user_context_.GetAccountId()); | 55 const cryptohome::Identification id(user_context_.GetAccountId()); |
40 cryptohome::HomedirMethods::GetInstance()->GetKeyDataEx( | 56 cryptohome::HomedirMethods::GetInstance()->GetKeyDataEx( |
41 id, | 57 id, |
42 EasyUnlockKeyManager::GetKeyLabel(key_index_), | 58 EasyUnlockKeyManager::GetKeyLabel(key_index_), |
43 base::Bind(&EasyUnlockGetKeysOperation::OnGetKeyData, | 59 base::Bind(&EasyUnlockGetKeysOperation::OnGetKeyData, |
44 weak_ptr_factory_.GetWeakPtr())); | 60 weak_ptr_factory_.GetWeakPtr())); |
45 | |
46 } | 61 } |
47 | 62 |
48 void EasyUnlockGetKeysOperation::OnGetKeyData( | 63 void EasyUnlockGetKeysOperation::OnGetKeyData( |
49 bool success, | 64 bool success, |
50 cryptohome::MountError return_code, | 65 cryptohome::MountError return_code, |
51 const std::vector<cryptohome::KeyDefinition>& key_definitions) { | 66 const std::vector<cryptohome::KeyDefinition>& key_definitions) { |
52 if (!success || key_definitions.empty()) { | 67 if (!success || key_definitions.empty()) { |
53 // MOUNT_ERROR_KEY_FAILURE is considered as success. Other error codes are | 68 // MOUNT_ERROR_KEY_FAILURE is considered as success. Other error codes are |
54 // treated as failures. | 69 // treated as failures. |
55 if (return_code == cryptohome::MOUNT_ERROR_NONE || | 70 if (return_code == cryptohome::MOUNT_ERROR_NONE || |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 << entry.name; | 130 << entry.name; |
116 } | 131 } |
117 } | 132 } |
118 devices_.push_back(device); | 133 devices_.push_back(device); |
119 | 134 |
120 ++key_index_; | 135 ++key_index_; |
121 GetKeyData(); | 136 GetKeyData(); |
122 } | 137 } |
123 | 138 |
124 } // namespace chromeos | 139 } // namespace chromeos |
OLD | NEW |