| OLD | NEW |
| 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 "components/gcm_driver/gcm_app_handler.h" | 15 #include "components/gcm_driver/gcm_app_handler.h" |
| 15 | 16 |
| 16 namespace gcm { | 17 namespace gcm { |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 const size_t kMaxSenders = 100; | 21 const size_t kMaxSenders = 100; |
| 21 | 22 |
| 22 } // namespace | 23 } // namespace |
| 23 | 24 |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 } | 267 } |
| 267 | 268 |
| 268 void GCMDriver::ClearCallbacks() { | 269 void GCMDriver::ClearCallbacks() { |
| 269 register_callbacks_.clear(); | 270 register_callbacks_.clear(); |
| 270 unregister_callbacks_.clear(); | 271 unregister_callbacks_.clear(); |
| 271 send_callbacks_.clear(); | 272 send_callbacks_.clear(); |
| 272 } | 273 } |
| 273 | 274 |
| 274 void GCMDriver::DispatchMessage(const std::string& app_id, | 275 void GCMDriver::DispatchMessage(const std::string& app_id, |
| 275 const IncomingMessage& message) { | 276 const IncomingMessage& message) { |
| 276 if (!encryption_provider_.IsEncryptedMessage(message)) { | 277 encryption_provider_.DecryptMessage( |
| 277 GetAppHandler(app_id)->OnMessage(app_id, message); | 278 app_id, message, base::Bind(&GCMDriver::DispatchMessageInternal, |
| 278 return; | 279 weak_ptr_factory_.GetWeakPtr(), app_id)); |
| 280 } |
| 281 |
| 282 void GCMDriver::DispatchMessageInternal( |
| 283 const std::string& app_id, |
| 284 GCMEncryptionProvider::DecryptionResult result, |
| 285 const IncomingMessage& message) { |
| 286 UMA_HISTOGRAM_ENUMERATION("GCM.Crypto.DecryptMessageResult", result, |
| 287 GCMEncryptionProvider::DECRYPTION_RESULT_LAST + 1); |
| 288 |
| 289 switch (result) { |
| 290 case GCMEncryptionProvider::DECRYPTION_RESULT_UNENCRYPTED: |
| 291 case GCMEncryptionProvider::DECRYPTION_RESULT_DECRYPTED: |
| 292 GetAppHandler(app_id)->OnMessage(app_id, message); |
| 293 return; |
| 294 case GCMEncryptionProvider::DECRYPTION_RESULT_INVALID_ENCRYPTION_HEADER: |
| 295 case GCMEncryptionProvider::DECRYPTION_RESULT_INVALID_CRYPTO_KEY_HEADER: |
| 296 case GCMEncryptionProvider::DECRYPTION_RESULT_NO_KEYS: |
| 297 case GCMEncryptionProvider::DECRYPTION_RESULT_INVALID_SHARED_SECRET: |
| 298 case GCMEncryptionProvider::DECRYPTION_RESULT_INVALID_PAYLOAD: |
| 299 RecordDecryptionFailure(app_id, result); |
| 300 return; |
| 279 } | 301 } |
| 280 | 302 |
| 281 encryption_provider_.DecryptMessage( | 303 NOTREACHED(); |
| 282 app_id, message, | |
| 283 base::Bind(&GCMDriver::DispatchMessage, | |
| 284 weak_ptr_factory_.GetWeakPtr(), app_id), | |
| 285 base::Bind(&GCMDriver::RecordDecryptionFailure, | |
| 286 weak_ptr_factory_.GetWeakPtr(), app_id)); | |
| 287 } | 304 } |
| 288 | 305 |
| 289 void GCMDriver::RegisterAfterUnregister( | 306 void GCMDriver::RegisterAfterUnregister( |
| 290 const std::string& app_id, | 307 const std::string& app_id, |
| 291 const std::vector<std::string>& normalized_sender_ids, | 308 const std::vector<std::string>& normalized_sender_ids, |
| 292 const UnregisterCallback& unregister_callback, | 309 const UnregisterCallback& unregister_callback, |
| 293 GCMClient::Result result) { | 310 GCMClient::Result result) { |
| 294 // Invoke the original unregister callback. | 311 // Invoke the original unregister callback. |
| 295 unregister_callback.Run(result); | 312 unregister_callback.Run(result); |
| 296 | 313 |
| 297 // Trigger the pending registration. | 314 // Trigger the pending registration. |
| 298 DCHECK(register_callbacks_.find(app_id) != register_callbacks_.end()); | 315 DCHECK(register_callbacks_.find(app_id) != register_callbacks_.end()); |
| 299 RegisterImpl(app_id, normalized_sender_ids); | 316 RegisterImpl(app_id, normalized_sender_ids); |
| 300 } | 317 } |
| 301 | 318 |
| 302 } // namespace gcm | 319 } // namespace gcm |
| OLD | NEW |