OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 COMPONENTS_GCM_DRIVER_CRYPTO_GCM_KEY_STORE_H_ | 5 #ifndef COMPONENTS_GCM_DRIVER_CRYPTO_GCM_KEY_STORE_H_ |
6 #define COMPONENTS_GCM_DRIVER_CRYPTO_GCM_KEY_STORE_H_ | 6 #define COMPONENTS_GCM_DRIVER_CRYPTO_GCM_KEY_STORE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 // a background task runner. For this reason, all public APIs take a callback | 29 // a background task runner. For this reason, all public APIs take a callback |
30 // rather than returning the result. Do not rely on the timing of the callbacks. | 30 // rather than returning the result. Do not rely on the timing of the callbacks. |
31 // | 31 // |
32 // Started operations will be completed even after the reference to the store | 32 // Started operations will be completed even after the reference to the store |
33 // has been freed (asynchronous operations increase reference count to |this|). | 33 // has been freed (asynchronous operations increase reference count to |this|). |
34 class GCMKeyStore : public base::RefCounted<GCMKeyStore> { | 34 class GCMKeyStore : public base::RefCounted<GCMKeyStore> { |
35 public: | 35 public: |
36 using KeysCallback = base::Callback<void(const KeyPair& pair)>; | 36 using KeysCallback = base::Callback<void(const KeyPair& pair)>; |
37 using DeleteCallback = base::Callback<void(bool success)>; | 37 using DeleteCallback = base::Callback<void(bool success)>; |
38 | 38 |
39 GCMKeyStore(const base::FilePath& key_store_path, | 39 GCMKeyStore( |
40 scoped_refptr<base::SequencedTaskRunner> background_task_runner); | 40 const base::FilePath& key_store_path, |
| 41 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner); |
41 | 42 |
42 // Retrieves the public/private key-pair associated with |app_id|, and | 43 // Retrieves the public/private key-pair associated with |app_id|, and |
43 // invokes |callback| when they are available, or when an error occurred. | 44 // invokes |callback| when they are available, or when an error occurred. |
44 void GetKeys(const std::string& app_id, const KeysCallback& callback); | 45 void GetKeys(const std::string& app_id, const KeysCallback& callback); |
45 | 46 |
46 // Creates a new public/private key-pair for |app_id|, and invokes | 47 // Creates a new public/private key-pair for |app_id|, and invokes |
47 // |callback| when they are available, or when an error occurred. | 48 // |callback| when they are available, or when an error occurred. |
48 void CreateKeys(const std::string& app_id, const KeysCallback& callback); | 49 void CreateKeys(const std::string& app_id, const KeysCallback& callback); |
49 | 50 |
50 // Deletes the keys associated with |app_id|, and invokes |callback| when | 51 // Deletes the keys associated with |app_id|, and invokes |callback| when |
(...skipping 27 matching lines...) Expand all Loading... |
78 void GetKeysAfterInitialize(const std::string& app_id, | 79 void GetKeysAfterInitialize(const std::string& app_id, |
79 const KeysCallback& callback); | 80 const KeysCallback& callback); |
80 void CreateKeysAfterInitialize(const std::string& app_id, | 81 void CreateKeysAfterInitialize(const std::string& app_id, |
81 const KeysCallback& callback); | 82 const KeysCallback& callback); |
82 void DeleteKeysAfterInitialize(const std::string& app_id, | 83 void DeleteKeysAfterInitialize(const std::string& app_id, |
83 const DeleteCallback& callback); | 84 const DeleteCallback& callback); |
84 | 85 |
85 // Path in which the key store database will be saved. | 86 // Path in which the key store database will be saved. |
86 base::FilePath key_store_path_; | 87 base::FilePath key_store_path_; |
87 | 88 |
| 89 // Blocking task runner which the database will do I/O operations on. |
| 90 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
| 91 |
88 // Instance of the ProtoDatabase backing the key store. | 92 // Instance of the ProtoDatabase backing the key store. |
89 scoped_ptr<leveldb_proto::ProtoDatabase<EncryptionData>> database_; | 93 scoped_ptr<leveldb_proto::ProtoDatabase<EncryptionData>> database_; |
90 | 94 |
91 enum class State; | 95 enum class State; |
92 | 96 |
93 // The current state of the database. It has to be initialized before use. | 97 // The current state of the database. It has to be initialized before use. |
94 State state_; | 98 State state_; |
95 | 99 |
96 // Controller for tasks that should be executed once the key store has | 100 // Controller for tasks that should be executed once the key store has |
97 // finished initializing. | 101 // finished initializing. |
98 GCMDelayedTaskController delayed_task_controller_; | 102 GCMDelayedTaskController delayed_task_controller_; |
99 | 103 |
100 // Mapping of an app id to the loaded EncryptedData structure. | 104 // Mapping of an app id to the loaded EncryptedData structure. |
101 std::map<std::string, KeyPair> key_pairs_; | 105 std::map<std::string, KeyPair> key_pairs_; |
102 | 106 |
103 DISALLOW_COPY_AND_ASSIGN(GCMKeyStore); | 107 DISALLOW_COPY_AND_ASSIGN(GCMKeyStore); |
104 }; | 108 }; |
105 | 109 |
106 } // namespace gcm | 110 } // namespace gcm |
107 | 111 |
108 #endif // COMPONENTS_GCM_DRIVER_CRYPTO_GCM_KEY_STORE_H_ | 112 #endif // COMPONENTS_GCM_DRIVER_CRYPTO_GCM_KEY_STORE_H_ |
OLD | NEW |