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

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: comments + win fix Created 5 years, 5 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 GCMEncryptionProvider::GCMEncryptionProvider()
15 : weak_ptr_factory_(this) {
16 }
17
18 GCMEncryptionProvider::~GCMEncryptionProvider() {
19 }
20
21 void GCMEncryptionProvider::Init(
22 const base::FilePath& store_path,
23 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner) {
24 DCHECK(!key_store_);
25 key_store_ = new GCMKeyStore(store_path, blocking_task_runner);
26 }
27
28 void GCMEncryptionProvider::GetPublicKey(const std::string& app_id,
29 const PublicKeyCallback& callback) {
30 DCHECK(key_store_);
31 key_store_->GetKeys(
32 app_id, base::Bind(&GCMEncryptionProvider::DidGetPublicKey,
33 weak_ptr_factory_.GetWeakPtr(), app_id, callback));
34 }
35
36 void GCMEncryptionProvider::DidGetPublicKey(const std::string& app_id,
37 const PublicKeyCallback& callback,
38 const KeyPair& pair) {
39 if (!pair.IsInitialized()) {
40 key_store_->CreateKeys(
41 app_id, base::Bind(&GCMEncryptionProvider::DidCreatePublicKey,
42 weak_ptr_factory_.GetWeakPtr(), callback));
43 return;
44 }
45
46 DCHECK_EQ(KeyPair::ECDH_CURVE_25519, pair.type());
47 callback.Run(pair.public_key());
48 }
49
50 void GCMEncryptionProvider::DidCreatePublicKey(
51 const PublicKeyCallback& callback,
52 const KeyPair& pair) {
53 if (!pair.IsInitialized()) {
54 callback.Run(std::string());
55 return;
56 }
57
58 DCHECK_EQ(KeyPair::ECDH_CURVE_25519, pair.type());
59 callback.Run(pair.public_key());
60 }
61
62 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698