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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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(const std::string& app_id, |
57 const IncomingMessage& message) override; | 57 const IncomingMessage& message, |
58 const MessageReceiptCallback& callback) override; | |
58 void OnMessagesDeleted(const std::string& app_id) override; | 59 void OnMessagesDeleted(const std::string& app_id) override; |
59 void OnMessageSendError( | 60 void OnMessageSendError( |
60 const std::string& app_id, | 61 const std::string& app_id, |
61 const GCMClient::SendErrorDetails& send_error_details) override; | 62 const GCMClient::SendErrorDetails& send_error_details) override; |
62 void OnSendAcknowledged(const std::string& app_id, | 63 void OnSendAcknowledged(const std::string& app_id, |
63 const std::string& message_id) override; | 64 const std::string& message_id) override; |
64 void OnGCMReady(const std::vector<AccountMapping>& account_mappings, | 65 void OnGCMReady(const std::vector<AccountMapping>& account_mappings, |
65 const base::Time& last_token_fetch_time) override; | 66 const base::Time& last_token_fetch_time) override; |
66 void OnActivityRecorded() override; | 67 void OnActivityRecorded() override; |
67 void OnConnected(const net::IPEndPoint& ip_endpoint) override; | 68 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, | 105 void GetToken(const std::string& app_id, |
105 const std::string& authorized_entity, | 106 const std::string& authorized_entity, |
106 const std::string& scope, | 107 const std::string& scope, |
107 const std::map<std::string, std::string>& options); | 108 const std::map<std::string, std::string>& options); |
108 void DeleteToken(const std::string& app_id, | 109 void DeleteToken(const std::string& app_id, |
109 const std::string& authorized_entity, | 110 const std::string& authorized_entity, |
110 const std::string& scope); | 111 const std::string& scope); |
111 | 112 |
112 void RecordDecryptionFailure(const std::string& app_id, | 113 void RecordDecryptionFailure(const std::string& app_id, |
113 GCMEncryptionProvider::DecryptionResult result); | 114 GCMEncryptionProvider::DecryptionResult result); |
115 void SendMessageReceipt(const MessageReceiptCallback& callback, | |
116 GCMMessageStatus status); | |
114 | 117 |
115 // For testing purpose. Can be called from UI thread. Use with care. | 118 // For testing purpose. Can be called from UI thread. Use with care. |
116 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); } | 119 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); } |
117 | 120 |
118 private: | 121 private: |
119 scoped_refptr<base::SequencedTaskRunner> ui_thread_; | 122 scoped_refptr<base::SequencedTaskRunner> ui_thread_; |
120 scoped_refptr<base::SequencedTaskRunner> io_thread_; | 123 scoped_refptr<base::SequencedTaskRunner> io_thread_; |
121 | 124 |
122 base::WeakPtr<GCMDriverDesktop> service_; | 125 base::WeakPtr<GCMDriverDesktop> service_; |
123 | 126 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
226 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 229 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
227 | 230 |
228 ui_thread_->PostTask( | 231 ui_thread_->PostTask( |
229 FROM_HERE, | 232 FROM_HERE, |
230 base::Bind(&GCMDriverDesktop::SendFinished, service_, app_id, message_id, | 233 base::Bind(&GCMDriverDesktop::SendFinished, service_, app_id, message_id, |
231 result)); | 234 result)); |
232 } | 235 } |
233 | 236 |
234 void GCMDriverDesktop::IOWorker::OnMessageReceived( | 237 void GCMDriverDesktop::IOWorker::OnMessageReceived( |
235 const std::string& app_id, | 238 const std::string& app_id, |
236 const IncomingMessage& message) { | 239 const IncomingMessage& message, |
240 const MessageReceiptCallback& callback) { | |
237 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 241 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
238 | 242 |
239 ui_thread_->PostTask( | 243 ui_thread_->PostTask(FROM_HERE, |
240 FROM_HERE, | 244 base::Bind(&GCMDriverDesktop::MessageReceived, service_, |
241 base::Bind(&GCMDriverDesktop::MessageReceived, | 245 app_id, message, callback)); |
242 service_, | |
243 app_id, | |
244 message)); | |
245 } | 246 } |
246 | 247 |
247 void GCMDriverDesktop::IOWorker::OnMessagesDeleted(const std::string& app_id) { | 248 void GCMDriverDesktop::IOWorker::OnMessagesDeleted(const std::string& app_id) { |
248 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 249 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
249 | 250 |
250 ui_thread_->PostTask( | 251 ui_thread_->PostTask( |
251 FROM_HERE, | 252 FROM_HERE, |
252 base::Bind(&GCMDriverDesktop::MessagesDeleted, service_, app_id)); | 253 base::Bind(&GCMDriverDesktop::MessagesDeleted, service_, app_id)); |
253 } | 254 } |
254 | 255 |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
503 gcm_client_->RemoveHeartbeatInterval(scope); | 504 gcm_client_->RemoveHeartbeatInterval(scope); |
504 } | 505 } |
505 | 506 |
506 void GCMDriverDesktop::IOWorker::RecordDecryptionFailure( | 507 void GCMDriverDesktop::IOWorker::RecordDecryptionFailure( |
507 const std::string& app_id, | 508 const std::string& app_id, |
508 GCMEncryptionProvider::DecryptionResult result) { | 509 GCMEncryptionProvider::DecryptionResult result) { |
509 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 510 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
510 gcm_client_->RecordDecryptionFailure(app_id, result); | 511 gcm_client_->RecordDecryptionFailure(app_id, result); |
511 } | 512 } |
512 | 513 |
514 void GCMDriverDesktop::IOWorker::SendMessageReceipt( | |
515 const MessageReceiptCallback& callback, | |
516 GCMMessageStatus status) { | |
517 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | |
518 | |
519 // The callback was created by the GCMClient on the IO thead so it is safe to | |
520 // invoke from here. | |
521 callback.Run(status); | |
522 } | |
523 | |
513 GCMDriverDesktop::GCMDriverDesktop( | 524 GCMDriverDesktop::GCMDriverDesktop( |
514 std::unique_ptr<GCMClientFactory> gcm_client_factory, | 525 std::unique_ptr<GCMClientFactory> gcm_client_factory, |
515 const GCMClient::ChromeBuildInfo& chrome_build_info, | 526 const GCMClient::ChromeBuildInfo& chrome_build_info, |
516 const std::string& channel_status_request_url, | 527 const std::string& channel_status_request_url, |
517 const std::string& user_agent, | 528 const std::string& user_agent, |
518 PrefService* prefs, | 529 PrefService* prefs, |
519 const base::FilePath& store_path, | 530 const base::FilePath& store_path, |
520 const scoped_refptr<net::URLRequestContextGetter>& request_context, | 531 const scoped_refptr<net::URLRequestContextGetter>& request_context, |
521 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, | 532 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, |
522 const scoped_refptr<base::SequencedTaskRunner>& io_thread, | 533 const scoped_refptr<base::SequencedTaskRunner>& io_thread, |
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1209 // Remove all the queued tasks since they no longer make sense after | 1220 // Remove all the queued tasks since they no longer make sense after |
1210 // GCM service is stopped. | 1221 // GCM service is stopped. |
1211 weak_ptr_factory_.InvalidateWeakPtrs(); | 1222 weak_ptr_factory_.InvalidateWeakPtrs(); |
1212 | 1223 |
1213 gcm_started_ = false; | 1224 gcm_started_ = false; |
1214 delayed_task_controller_.reset(); | 1225 delayed_task_controller_.reset(); |
1215 ClearCallbacks(); | 1226 ClearCallbacks(); |
1216 } | 1227 } |
1217 | 1228 |
1218 void GCMDriverDesktop::MessageReceived(const std::string& app_id, | 1229 void GCMDriverDesktop::MessageReceived(const std::string& app_id, |
1219 const IncomingMessage& message) { | 1230 const IncomingMessage& message, |
1231 const MessageReceiptCallback& callback) { | |
1220 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 1232 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
1221 | 1233 |
1222 // Drop the event if the service has been stopped. | 1234 // Drop the event if the service has been stopped. |
1223 if (!gcm_started_) | 1235 if (!gcm_started_) |
1224 return; | 1236 return; |
1225 | 1237 |
1226 DispatchMessage(app_id, message); | 1238 DispatchMessage(app_id, message, callback); |
Peter Beverloo
2017/02/08 17:09:09
The |callback| passed to DispatchMessage any beyon
harkness
2017/02/09 16:27:30
Good point, I hadn't considered that there was a s
| |
1227 } | 1239 } |
1228 | 1240 |
1229 void GCMDriverDesktop::MessagesDeleted(const std::string& app_id) { | 1241 void GCMDriverDesktop::MessagesDeleted(const std::string& app_id) { |
1230 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 1242 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
1231 | 1243 |
1232 // Drop the event if the service has been stopped. | 1244 // Drop the event if the service has been stopped. |
1233 if (!gcm_started_) | 1245 if (!gcm_started_) |
1234 return; | 1246 return; |
1235 | 1247 |
1236 GetAppHandler(app_id)->OnMessagesDeleted(app_id); | 1248 GetAppHandler(app_id)->OnMessagesDeleted(app_id); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1335 return false; | 1347 return false; |
1336 | 1348 |
1337 if (std::get<1>(a) < std::get<1>(b)) | 1349 if (std::get<1>(a) < std::get<1>(b)) |
1338 return true; | 1350 return true; |
1339 if (std::get<1>(a) > std::get<1>(b)) | 1351 if (std::get<1>(a) > std::get<1>(b)) |
1340 return false; | 1352 return false; |
1341 | 1353 |
1342 return std::get<2>(a) < std::get<2>(b); | 1354 return std::get<2>(a) < std::get<2>(b); |
1343 } | 1355 } |
1344 | 1356 |
1357 void GCMDriverDesktop::DoSendMessageReceipt( | |
1358 const MessageReceiptCallback& callback, | |
1359 GCMMessageStatus status) { | |
1360 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | |
1361 | |
1362 io_thread_->PostTask( | |
1363 FROM_HERE, | |
1364 base::Bind(&GCMDriverDesktop::IOWorker::SendMessageReceipt, | |
1365 base::Unretained(io_worker_.get()), callback, status)); | |
1366 } | |
1345 } // namespace gcm | 1367 } // namespace gcm |
OLD | NEW |