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_fetching_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 SetLastTokenFetchingTime(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, |
| 209 const base::Time& last_token_fetching_time) { |
207 ui_thread_->PostTask( | 210 ui_thread_->PostTask( |
208 FROM_HERE, | 211 FROM_HERE, |
209 base::Bind( | 212 base::Bind(&GCMDriverDesktop::GCMClientReady, |
210 &GCMDriverDesktop::GCMClientReady, service_, account_mappings)); | 213 service_, |
| 214 account_mappings, |
| 215 last_token_fetching_time)); |
211 } | 216 } |
212 | 217 |
213 void GCMDriverDesktop::IOWorker::OnActivityRecorded() { | 218 void GCMDriverDesktop::IOWorker::OnActivityRecorded() { |
214 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 219 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
215 // When an activity is recorded, get all the stats and refresh the UI of | 220 // When an activity is recorded, get all the stats and refresh the UI of |
216 // gcm-internals page. | 221 // gcm-internals page. |
217 GetGCMStatistics(false); | 222 GetGCMStatistics(false); |
218 } | 223 } |
219 | 224 |
220 void GCMDriverDesktop::IOWorker::OnConnected( | 225 void GCMDriverDesktop::IOWorker::OnConnected( |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 } | 328 } |
324 | 329 |
325 void GCMDriverDesktop::IOWorker::RemoveAccountMapping( | 330 void GCMDriverDesktop::IOWorker::RemoveAccountMapping( |
326 const std::string& account_id) { | 331 const std::string& account_id) { |
327 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 332 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
328 | 333 |
329 if (gcm_client_.get()) | 334 if (gcm_client_.get()) |
330 gcm_client_->RemoveAccountMapping(account_id); | 335 gcm_client_->RemoveAccountMapping(account_id); |
331 } | 336 } |
332 | 337 |
| 338 void GCMDriverDesktop::IOWorker::SetLastTokenFetchingTime( |
| 339 const base::Time& time) { |
| 340 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
| 341 |
| 342 if (gcm_client_.get()) |
| 343 gcm_client_->SetLastTokenFetchingTime(time); |
| 344 } |
| 345 |
333 GCMDriverDesktop::GCMDriverDesktop( | 346 GCMDriverDesktop::GCMDriverDesktop( |
334 scoped_ptr<GCMClientFactory> gcm_client_factory, | 347 scoped_ptr<GCMClientFactory> gcm_client_factory, |
335 const GCMClient::ChromeBuildInfo& chrome_build_info, | 348 const GCMClient::ChromeBuildInfo& chrome_build_info, |
336 const std::string& channel_status_request_url, | 349 const std::string& channel_status_request_url, |
337 const std::string& user_agent, | 350 const std::string& user_agent, |
338 PrefService* prefs, | 351 PrefService* prefs, |
339 const base::FilePath& store_path, | 352 const base::FilePath& store_path, |
340 const scoped_refptr<net::URLRequestContextGetter>& request_context, | 353 const scoped_refptr<net::URLRequestContextGetter>& request_context, |
341 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, | 354 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, |
342 const scoped_refptr<base::SequencedTaskRunner>& io_thread, | 355 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) { | 634 void GCMDriverDesktop::RemoveAccountMapping(const std::string& account_id) { |
622 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 635 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
623 | 636 |
624 io_thread_->PostTask( | 637 io_thread_->PostTask( |
625 FROM_HERE, | 638 FROM_HERE, |
626 base::Bind(&GCMDriverDesktop::IOWorker::RemoveAccountMapping, | 639 base::Bind(&GCMDriverDesktop::IOWorker::RemoveAccountMapping, |
627 base::Unretained(io_worker_.get()), | 640 base::Unretained(io_worker_.get()), |
628 account_id)); | 641 account_id)); |
629 } | 642 } |
630 | 643 |
| 644 base::Time GCMDriverDesktop::GetLastTokenFetchingTime() { |
| 645 return last_token_fetching_time_; |
| 646 } |
| 647 |
| 648 void GCMDriverDesktop::SetLastTokenFetchingTime(const base::Time& time) { |
| 649 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| 650 |
| 651 io_thread_->PostTask( |
| 652 FROM_HERE, |
| 653 base::Bind(&GCMDriverDesktop::IOWorker::SetLastTokenFetchingTime, |
| 654 base::Unretained(io_worker_.get()), |
| 655 time)); |
| 656 } |
| 657 |
631 void GCMDriverDesktop::SetAccountTokens( | 658 void GCMDriverDesktop::SetAccountTokens( |
632 const std::vector<GCMClient::AccountTokenInfo>& account_tokens) { | 659 const std::vector<GCMClient::AccountTokenInfo>& account_tokens) { |
633 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 660 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
634 | 661 |
635 account_mapper_->SetAccountTokens(account_tokens); | 662 account_mapper_->SetAccountTokens(account_tokens); |
636 | 663 |
637 io_thread_->PostTask( | 664 io_thread_->PostTask( |
638 FROM_HERE, | 665 FROM_HERE, |
639 base::Bind(&GCMDriverDesktop::IOWorker::SetAccountTokens, | 666 base::Bind(&GCMDriverDesktop::IOWorker::SetAccountTokens, |
640 base::Unretained(io_worker_.get()), | 667 base::Unretained(io_worker_.get()), |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 763 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
737 | 764 |
738 // Drop the event if the service has been stopped. | 765 // Drop the event if the service has been stopped. |
739 if (!gcm_started_) | 766 if (!gcm_started_) |
740 return; | 767 return; |
741 | 768 |
742 GetAppHandler(app_id)->OnSendAcknowledged(app_id, message_id); | 769 GetAppHandler(app_id)->OnSendAcknowledged(app_id, message_id); |
743 } | 770 } |
744 | 771 |
745 void GCMDriverDesktop::GCMClientReady( | 772 void GCMDriverDesktop::GCMClientReady( |
746 const std::vector<AccountMapping>& account_mappings) { | 773 const std::vector<AccountMapping>& account_mappings, |
| 774 const base::Time& last_token_fetching_time) { |
747 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 775 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
748 | 776 |
749 GCMDriver::AddAppHandler(kGCMAccountMapperAppId, account_mapper_.get()); | 777 GCMDriver::AddAppHandler(kGCMAccountMapperAppId, account_mapper_.get()); |
750 account_mapper_->Initialize(account_mappings); | 778 account_mapper_->Initialize(account_mappings); |
| 779 last_token_fetching_time_ = last_token_fetching_time; |
751 | 780 |
752 delayed_task_controller_->SetReady(); | 781 delayed_task_controller_->SetReady(); |
753 } | 782 } |
754 | 783 |
755 void GCMDriverDesktop::OnConnected(const net::IPEndPoint& ip_endpoint) { | 784 void GCMDriverDesktop::OnConnected(const net::IPEndPoint& ip_endpoint) { |
756 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 785 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
757 | 786 |
758 connected_ = true; | 787 connected_ = true; |
759 | 788 |
760 // Drop the event if the service has been stopped. | 789 // Drop the event if the service has been stopped. |
(...skipping 24 matching lines...) Expand all Loading... |
785 | 814 |
786 // Normally request_gcm_statistics_callback_ would not be null. | 815 // Normally request_gcm_statistics_callback_ would not be null. |
787 if (!request_gcm_statistics_callback_.is_null()) | 816 if (!request_gcm_statistics_callback_.is_null()) |
788 request_gcm_statistics_callback_.Run(stats); | 817 request_gcm_statistics_callback_.Run(stats); |
789 else | 818 else |
790 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; | 819 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; |
791 } | 820 } |
792 | 821 |
793 } // namespace gcm | 822 } // namespace gcm |
794 | 823 |
OLD | NEW |