Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2833)

Unified Diff: chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.cc

Issue 808563004: Clean up Smart Lock cryptohome keys logic: (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use UserContext after create keys operation Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.cc
diff --git a/chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.cc b/chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.cc
index 33750f140b8cebac23f52221b0fc5310c1e76dec..a33cc5206c2e07128348c707dfc0fe4a6eefa07e 100644
--- a/chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.cc
+++ b/chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.cc
@@ -6,7 +6,7 @@
#include "base/bind.h"
#include "base/logging.h"
-#include "base/stl_util.h"
+#include "base/memory/scoped_ptr.h"
#include "base/strings/stringprintf.h"
#include "base/values.h"
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager.h"
@@ -32,21 +32,17 @@ const char kPermitTypeLicence[] = "licence";
} // namespace
EasyUnlockKeyManager::EasyUnlockKeyManager()
- : operation_id_(0),
+ : write_queue_deleter_(&write_operation_queue_),
+ read_queue_deleter_(&read_operation_queue_),
weak_ptr_factory_(this) {
}
EasyUnlockKeyManager::~EasyUnlockKeyManager() {
- STLDeleteContainerPairSecondPointers(get_keys_ops_.begin(),
- get_keys_ops_.end());
}
void EasyUnlockKeyManager::RefreshKeys(const UserContext& user_context,
const base::ListValue& remote_devices,
const RefreshKeysCallback& callback) {
- // Must have the secret.
- DCHECK(!user_context.GetKey()->GetSecret().empty());
-
base::Closure do_refresh_keys = base::Bind(
&EasyUnlockKeyManager::RefreshKeysWithTpmKeyPresent,
weak_ptr_factory_.GetWeakPtr(),
@@ -91,58 +87,20 @@ void EasyUnlockKeyManager::RefreshKeysWithTpmKeyPresent(
if (!RemoteDeviceListToDeviceDataList(*remote_devices, &devices))
devices.clear();
- // Only one pending request.
- DCHECK(!HasPendingOperations());
- create_keys_op_.reset(new EasyUnlockCreateKeysOperation(
- user_context,
- tpm_public_key,
- devices,
- base::Bind(&EasyUnlockKeyManager::OnKeysCreated,
- weak_ptr_factory_.GetWeakPtr(),
- devices.size(),
- callback)));
- create_keys_op_->Start();
-}
-
-void EasyUnlockKeyManager::RemoveKeys(const UserContext& user_context,
- size_t start_index,
- const RemoveKeysCallback& callback) {
- // Must have the secret.
- DCHECK(!user_context.GetKey()->GetSecret().empty());
- // Only one pending request.
- DCHECK(!HasPendingOperations());
-
- remove_keys_op_.reset(
- new EasyUnlockRemoveKeysOperation(
- user_context,
- start_index,
- base::Bind(&EasyUnlockKeyManager::OnKeysRemoved,
- weak_ptr_factory_.GetWeakPtr(),
- callback)));
- remove_keys_op_->Start();
+ write_operation_queue_.push_back(new EasyUnlockRefreshKeysOperation(
+ user_context, tpm_public_key, devices,
+ base::Bind(&EasyUnlockKeyManager::OnKeysRefreshed,
+ weak_ptr_factory_.GetWeakPtr(), callback)));
+ RunNextOperation();
}
void EasyUnlockKeyManager::GetDeviceDataList(
const UserContext& user_context,
const GetDeviceDataListCallback& callback) {
- // Defer the get operation if there is pending write operations.
- if (create_keys_op_ || remove_keys_op_) {
- pending_ops_.push_back(base::Bind(&EasyUnlockKeyManager::GetDeviceDataList,
- weak_ptr_factory_.GetWeakPtr(),
- user_context,
- callback));
- return;
- }
-
- const int op_id = GetNextOperationId();
- scoped_ptr<EasyUnlockGetKeysOperation> op(new EasyUnlockGetKeysOperation(
- user_context,
- base::Bind(&EasyUnlockKeyManager::OnKeysFetched,
- weak_ptr_factory_.GetWeakPtr(),
- op_id,
- callback)));
- op->Start();
- get_keys_ops_[op_id] = op.release();
+ read_operation_queue_.push_back(new EasyUnlockGetKeysOperation(
+ user_context, base::Bind(&EasyUnlockKeyManager::OnKeysFetched,
+ weak_ptr_factory_.GetWeakPtr(), callback)));
+ RunNextOperation();
}
// static
@@ -224,64 +182,41 @@ std::string EasyUnlockKeyManager::GetKeyLabel(size_t key_index) {
return base::StringPrintf("%s%zu", kKeyLabelPrefix, key_index);
}
-bool EasyUnlockKeyManager::HasPendingOperations() const {
- return create_keys_op_ || remove_keys_op_ || !get_keys_ops_.empty();
-}
-
-int EasyUnlockKeyManager::GetNextOperationId() {
- return ++operation_id_;
-}
-
-void EasyUnlockKeyManager::RunNextPendingOp() {
- if (pending_ops_.empty())
+void EasyUnlockKeyManager::RunNextOperation() {
+ if (pending_write_operation_ || pending_read_operation_)
return;
- pending_ops_.front().Run();
- pending_ops_.pop_front();
-}
-
-void EasyUnlockKeyManager::OnKeysCreated(
- size_t remove_start_index,
- const RefreshKeysCallback& callback,
- bool create_success) {
- scoped_ptr<EasyUnlockCreateKeysOperation> op = create_keys_op_.Pass();
- if (!callback.is_null())
- callback.Run(create_success);
-
- // Remove extra existing keys.
- RemoveKeys(op->user_context(), remove_start_index, RemoveKeysCallback());
+ if (!write_operation_queue_.empty()) {
+ pending_write_operation_ = make_scoped_ptr(write_operation_queue_.front());
+ write_operation_queue_.pop_front();
+ pending_write_operation_->Start();
+ } else if (!read_operation_queue_.empty()) {
+ pending_read_operation_ = make_scoped_ptr(read_operation_queue_.front());
+ read_operation_queue_.pop_front();
+ pending_read_operation_->Start();
+ }
}
-void EasyUnlockKeyManager::OnKeysRemoved(const RemoveKeysCallback& callback,
- bool remove_success) {
- scoped_ptr<EasyUnlockRemoveKeysOperation> op = remove_keys_op_.Pass();
+void EasyUnlockKeyManager::OnKeysRefreshed(const RefreshKeysCallback& callback,
+ bool refresh_success) {
if (!callback.is_null())
- callback.Run(remove_success);
+ callback.Run(refresh_success);
- if (!HasPendingOperations())
- RunNextPendingOp();
+ DCHECK(pending_write_operation_);
+ pending_write_operation_.reset();
+ RunNextOperation();
}
void EasyUnlockKeyManager::OnKeysFetched(
- int op_id,
const GetDeviceDataListCallback& callback,
bool fetch_success,
const EasyUnlockDeviceKeyDataList& fetched_data) {
- std::map<int, EasyUnlockGetKeysOperation*>::iterator it =
- get_keys_ops_.find(op_id);
- scoped_ptr<EasyUnlockGetKeysOperation> op;
- if (it != get_keys_ops_.end()) {
- op.reset(it->second);
- get_keys_ops_.erase(it);
- } else {
- NOTREACHED();
- }
-
if (!callback.is_null())
callback.Run(fetch_success, fetched_data);
- if (!HasPendingOperations())
- RunNextPendingOp();
+ DCHECK(pending_read_operation_);
+ pending_read_operation_.reset();
+ RunNextOperation();
}
} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698