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

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

Issue 2578583002: Provide a mechanism for the GCM driver to send message receipts to GCM.
Patch Set: Fix issue with rebase Created 3 years, 10 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
« no previous file with comments | « components/gcm_driver/gcm_driver.h ('k') | components/gcm_driver/gcm_driver_android.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 bool GCMDriver::HasRegisterCallback(const std::string& app_id) { 271 bool GCMDriver::HasRegisterCallback(const std::string& app_id) {
272 return register_callbacks_.find(app_id) != register_callbacks_.end(); 272 return register_callbacks_.find(app_id) != register_callbacks_.end();
273 } 273 }
274 274
275 void GCMDriver::ClearCallbacks() { 275 void GCMDriver::ClearCallbacks() {
276 register_callbacks_.clear(); 276 register_callbacks_.clear();
277 unregister_callbacks_.clear(); 277 unregister_callbacks_.clear();
278 send_callbacks_.clear(); 278 send_callbacks_.clear();
279 } 279 }
280 280
281 void GCMDriver::DispatchMessage(const std::string& app_id, 281 void GCMDriver::DispatchMessage(
282 const IncomingMessage& message) { 282 const std::string& app_id,
283 const IncomingMessage& message,
284 const MessageReceiptCallback& optional_receipt_callback) {
283 encryption_provider_.DecryptMessage( 285 encryption_provider_.DecryptMessage(
284 app_id, message, base::Bind(&GCMDriver::DispatchMessageInternal, 286 app_id, message, base::Bind(&GCMDriver::DispatchMessageInternal,
285 weak_ptr_factory_.GetWeakPtr(), app_id)); 287 weak_ptr_factory_.GetWeakPtr(), app_id,
288 optional_receipt_callback));
286 } 289 }
287 290
288 void GCMDriver::DispatchMessageInternal( 291 void GCMDriver::DispatchMessageInternal(
289 const std::string& app_id, 292 const std::string& app_id,
293 const MessageReceiptCallback& optional_receipt_callback,
290 GCMEncryptionProvider::DecryptionResult result, 294 GCMEncryptionProvider::DecryptionResult result,
291 const IncomingMessage& message) { 295 const IncomingMessage& message) {
292 UMA_HISTOGRAM_ENUMERATION("GCM.Crypto.DecryptMessageResult", result, 296 UMA_HISTOGRAM_ENUMERATION("GCM.Crypto.DecryptMessageResult", result,
293 GCMEncryptionProvider::DECRYPTION_RESULT_LAST + 1); 297 GCMEncryptionProvider::DECRYPTION_RESULT_LAST + 1);
294 298
295 switch (result) { 299 switch (result) {
296 case GCMEncryptionProvider::DECRYPTION_RESULT_UNENCRYPTED: 300 case GCMEncryptionProvider::DECRYPTION_RESULT_UNENCRYPTED:
297 case GCMEncryptionProvider::DECRYPTION_RESULT_DECRYPTED: 301 case GCMEncryptionProvider::DECRYPTION_RESULT_DECRYPTED:
302 // TODO(beverloo): When the DefaultAppHandler is gone, call
303 // SendMessageReceipt here if there isn't a valid app handler.
298 GetAppHandler(app_id)->OnMessage(app_id, message); 304 GetAppHandler(app_id)->OnMessage(app_id, message);
299 return; 305 return;
300 case GCMEncryptionProvider::DECRYPTION_RESULT_INVALID_ENCRYPTION_HEADER: 306 case GCMEncryptionProvider::DECRYPTION_RESULT_INVALID_ENCRYPTION_HEADER:
301 case GCMEncryptionProvider::DECRYPTION_RESULT_INVALID_CRYPTO_KEY_HEADER: 307 case GCMEncryptionProvider::DECRYPTION_RESULT_INVALID_CRYPTO_KEY_HEADER:
302 case GCMEncryptionProvider::DECRYPTION_RESULT_NO_KEYS: 308 case GCMEncryptionProvider::DECRYPTION_RESULT_NO_KEYS:
303 case GCMEncryptionProvider::DECRYPTION_RESULT_INVALID_SHARED_SECRET: 309 case GCMEncryptionProvider::DECRYPTION_RESULT_INVALID_SHARED_SECRET:
304 case GCMEncryptionProvider::DECRYPTION_RESULT_INVALID_PAYLOAD: 310 case GCMEncryptionProvider::DECRYPTION_RESULT_INVALID_PAYLOAD:
311 optional_receipt_callback.Run(GCMMessageStatus::GCM_DECRYPTION_FAILURE);
305 RecordDecryptionFailure(app_id, result); 312 RecordDecryptionFailure(app_id, result);
306 return; 313 return;
307 } 314 }
308 315
309 NOTREACHED(); 316 NOTREACHED();
310 } 317 }
311 318
312 void GCMDriver::RegisterAfterUnregister( 319 void GCMDriver::RegisterAfterUnregister(
313 const std::string& app_id, 320 const std::string& app_id,
314 const std::vector<std::string>& normalized_sender_ids, 321 const std::vector<std::string>& normalized_sender_ids,
315 const UnregisterCallback& unregister_callback, 322 const UnregisterCallback& unregister_callback,
316 GCMClient::Result result) { 323 GCMClient::Result result) {
317 // Invoke the original unregister callback. 324 // Invoke the original unregister callback.
318 unregister_callback.Run(result); 325 unregister_callback.Run(result);
319 326
320 // Trigger the pending registration. 327 // Trigger the pending registration.
321 DCHECK(register_callbacks_.find(app_id) != register_callbacks_.end()); 328 DCHECK(register_callbacks_.find(app_id) != register_callbacks_.end());
322 RegisterImpl(app_id, normalized_sender_ids); 329 RegisterImpl(app_id, normalized_sender_ids);
323 } 330 }
324 331
325 } // namespace gcm 332 } // namespace gcm
OLDNEW
« no previous file with comments | « components/gcm_driver/gcm_driver.h ('k') | components/gcm_driver/gcm_driver_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698