Chromium Code Reviews| 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 |
| 244 io_thread_->PostTask( | 245 io_thread_->PostTask( |
| 245 FROM_HERE, | 246 FROM_HERE, base::Bind(&FakeGCMClient::MessageReceived, |
| 246 base::Bind(&FakeGCMClient::MessageReceived, | 247 weak_ptr_factory_.GetWeakPtr(), app_id, message, |
| 247 weak_ptr_factory_.GetWeakPtr(), | 248 base::Bind(&FakeGCMClient::SendMessageReceipt, |
|
Peter Beverloo
2017/02/08 17:09:08
nit: generally we have a mild preference of writin
harkness
2017/02/09 16:27:29
Done.
| |
| 248 app_id, | 249 weak_ptr_factory_.GetWeakPtr(), |
| 249 message)); | 250 message_id, app_id))); |
| 251 } | |
| 252 | |
| 253 void FakeGCMClient::SendMessageReceipt(const std::string& message_id, | |
| 254 const std::string& app_id, | |
| 255 GCMMessageStatus status) { | |
| 256 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | |
| 257 | |
| 258 receipt_message_id_ = message_id; | |
| 259 receipt_app_id_ = app_id; | |
| 260 receipt_status_ = status; | |
| 250 } | 261 } |
| 251 | 262 |
| 252 void FakeGCMClient::DeleteMessages(const std::string& app_id) { | 263 void FakeGCMClient::DeleteMessages(const std::string& app_id) { |
| 253 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 264 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| 254 | 265 |
| 255 io_thread_->PostTask( | 266 io_thread_->PostTask( |
| 256 FROM_HERE, | 267 FROM_HERE, |
| 257 base::Bind(&FakeGCMClient::MessagesDeleted, | 268 base::Bind(&FakeGCMClient::MessagesDeleted, |
| 258 weak_ptr_factory_.GetWeakPtr(), | 269 weak_ptr_factory_.GetWeakPtr(), |
| 259 app_id)); | 270 app_id)); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 } else if(message.id.find("ack") != std::string::npos) { | 307 } else if(message.id.find("ack") != std::string::npos) { |
| 297 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 308 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 298 FROM_HERE, | 309 FROM_HERE, |
| 299 base::Bind(&FakeGCMClient::SendAcknowledgement, | 310 base::Bind(&FakeGCMClient::SendAcknowledgement, |
| 300 weak_ptr_factory_.GetWeakPtr(), app_id, message.id), | 311 weak_ptr_factory_.GetWeakPtr(), app_id, message.id), |
| 301 base::TimeDelta::FromMilliseconds(200)); | 312 base::TimeDelta::FromMilliseconds(200)); |
| 302 } | 313 } |
| 303 } | 314 } |
| 304 | 315 |
| 305 void FakeGCMClient::MessageReceived(const std::string& app_id, | 316 void FakeGCMClient::MessageReceived(const std::string& app_id, |
| 306 const IncomingMessage& message) { | 317 const IncomingMessage& message, |
| 318 const MessageReceiptCallback& callback) { | |
| 307 if (delegate_) | 319 if (delegate_) |
| 308 delegate_->OnMessageReceived(app_id, message); | 320 delegate_->OnMessageReceived(app_id, message, callback); |
| 309 } | 321 } |
| 310 | 322 |
| 311 void FakeGCMClient::MessagesDeleted(const std::string& app_id) { | 323 void FakeGCMClient::MessagesDeleted(const std::string& app_id) { |
| 312 if (delegate_) | 324 if (delegate_) |
| 313 delegate_->OnMessagesDeleted(app_id); | 325 delegate_->OnMessagesDeleted(app_id); |
| 314 } | 326 } |
| 315 | 327 |
| 316 void FakeGCMClient::MessageSendError( | 328 void FakeGCMClient::MessageSendError( |
| 317 const std::string& app_id, | 329 const std::string& app_id, |
| 318 const GCMClient::SendErrorDetails& send_error_details) { | 330 const GCMClient::SendErrorDetails& send_error_details) { |
| 319 if (delegate_) | 331 if (delegate_) |
| 320 delegate_->OnMessageSendError(app_id, send_error_details); | 332 delegate_->OnMessageSendError(app_id, send_error_details); |
| 321 } | 333 } |
| 322 | 334 |
| 323 void FakeGCMClient::SendAcknowledgement(const std::string& app_id, | 335 void FakeGCMClient::SendAcknowledgement(const std::string& app_id, |
| 324 const std::string& message_id) { | 336 const std::string& message_id) { |
| 325 if (delegate_) | 337 if (delegate_) |
| 326 delegate_->OnSendAcknowledged(app_id, message_id); | 338 delegate_->OnSendAcknowledged(app_id, message_id); |
| 327 } | 339 } |
| 328 | 340 |
| 329 } // namespace gcm | 341 } // namespace gcm |
| OLD | NEW |