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/fake_gcm_client.h" | 5 #include "components/gcm_driver/fake_gcm_client.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/sequenced_task_runner.h" | 10 #include "base/sequenced_task_runner.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 base::Bind(&FakeGCMClient::Started, | 67 base::Bind(&FakeGCMClient::Started, |
68 weak_ptr_factory_.GetWeakPtr())); | 68 weak_ptr_factory_.GetWeakPtr())); |
69 } | 69 } |
70 | 70 |
71 void FakeGCMClient::Stop() { | 71 void FakeGCMClient::Stop() { |
72 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 72 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
73 started_ = false; | 73 started_ = false; |
74 delegate_->OnDisconnected(); | 74 delegate_->OnDisconnected(); |
75 } | 75 } |
76 | 76 |
77 void FakeGCMClient::Register(const std::string& app_id, | 77 void FakeGCMClient::Register( |
78 const std::vector<std::string>& sender_ids) { | 78 const linked_ptr<RegistrationInfo>& registration_info) { |
79 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 79 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
80 | 80 |
81 std::string registration_id = GetRegistrationIdFromSenderIds(sender_ids); | 81 GCMRegistrationInfo* gcm_registration_info = |
| 82 GCMRegistrationInfo::FromRegistrationInfo(registration_info.get()); |
| 83 DCHECK(gcm_registration_info); |
| 84 |
| 85 std::string registration_id = GetRegistrationIdFromSenderIds( |
| 86 gcm_registration_info->sender_ids); |
82 base::MessageLoop::current()->PostTask( | 87 base::MessageLoop::current()->PostTask( |
83 FROM_HERE, | 88 FROM_HERE, |
84 base::Bind(&FakeGCMClient::RegisterFinished, | 89 base::Bind(&FakeGCMClient::RegisterFinished, |
85 weak_ptr_factory_.GetWeakPtr(), | 90 weak_ptr_factory_.GetWeakPtr(), |
86 app_id, | 91 registration_info, |
87 registration_id)); | 92 registration_id)); |
88 } | 93 } |
89 | 94 |
90 void FakeGCMClient::Unregister(const std::string& app_id) { | 95 void FakeGCMClient::Unregister( |
| 96 const linked_ptr<RegistrationInfo>& registration_info) { |
91 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 97 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
92 | 98 |
93 base::MessageLoop::current()->PostTask( | 99 base::MessageLoop::current()->PostTask( |
94 FROM_HERE, | 100 FROM_HERE, |
95 base::Bind(&FakeGCMClient::UnregisterFinished, | 101 base::Bind(&FakeGCMClient::UnregisterFinished, |
96 weak_ptr_factory_.GetWeakPtr(), | 102 weak_ptr_factory_.GetWeakPtr(), |
97 app_id)); | 103 registration_info)); |
98 } | 104 } |
99 | 105 |
100 void FakeGCMClient::Send(const std::string& app_id, | 106 void FakeGCMClient::Send(const std::string& app_id, |
101 const std::string& receiver_id, | 107 const std::string& receiver_id, |
102 const OutgoingMessage& message) { | 108 const OutgoingMessage& message) { |
103 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 109 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
104 | 110 |
105 base::MessageLoop::current()->PostTask( | 111 base::MessageLoop::current()->PostTask( |
106 FROM_HERE, | 112 FROM_HERE, |
107 base::Bind(&FakeGCMClient::SendFinished, | 113 base::Bind(&FakeGCMClient::SendFinished, |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 } | 203 } |
198 } | 204 } |
199 return registration_id; | 205 return registration_id; |
200 } | 206 } |
201 | 207 |
202 void FakeGCMClient::Started() { | 208 void FakeGCMClient::Started() { |
203 delegate_->OnGCMReady(std::vector<AccountMapping>(), base::Time()); | 209 delegate_->OnGCMReady(std::vector<AccountMapping>(), base::Time()); |
204 delegate_->OnConnected(net::IPEndPoint()); | 210 delegate_->OnConnected(net::IPEndPoint()); |
205 } | 211 } |
206 | 212 |
207 void FakeGCMClient::RegisterFinished(const std::string& app_id, | 213 void FakeGCMClient::RegisterFinished( |
208 const std::string& registrion_id) { | 214 const linked_ptr<RegistrationInfo>& registration_info, |
| 215 const std::string& registrion_id) { |
209 delegate_->OnRegisterFinished( | 216 delegate_->OnRegisterFinished( |
210 app_id, registrion_id, registrion_id.empty() ? SERVER_ERROR : SUCCESS); | 217 registration_info, |
| 218 registrion_id, |
| 219 registrion_id.empty() ? SERVER_ERROR : SUCCESS); |
211 } | 220 } |
212 | 221 |
213 void FakeGCMClient::UnregisterFinished(const std::string& app_id) { | 222 void FakeGCMClient::UnregisterFinished( |
214 delegate_->OnUnregisterFinished(app_id, GCMClient::SUCCESS); | 223 const linked_ptr<RegistrationInfo>& registration_info) { |
| 224 delegate_->OnUnregisterFinished(registration_info, GCMClient::SUCCESS); |
215 } | 225 } |
216 | 226 |
217 void FakeGCMClient::SendFinished(const std::string& app_id, | 227 void FakeGCMClient::SendFinished(const std::string& app_id, |
218 const OutgoingMessage& message) { | 228 const OutgoingMessage& message) { |
219 delegate_->OnSendFinished(app_id, message.id, SUCCESS); | 229 delegate_->OnSendFinished(app_id, message.id, SUCCESS); |
220 | 230 |
221 // Simulate send error if message id contains a hint. | 231 // Simulate send error if message id contains a hint. |
222 if (message.id.find("error") != std::string::npos) { | 232 if (message.id.find("error") != std::string::npos) { |
223 SendErrorDetails send_error_details; | 233 SendErrorDetails send_error_details; |
224 send_error_details.message_id = message.id; | 234 send_error_details.message_id = message.id; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 delegate_->OnMessageSendError(app_id, send_error_details); | 271 delegate_->OnMessageSendError(app_id, send_error_details); |
262 } | 272 } |
263 | 273 |
264 void FakeGCMClient::SendAcknowledgement(const std::string& app_id, | 274 void FakeGCMClient::SendAcknowledgement(const std::string& app_id, |
265 const std::string& message_id) { | 275 const std::string& message_id) { |
266 if (delegate_) | 276 if (delegate_) |
267 delegate_->OnSendAcknowledged(app_id, message_id); | 277 delegate_->OnSendAcknowledged(app_id, message_id); |
268 } | 278 } |
269 | 279 |
270 } // namespace gcm | 280 } // namespace gcm |
OLD | NEW |