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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: components/gcm_driver/crypto/gcm_encryption_provider.cc
diff --git a/components/gcm_driver/crypto/gcm_encryption_provider.cc b/components/gcm_driver/crypto/gcm_encryption_provider.cc
new file mode 100644
index 0000000000000000000000000000000000000000..52ee156133d35a810208dd0e0f6fabacd50a5512
--- /dev/null
+++ b/components/gcm_driver/crypto/gcm_encryption_provider.cc
@@ -0,0 +1,62 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/gcm_driver/crypto/gcm_encryption_provider.h"
+
+#include "base/bind.h"
+#include "base/logging.h"
+#include "components/gcm_driver/crypto/gcm_key_store.h"
+#include "components/gcm_driver/crypto/proto/gcm_encryption_data.pb.h"
+
+namespace gcm {
+
+GCMEncryptionProvider::GCMEncryptionProvider()
+ : weak_ptr_factory_(this) {
+}
+
+GCMEncryptionProvider::~GCMEncryptionProvider() {
+}
+
+void GCMEncryptionProvider::Init(
+ const base::FilePath& store_path,
+ const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner) {
+ DCHECK(!key_store_);
+ key_store_ = new GCMKeyStore(store_path, blocking_task_runner);
+}
+
+void GCMEncryptionProvider::GetPublicKey(const std::string& app_id,
+ const PublicKeyCallback& callback) {
+ DCHECK(key_store_);
+ key_store_->GetKeys(
+ app_id, base::Bind(&GCMEncryptionProvider::DidGetPublicKey,
+ weak_ptr_factory_.GetWeakPtr(), app_id, callback));
+}
+
+void GCMEncryptionProvider::DidGetPublicKey(const std::string& app_id,
+ const PublicKeyCallback& callback,
+ const KeyPair& pair) {
+ if (!pair.IsInitialized()) {
+ key_store_->CreateKeys(
+ app_id, base::Bind(&GCMEncryptionProvider::DidCreatePublicKey,
+ weak_ptr_factory_.GetWeakPtr(), callback));
+ return;
+ }
+
+ DCHECK_EQ(KeyPair::ECDH_CURVE_25519, pair.type());
+ callback.Run(pair.public_key());
+}
+
+void GCMEncryptionProvider::DidCreatePublicKey(
+ const PublicKeyCallback& callback,
+ const KeyPair& pair) {
+ if (!pair.IsInitialized()) {
+ callback.Run(std::string());
+ return;
+ }
+
+ DCHECK_EQ(KeyPair::ECDH_CURVE_25519, pair.type());
+ callback.Run(pair.public_key());
+}
+
+} // namespace gcm

Powered by Google App Engine
This is Rietveld 408576698