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

Side by Side Diff: components/gcm_driver/gcm_driver.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, 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/gcm_driver.h" 5 #include "components/gcm_driver/gcm_driver.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_path.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "components/gcm_driver/gcm_app_handler.h" 12 #include "components/gcm_driver/gcm_app_handler.h"
12 13
13 namespace gcm { 14 namespace gcm {
14 15
15 namespace {
16 const size_t kMaxSenders = 100; 16 const size_t kMaxSenders = 100;
17 } // namespace 17
18 const char kEncryptionDirectoryName[] = "Encryption";
jianli 2015/07/17 20:55:21 Should this be defined in chrome/common/chrome_con
Peter Beverloo 2015/07/20 17:55:53 This is an implementation detail - chrome_constant
18 19
19 InstanceIDHandler::InstanceIDHandler() { 20 InstanceIDHandler::InstanceIDHandler() {
20 } 21 }
21 22
22 InstanceIDHandler::~InstanceIDHandler() { 23 InstanceIDHandler::~InstanceIDHandler() {
23 } 24 }
24 25
25 void InstanceIDHandler::DeleteAllTokensForApp( 26 void InstanceIDHandler::DeleteAllTokensForApp(
26 const std::string& app_id, const DeleteTokenCallback& callback) { 27 const std::string& app_id, const DeleteTokenCallback& callback) {
27 DeleteToken(app_id, "*", "*", callback); 28 DeleteToken(app_id, "*", "*", callback);
28 } 29 }
29 30
30 GCMDriver::GCMDriver() : weak_ptr_factory_(this) { 31 GCMDriver::GCMDriver(
32 const base::FilePath& store_path,
33 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner)
34 : encryption_handler_(store_path.Append(kEncryptionDirectoryName),
35 blocking_task_runner),
36 weak_ptr_factory_(this) {
31 } 37 }
32 38
33 GCMDriver::~GCMDriver() { 39 GCMDriver::~GCMDriver() {
34 } 40 }
35 41
36 void GCMDriver::Register(const std::string& app_id, 42 void GCMDriver::Register(const std::string& app_id,
37 const std::vector<std::string>& sender_ids, 43 const std::vector<std::string>& sender_ids,
38 const RegisterCallback& callback) { 44 const RegisterCallback& callback) {
39 DCHECK(!app_id.empty()); 45 DCHECK(!app_id.empty());
40 DCHECK(!sender_ids.empty() && sender_ids.size() <= kMaxSenders); 46 DCHECK(!sender_ids.empty() && sender_ids.size() <= kMaxSenders);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 if (send_callbacks_.find(key) != send_callbacks_.end()) { 148 if (send_callbacks_.find(key) != send_callbacks_.end()) {
143 callback.Run(message.id, GCMClient::INVALID_PARAMETER); 149 callback.Run(message.id, GCMClient::INVALID_PARAMETER);
144 return; 150 return;
145 } 151 }
146 152
147 send_callbacks_[key] = callback; 153 send_callbacks_[key] = callback;
148 154
149 SendImpl(app_id, receiver_id, message); 155 SendImpl(app_id, receiver_id, message);
150 } 156 }
151 157
158 void GCMDriver::GetPublicEncryptionKey(
159 const std::string& app_id,
160 const GCMEncryptionHandler::KeyCallback& callback) {
161 encryption_handler_.GetPublicEncryptionKey(app_id, callback);
162 }
163
152 void GCMDriver::UnregisterWithSenderIdImpl(const std::string& app_id, 164 void GCMDriver::UnregisterWithSenderIdImpl(const std::string& app_id,
153 const std::string& sender_id) { 165 const std::string& sender_id) {
154 NOTREACHED(); 166 NOTREACHED();
155 } 167 }
156 168
157 void GCMDriver::RegisterFinished(const std::string& app_id, 169 void GCMDriver::RegisterFinished(const std::string& app_id,
158 const std::string& registration_id, 170 const std::string& registration_id,
159 GCMClient::Result result) { 171 GCMClient::Result result) {
160 std::map<std::string, RegisterCallback>::iterator callback_iter = 172 std::map<std::string, RegisterCallback>::iterator callback_iter =
161 register_callbacks_.find(app_id); 173 register_callbacks_.find(app_id);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 GCMClient::Result result) { 265 GCMClient::Result result) {
254 // Invoke the original unregister callback. 266 // Invoke the original unregister callback.
255 unregister_callback.Run(result); 267 unregister_callback.Run(result);
256 268
257 // Trigger the pending registration. 269 // Trigger the pending registration.
258 DCHECK(register_callbacks_.find(app_id) != register_callbacks_.end()); 270 DCHECK(register_callbacks_.find(app_id) != register_callbacks_.end());
259 RegisterImpl(app_id, normalized_sender_ids); 271 RegisterImpl(app_id, normalized_sender_ids);
260 } 272 }
261 273
262 } // namespace gcm 274 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698