Index: chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h |
diff --git a/chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h b/chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..082d95f5480c13829645ab5a7a40d642020f9eb6 |
--- /dev/null |
+++ b/chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h |
@@ -0,0 +1,99 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_EASY_UNLOCK_EASY_UNLOCK_KEY_MANAGER_H_ |
+#define CHROME_BROWSER_CHROMEOS_LOGIN_EASY_UNLOCK_EASY_UNLOCK_KEY_MANAGER_H_ |
+ |
+#include <string> |
+#include <vector> |
+ |
+#include "base/callback.h" |
+#include "base/macros.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/memory/weak_ptr.h" |
+#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_create_keys_operation.h" |
+#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_get_keys_operation.h" |
+#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_remove_keys_operation.h" |
+#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_types.h" |
+ |
+namespace base { |
+class DictionaryValue; |
+class ListValue; |
+} |
+ |
+namespace chromeos { |
+ |
+class UserContext; |
+ |
+// A class to manage Easy unlock cryptohome keys. |
+class EasyUnlockKeyManager { |
+ public: |
+ typedef EasyUnlockCreateKeysOperation::CreateKeysCallback CreateKeysCallback; |
+ typedef EasyUnlockRemoveKeysOperation::RemoveKeysCallback RemoveKeysCallback; |
+ typedef EasyUnlockGetKeysOperation::GetKeysCallback GetDeviceDataListCallback; |
+ |
+ EasyUnlockKeyManager(); |
+ ~EasyUnlockKeyManager(); |
+ |
+ // Nukes existing Easy unlock keys and creates new ones for the given |
+ // |remote_devices| and the given |user_context|. |user_context| must have |
+ // secret to allow keys to be created. |
+ void CreateKeys(const UserContext& user_context, |
tbarzic
2014/09/09 19:32:21
I'd rename this to Refresh/Update keys
xiyuan
2014/09/09 20:25:31
Done.
|
+ const base::ListValue& remote_devices, |
+ const CreateKeysCallback& callback); |
+ |
+ // Remove all Easy unlock keys for the given |user_context|. |
+ void RemoveKeys(const UserContext& user_context, |
+ const RemoveKeysCallback& callback); |
+ |
+ // Retrieves the remote device data from cryptohome keys for the given |
+ // |user_context|. |
+ void GetDeviceDataList(const UserContext& user_context, |
+ const GetDeviceDataListCallback& callback); |
+ |
+ // Helpers to convert between DeivceData and remote device dictionary. Returns |
+ // false if the conversion fails. Note that EasyUnlockDeviceKeyData contains a |
+ // sub set of the remote device dictionary. |
+ static void DeviceDataToRemoteDeviceDictionary( |
tbarzic
2014/09/09 19:32:21
do these have to be public? If not we could make t
xiyuan
2014/09/09 20:25:31
Not needed for this CL. But we might need those he
|
+ const EasyUnlockDeviceKeyData& data, |
+ base::DictionaryValue* dict); |
+ static bool RemoteDeviceDictionaryToDeviceData( |
+ const base::DictionaryValue& dict, |
+ EasyUnlockDeviceKeyData* data); |
+ |
+ // Helpers to convert between EasyUnlockDeviceKeyDataList and remote devices |
+ // ListValue. |
+ static void DeviceDataListToRemoteDeviceList( |
+ const EasyUnlockDeviceKeyDataList& data_list, |
+ base::ListValue* device_list); |
+ static bool RemoteDeviceListToDeviceDataList( |
+ const base::ListValue& device_list, |
+ EasyUnlockDeviceKeyDataList* data_list); |
+ |
+ // Gets key label for the given key index. |
+ static std::string GetKeyLabel(int key_index); |
+ |
+ private: |
+ void OnKeysRemovedForCreateKeys(const CreateKeysCallback& callback, |
+ bool remove_success); |
+ void OnKeysCreated(const CreateKeysCallback& callback, bool create_success); |
+ |
+ void OnKeysRemoved(const RemoveKeysCallback& callback, bool remove_success); |
+ |
+ void OnKeysFetched(const GetDeviceDataListCallback& callback, |
+ bool fetch_success, |
+ const EasyUnlockDeviceKeyDataList& fetched_data); |
+ |
+ scoped_ptr<EasyUnlockCreateKeysOperation> create_keys_op_; |
+ scoped_ptr<EasyUnlockRemoveKeysOperation> remove_keys_op_; |
+ scoped_ptr<EasyUnlockGetKeysOperation> get_keys_op_; |
+ |
+ base::WeakPtrFactory<EasyUnlockKeyManager> weak_ptr_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(EasyUnlockKeyManager); |
+}; |
+ |
+} // namespace chromeos |
+ |
+#endif // CHROME_BROWSER_CHROMEOS_LOGIN_EASY_UNLOCK_EASY_UNLOCK_KEY_MANAGER_H_ |