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

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: 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 c5085d2d2bfd439cf98ec7d64f6f44259703f374..ee7418ffc824f9594168b78451cd9a3b6eb43448 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
@@ -30,76 +30,35 @@ const char kPermitTypeLicence[] = "licence";
} // namespace
EasyUnlockKeyManager::EasyUnlockKeyManager()
- : operation_id_(0),
- weak_ptr_factory_(this) {
+ : operation_in_progress_(false), 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());
-
EasyUnlockDeviceKeyDataList devices;
if (!RemoteDeviceListToDeviceDataList(remote_devices, &devices))
devices.clear();
- // Only one pending request.
- DCHECK(!HasPendingOperations());
- create_keys_op_.reset(new EasyUnlockCreateKeysOperation(
- user_context,
- 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(
+ make_scoped_ptr(new EasyUnlockRefreshKeysOperation(
+ user_context, devices,
+ base::Bind(&EasyUnlockKeyManager::OnKeysRefreshed,
+ weak_ptr_factory_.GetWeakPtr(), callback))));
+ RunNextOperation();
xiyuan 2014/12/17 00:23:14 What happens if there is a running operation? This
Tim Song 2014/12/17 02:05:14 Done. Sorry, I meant to check operation_in_progres
}
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(
+ make_scoped_ptr(new EasyUnlockGetKeysOperation(
+ user_context, base::Bind(&EasyUnlockKeyManager::OnKeysFetched,
+ weak_ptr_factory_.GetWeakPtr(), callback))));
+ RunNextOperation();
xiyuan 2014/12/17 00:23:14 same here.
Tim Song 2014/12/17 02:05:14 Done.
}
// static
@@ -181,64 +140,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())
- 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());
+void EasyUnlockKeyManager::RunNextOperation() {
+ // The front operation will be removed upon completion.
+ if (!write_operation_queue_.empty()) {
+ operation_in_progress_ = true;
+ write_operation_queue_.front()->Start();
+ } else if (!read_operation_queue_.empty()) {
+ operation_in_progress_ = true;
+ read_operation_queue_.front()->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();
+ operation_in_progress_ = false;
+ DCHECK(!write_operation_queue_.empty());
+ if (!write_operation_queue_.empty())
+ write_operation_queue_.pop_front();
+ 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();
+ operation_in_progress_ = false;
+ DCHECK(!read_operation_queue_.empty());
+ if (!read_operation_queue_.empty())
+ read_operation_queue_.pop_front();
+ RunNextOperation();
}
} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698