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

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, 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
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"
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 return iter->second; 245 return iter->second;
246 } 246 }
247 247
248 return &default_app_handler_; 248 return &default_app_handler_;
249 } 249 }
250 250
251 bool GCMDriver::HasRegisterCallback(const std::string& app_id) { 251 bool GCMDriver::HasRegisterCallback(const std::string& app_id) {
252 return register_callbacks_.find(app_id) != register_callbacks_.end(); 252 return register_callbacks_.find(app_id) != register_callbacks_.end();
253 } 253 }
254 254
255 void GCMDriver::DispatchMessage(const std::string& app_id,
256 const IncomingMessage& message) {
257 if (!encryption_provider_.IsEncryptedMessage(message)) {
258 GetAppHandler(app_id)->OnMessage(app_id, message);
259 return;
260 }
261
262 encryption_provider_.DecryptMessage(
263 app_id, message, base::Bind(&GCMDriver::DispatchDecryptedMessage,
264 weak_ptr_factory_.GetWeakPtr(), app_id));
265 }
266
267 void GCMDriver::DispatchDecryptedMessage(const std::string& app_id,
268 const IncomingMessage& message,
269 bool decryption_successful) {
270 if (!decryption_successful) {
271 // TODO(peter): Introduce a new event on app handlers for this scenario.
272 LOG(ERROR) << "Unable to decrypt message for " << app_id;
273 return;
274 }
275
276 GetAppHandler(app_id)->OnMessage(app_id, message);
277 }
278
255 void GCMDriver::ClearCallbacks() { 279 void GCMDriver::ClearCallbacks() {
256 register_callbacks_.clear(); 280 register_callbacks_.clear();
257 unregister_callbacks_.clear(); 281 unregister_callbacks_.clear();
258 send_callbacks_.clear(); 282 send_callbacks_.clear();
259 } 283 }
260 284
261 void GCMDriver::RegisterAfterUnregister( 285 void GCMDriver::RegisterAfterUnregister(
262 const std::string& app_id, 286 const std::string& app_id,
263 const std::vector<std::string>& normalized_sender_ids, 287 const std::vector<std::string>& normalized_sender_ids,
264 const UnregisterCallback& unregister_callback, 288 const UnregisterCallback& unregister_callback,
265 GCMClient::Result result) { 289 GCMClient::Result result) {
266 // Invoke the original unregister callback. 290 // Invoke the original unregister callback.
267 unregister_callback.Run(result); 291 unregister_callback.Run(result);
268 292
269 // Trigger the pending registration. 293 // Trigger the pending registration.
270 DCHECK(register_callbacks_.find(app_id) != register_callbacks_.end()); 294 DCHECK(register_callbacks_.find(app_id) != register_callbacks_.end());
271 RegisterImpl(app_id, normalized_sender_ids); 295 RegisterImpl(app_id, normalized_sender_ids);
272 } 296 }
273 297
274 } // namespace gcm 298 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698