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 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/sequenced_task_runner.h" | 14 #include "base/sequenced_task_runner.h" |
15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
17 #include "base/sys_byteorder.h" | 17 #include "base/sys_byteorder.h" |
18 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
19 #include "base/time/time.h" | 19 #include "base/time/time.h" |
20 #include "base/timer/timer.h" | 20 #include "base/timer/timer.h" |
| 21 #include "components/sync/base/bind_to_task_runner.h" |
21 #include "google_apis/gcm/base/encryptor.h" | 22 #include "google_apis/gcm/base/encryptor.h" |
22 #include "google_apis/gcm/engine/account_mapping.h" | 23 #include "google_apis/gcm/engine/account_mapping.h" |
23 #include "net/base/ip_endpoint.h" | 24 #include "net/base/ip_endpoint.h" |
24 | 25 |
25 namespace gcm { | 26 namespace gcm { |
26 | 27 |
27 // static | 28 // static |
28 std::string FakeGCMClient::GenerateGCMRegistrationID( | 29 std::string FakeGCMClient::GenerateGCMRegistrationID( |
29 const std::vector<std::string>& sender_ids) { | 30 const std::vector<std::string>& sender_ids) { |
30 // GCMService normalizes the sender IDs by making them sorted. | 31 // GCMService normalizes the sender IDs by making them sorted. |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 | 232 |
232 void FakeGCMClient::PerformDelayedStart() { | 233 void FakeGCMClient::PerformDelayedStart() { |
233 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 234 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
234 | 235 |
235 io_thread_->PostTask( | 236 io_thread_->PostTask( |
236 FROM_HERE, | 237 FROM_HERE, |
237 base::Bind(&FakeGCMClient::DoStart, weak_ptr_factory_.GetWeakPtr())); | 238 base::Bind(&FakeGCMClient::DoStart, weak_ptr_factory_.GetWeakPtr())); |
238 } | 239 } |
239 | 240 |
240 void FakeGCMClient::ReceiveMessage(const std::string& app_id, | 241 void FakeGCMClient::ReceiveMessage(const std::string& app_id, |
| 242 const std::string& message_id, |
241 const IncomingMessage& message) { | 243 const IncomingMessage& message) { |
242 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 244 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
243 | 245 |
244 io_thread_->PostTask( | 246 io_thread_->PostTask( |
245 FROM_HERE, | 247 FROM_HERE, base::Bind(&FakeGCMClient::MessageReceived, |
246 base::Bind(&FakeGCMClient::MessageReceived, | 248 weak_ptr_factory_.GetWeakPtr(), app_id, message, |
247 weak_ptr_factory_.GetWeakPtr(), | 249 base::Bind(&FakeGCMClient::SendMessageReceipt, |
248 app_id, | 250 weak_ptr_factory_.GetWeakPtr(), |
249 message)); | 251 message_id, app_id))); |
| 252 } |
| 253 |
| 254 void FakeGCMClient::SendMessageReceipt(const std::string& message_id, |
| 255 const std::string& app_id, |
| 256 GCMMessageStatus status) { |
| 257 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
| 258 |
| 259 receipt_message_id_ = message_id; |
| 260 receipt_app_id_ = app_id; |
| 261 receipt_status_ = status; |
250 } | 262 } |
251 | 263 |
252 void FakeGCMClient::DeleteMessages(const std::string& app_id) { | 264 void FakeGCMClient::DeleteMessages(const std::string& app_id) { |
253 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 265 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
254 | 266 |
255 io_thread_->PostTask( | 267 io_thread_->PostTask( |
256 FROM_HERE, | 268 FROM_HERE, |
257 base::Bind(&FakeGCMClient::MessagesDeleted, | 269 base::Bind(&FakeGCMClient::MessagesDeleted, |
258 weak_ptr_factory_.GetWeakPtr(), | 270 weak_ptr_factory_.GetWeakPtr(), |
259 app_id)); | 271 app_id)); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 base::TimeDelta::FromMilliseconds(200)); | 307 base::TimeDelta::FromMilliseconds(200)); |
296 } else if(message.id.find("ack") != std::string::npos) { | 308 } else if(message.id.find("ack") != std::string::npos) { |
297 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 309 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
298 FROM_HERE, | 310 FROM_HERE, |
299 base::Bind(&FakeGCMClient::SendAcknowledgement, | 311 base::Bind(&FakeGCMClient::SendAcknowledgement, |
300 weak_ptr_factory_.GetWeakPtr(), app_id, message.id), | 312 weak_ptr_factory_.GetWeakPtr(), app_id, message.id), |
301 base::TimeDelta::FromMilliseconds(200)); | 313 base::TimeDelta::FromMilliseconds(200)); |
302 } | 314 } |
303 } | 315 } |
304 | 316 |
305 void FakeGCMClient::MessageReceived(const std::string& app_id, | 317 void FakeGCMClient::MessageReceived( |
306 const IncomingMessage& message) { | 318 const std::string& app_id, |
| 319 const IncomingMessage& message, |
| 320 const GCMClient::MessageReceiptCallback& callback) { |
307 if (delegate_) | 321 if (delegate_) |
308 delegate_->OnMessageReceived(app_id, message); | 322 delegate_->OnMessageReceived(app_id, message, |
| 323 syncer::BindToCurrentThread(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 |