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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 | 231 |
232 void FakeGCMClient::PerformDelayedStart() { | 232 void FakeGCMClient::PerformDelayedStart() { |
233 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 233 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
234 | 234 |
235 io_thread_->PostTask( | 235 io_thread_->PostTask( |
236 FROM_HERE, | 236 FROM_HERE, |
237 base::Bind(&FakeGCMClient::DoStart, weak_ptr_factory_.GetWeakPtr())); | 237 base::Bind(&FakeGCMClient::DoStart, weak_ptr_factory_.GetWeakPtr())); |
238 } | 238 } |
239 | 239 |
240 void FakeGCMClient::ReceiveMessage(const std::string& app_id, | 240 void FakeGCMClient::ReceiveMessage(const std::string& app_id, |
| 241 const std::string& message_id, |
241 const IncomingMessage& message) { | 242 const IncomingMessage& message) { |
242 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 243 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
243 | 244 |
| 245 MessageReceiptCallback optional_receipt_callback = |
| 246 base::Bind(&FakeGCMClient::SendMessageReceipt, |
| 247 weak_ptr_factory_.GetWeakPtr(), message_id, app_id); |
| 248 |
244 io_thread_->PostTask( | 249 io_thread_->PostTask( |
245 FROM_HERE, | 250 FROM_HERE, base::Bind(&FakeGCMClient::MessageReceived, |
246 base::Bind(&FakeGCMClient::MessageReceived, | 251 weak_ptr_factory_.GetWeakPtr(), app_id, message, |
247 weak_ptr_factory_.GetWeakPtr(), | 252 optional_receipt_callback)); |
248 app_id, | 253 } |
249 message)); | 254 |
| 255 void FakeGCMClient::SendMessageReceipt(const std::string& message_id, |
| 256 const std::string& app_id, |
| 257 GCMMessageStatus status) { |
| 258 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
| 259 |
| 260 receipt_message_id_ = message_id; |
| 261 receipt_app_id_ = app_id; |
| 262 receipt_status_ = status; |
250 } | 263 } |
251 | 264 |
252 void FakeGCMClient::DeleteMessages(const std::string& app_id) { | 265 void FakeGCMClient::DeleteMessages(const std::string& app_id) { |
253 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 266 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
254 | 267 |
255 io_thread_->PostTask( | 268 io_thread_->PostTask( |
256 FROM_HERE, | 269 FROM_HERE, |
257 base::Bind(&FakeGCMClient::MessagesDeleted, | 270 base::Bind(&FakeGCMClient::MessagesDeleted, |
258 weak_ptr_factory_.GetWeakPtr(), | 271 weak_ptr_factory_.GetWeakPtr(), |
259 app_id)); | 272 app_id)); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 base::TimeDelta::FromMilliseconds(200)); | 308 base::TimeDelta::FromMilliseconds(200)); |
296 } else if(message.id.find("ack") != std::string::npos) { | 309 } else if(message.id.find("ack") != std::string::npos) { |
297 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 310 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
298 FROM_HERE, | 311 FROM_HERE, |
299 base::Bind(&FakeGCMClient::SendAcknowledgement, | 312 base::Bind(&FakeGCMClient::SendAcknowledgement, |
300 weak_ptr_factory_.GetWeakPtr(), app_id, message.id), | 313 weak_ptr_factory_.GetWeakPtr(), app_id, message.id), |
301 base::TimeDelta::FromMilliseconds(200)); | 314 base::TimeDelta::FromMilliseconds(200)); |
302 } | 315 } |
303 } | 316 } |
304 | 317 |
305 void FakeGCMClient::MessageReceived(const std::string& app_id, | 318 void FakeGCMClient::MessageReceived( |
306 const IncomingMessage& message) { | 319 const std::string& app_id, |
| 320 const IncomingMessage& message, |
| 321 const MessageReceiptCallback& optional_receipt_callback) { |
307 if (delegate_) | 322 if (delegate_) |
308 delegate_->OnMessageReceived(app_id, message); | 323 delegate_->OnMessageReceived(app_id, message, optional_receipt_callback); |
309 } | 324 } |
310 | 325 |
311 void FakeGCMClient::MessagesDeleted(const std::string& app_id) { | 326 void FakeGCMClient::MessagesDeleted(const std::string& app_id) { |
312 if (delegate_) | 327 if (delegate_) |
313 delegate_->OnMessagesDeleted(app_id); | 328 delegate_->OnMessagesDeleted(app_id); |
314 } | 329 } |
315 | 330 |
316 void FakeGCMClient::MessageSendError( | 331 void FakeGCMClient::MessageSendError( |
317 const std::string& app_id, | 332 const std::string& app_id, |
318 const GCMClient::SendErrorDetails& send_error_details) { | 333 const GCMClient::SendErrorDetails& send_error_details) { |
319 if (delegate_) | 334 if (delegate_) |
320 delegate_->OnMessageSendError(app_id, send_error_details); | 335 delegate_->OnMessageSendError(app_id, send_error_details); |
321 } | 336 } |
322 | 337 |
323 void FakeGCMClient::SendAcknowledgement(const std::string& app_id, | 338 void FakeGCMClient::SendAcknowledgement(const std::string& app_id, |
324 const std::string& message_id) { | 339 const std::string& message_id) { |
325 if (delegate_) | 340 if (delegate_) |
326 delegate_->OnSendAcknowledged(app_id, message_id); | 341 delegate_->OnSendAcknowledged(app_id, message_id); |
327 } | 342 } |
328 | 343 |
329 } // namespace gcm | 344 } // namespace gcm |
OLD | NEW |