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/gcm_driver_desktop.h" | 5 #include "components/gcm_driver/gcm_driver_desktop.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 // Called on IO thread. | 46 // Called on IO thread. |
47 void OnRegisterFinished(const linked_ptr<RegistrationInfo>& registration_info, | 47 void OnRegisterFinished(const linked_ptr<RegistrationInfo>& registration_info, |
48 const std::string& registration_id, | 48 const std::string& registration_id, |
49 GCMClient::Result result) override; | 49 GCMClient::Result result) override; |
50 void OnUnregisterFinished( | 50 void OnUnregisterFinished( |
51 const linked_ptr<RegistrationInfo>& registration_info, | 51 const linked_ptr<RegistrationInfo>& registration_info, |
52 GCMClient::Result result) override; | 52 GCMClient::Result result) override; |
53 void OnSendFinished(const std::string& app_id, | 53 void OnSendFinished(const std::string& app_id, |
54 const std::string& message_id, | 54 const std::string& message_id, |
55 GCMClient::Result result) override; | 55 GCMClient::Result result) override; |
56 void OnMessageReceived(const std::string& app_id, | 56 void OnMessageReceived( |
57 const IncomingMessage& message) override; | 57 const std::string& app_id, |
| 58 const IncomingMessage& message, |
| 59 const MessageReceiptCallback& optional_receipt_callback) override; |
58 void OnMessagesDeleted(const std::string& app_id) override; | 60 void OnMessagesDeleted(const std::string& app_id) override; |
59 void OnMessageSendError( | 61 void OnMessageSendError( |
60 const std::string& app_id, | 62 const std::string& app_id, |
61 const GCMClient::SendErrorDetails& send_error_details) override; | 63 const GCMClient::SendErrorDetails& send_error_details) override; |
62 void OnSendAcknowledged(const std::string& app_id, | 64 void OnSendAcknowledged(const std::string& app_id, |
63 const std::string& message_id) override; | 65 const std::string& message_id) override; |
64 void OnGCMReady(const std::vector<AccountMapping>& account_mappings, | 66 void OnGCMReady(const std::vector<AccountMapping>& account_mappings, |
65 const base::Time& last_token_fetch_time) override; | 67 const base::Time& last_token_fetch_time) override; |
66 void OnActivityRecorded() override; | 68 void OnActivityRecorded() override; |
67 void OnConnected(const net::IPEndPoint& ip_endpoint) override; | 69 void OnConnected(const net::IPEndPoint& ip_endpoint) override; |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 228 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
227 | 229 |
228 ui_thread_->PostTask( | 230 ui_thread_->PostTask( |
229 FROM_HERE, | 231 FROM_HERE, |
230 base::Bind(&GCMDriverDesktop::SendFinished, service_, app_id, message_id, | 232 base::Bind(&GCMDriverDesktop::SendFinished, service_, app_id, message_id, |
231 result)); | 233 result)); |
232 } | 234 } |
233 | 235 |
234 void GCMDriverDesktop::IOWorker::OnMessageReceived( | 236 void GCMDriverDesktop::IOWorker::OnMessageReceived( |
235 const std::string& app_id, | 237 const std::string& app_id, |
236 const IncomingMessage& message) { | 238 const IncomingMessage& message, |
| 239 const MessageReceiptCallback& optional_receipt_callback) { |
237 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 240 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
238 | 241 |
239 ui_thread_->PostTask( | 242 ui_thread_->PostTask(FROM_HERE, |
240 FROM_HERE, | 243 base::Bind(&GCMDriverDesktop::MessageReceived, service_, |
241 base::Bind(&GCMDriverDesktop::MessageReceived, | 244 app_id, message, optional_receipt_callback)); |
242 service_, | |
243 app_id, | |
244 message)); | |
245 } | 245 } |
246 | 246 |
247 void GCMDriverDesktop::IOWorker::OnMessagesDeleted(const std::string& app_id) { | 247 void GCMDriverDesktop::IOWorker::OnMessagesDeleted(const std::string& app_id) { |
248 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 248 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
249 | 249 |
250 ui_thread_->PostTask( | 250 ui_thread_->PostTask( |
251 FROM_HERE, | 251 FROM_HERE, |
252 base::Bind(&GCMDriverDesktop::MessagesDeleted, service_, app_id)); | 252 base::Bind(&GCMDriverDesktop::MessagesDeleted, service_, app_id)); |
253 } | 253 } |
254 | 254 |
(...skipping 953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1208 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 1208 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
1209 // Remove all the queued tasks since they no longer make sense after | 1209 // Remove all the queued tasks since they no longer make sense after |
1210 // GCM service is stopped. | 1210 // GCM service is stopped. |
1211 weak_ptr_factory_.InvalidateWeakPtrs(); | 1211 weak_ptr_factory_.InvalidateWeakPtrs(); |
1212 | 1212 |
1213 gcm_started_ = false; | 1213 gcm_started_ = false; |
1214 delayed_task_controller_.reset(); | 1214 delayed_task_controller_.reset(); |
1215 ClearCallbacks(); | 1215 ClearCallbacks(); |
1216 } | 1216 } |
1217 | 1217 |
1218 void GCMDriverDesktop::MessageReceived(const std::string& app_id, | 1218 void GCMDriverDesktop::MessageReceived( |
1219 const IncomingMessage& message) { | 1219 const std::string& app_id, |
| 1220 const IncomingMessage& message, |
| 1221 const MessageReceiptCallback& optional_receipt_callback) { |
1220 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 1222 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
1221 | 1223 |
1222 // Drop the event if the service has been stopped. | 1224 // Drop the event if the service has been stopped. |
1223 if (!gcm_started_) | 1225 if (!gcm_started_) |
1224 return; | 1226 return; |
1225 | 1227 |
1226 DispatchMessage(app_id, message); | 1228 // Dispatch the message to the GCMDriver, but wrap the IO bound callback in a |
| 1229 // new callback which should be called on the UI thread. |
| 1230 DispatchMessage( |
| 1231 app_id, message, |
| 1232 base::Bind(&GCMDriverDesktop::DoSendMessageReceipt, |
| 1233 weak_ptr_factory_.GetWeakPtr(), optional_receipt_callback)); |
1227 } | 1234 } |
1228 | 1235 |
1229 void GCMDriverDesktop::MessagesDeleted(const std::string& app_id) { | 1236 void GCMDriverDesktop::MessagesDeleted(const std::string& app_id) { |
1230 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 1237 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
1231 | 1238 |
1232 // Drop the event if the service has been stopped. | 1239 // Drop the event if the service has been stopped. |
1233 if (!gcm_started_) | 1240 if (!gcm_started_) |
1234 return; | 1241 return; |
1235 | 1242 |
1236 GetAppHandler(app_id)->OnMessagesDeleted(app_id); | 1243 GetAppHandler(app_id)->OnMessagesDeleted(app_id); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1335 return false; | 1342 return false; |
1336 | 1343 |
1337 if (std::get<1>(a) < std::get<1>(b)) | 1344 if (std::get<1>(a) < std::get<1>(b)) |
1338 return true; | 1345 return true; |
1339 if (std::get<1>(a) > std::get<1>(b)) | 1346 if (std::get<1>(a) > std::get<1>(b)) |
1340 return false; | 1347 return false; |
1341 | 1348 |
1342 return std::get<2>(a) < std::get<2>(b); | 1349 return std::get<2>(a) < std::get<2>(b); |
1343 } | 1350 } |
1344 | 1351 |
| 1352 void GCMDriverDesktop::DoSendMessageReceipt( |
| 1353 const MessageReceiptCallback& optional_receipt_callback, |
| 1354 GCMMessageStatus status) { |
| 1355 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| 1356 |
| 1357 io_thread_->PostTask(FROM_HERE, |
| 1358 base::Bind(optional_receipt_callback, status)); |
| 1359 } |
1345 } // namespace gcm | 1360 } // namespace gcm |
OLD | NEW |