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& 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 void GetToken(const std::string& app_id, | 106 void GetToken(const std::string& app_id, |
105 const std::string& authorized_entity, | 107 const std::string& authorized_entity, |
106 const std::string& scope, | 108 const std::string& scope, |
107 const std::map<std::string, std::string>& options); | 109 const std::map<std::string, std::string>& options); |
108 void DeleteToken(const std::string& app_id, | 110 void DeleteToken(const std::string& app_id, |
109 const std::string& authorized_entity, | 111 const std::string& authorized_entity, |
110 const std::string& scope); | 112 const std::string& scope); |
111 | 113 |
112 void RecordDecryptionFailure(const std::string& app_id, | 114 void RecordDecryptionFailure(const std::string& app_id, |
113 GCMEncryptionProvider::DecryptionResult result); | 115 GCMEncryptionProvider::DecryptionResult result); |
116 void SendMessageReceipt(const MessageReceiptCallback& receipt_callback, | |
117 GCMMessageStatus status); | |
114 | 118 |
115 // For testing purpose. Can be called from UI thread. Use with care. | 119 // For testing purpose. Can be called from UI thread. Use with care. |
116 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); } | 120 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); } |
117 | 121 |
118 private: | 122 private: |
119 scoped_refptr<base::SequencedTaskRunner> ui_thread_; | 123 scoped_refptr<base::SequencedTaskRunner> ui_thread_; |
120 scoped_refptr<base::SequencedTaskRunner> io_thread_; | 124 scoped_refptr<base::SequencedTaskRunner> io_thread_; |
121 | 125 |
122 base::WeakPtr<GCMDriverDesktop> service_; | 126 base::WeakPtr<GCMDriverDesktop> service_; |
123 | 127 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
226 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 230 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
227 | 231 |
228 ui_thread_->PostTask( | 232 ui_thread_->PostTask( |
229 FROM_HERE, | 233 FROM_HERE, |
230 base::Bind(&GCMDriverDesktop::SendFinished, service_, app_id, message_id, | 234 base::Bind(&GCMDriverDesktop::SendFinished, service_, app_id, message_id, |
231 result)); | 235 result)); |
232 } | 236 } |
233 | 237 |
234 void GCMDriverDesktop::IOWorker::OnMessageReceived( | 238 void GCMDriverDesktop::IOWorker::OnMessageReceived( |
235 const std::string& app_id, | 239 const std::string& app_id, |
236 const IncomingMessage& message) { | 240 const IncomingMessage& message, |
241 const MessageReceiptCallback& receipt_callback) { | |
237 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 242 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
238 | 243 |
239 ui_thread_->PostTask( | 244 ui_thread_->PostTask(FROM_HERE, |
240 FROM_HERE, | 245 base::Bind(&GCMDriverDesktop::MessageReceived, service_, |
241 base::Bind(&GCMDriverDesktop::MessageReceived, | 246 app_id, message, receipt_callback)); |
242 service_, | |
243 app_id, | |
244 message)); | |
245 } | 247 } |
246 | 248 |
247 void GCMDriverDesktop::IOWorker::OnMessagesDeleted(const std::string& app_id) { | 249 void GCMDriverDesktop::IOWorker::OnMessagesDeleted(const std::string& app_id) { |
248 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 250 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
249 | 251 |
250 ui_thread_->PostTask( | 252 ui_thread_->PostTask( |
251 FROM_HERE, | 253 FROM_HERE, |
252 base::Bind(&GCMDriverDesktop::MessagesDeleted, service_, app_id)); | 254 base::Bind(&GCMDriverDesktop::MessagesDeleted, service_, app_id)); |
253 } | 255 } |
254 | 256 |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
503 gcm_client_->RemoveHeartbeatInterval(scope); | 505 gcm_client_->RemoveHeartbeatInterval(scope); |
504 } | 506 } |
505 | 507 |
506 void GCMDriverDesktop::IOWorker::RecordDecryptionFailure( | 508 void GCMDriverDesktop::IOWorker::RecordDecryptionFailure( |
507 const std::string& app_id, | 509 const std::string& app_id, |
508 GCMEncryptionProvider::DecryptionResult result) { | 510 GCMEncryptionProvider::DecryptionResult result) { |
509 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 511 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
510 gcm_client_->RecordDecryptionFailure(app_id, result); | 512 gcm_client_->RecordDecryptionFailure(app_id, result); |
511 } | 513 } |
512 | 514 |
515 void GCMDriverDesktop::IOWorker::SendMessageReceipt( | |
516 const MessageReceiptCallback& receipt_callback, | |
517 GCMMessageStatus status) { | |
518 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | |
519 | |
520 // The callback was created by the GCMClient on the IO thead so it is safe to | |
521 // invoke from here. | |
522 receipt_callback.Run(status); | |
523 } | |
524 | |
513 GCMDriverDesktop::GCMDriverDesktop( | 525 GCMDriverDesktop::GCMDriverDesktop( |
514 std::unique_ptr<GCMClientFactory> gcm_client_factory, | 526 std::unique_ptr<GCMClientFactory> gcm_client_factory, |
515 const GCMClient::ChromeBuildInfo& chrome_build_info, | 527 const GCMClient::ChromeBuildInfo& chrome_build_info, |
516 const std::string& channel_status_request_url, | 528 const std::string& channel_status_request_url, |
517 const std::string& user_agent, | 529 const std::string& user_agent, |
518 PrefService* prefs, | 530 PrefService* prefs, |
519 const base::FilePath& store_path, | 531 const base::FilePath& store_path, |
520 const scoped_refptr<net::URLRequestContextGetter>& request_context, | 532 const scoped_refptr<net::URLRequestContextGetter>& request_context, |
521 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, | 533 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, |
522 const scoped_refptr<base::SequencedTaskRunner>& io_thread, | 534 const scoped_refptr<base::SequencedTaskRunner>& io_thread, |
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1208 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 1220 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
1209 // Remove all the queued tasks since they no longer make sense after | 1221 // Remove all the queued tasks since they no longer make sense after |
1210 // GCM service is stopped. | 1222 // GCM service is stopped. |
1211 weak_ptr_factory_.InvalidateWeakPtrs(); | 1223 weak_ptr_factory_.InvalidateWeakPtrs(); |
1212 | 1224 |
1213 gcm_started_ = false; | 1225 gcm_started_ = false; |
1214 delayed_task_controller_.reset(); | 1226 delayed_task_controller_.reset(); |
1215 ClearCallbacks(); | 1227 ClearCallbacks(); |
1216 } | 1228 } |
1217 | 1229 |
1218 void GCMDriverDesktop::MessageReceived(const std::string& app_id, | 1230 void GCMDriverDesktop::MessageReceived( |
1219 const IncomingMessage& message) { | 1231 const std::string& app_id, |
1232 const IncomingMessage& message, | |
1233 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
| |
1220 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 1234 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
1221 | 1235 |
1222 // Drop the event if the service has been stopped. | 1236 // Drop the event if the service has been stopped. |
1223 if (!gcm_started_) | 1237 if (!gcm_started_) |
1224 return; | 1238 return; |
1225 | 1239 |
1226 DispatchMessage(app_id, message); | 1240 // Dispatch the message to the GCMDriver, but wrap the IO bound callback in a |
1241 // new callback which should be called on the UI thread. | |
1242 DispatchMessage(app_id, message, | |
1243 base::Bind(&GCMDriverDesktop::DoSendMessageReceipt, | |
1244 weak_ptr_factory_.GetWeakPtr(), receipt_callback)); | |
1227 } | 1245 } |
1228 | 1246 |
1229 void GCMDriverDesktop::MessagesDeleted(const std::string& app_id) { | 1247 void GCMDriverDesktop::MessagesDeleted(const std::string& app_id) { |
1230 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 1248 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
1231 | 1249 |
1232 // Drop the event if the service has been stopped. | 1250 // Drop the event if the service has been stopped. |
1233 if (!gcm_started_) | 1251 if (!gcm_started_) |
1234 return; | 1252 return; |
1235 | 1253 |
1236 GetAppHandler(app_id)->OnMessagesDeleted(app_id); | 1254 GetAppHandler(app_id)->OnMessagesDeleted(app_id); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1335 return false; | 1353 return false; |
1336 | 1354 |
1337 if (std::get<1>(a) < std::get<1>(b)) | 1355 if (std::get<1>(a) < std::get<1>(b)) |
1338 return true; | 1356 return true; |
1339 if (std::get<1>(a) > std::get<1>(b)) | 1357 if (std::get<1>(a) > std::get<1>(b)) |
1340 return false; | 1358 return false; |
1341 | 1359 |
1342 return std::get<2>(a) < std::get<2>(b); | 1360 return std::get<2>(a) < std::get<2>(b); |
1343 } | 1361 } |
1344 | 1362 |
1363 void GCMDriverDesktop::DoSendMessageReceipt( | |
1364 const MessageReceiptCallback& receipt_callback, | |
1365 GCMMessageStatus status) { | |
1366 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | |
1367 | |
1368 io_thread_->PostTask( | |
1369 FROM_HERE, | |
1370 base::Bind(&GCMDriverDesktop::IOWorker::SendMessageReceipt, | |
1371 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
| |
1372 } | |
1345 } // namespace gcm | 1373 } // namespace gcm |
OLD | NEW |