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 CreateKeysCallback; | |
tbarzic
2014/09/10 19:01:11
rename to RefreshKeysCallback
xiyuan
2014/09/10 20:37:13
Done.
| |
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 CreateKeysCallback& 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 int GetNextOperationId(); | |
84 | |
85 void OnKeysCreated(const UserContext& user_context, | |
86 const EasyUnlockDeviceKeyDataList& devices, | |
87 const CreateKeysCallback& callback, bool create_success); | |
88 | |
89 void OnKeysRemoved(const RemoveKeysCallback& callback, bool remove_success); | |
90 | |
91 void OnKeysFetched(int op_id, | |
92 const GetDeviceDataListCallback& callback, | |
93 bool fetch_success, | |
94 const EasyUnlockDeviceKeyDataList& fetched_data); | |
95 | |
96 int operation_id_; | |
97 | |
98 scoped_ptr<EasyUnlockCreateKeysOperation> create_keys_op_; | |
99 scoped_ptr<EasyUnlockRemoveKeysOperation> remove_keys_op_; | |
100 std::map<int, EasyUnlockGetKeysOperation*> get_keys_ops_; | |
101 | |
102 base::WeakPtrFactory<EasyUnlockKeyManager> weak_ptr_factory_; | |
103 | |
104 DISALLOW_COPY_AND_ASSIGN(EasyUnlockKeyManager); | |
105 }; | |
106 | |
107 } // namespace chromeos | |
108 | |
109 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_EASY_UNLOCK_EASY_UNLOCK_KEY_MANAGER_H_ | |
OLD | NEW |