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..434c431cd8abf6d829ea2c50dfa1f97e4a073048 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& receipt_callback) override; |
void OnMessagesDeleted(const std::string& app_id) override; |
void OnMessageSendError( |
const std::string& app_id, |
@@ -111,6 +113,8 @@ class GCMDriverDesktop::IOWorker : public GCMClient::Delegate { |
void RecordDecryptionFailure(const std::string& app_id, |
GCMEncryptionProvider::DecryptionResult result); |
+ void SendMessageReceipt(const MessageReceiptCallback& receipt_callback, |
+ GCMMessageStatus status); |
// For testing purpose. Can be called from UI thread. Use with care. |
GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); } |
@@ -233,15 +237,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& 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, receipt_callback)); |
} |
void GCMDriverDesktop::IOWorker::OnMessagesDeleted(const std::string& app_id) { |
@@ -510,6 +512,16 @@ void GCMDriverDesktop::IOWorker::RecordDecryptionFailure( |
gcm_client_->RecordDecryptionFailure(app_id, result); |
} |
+void GCMDriverDesktop::IOWorker::SendMessageReceipt( |
+ const MessageReceiptCallback& receipt_callback, |
+ GCMMessageStatus status) { |
+ DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
+ |
+ // The callback was created by the GCMClient on the IO thead so it is safe to |
+ // invoke from here. |
+ receipt_callback.Run(status); |
+} |
+ |
GCMDriverDesktop::GCMDriverDesktop( |
std::unique_ptr<GCMClientFactory> gcm_client_factory, |
const GCMClient::ChromeBuildInfo& chrome_build_info, |
@@ -1215,15 +1227,21 @@ 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& receipt_callback) { |
Peter Beverloo
2017/02/13 13:47:07
nit: it'd be a lot clearer if this were called io_
harkness
2017/02/14 19:22:29
I agree, but I also think everything is better wit
|
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(), receipt_callback)); |
} |
void GCMDriverDesktop::MessagesDeleted(const std::string& app_id) { |
@@ -1342,4 +1360,14 @@ bool GCMDriverDesktop::TokenTupleComparer::operator()( |
return std::get<2>(a) < std::get<2>(b); |
} |
+void GCMDriverDesktop::DoSendMessageReceipt( |
+ const MessageReceiptCallback& receipt_callback, |
+ GCMMessageStatus status) { |
+ DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
+ |
+ io_thread_->PostTask( |
+ FROM_HERE, |
+ base::Bind(&GCMDriverDesktop::IOWorker::SendMessageReceipt, |
+ base::Unretained(io_worker_.get()), receipt_callback, status)); |
Peter Beverloo
2017/02/13 13:47:07
You can skip the indirection and just invoke |rece
harkness
2017/02/14 19:22:29
Good point, I'd forgotten that it wasn't being cal
|
+} |
} // namespace gcm |