fake_gcm_app_handler.cc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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
  3. // found in the LICENSE file.
  4. #include "components/gcm_driver/fake_gcm_app_handler.h"
  5. #include <memory>
  6. #include "base/run_loop.h"
  7. namespace gcm {
  8. FakeGCMAppHandler::FakeGCMAppHandler() : received_event_(NO_EVENT) {}
  9. FakeGCMAppHandler::~FakeGCMAppHandler() = default;
  10. void FakeGCMAppHandler::WaitForNotification() {
  11. run_loop_ = std::make_unique<base::RunLoop>();
  12. run_loop_->Run();
  13. run_loop_.reset();
  14. }
  15. void FakeGCMAppHandler::ShutdownHandler() {}
  16. void FakeGCMAppHandler::OnStoreReset() {}
  17. void FakeGCMAppHandler::OnMessage(const std::string& app_id,
  18. const IncomingMessage& message) {
  19. ClearResults();
  20. received_event_ = MESSAGE_EVENT;
  21. app_id_ = app_id;
  22. message_ = message;
  23. if (run_loop_)
  24. run_loop_->Quit();
  25. }
  26. void FakeGCMAppHandler::OnMessagesDeleted(const std::string& app_id) {
  27. ClearResults();
  28. received_event_ = MESSAGES_DELETED_EVENT;
  29. app_id_ = app_id;
  30. if (run_loop_)
  31. run_loop_->Quit();
  32. }
  33. void FakeGCMAppHandler::OnSendError(
  34. const std::string& app_id,
  35. const GCMClient::SendErrorDetails& send_error_details) {
  36. ClearResults();
  37. received_event_ = SEND_ERROR_EVENT;
  38. app_id_ = app_id;
  39. send_error_details_ = send_error_details;
  40. if (run_loop_)
  41. run_loop_->Quit();
  42. }
  43. void FakeGCMAppHandler::OnSendAcknowledged(
  44. const std::string& app_id,
  45. const std::string& message_id) {
  46. ClearResults();
  47. app_id_ = app_id;
  48. acked_message_id_ = message_id;
  49. if (run_loop_)
  50. run_loop_->Quit();
  51. }
  52. void FakeGCMAppHandler::OnMessageDecryptionFailed(
  53. const std::string& app_id,
  54. const std::string& message_id,
  55. const std::string& error_message) {
  56. ClearResults();
  57. received_event_ = DECRYPTION_FAILED_EVENT;
  58. app_id_ = app_id;
  59. if (run_loop_)
  60. run_loop_->Quit();
  61. }
  62. void FakeGCMAppHandler::ClearResults() {
  63. received_event_ = NO_EVENT;
  64. app_id_.clear();
  65. acked_message_id_.clear();
  66. message_ = IncomingMessage();
  67. send_error_details_ = GCMClient::SendErrorDetails();
  68. }
  69. } // namespace gcm