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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 const std::string& message_id, | 44 const std::string& message_id, |
45 GCMClient::Result result) override; | 45 GCMClient::Result result) override; |
46 void OnMessageReceived(const std::string& app_id, | 46 void OnMessageReceived(const std::string& app_id, |
47 const GCMClient::IncomingMessage& message) override; | 47 const GCMClient::IncomingMessage& message) override; |
48 void OnMessagesDeleted(const std::string& app_id) override; | 48 void OnMessagesDeleted(const std::string& app_id) override; |
49 void OnMessageSendError( | 49 void OnMessageSendError( |
50 const std::string& app_id, | 50 const std::string& app_id, |
51 const GCMClient::SendErrorDetails& send_error_details) override; | 51 const GCMClient::SendErrorDetails& send_error_details) override; |
52 void OnSendAcknowledged(const std::string& app_id, | 52 void OnSendAcknowledged(const std::string& app_id, |
53 const std::string& message_id) override; | 53 const std::string& message_id) override; |
54 void OnGCMReady(const std::vector<AccountMapping>& account_mappings) override; | 54 void OnGCMReady(const std::vector<AccountMapping>& account_mappings, |
| 55 const base::Time& last_token_fetch_time) override; |
55 void OnActivityRecorded() override; | 56 void OnActivityRecorded() override; |
56 void OnConnected(const net::IPEndPoint& ip_endpoint) override; | 57 void OnConnected(const net::IPEndPoint& ip_endpoint) override; |
57 void OnDisconnected() override; | 58 void OnDisconnected() override; |
58 | 59 |
59 // Called on IO thread. | 60 // Called on IO thread. |
60 void Initialize( | 61 void Initialize( |
61 scoped_ptr<GCMClientFactory> gcm_client_factory, | 62 scoped_ptr<GCMClientFactory> gcm_client_factory, |
62 const GCMClient::ChromeBuildInfo& chrome_build_info, | 63 const GCMClient::ChromeBuildInfo& chrome_build_info, |
63 const base::FilePath& store_path, | 64 const base::FilePath& store_path, |
64 const scoped_refptr<net::URLRequestContextGetter>& request_context, | 65 const scoped_refptr<net::URLRequestContextGetter>& request_context, |
65 const scoped_refptr<base::SequencedTaskRunner> blocking_task_runner); | 66 const scoped_refptr<base::SequencedTaskRunner> blocking_task_runner); |
66 void Start(const base::WeakPtr<GCMDriverDesktop>& service); | 67 void Start(const base::WeakPtr<GCMDriverDesktop>& service); |
67 void Stop(); | 68 void Stop(); |
68 void CheckOut(); | 69 void CheckOut(); |
69 void Register(const std::string& app_id, | 70 void Register(const std::string& app_id, |
70 const std::vector<std::string>& sender_ids); | 71 const std::vector<std::string>& sender_ids); |
71 void Unregister(const std::string& app_id); | 72 void Unregister(const std::string& app_id); |
72 void Send(const std::string& app_id, | 73 void Send(const std::string& app_id, |
73 const std::string& receiver_id, | 74 const std::string& receiver_id, |
74 const GCMClient::OutgoingMessage& message); | 75 const GCMClient::OutgoingMessage& message); |
75 void GetGCMStatistics(bool clear_logs); | 76 void GetGCMStatistics(bool clear_logs); |
76 void SetGCMRecording(bool recording); | 77 void SetGCMRecording(bool recording); |
77 | 78 |
78 void SetAccountTokens( | 79 void SetAccountTokens( |
79 const std::vector<GCMClient::AccountTokenInfo>& account_tokens); | 80 const std::vector<GCMClient::AccountTokenInfo>& account_tokens); |
80 void UpdateAccountMapping(const AccountMapping& account_mapping); | 81 void UpdateAccountMapping(const AccountMapping& account_mapping); |
81 void RemoveAccountMapping(const std::string& account_id); | 82 void RemoveAccountMapping(const std::string& account_id); |
| 83 void SetLastTokenFetchTime(const base::Time& time); |
82 | 84 |
83 // For testing purpose. Can be called from UI thread. Use with care. | 85 // For testing purpose. Can be called from UI thread. Use with care. |
84 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); } | 86 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); } |
85 | 87 |
86 private: | 88 private: |
87 scoped_refptr<base::SequencedTaskRunner> ui_thread_; | 89 scoped_refptr<base::SequencedTaskRunner> ui_thread_; |
88 scoped_refptr<base::SequencedTaskRunner> io_thread_; | 90 scoped_refptr<base::SequencedTaskRunner> io_thread_; |
89 | 91 |
90 base::WeakPtr<GCMDriverDesktop> service_; | 92 base::WeakPtr<GCMDriverDesktop> service_; |
91 | 93 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 const std::string& message_id) { | 198 const std::string& message_id) { |
197 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 199 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
198 | 200 |
199 ui_thread_->PostTask( | 201 ui_thread_->PostTask( |
200 FROM_HERE, | 202 FROM_HERE, |
201 base::Bind( | 203 base::Bind( |
202 &GCMDriverDesktop::SendAcknowledged, service_, app_id, message_id)); | 204 &GCMDriverDesktop::SendAcknowledged, service_, app_id, message_id)); |
203 } | 205 } |
204 | 206 |
205 void GCMDriverDesktop::IOWorker::OnGCMReady( | 207 void GCMDriverDesktop::IOWorker::OnGCMReady( |
206 const std::vector<AccountMapping>& account_mappings) { | 208 const std::vector<AccountMapping>& account_mappings, |
207 ui_thread_->PostTask( | 209 const base::Time& last_token_fetch_time) { |
208 FROM_HERE, | 210 ui_thread_->PostTask(FROM_HERE, |
209 base::Bind( | 211 base::Bind(&GCMDriverDesktop::GCMClientReady, |
210 &GCMDriverDesktop::GCMClientReady, service_, account_mappings)); | 212 service_, |
| 213 account_mappings, |
| 214 last_token_fetch_time)); |
211 } | 215 } |
212 | 216 |
213 void GCMDriverDesktop::IOWorker::OnActivityRecorded() { | 217 void GCMDriverDesktop::IOWorker::OnActivityRecorded() { |
214 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 218 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
215 // When an activity is recorded, get all the stats and refresh the UI of | 219 // When an activity is recorded, get all the stats and refresh the UI of |
216 // gcm-internals page. | 220 // gcm-internals page. |
217 GetGCMStatistics(false); | 221 GetGCMStatistics(false); |
218 } | 222 } |
219 | 223 |
220 void GCMDriverDesktop::IOWorker::OnConnected( | 224 void GCMDriverDesktop::IOWorker::OnConnected( |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 } | 327 } |
324 | 328 |
325 void GCMDriverDesktop::IOWorker::RemoveAccountMapping( | 329 void GCMDriverDesktop::IOWorker::RemoveAccountMapping( |
326 const std::string& account_id) { | 330 const std::string& account_id) { |
327 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 331 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
328 | 332 |
329 if (gcm_client_.get()) | 333 if (gcm_client_.get()) |
330 gcm_client_->RemoveAccountMapping(account_id); | 334 gcm_client_->RemoveAccountMapping(account_id); |
331 } | 335 } |
332 | 336 |
| 337 void GCMDriverDesktop::IOWorker::SetLastTokenFetchTime(const base::Time& time) { |
| 338 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
| 339 |
| 340 if (gcm_client_.get()) |
| 341 gcm_client_->SetLastTokenFetchTime(time); |
| 342 } |
| 343 |
333 GCMDriverDesktop::GCMDriverDesktop( | 344 GCMDriverDesktop::GCMDriverDesktop( |
334 scoped_ptr<GCMClientFactory> gcm_client_factory, | 345 scoped_ptr<GCMClientFactory> gcm_client_factory, |
335 const GCMClient::ChromeBuildInfo& chrome_build_info, | 346 const GCMClient::ChromeBuildInfo& chrome_build_info, |
336 const std::string& channel_status_request_url, | 347 const std::string& channel_status_request_url, |
337 const std::string& user_agent, | 348 const std::string& user_agent, |
338 PrefService* prefs, | 349 PrefService* prefs, |
339 const base::FilePath& store_path, | 350 const base::FilePath& store_path, |
340 const scoped_refptr<net::URLRequestContextGetter>& request_context, | 351 const scoped_refptr<net::URLRequestContextGetter>& request_context, |
341 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, | 352 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, |
342 const scoped_refptr<base::SequencedTaskRunner>& io_thread, | 353 const scoped_refptr<base::SequencedTaskRunner>& io_thread, |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 void GCMDriverDesktop::RemoveAccountMapping(const std::string& account_id) { | 632 void GCMDriverDesktop::RemoveAccountMapping(const std::string& account_id) { |
622 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 633 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
623 | 634 |
624 io_thread_->PostTask( | 635 io_thread_->PostTask( |
625 FROM_HERE, | 636 FROM_HERE, |
626 base::Bind(&GCMDriverDesktop::IOWorker::RemoveAccountMapping, | 637 base::Bind(&GCMDriverDesktop::IOWorker::RemoveAccountMapping, |
627 base::Unretained(io_worker_.get()), | 638 base::Unretained(io_worker_.get()), |
628 account_id)); | 639 account_id)); |
629 } | 640 } |
630 | 641 |
| 642 base::Time GCMDriverDesktop::GetLastTokenFetchTime() { |
| 643 return last_token_fetch_time_; |
| 644 } |
| 645 |
| 646 void GCMDriverDesktop::SetLastTokenFetchTime(const base::Time& time) { |
| 647 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| 648 |
| 649 io_thread_->PostTask( |
| 650 FROM_HERE, |
| 651 base::Bind(&GCMDriverDesktop::IOWorker::SetLastTokenFetchTime, |
| 652 base::Unretained(io_worker_.get()), |
| 653 time)); |
| 654 } |
| 655 |
631 void GCMDriverDesktop::SetAccountTokens( | 656 void GCMDriverDesktop::SetAccountTokens( |
632 const std::vector<GCMClient::AccountTokenInfo>& account_tokens) { | 657 const std::vector<GCMClient::AccountTokenInfo>& account_tokens) { |
633 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 658 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
634 | 659 |
635 account_mapper_->SetAccountTokens(account_tokens); | 660 account_mapper_->SetAccountTokens(account_tokens); |
636 | 661 |
637 io_thread_->PostTask( | 662 io_thread_->PostTask( |
638 FROM_HERE, | 663 FROM_HERE, |
639 base::Bind(&GCMDriverDesktop::IOWorker::SetAccountTokens, | 664 base::Bind(&GCMDriverDesktop::IOWorker::SetAccountTokens, |
640 base::Unretained(io_worker_.get()), | 665 base::Unretained(io_worker_.get()), |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 761 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
737 | 762 |
738 // Drop the event if the service has been stopped. | 763 // Drop the event if the service has been stopped. |
739 if (!gcm_started_) | 764 if (!gcm_started_) |
740 return; | 765 return; |
741 | 766 |
742 GetAppHandler(app_id)->OnSendAcknowledged(app_id, message_id); | 767 GetAppHandler(app_id)->OnSendAcknowledged(app_id, message_id); |
743 } | 768 } |
744 | 769 |
745 void GCMDriverDesktop::GCMClientReady( | 770 void GCMDriverDesktop::GCMClientReady( |
746 const std::vector<AccountMapping>& account_mappings) { | 771 const std::vector<AccountMapping>& account_mappings, |
| 772 const base::Time& last_token_fetch_time) { |
747 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 773 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
748 | 774 |
749 GCMDriver::AddAppHandler(kGCMAccountMapperAppId, account_mapper_.get()); | 775 GCMDriver::AddAppHandler(kGCMAccountMapperAppId, account_mapper_.get()); |
750 account_mapper_->Initialize(account_mappings); | 776 account_mapper_->Initialize(account_mappings); |
| 777 last_token_fetch_time_ = last_token_fetch_time; |
751 | 778 |
752 delayed_task_controller_->SetReady(); | 779 delayed_task_controller_->SetReady(); |
753 } | 780 } |
754 | 781 |
755 void GCMDriverDesktop::OnConnected(const net::IPEndPoint& ip_endpoint) { | 782 void GCMDriverDesktop::OnConnected(const net::IPEndPoint& ip_endpoint) { |
756 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 783 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
757 | 784 |
758 connected_ = true; | 785 connected_ = true; |
759 | 786 |
760 // Drop the event if the service has been stopped. | 787 // Drop the event if the service has been stopped. |
(...skipping 24 matching lines...) Expand all Loading... |
785 | 812 |
786 // Normally request_gcm_statistics_callback_ would not be null. | 813 // Normally request_gcm_statistics_callback_ would not be null. |
787 if (!request_gcm_statistics_callback_.is_null()) | 814 if (!request_gcm_statistics_callback_.is_null()) |
788 request_gcm_statistics_callback_.Run(stats); | 815 request_gcm_statistics_callback_.Run(stats); |
789 else | 816 else |
790 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; | 817 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; |
791 } | 818 } |
792 | 819 |
793 } // namespace gcm | 820 } // namespace gcm |
794 | 821 |
OLD | NEW |