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

Side by Side Diff: chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h

Issue 789793005: Revert of Clean up Smart Lock cryptohome keys logic: (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 12 months 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 unified diff | Download patch
OLDNEW
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 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_EASY_UNLOCK_EASY_UNLOCK_KEY_MANAGER_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_EASY_UNLOCK_EASY_UNLOCK_KEY_MANAGER_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_EASY_UNLOCK_EASY_UNLOCK_KEY_MANAGER_H_ 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_EASY_UNLOCK_EASY_UNLOCK_KEY_MANAGER_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
11 11
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
15 #include "base/stl_util.h" 16 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_create_keys_oper ation.h"
16 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_get_keys_operati on.h" 17 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_get_keys_operati on.h"
17 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_refresh_keys_ope ration.h" 18 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_remove_keys_oper ation.h"
18 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_types.h" 19 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_types.h"
19 20
20 namespace base { 21 namespace base {
21 class DictionaryValue; 22 class DictionaryValue;
22 class ListValue; 23 class ListValue;
23 } 24 }
24 25
25 namespace chromeos { 26 namespace chromeos {
26 27
27 class UserContext; 28 class UserContext;
28 29
29 // A class to manage Easy unlock cryptohome keys. 30 // A class to manage Easy unlock cryptohome keys.
30 class EasyUnlockKeyManager { 31 class EasyUnlockKeyManager {
31 public: 32 public:
32 typedef EasyUnlockRefreshKeysOperation::RefreshKeysCallback 33 typedef EasyUnlockCreateKeysOperation::CreateKeysCallback RefreshKeysCallback;
33 RefreshKeysCallback; 34 typedef EasyUnlockRemoveKeysOperation::RemoveKeysCallback RemoveKeysCallback;
34 typedef EasyUnlockGetKeysOperation::GetKeysCallback GetDeviceDataListCallback; 35 typedef EasyUnlockGetKeysOperation::GetKeysCallback GetDeviceDataListCallback;
35 36
36 EasyUnlockKeyManager(); 37 EasyUnlockKeyManager();
37 ~EasyUnlockKeyManager(); 38 ~EasyUnlockKeyManager();
38 39
39 // Nukes existing Easy unlock keys and creates new ones for the given 40 // Nukes existing Easy unlock keys and creates new ones for the given
40 // |remote_devices| and the given |user_context|. |user_context| must have 41 // |remote_devices| and the given |user_context|. |user_context| must have
41 // secret to allow keys to be created. 42 // secret to allow keys to be created.
42 void RefreshKeys(const UserContext& user_context, 43 void RefreshKeys(const UserContext& user_context,
43 const base::ListValue& remote_devices, 44 const base::ListValue& remote_devices,
44 const RefreshKeysCallback& callback); 45 const RefreshKeysCallback& callback);
45 46
47 // Remove Easy unlock keys starting at the given index for the given
48 // |user_context|.
49 void RemoveKeys(const UserContext& user_context,
50 size_t start_index,
51 const RemoveKeysCallback& callback);
52
46 // Retrieves the remote device data from cryptohome keys for the given 53 // Retrieves the remote device data from cryptohome keys for the given
47 // |user_context|. 54 // |user_context|.
48 void GetDeviceDataList(const UserContext& user_context, 55 void GetDeviceDataList(const UserContext& user_context,
49 const GetDeviceDataListCallback& callback); 56 const GetDeviceDataListCallback& callback);
50 57
51 // Helpers to convert between DeviceData and remote device dictionary. 58 // Helpers to convert between DeviceData and remote device dictionary.
52 // DeviceDataToRemoteDeviceDictionary fills the remote device dictionary and 59 // DeviceDataToRemoteDeviceDictionary fills the remote device dictionary and
53 // always succeeds. RemoteDeviceDictionaryToDeviceData returns false if the 60 // always succeeds. RemoteDeviceDictionaryToDeviceData returns false if the
54 // conversion fails (missing required propery). Note that 61 // conversion fails (missing required propery). Note that
55 // EasyUnlockDeviceKeyData contains a sub set of the remote device dictionary. 62 // EasyUnlockDeviceKeyData contains a sub set of the remote device dictionary.
(...skipping 12 matching lines...) Expand all
68 const EasyUnlockDeviceKeyDataList& data_list, 75 const EasyUnlockDeviceKeyDataList& data_list,
69 base::ListValue* device_list); 76 base::ListValue* device_list);
70 static bool RemoteDeviceListToDeviceDataList( 77 static bool RemoteDeviceListToDeviceDataList(
71 const base::ListValue& device_list, 78 const base::ListValue& device_list,
72 EasyUnlockDeviceKeyDataList* data_list); 79 EasyUnlockDeviceKeyDataList* data_list);
73 80
74 // Gets key label for the given key index. 81 // Gets key label for the given key index.
75 static std::string GetKeyLabel(size_t key_index); 82 static std::string GetKeyLabel(size_t key_index);
76 83
77 private: 84 private:
78 // Runs the next operation if there is one. We first run all the operations in
79 // the |write_operation_queue_| and then run all the operations in the
80 // |read_operation_queue_|.
81 void RunNextOperation();
82
83 // Called when the TPM key is ready to be used for creating Easy Unlock key
84 // challenges.
85 void RefreshKeysWithTpmKeyPresent(const UserContext& user_context, 85 void RefreshKeysWithTpmKeyPresent(const UserContext& user_context,
86 base::ListValue* remote_devices, 86 base::ListValue* remote_devices,
87 const RefreshKeysCallback& callback); 87 const RefreshKeysCallback& callback);
88 88
89 // Returns true if there are pending operations. 89 // Returns true if there are pending operations.
90 bool HasPendingOperations() const; 90 bool HasPendingOperations() const;
91 91
92 // Callback invoked after refresh keys operation. 92 // Returns the next operations id. Currently only used for get keys ops.
93 void OnKeysRefreshed(const RefreshKeysCallback& callback, 93 int GetNextOperationId();
94 bool create_success); 94
95 // Runs the first pending op in |pending_ops_|. No-op if |pending_ops_| is
96 // emtpy.
97 void RunNextPendingOp();
98
99 // Callback invoked after create keys op.
100 void OnKeysCreated(size_t remove_start_index,
101 const RefreshKeysCallback& callback,
102 bool create_success);
103
104 // Callback invoked after remove keys op.
105 void OnKeysRemoved(const RemoveKeysCallback& callback, bool remove_success);
95 106
96 // Callback invoked after get keys op. 107 // Callback invoked after get keys op.
97 void OnKeysFetched(const GetDeviceDataListCallback& callback, 108 void OnKeysFetched(int op_id,
109 const GetDeviceDataListCallback& callback,
98 bool fetch_success, 110 bool fetch_success,
99 const EasyUnlockDeviceKeyDataList& fetched_data); 111 const EasyUnlockDeviceKeyDataList& fetched_data);
100 112
101 // Queued operations are stored as raw pointers, as scoped_ptrs may not behave 113 int operation_id_;
102 // nicely with std::deque.
103 using WriteOperationQueue = std::deque<EasyUnlockRefreshKeysOperation*>;
104 using ReadOperationQueue = std::deque<EasyUnlockGetKeysOperation*>;
105 WriteOperationQueue write_operation_queue_;
106 ReadOperationQueue read_operation_queue_;
107 114
108 // Scopes the raw operation pointers to the lifetime of this object. 115 scoped_ptr<EasyUnlockCreateKeysOperation> create_keys_op_;
109 STLElementDeleter<WriteOperationQueue> write_queue_deleter_; 116 scoped_ptr<EasyUnlockRemoveKeysOperation> remove_keys_op_;
110 STLElementDeleter<ReadOperationQueue> read_queue_deleter_; 117 std::map<int, EasyUnlockGetKeysOperation*> get_keys_ops_;
111 118
112 // Stores the current operation in progress. At most one of these variables 119 std::deque<base::Closure> pending_ops_;
113 // can be non-null at any time.
114 scoped_ptr<EasyUnlockRefreshKeysOperation> pending_write_operation_;
115 scoped_ptr<EasyUnlockGetKeysOperation> pending_read_operation_;
116 120
117 base::WeakPtrFactory<EasyUnlockKeyManager> weak_ptr_factory_; 121 base::WeakPtrFactory<EasyUnlockKeyManager> weak_ptr_factory_;
118 122
119 DISALLOW_COPY_AND_ASSIGN(EasyUnlockKeyManager); 123 DISALLOW_COPY_AND_ASSIGN(EasyUnlockKeyManager);
120 }; 124 };
121 125
122 } // namespace chromeos 126 } // namespace chromeos
123 127
124 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_EASY_UNLOCK_EASY_UNLOCK_KEY_MANAGER_H_ 128 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_EASY_UNLOCK_EASY_UNLOCK_KEY_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698