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