OLD | NEW |
---|---|
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/scoped_ptr.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_create_keys_oper ation.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 Loading... | |
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: |
85 // Returns true if there are pending operations. | 78 // Runs the next operation if there is one. We first run all the operations in |
86 bool HasPendingOperations() const; | 79 // the |write_operation_queue_| and then run all the operations in the |
80 // |read_operation_queue_|. | |
81 void RunNextOperation(); | |
87 | 82 |
88 // Returns the next operations id. Currently only used for get keys ops. | 83 // Callback invoked after refresh keys operation. |
89 int GetNextOperationId(); | 84 void OnKeysRefreshed(const RefreshKeysCallback& callback, |
90 | 85 bool create_success); |
91 // Runs the first pending op in |pending_ops_|. No-op if |pending_ops_| is | |
92 // emtpy. | |
93 void RunNextPendingOp(); | |
94 | |
95 // Callback invoked after create keys op. | |
96 void OnKeysCreated(size_t remove_start_index, | |
97 const RefreshKeysCallback& callback, | |
98 bool create_success); | |
99 | |
100 // Callback invoked after remove keys op. | |
101 void OnKeysRemoved(const RemoveKeysCallback& callback, bool remove_success); | |
102 | 86 |
103 // Callback invoked after get keys op. | 87 // Callback invoked after get keys op. |
104 void OnKeysFetched(int op_id, | 88 void OnKeysFetched(const GetDeviceDataListCallback& callback, |
105 const GetDeviceDataListCallback& callback, | |
106 bool fetch_success, | 89 bool fetch_success, |
107 const EasyUnlockDeviceKeyDataList& fetched_data); | 90 const EasyUnlockDeviceKeyDataList& fetched_data); |
108 | 91 |
109 int operation_id_; | 92 std::deque<scoped_ptr<EasyUnlockRefreshKeysOperation>> write_operation_queue_; |
110 | 93 std::deque<scoped_ptr<EasyUnlockGetKeysOperation>> read_operation_queue_; |
xiyuan
2014/12/17 00:23:14
Is it safe to put scoped_ptr in stl containers? Sh
Tim Song
2014/12/17 02:05:14
Hmm... I'm not sure how safe it is. There might be
| |
111 scoped_ptr<EasyUnlockCreateKeysOperation> create_keys_op_; | 94 bool operation_in_progress_; |
112 scoped_ptr<EasyUnlockRemoveKeysOperation> remove_keys_op_; | |
113 std::map<int, EasyUnlockGetKeysOperation*> get_keys_ops_; | |
114 | |
115 std::deque<base::Closure> pending_ops_; | |
116 | 95 |
117 base::WeakPtrFactory<EasyUnlockKeyManager> weak_ptr_factory_; | 96 base::WeakPtrFactory<EasyUnlockKeyManager> weak_ptr_factory_; |
118 | 97 |
119 DISALLOW_COPY_AND_ASSIGN(EasyUnlockKeyManager); | 98 DISALLOW_COPY_AND_ASSIGN(EasyUnlockKeyManager); |
120 }; | 99 }; |
121 | 100 |
122 } // namespace chromeos | 101 } // namespace chromeos |
123 | 102 |
124 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_EASY_UNLOCK_EASY_UNLOCK_KEY_MANAGER_H_ | 103 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_EASY_UNLOCK_EASY_UNLOCK_KEY_MANAGER_H_ |
OLD | NEW |