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

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

Issue 1243563002: Teach the GCM Driver how to decrypt incoming messages. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gcm-push-keys
Patch Set: Created 5 years, 2 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/files/file_path.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "components/gcm_driver/gcm_app_handler.h" 12 #include "components/gcm_driver/gcm_app_handler.h"
13 13
14 namespace gcm { 14 namespace gcm {
15 15
16 namespace {
17
18 // TODO(peter): Implement an event for GCMAppHandlers that should be called
19 // when decryption of an incoming message has failed.
20 void DecryptionFailedCallback(
Michael van Ouwerkerk 2015/10/02 14:30:42 nit: Can we add some Info level logging for when t
Peter Beverloo 2015/10/02 15:01:22 Each path towards reaching this message will alrea
21 GCMEncryptionProvider::DecryptionFailure reason) {}
22
16 const size_t kMaxSenders = 100; 23 const size_t kMaxSenders = 100;
17 24
25 } // namespace
26
18 InstanceIDHandler::InstanceIDHandler() { 27 InstanceIDHandler::InstanceIDHandler() {
19 } 28 }
20 29
21 InstanceIDHandler::~InstanceIDHandler() { 30 InstanceIDHandler::~InstanceIDHandler() {
22 } 31 }
23 32
24 void InstanceIDHandler::DeleteAllTokensForApp( 33 void InstanceIDHandler::DeleteAllTokensForApp(
25 const std::string& app_id, const DeleteTokenCallback& callback) { 34 const std::string& app_id, const DeleteTokenCallback& callback) {
26 DeleteToken(app_id, "*", "*", callback); 35 DeleteToken(app_id, "*", "*", callback);
27 } 36 }
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 bool GCMDriver::HasRegisterCallback(const std::string& app_id) { 260 bool GCMDriver::HasRegisterCallback(const std::string& app_id) {
252 return register_callbacks_.find(app_id) != register_callbacks_.end(); 261 return register_callbacks_.find(app_id) != register_callbacks_.end();
253 } 262 }
254 263
255 void GCMDriver::ClearCallbacks() { 264 void GCMDriver::ClearCallbacks() {
256 register_callbacks_.clear(); 265 register_callbacks_.clear();
257 unregister_callbacks_.clear(); 266 unregister_callbacks_.clear();
258 send_callbacks_.clear(); 267 send_callbacks_.clear();
259 } 268 }
260 269
270 void GCMDriver::DispatchMessage(const std::string& app_id,
271 const IncomingMessage& message) {
272 if (!encryption_provider_.IsEncryptedMessage(message)) {
273 GetAppHandler(app_id)->OnMessage(app_id, message);
274 return;
275 }
276
277 encryption_provider_.DecryptMessage(
278 app_id, message,
279 base::Bind(&GCMDriver::DispatchMessage,
280 weak_ptr_factory_.GetWeakPtr(), app_id),
281 base::Bind(&DecryptionFailedCallback));
282 }
283
261 void GCMDriver::RegisterAfterUnregister( 284 void GCMDriver::RegisterAfterUnregister(
262 const std::string& app_id, 285 const std::string& app_id,
263 const std::vector<std::string>& normalized_sender_ids, 286 const std::vector<std::string>& normalized_sender_ids,
264 const UnregisterCallback& unregister_callback, 287 const UnregisterCallback& unregister_callback,
265 GCMClient::Result result) { 288 GCMClient::Result result) {
266 // Invoke the original unregister callback. 289 // Invoke the original unregister callback.
267 unregister_callback.Run(result); 290 unregister_callback.Run(result);
268 291
269 // Trigger the pending registration. 292 // Trigger the pending registration.
270 DCHECK(register_callbacks_.find(app_id) != register_callbacks_.end()); 293 DCHECK(register_callbacks_.find(app_id) != register_callbacks_.end());
271 RegisterImpl(app_id, normalized_sender_ids); 294 RegisterImpl(app_id, normalized_sender_ids);
272 } 295 }
273 296
274 } // namespace gcm 297 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698