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

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

Issue 808563004: Clean up Smart Lock cryptohome keys logic: (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes 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.h
diff --git a/chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h b/chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h
index ebe9c3fba162fcdf9bef9551b82d9a5406b3e478..9d838753c09b2047c39b698f42303f3e2f24dd06 100644
--- a/chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h
+++ b/chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h
@@ -11,11 +11,10 @@
#include "base/callback.h"
#include "base/macros.h"
-#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
-#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_create_keys_operation.h"
+#include "base/stl_util.h"
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_get_keys_operation.h"
-#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_remove_keys_operation.h"
+#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_refresh_keys_operation.h"
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_types.h"
namespace base {
@@ -30,8 +29,8 @@ class UserContext;
// A class to manage Easy unlock cryptohome keys.
class EasyUnlockKeyManager {
public:
- typedef EasyUnlockCreateKeysOperation::CreateKeysCallback RefreshKeysCallback;
- typedef EasyUnlockRemoveKeysOperation::RemoveKeysCallback RemoveKeysCallback;
+ typedef EasyUnlockRefreshKeysOperation::RefreshKeysCallback
+ RefreshKeysCallback;
typedef EasyUnlockGetKeysOperation::GetKeysCallback GetDeviceDataListCallback;
EasyUnlockKeyManager();
@@ -44,12 +43,6 @@ class EasyUnlockKeyManager {
const base::ListValue& remote_devices,
const RefreshKeysCallback& callback);
- // Remove Easy unlock keys starting at the given index for the given
- // |user_context|.
- void RemoveKeys(const UserContext& user_context,
- size_t start_index,
- const RemoveKeysCallback& callback);
-
// Retrieves the remote device data from cryptohome keys for the given
// |user_context|.
void GetDeviceDataList(const UserContext& user_context,
@@ -82,6 +75,13 @@ class EasyUnlockKeyManager {
static std::string GetKeyLabel(size_t key_index);
private:
+ // Runs the next operation if there is one. We first run all the operations in
+ // the |write_operation_queue_| and then run all the operations in the
+ // |read_operation_queue_|.
+ void RunNextOperation();
+
+ // Called when the TPM key is ready to be used for creating Easy Unlock key
+ // challenges.
void RefreshKeysWithTpmKeyPresent(const UserContext& user_context,
base::ListValue* remote_devices,
const RefreshKeysCallback& callback);
@@ -89,34 +89,30 @@ class EasyUnlockKeyManager {
// Returns true if there are pending operations.
bool HasPendingOperations() const;
- // Returns the next operations id. Currently only used for get keys ops.
- int GetNextOperationId();
-
- // Runs the first pending op in |pending_ops_|. No-op if |pending_ops_| is
- // emtpy.
- void RunNextPendingOp();
-
- // Callback invoked after create keys op.
- void OnKeysCreated(size_t remove_start_index,
- const RefreshKeysCallback& callback,
- bool create_success);
-
- // Callback invoked after remove keys op.
- void OnKeysRemoved(const RemoveKeysCallback& callback, bool remove_success);
+ // Callback invoked after refresh keys operation.
+ void OnKeysRefreshed(const RefreshKeysCallback& callback,
+ bool create_success);
// Callback invoked after get keys op.
- void OnKeysFetched(int op_id,
- const GetDeviceDataListCallback& callback,
+ void OnKeysFetched(const GetDeviceDataListCallback& callback,
bool fetch_success,
const EasyUnlockDeviceKeyDataList& fetched_data);
- int operation_id_;
-
- scoped_ptr<EasyUnlockCreateKeysOperation> create_keys_op_;
- scoped_ptr<EasyUnlockRemoveKeysOperation> remove_keys_op_;
- std::map<int, EasyUnlockGetKeysOperation*> get_keys_ops_;
-
- std::deque<base::Closure> pending_ops_;
+ // Queued operations are stored as raw pointers, as scoped_ptrs may not behave
+ // nicely with std::deque.
+ using WriteOperationQueue = std::deque<EasyUnlockRefreshKeysOperation*>;
+ using ReadOperationQueue = std::deque<EasyUnlockGetKeysOperation*>;
+ WriteOperationQueue write_operation_queue_;
+ ReadOperationQueue read_operation_queue_;
+
+ // Scopes the raw operation pointers to the lifetime of this object.
+ STLElementDeleter<WriteOperationQueue> write_queue_deleter_;
+ STLElementDeleter<ReadOperationQueue> read_queue_deleter_;
+
+ // Stores the current operation in progress. At most one of these variables
+ // can be non-null at any time.
+ scoped_ptr<EasyUnlockRefreshKeysOperation> pending_write_operation_;
+ scoped_ptr<EasyUnlockGetKeysOperation> pending_read_operation_;
base::WeakPtrFactory<EasyUnlockKeyManager> weak_ptr_factory_;

Powered by Google App Engine
This is Rietveld 408576698