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 <string> | |
9 #include <vector> | |
10 | |
11 #include "base/callback.h" | |
12 #include "base/macros.h" | |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/memory/weak_ptr.h" | |
15 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_create_keys_oper ation.h" | |
16 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_get_keys_operati on.h" | |
17 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_remove_keys_oper ation.h" | |
18 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_types.h" | |
19 | |
20 namespace base { | |
21 class DictionaryValue; | |
22 class ListValue; | |
23 } | |
24 | |
25 namespace chromeos { | |
26 | |
27 class UserContext; | |
28 | |
29 // A class to manage Easy unlock cryptohome keys. | |
30 class EasyUnlockKeyManager { | |
31 public: | |
32 typedef EasyUnlockCreateKeysOperation::CreateKeysCallback CreateKeysCallback; | |
33 typedef EasyUnlockRemoveKeysOperation::RemoveKeysCallback RemoveKeysCallback; | |
34 typedef EasyUnlockGetKeysOperation::GetKeysCallback GetDeviceDataListCallback; | |
35 | |
36 EasyUnlockKeyManager(); | |
37 ~EasyUnlockKeyManager(); | |
38 | |
39 // Nukes existing Easy unlock keys and creates new ones for the given | |
40 // |remote_devices| and the given |user_context|. |user_context| must have | |
41 // secret to allow keys to be created. | |
42 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.
| |
43 const base::ListValue& remote_devices, | |
44 const CreateKeysCallback& callback); | |
45 | |
46 // Remove all Easy unlock keys for the given |user_context|. | |
47 void RemoveKeys(const UserContext& user_context, | |
48 const RemoveKeysCallback& callback); | |
49 | |
50 // Retrieves the remote device data from cryptohome keys for the given | |
51 // |user_context|. | |
52 void GetDeviceDataList(const UserContext& user_context, | |
53 const GetDeviceDataListCallback& callback); | |
54 | |
55 // Helpers to convert between DeivceData and remote device dictionary. Returns | |
56 // false if the conversion fails. Note that EasyUnlockDeviceKeyData contains a | |
57 // sub set of the remote device dictionary. | |
58 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
| |
59 const EasyUnlockDeviceKeyData& data, | |
60 base::DictionaryValue* dict); | |
61 static bool RemoteDeviceDictionaryToDeviceData( | |
62 const base::DictionaryValue& dict, | |
63 EasyUnlockDeviceKeyData* data); | |
64 | |
65 // Helpers to convert between EasyUnlockDeviceKeyDataList and remote devices | |
66 // ListValue. | |
67 static void DeviceDataListToRemoteDeviceList( | |
68 const EasyUnlockDeviceKeyDataList& data_list, | |
69 base::ListValue* device_list); | |
70 static bool RemoteDeviceListToDeviceDataList( | |
71 const base::ListValue& device_list, | |
72 EasyUnlockDeviceKeyDataList* data_list); | |
73 | |
74 // Gets key label for the given key index. | |
75 static std::string GetKeyLabel(int key_index); | |
76 | |
77 private: | |
78 void OnKeysRemovedForCreateKeys(const CreateKeysCallback& callback, | |
79 bool remove_success); | |
80 void OnKeysCreated(const CreateKeysCallback& callback, bool create_success); | |
81 | |
82 void OnKeysRemoved(const RemoveKeysCallback& callback, bool remove_success); | |
83 | |
84 void OnKeysFetched(const GetDeviceDataListCallback& callback, | |
85 bool fetch_success, | |
86 const EasyUnlockDeviceKeyDataList& fetched_data); | |
87 | |
88 scoped_ptr<EasyUnlockCreateKeysOperation> create_keys_op_; | |
89 scoped_ptr<EasyUnlockRemoveKeysOperation> remove_keys_op_; | |
90 scoped_ptr<EasyUnlockGetKeysOperation> get_keys_op_; | |
91 | |
92 base::WeakPtrFactory<EasyUnlockKeyManager> weak_ptr_factory_; | |
93 | |
94 DISALLOW_COPY_AND_ASSIGN(EasyUnlockKeyManager); | |
95 }; | |
96 | |
97 } // namespace chromeos | |
98 | |
99 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_EASY_UNLOCK_EASY_UNLOCK_KEY_MANAGER_H_ | |
OLD | NEW |