Index: components/gcm_driver/gcm_driver_desktop.cc |
diff --git a/components/gcm_driver/gcm_driver_desktop.cc b/components/gcm_driver/gcm_driver_desktop.cc |
index 599957d2a5979fced996c2440031f4cee4344b7c..4d7cf9beb8b9ea696e8e289be6dc7602d783b978 100644 |
--- a/components/gcm_driver/gcm_driver_desktop.cc |
+++ b/components/gcm_driver/gcm_driver_desktop.cc |
@@ -53,8 +53,10 @@ class GCMDriverDesktop::IOWorker : public GCMClient::Delegate { |
void OnSendFinished(const std::string& app_id, |
const std::string& message_id, |
GCMClient::Result result) override; |
- void OnMessageReceived(const std::string& app_id, |
- const IncomingMessage& message) override; |
+ void OnMessageReceived( |
+ const std::string& app_id, |
+ const IncomingMessage& message, |
+ const MessageReceiptCallback& optional_receipt_callback) override; |
void OnMessagesDeleted(const std::string& app_id) override; |
void OnMessageSendError( |
const std::string& app_id, |
@@ -233,15 +235,13 @@ void GCMDriverDesktop::IOWorker::OnSendFinished(const std::string& app_id, |
void GCMDriverDesktop::IOWorker::OnMessageReceived( |
const std::string& app_id, |
- const IncomingMessage& message) { |
+ const IncomingMessage& message, |
+ const MessageReceiptCallback& optional_receipt_callback) { |
DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
- ui_thread_->PostTask( |
- FROM_HERE, |
- base::Bind(&GCMDriverDesktop::MessageReceived, |
- service_, |
- app_id, |
- message)); |
+ ui_thread_->PostTask(FROM_HERE, |
+ base::Bind(&GCMDriverDesktop::MessageReceived, service_, |
+ app_id, message, optional_receipt_callback)); |
} |
void GCMDriverDesktop::IOWorker::OnMessagesDeleted(const std::string& app_id) { |
@@ -1215,15 +1215,22 @@ void GCMDriverDesktop::RemoveCachedData() { |
ClearCallbacks(); |
} |
-void GCMDriverDesktop::MessageReceived(const std::string& app_id, |
- const IncomingMessage& message) { |
+void GCMDriverDesktop::MessageReceived( |
+ const std::string& app_id, |
+ const IncomingMessage& message, |
+ const MessageReceiptCallback& optional_receipt_callback) { |
DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
// Drop the event if the service has been stopped. |
if (!gcm_started_) |
return; |
- DispatchMessage(app_id, message); |
+ // Dispatch the message to the GCMDriver, but wrap the IO bound callback in a |
+ // new callback which should be called on the UI thread. |
+ DispatchMessage( |
+ app_id, message, |
+ base::Bind(&GCMDriverDesktop::DoSendMessageReceipt, |
+ weak_ptr_factory_.GetWeakPtr(), optional_receipt_callback)); |
} |
void GCMDriverDesktop::MessagesDeleted(const std::string& app_id) { |
@@ -1342,4 +1349,12 @@ bool GCMDriverDesktop::TokenTupleComparer::operator()( |
return std::get<2>(a) < std::get<2>(b); |
} |
+void GCMDriverDesktop::DoSendMessageReceipt( |
+ const MessageReceiptCallback& optional_receipt_callback, |
+ GCMMessageStatus status) { |
+ DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
+ |
+ io_thread_->PostTask(FROM_HERE, |
+ base::Bind(optional_receipt_callback, status)); |
+} |
} // namespace gcm |