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

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: Added a callback entry point to GCMDriver, moved MessageReceiptCallback to gcm_message_status. 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
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
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/metrics/histogram_macros.h" 14 #include "base/metrics/histogram_macros.h"
15 #include "components/gcm_driver/gcm_app_handler.h" 15 #include "components/gcm_driver/gcm_app_handler.h"
16 #include "components/gcm_driver/gcm_message_status.h"
Peter Beverloo 2017/02/08 17:09:09 nit: this is already included in the header
harkness 2017/02/09 16:27:30 Done.
16 17
17 namespace gcm { 18 namespace gcm {
18 19
19 namespace { 20 namespace {
20 21
21 const size_t kMaxSenders = 100; 22 const size_t kMaxSenders = 100;
22 23
23 } // namespace 24 } // namespace
24 25
25 InstanceIDHandler::InstanceIDHandler() { 26 InstanceIDHandler::InstanceIDHandler() {
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 return register_callbacks_.find(app_id) != register_callbacks_.end(); 273 return register_callbacks_.find(app_id) != register_callbacks_.end();
273 } 274 }
274 275
275 void GCMDriver::ClearCallbacks() { 276 void GCMDriver::ClearCallbacks() {
276 register_callbacks_.clear(); 277 register_callbacks_.clear();
277 unregister_callbacks_.clear(); 278 unregister_callbacks_.clear();
278 send_callbacks_.clear(); 279 send_callbacks_.clear();
279 } 280 }
280 281
281 void GCMDriver::DispatchMessage(const std::string& app_id, 282 void GCMDriver::DispatchMessage(const std::string& app_id,
282 const IncomingMessage& message) { 283 const IncomingMessage& message,
284 const MessageReceiptCallback& callback) {
283 encryption_provider_.DecryptMessage( 285 encryption_provider_.DecryptMessage(
284 app_id, message, base::Bind(&GCMDriver::DispatchMessageInternal, 286 app_id, message,
285 weak_ptr_factory_.GetWeakPtr(), app_id)); 287 base::Bind(&GCMDriver::DispatchMessageInternal,
288 weak_ptr_factory_.GetWeakPtr(), app_id, 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& 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 DoSendMessageReceipt(callback, GCMMessageStatus::GCM_ENCRYPTION_FAILURE);
Peter Beverloo 2017/02/08 17:09:09 I'd argue that this should just be SendMessageRece
harkness 2017/02/09 16:27:30 Now it just invokes the callback.
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

Powered by Google App Engine
This is Rietveld 408576698