OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 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_ |
| 7 |
| 8 #include <map> |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/callback.h" |
| 13 #include "base/macros.h" |
| 14 #include "base/memory/scoped_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" |
| 18 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_remove_keys_oper
ation.h" |
| 19 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_types.h" |
| 20 |
| 21 namespace base { |
| 22 class DictionaryValue; |
| 23 class ListValue; |
| 24 } |
| 25 |
| 26 namespace chromeos { |
| 27 |
| 28 class UserContext; |
| 29 |
| 30 // A class to manage Easy unlock cryptohome keys. |
| 31 class EasyUnlockKeyManager { |
| 32 public: |
| 33 typedef EasyUnlockCreateKeysOperation::CreateKeysCallback RefreshKeysCallback; |
| 34 typedef EasyUnlockRemoveKeysOperation::RemoveKeysCallback RemoveKeysCallback; |
| 35 typedef EasyUnlockGetKeysOperation::GetKeysCallback GetDeviceDataListCallback; |
| 36 |
| 37 EasyUnlockKeyManager(); |
| 38 ~EasyUnlockKeyManager(); |
| 39 |
| 40 // Nukes existing Easy unlock keys and creates new ones for the given |
| 41 // |remote_devices| and the given |user_context|. |user_context| must have |
| 42 // secret to allow keys to be created. |
| 43 void RefreshKeys(const UserContext& user_context, |
| 44 const base::ListValue& remote_devices, |
| 45 const RefreshKeysCallback& callback); |
| 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 |
| 53 // Retrieves the remote device data from cryptohome keys for the given |
| 54 // |user_context|. |
| 55 void GetDeviceDataList(const UserContext& user_context, |
| 56 const GetDeviceDataListCallback& callback); |
| 57 |
| 58 // Helpers to convert between DeviceData and remote device dictionary. |
| 59 // DeviceDataToRemoteDeviceDictionary fills the remote device dictionary and |
| 60 // always succeeds. RemoteDeviceDictionaryToDeviceData returns false if the |
| 61 // conversion fails (missing required propery). Note that |
| 62 // EasyUnlockDeviceKeyData contains a sub set of the remote device dictionary. |
| 63 static void DeviceDataToRemoteDeviceDictionary( |
| 64 const EasyUnlockDeviceKeyData& data, |
| 65 base::DictionaryValue* dict); |
| 66 static bool RemoteDeviceDictionaryToDeviceData( |
| 67 const base::DictionaryValue& dict, |
| 68 EasyUnlockDeviceKeyData* data); |
| 69 |
| 70 // Helpers to convert between EasyUnlockDeviceKeyDataList and remote devices |
| 71 // ListValue. |
| 72 static void DeviceDataListToRemoteDeviceList( |
| 73 const EasyUnlockDeviceKeyDataList& data_list, |
| 74 base::ListValue* device_list); |
| 75 static bool RemoteDeviceListToDeviceDataList( |
| 76 const base::ListValue& device_list, |
| 77 EasyUnlockDeviceKeyDataList* data_list); |
| 78 |
| 79 // Gets key label for the given key index. |
| 80 static std::string GetKeyLabel(size_t key_index); |
| 81 |
| 82 private: |
| 83 // Returns true if there are pending operations. |
| 84 bool HasPendingOperations() const; |
| 85 |
| 86 // Returns the next operations id. Currently only used for get keys ops. |
| 87 int GetNextOperationId(); |
| 88 |
| 89 // Callback invoked after create keys op. |
| 90 void OnKeysCreated(const UserContext& user_context, |
| 91 const EasyUnlockDeviceKeyDataList& devices, |
| 92 const RefreshKeysCallback& callback, |
| 93 bool create_success); |
| 94 |
| 95 // Callback invoked after remove keys op. |
| 96 void OnKeysRemoved(const RemoveKeysCallback& callback, bool remove_success); |
| 97 |
| 98 // Callback invoked after get keys op. |
| 99 void OnKeysFetched(int op_id, |
| 100 const GetDeviceDataListCallback& callback, |
| 101 bool fetch_success, |
| 102 const EasyUnlockDeviceKeyDataList& fetched_data); |
| 103 |
| 104 int operation_id_; |
| 105 |
| 106 scoped_ptr<EasyUnlockCreateKeysOperation> create_keys_op_; |
| 107 scoped_ptr<EasyUnlockRemoveKeysOperation> remove_keys_op_; |
| 108 std::map<int, EasyUnlockGetKeysOperation*> get_keys_ops_; |
| 109 |
| 110 base::WeakPtrFactory<EasyUnlockKeyManager> weak_ptr_factory_; |
| 111 |
| 112 DISALLOW_COPY_AND_ASSIGN(EasyUnlockKeyManager); |
| 113 }; |
| 114 |
| 115 } // namespace chromeos |
| 116 |
| 117 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_EASY_UNLOCK_EASY_UNLOCK_KEY_MANAGER_H_ |
OLD | NEW |