[email protected] | 3ecb2b58 | 2014-05-23 00:25:39 | [diff] [blame] | 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 | |||||
[email protected] | 8d41e5a | 2014-05-28 03:18:49 | [diff] [blame] | 5 | #include "components/gcm_driver/fake_gcm_app_handler.h" |
[email protected] | 3ecb2b58 | 2014-05-23 00:25:39 | [diff] [blame] | 6 | |
7 | #include "base/run_loop.h" | ||||
8 | |||||
9 | namespace gcm { | ||||
10 | |||||
[email protected] | fc6078a | 2014-06-14 08:28:43 | [diff] [blame] | 11 | FakeGCMAppHandler::FakeGCMAppHandler() |
fgorski | 0d5c00d | 2014-08-28 16:21:45 | [diff] [blame] | 12 | : received_event_(NO_EVENT) { |
[email protected] | 3ecb2b58 | 2014-05-23 00:25:39 | [diff] [blame] | 13 | } |
14 | |||||
15 | FakeGCMAppHandler::~FakeGCMAppHandler() { | ||||
16 | } | ||||
17 | |||||
18 | void FakeGCMAppHandler::WaitForNotification() { | ||||
19 | run_loop_.reset(new base::RunLoop); | ||||
20 | run_loop_->Run(); | ||||
21 | run_loop_.reset(); | ||||
22 | } | ||||
23 | |||||
24 | void FakeGCMAppHandler::ShutdownHandler() { | ||||
25 | } | ||||
26 | |||||
johnme | 93ec793 | 2016-11-17 14:26:58 | [diff] [blame] | 27 | void FakeGCMAppHandler::OnStoreReset() {} |
28 | |||||
[email protected] | 3ecb2b58 | 2014-05-23 00:25:39 | [diff] [blame] | 29 | void FakeGCMAppHandler::OnMessage(const std::string& app_id, |
mvanouwerkerk | f8633deb | 2015-07-13 11:04:06 | [diff] [blame] | 30 | const IncomingMessage& message) { |
[email protected] | 3ecb2b58 | 2014-05-23 00:25:39 | [diff] [blame] | 31 | ClearResults(); |
32 | received_event_ = MESSAGE_EVENT; | ||||
33 | app_id_ = app_id; | ||||
34 | message_ = message; | ||||
35 | if (run_loop_) | ||||
36 | run_loop_->Quit(); | ||||
37 | } | ||||
38 | |||||
39 | void FakeGCMAppHandler::OnMessagesDeleted(const std::string& app_id) { | ||||
40 | ClearResults(); | ||||
41 | received_event_ = MESSAGES_DELETED_EVENT; | ||||
42 | app_id_ = app_id; | ||||
43 | if (run_loop_) | ||||
44 | run_loop_->Quit(); | ||||
45 | } | ||||
46 | |||||
47 | void FakeGCMAppHandler::OnSendError( | ||||
48 | const std::string& app_id, | ||||
49 | const GCMClient::SendErrorDetails& send_error_details) { | ||||
50 | ClearResults(); | ||||
51 | received_event_ = SEND_ERROR_EVENT; | ||||
52 | app_id_ = app_id; | ||||
53 | send_error_details_ = send_error_details; | ||||
54 | if (run_loop_) | ||||
55 | run_loop_->Quit(); | ||||
56 | } | ||||
57 | |||||
[email protected] | 292af2b2 | 2014-08-06 19:42:45 | [diff] [blame] | 58 | void FakeGCMAppHandler::OnSendAcknowledged( |
59 | const std::string& app_id, | ||||
60 | const std::string& message_id) { | ||||
61 | ClearResults(); | ||||
62 | app_id_ = app_id; | ||||
63 | acked_message_id_ = message_id; | ||||
64 | if (run_loop_) | ||||
65 | run_loop_->Quit(); | ||||
66 | } | ||||
67 | |||||
[email protected] | 3ecb2b58 | 2014-05-23 00:25:39 | [diff] [blame] | 68 | void FakeGCMAppHandler::ClearResults() { |
69 | received_event_ = NO_EVENT; | ||||
70 | app_id_.clear(); | ||||
[email protected] | 292af2b2 | 2014-08-06 19:42:45 | [diff] [blame] | 71 | acked_message_id_.clear(); |
mvanouwerkerk | f8633deb | 2015-07-13 11:04:06 | [diff] [blame] | 72 | message_ = IncomingMessage(); |
[email protected] | 3ecb2b58 | 2014-05-23 00:25:39 | [diff] [blame] | 73 | send_error_details_ = GCMClient::SendErrorDetails(); |
74 | } | ||||
75 | |||||
[email protected] | 3ecb2b58 | 2014-05-23 00:25:39 | [diff] [blame] | 76 | } // namespace gcm |