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

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

Powered by Google App Engine
This is Rietveld 408576698