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 #include "components/gcm_driver/crypto/gcm_key_store.h" | 5 #include "components/gcm_driver/crypto/gcm_key_store.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "components/leveldb_proto/proto_database_impl.h" | 10 #include "components/leveldb_proto/proto_database_impl.h" |
11 #include "crypto/curve25519.h" | 11 #include "crypto/curve25519.h" |
12 #include "crypto/random.h" | 12 #include "crypto/random.h" |
13 | 13 |
14 namespace gcm { | 14 namespace gcm { |
15 | 15 |
16 enum class GCMKeyStore::State { | 16 enum class GCMKeyStore::State { |
17 UNINITIALIZED, | 17 UNINITIALIZED, |
18 INITIALIZING, | 18 INITIALIZING, |
19 INITIALIZED, | 19 INITIALIZED, |
20 FAILED | 20 FAILED |
21 }; | 21 }; |
22 | 22 |
23 GCMKeyStore::GCMKeyStore( | 23 GCMKeyStore::GCMKeyStore( |
24 const base::FilePath& key_store_path, | 24 const base::FilePath& key_store_path, |
25 scoped_refptr<base::SequencedTaskRunner> background_task_runner) | 25 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner) |
26 : key_store_path_(key_store_path), | 26 : key_store_path_(key_store_path), |
27 database_(new leveldb_proto::ProtoDatabaseImpl<EncryptionData>( | 27 blocking_task_runner_(blocking_task_runner), |
28 background_task_runner)), | |
29 state_(State::UNINITIALIZED) { | 28 state_(State::UNINITIALIZED) { |
30 } | 29 } |
31 | 30 |
32 GCMKeyStore::~GCMKeyStore() {} | 31 GCMKeyStore::~GCMKeyStore() {} |
33 | 32 |
34 void GCMKeyStore::GetKeys(const std::string& app_id, | 33 void GCMKeyStore::GetKeys(const std::string& app_id, |
35 const KeysCallback& callback) { | 34 const KeysCallback& callback) { |
36 LazyInitialize(base::Bind(&GCMKeyStore::GetKeysAfterInitialize, this, app_id, | 35 LazyInitialize(base::Bind(&GCMKeyStore::GetKeysAfterInitialize, this, app_id, |
37 callback)); | 36 callback)); |
38 } | 37 } |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 done_closure.Run(); | 160 done_closure.Run(); |
162 return; | 161 return; |
163 } | 162 } |
164 | 163 |
165 delayed_task_controller_.AddTask(done_closure); | 164 delayed_task_controller_.AddTask(done_closure); |
166 if (state_ == State::INITIALIZING) | 165 if (state_ == State::INITIALIZING) |
167 return; | 166 return; |
168 | 167 |
169 state_ = State::INITIALIZING; | 168 state_ = State::INITIALIZING; |
170 | 169 |
170 DCHECK(blocking_task_runner_); | |
jianli
2015/07/17 20:55:21
This DCHECK should be moved to constructor.
Peter Beverloo
2015/07/20 17:55:53
Done.
| |
171 database_.reset(new leveldb_proto::ProtoDatabaseImpl<EncryptionData>( | |
172 blocking_task_runner_)); | |
173 | |
171 database_->Init(key_store_path_, | 174 database_->Init(key_store_path_, |
172 base::Bind(&GCMKeyStore::DidInitialize, this)); | 175 base::Bind(&GCMKeyStore::DidInitialize, this)); |
173 } | 176 } |
174 | 177 |
175 void GCMKeyStore::DidInitialize(bool success) { | 178 void GCMKeyStore::DidInitialize(bool success) { |
176 if (!success) { | 179 if (!success) { |
177 DVLOG(1) << "Unable to initialize the GCM Key Store."; | 180 DVLOG(1) << "Unable to initialize the GCM Key Store."; |
178 state_ = State::FAILED; | 181 state_ = State::FAILED; |
179 | 182 |
180 delayed_task_controller_.SetReady(); | 183 delayed_task_controller_.SetReady(); |
(...skipping 17 matching lines...) Expand all Loading... | |
198 DCHECK_EQ(1, entry.keys_size()); | 201 DCHECK_EQ(1, entry.keys_size()); |
199 key_pairs_[entry.app_id()] = entry.keys(0); | 202 key_pairs_[entry.app_id()] = entry.keys(0); |
200 } | 203 } |
201 | 204 |
202 state_ = State::INITIALIZED; | 205 state_ = State::INITIALIZED; |
203 | 206 |
204 delayed_task_controller_.SetReady(); | 207 delayed_task_controller_.SetReady(); |
205 } | 208 } |
206 | 209 |
207 } // namespace gcm | 210 } // namespace gcm |
OLD | NEW |