Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: components/gcm_driver/crypto/gcm_encryption_provider.cc

Issue 1231613005: Hook up the Push API with GCM's new ability to own encryption keys. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gcm-encryption
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/gcm_driver/crypto/gcm_encryption_provider.h"
6
7 #include "base/bind.h"
8 #include "base/logging.h"
9 #include "components/gcm_driver/crypto/gcm_key_store.h"
10 #include "components/gcm_driver/crypto/proto/gcm_encryption_data.pb.h"
11
12 namespace gcm {
13
14 // Directory in the GCM Store in which the encryption database will be stored.
15 const base::FilePath::CharType kEncryptionDirectoryName[] =
16 FILE_PATH_LITERAL("Encryption");
17
18 GCMEncryptionProvider::GCMEncryptionProvider()
19 : weak_ptr_factory_(this) {
20 }
21
22 GCMEncryptionProvider::~GCMEncryptionProvider() {
23 }
24
25 void GCMEncryptionProvider::Init(
26 const base::FilePath& store_path,
27 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner) {
28 DCHECK(!key_store_);
29
30 base::FilePath encryption_store_path = store_path;
31
32 // |store_path| can be empty in tests, which means that the database should
33 // be created in memory rather than on-disk.
34 if (!store_path.empty())
35 encryption_store_path = store_path.Append(kEncryptionDirectoryName);
36
37 key_store_ = new GCMKeyStore(encryption_store_path, blocking_task_runner);
38 }
39
40 void GCMEncryptionProvider::GetPublicKey(const std::string& app_id,
41 const PublicKeyCallback& callback) {
42 DCHECK(key_store_);
43 key_store_->GetKeys(
44 app_id, base::Bind(&GCMEncryptionProvider::DidGetPublicKey,
45 weak_ptr_factory_.GetWeakPtr(), app_id, callback));
46 }
47
48 void GCMEncryptionProvider::DidGetPublicKey(const std::string& app_id,
49 const PublicKeyCallback& callback,
50 const KeyPair& pair) {
51 if (!pair.IsInitialized()) {
52 key_store_->CreateKeys(
53 app_id, base::Bind(&GCMEncryptionProvider::DidCreatePublicKey,
54 weak_ptr_factory_.GetWeakPtr(), callback));
55 return;
56 }
57
58 DCHECK_EQ(KeyPair::ECDH_CURVE_25519, pair.type());
59 callback.Run(pair.public_key());
60 }
61
62 void GCMEncryptionProvider::DidCreatePublicKey(
63 const PublicKeyCallback& callback,
64 const KeyPair& pair) {
65 if (!pair.IsInitialized()) {
66 callback.Run(std::string());
67 return;
68 }
69
70 DCHECK_EQ(KeyPair::ECDH_CURVE_25519, pair.type());
71 callback.Run(pair.public_key());
72 }
73
74 } // namespace gcm
OLDNEW
« no previous file with comments | « components/gcm_driver/crypto/gcm_encryption_provider.h ('k') | components/gcm_driver/crypto/gcm_key_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698