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