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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 void SetAccountTokens( | 84 void SetAccountTokens( |
85 const std::vector<GCMClient::AccountTokenInfo>& account_tokens); | 85 const std::vector<GCMClient::AccountTokenInfo>& account_tokens); |
86 void UpdateAccountMapping(const AccountMapping& account_mapping); | 86 void UpdateAccountMapping(const AccountMapping& account_mapping); |
87 void RemoveAccountMapping(const std::string& account_id); | 87 void RemoveAccountMapping(const std::string& account_id); |
88 void SetLastTokenFetchTime(const base::Time& time); | 88 void SetLastTokenFetchTime(const base::Time& time); |
89 void WakeFromSuspendForHeartbeat(bool wake); | 89 void WakeFromSuspendForHeartbeat(bool wake); |
90 void AddInstanceIDData(const std::string& app_id, | 90 void AddInstanceIDData(const std::string& app_id, |
91 const std::string& instance_id_data); | 91 const std::string& instance_id_data); |
92 void RemoveInstanceIDData(const std::string& app_id); | 92 void RemoveInstanceIDData(const std::string& app_id); |
93 void GetInstanceIDData(const std::string& app_id); | 93 void GetInstanceIDData(const std::string& app_id); |
| 94 void AddHeartbeatInterval(const std::string& scope, int interval_ms); |
| 95 void RemoveHeartbeatInterval(const std::string& scope); |
94 | 96 |
95 // For testing purpose. Can be called from UI thread. Use with care. | 97 // For testing purpose. Can be called from UI thread. Use with care. |
96 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); } | 98 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); } |
97 | 99 |
98 private: | 100 private: |
99 scoped_refptr<base::SequencedTaskRunner> ui_thread_; | 101 scoped_refptr<base::SequencedTaskRunner> ui_thread_; |
100 scoped_refptr<base::SequencedTaskRunner> io_thread_; | 102 scoped_refptr<base::SequencedTaskRunner> io_thread_; |
101 | 103 |
102 base::WeakPtr<GCMDriverDesktop> service_; | 104 base::WeakPtr<GCMDriverDesktop> service_; |
103 | 105 |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 scoped_ptr<base::Timer> timer; | 387 scoped_ptr<base::Timer> timer; |
386 if (wake) | 388 if (wake) |
387 timer.reset(new timers::SimpleAlarmTimer()); | 389 timer.reset(new timers::SimpleAlarmTimer()); |
388 else | 390 else |
389 timer.reset(new base::Timer(true, false)); | 391 timer.reset(new base::Timer(true, false)); |
390 | 392 |
391 gcm_client_->UpdateHeartbeatTimer(timer.Pass()); | 393 gcm_client_->UpdateHeartbeatTimer(timer.Pass()); |
392 #endif | 394 #endif |
393 } | 395 } |
394 | 396 |
| 397 void GCMDriverDesktop::IOWorker::AddHeartbeatInterval( |
| 398 const std::string& scope, |
| 399 int interval_ms) { |
| 400 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
| 401 gcm_client_->AddHeartbeatInterval(scope, interval_ms); |
| 402 } |
| 403 |
| 404 void GCMDriverDesktop::IOWorker::RemoveHeartbeatInterval( |
| 405 const std::string& scope) { |
| 406 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
| 407 gcm_client_->RemoveHeartbeatInterval(scope); |
| 408 } |
| 409 |
395 GCMDriverDesktop::GCMDriverDesktop( | 410 GCMDriverDesktop::GCMDriverDesktop( |
396 scoped_ptr<GCMClientFactory> gcm_client_factory, | 411 scoped_ptr<GCMClientFactory> gcm_client_factory, |
397 const GCMClient::ChromeBuildInfo& chrome_build_info, | 412 const GCMClient::ChromeBuildInfo& chrome_build_info, |
398 const std::string& channel_status_request_url, | 413 const std::string& channel_status_request_url, |
399 const std::string& user_agent, | 414 const std::string& user_agent, |
400 PrefService* prefs, | 415 PrefService* prefs, |
401 const base::FilePath& store_path, | 416 const base::FilePath& store_path, |
402 const scoped_refptr<net::URLRequestContextGetter>& request_context, | 417 const scoped_refptr<net::URLRequestContextGetter>& request_context, |
403 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, | 418 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, |
404 const scoped_refptr<base::SequencedTaskRunner>& io_thread, | 419 const scoped_refptr<base::SequencedTaskRunner>& io_thread, |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 | 776 |
762 // The GCMClient is ready so we can go ahead and post this task to the | 777 // The GCMClient is ready so we can go ahead and post this task to the |
763 // IOWorker. | 778 // IOWorker. |
764 io_thread_->PostTask( | 779 io_thread_->PostTask( |
765 FROM_HERE, | 780 FROM_HERE, |
766 base::Bind(&GCMDriverDesktop::IOWorker::WakeFromSuspendForHeartbeat, | 781 base::Bind(&GCMDriverDesktop::IOWorker::WakeFromSuspendForHeartbeat, |
767 base::Unretained(io_worker_.get()), | 782 base::Unretained(io_worker_.get()), |
768 wake_from_suspend_enabled_)); | 783 wake_from_suspend_enabled_)); |
769 } | 784 } |
770 | 785 |
| 786 void GCMDriverDesktop::AddHeartbeatInterval(const std::string& scope, |
| 787 int interval_ms) { |
| 788 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| 789 |
| 790 // The GCM service has not been initialized. |
| 791 if (!delayed_task_controller_) |
| 792 return; |
| 793 |
| 794 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) { |
| 795 // The GCM service was initialized but has not started yet. |
| 796 delayed_task_controller_->AddTask( |
| 797 base::Bind(&GCMDriverDesktop::AddHeartbeatInterval, |
| 798 weak_ptr_factory_.GetWeakPtr(), |
| 799 scope, |
| 800 interval_ms)); |
| 801 return; |
| 802 } |
| 803 |
| 804 io_thread_->PostTask( |
| 805 FROM_HERE, |
| 806 base::Bind(&GCMDriverDesktop::IOWorker::AddHeartbeatInterval, |
| 807 base::Unretained(io_worker_.get()), |
| 808 scope, |
| 809 interval_ms)); |
| 810 } |
| 811 |
| 812 void GCMDriverDesktop::RemoveHeartbeatInterval(const std::string& scope) { |
| 813 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| 814 |
| 815 // The GCM service has not been initialized. |
| 816 if (!delayed_task_controller_) |
| 817 return; |
| 818 |
| 819 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) { |
| 820 // The GCM service was initialized but has not started yet. |
| 821 delayed_task_controller_->AddTask( |
| 822 base::Bind(&GCMDriverDesktop::RemoveHeartbeatInterval, |
| 823 weak_ptr_factory_.GetWeakPtr(), |
| 824 scope)); |
| 825 return; |
| 826 } |
| 827 |
| 828 io_thread_->PostTask( |
| 829 FROM_HERE, |
| 830 base::Bind(&GCMDriverDesktop::IOWorker::RemoveHeartbeatInterval, |
| 831 base::Unretained(io_worker_.get()), |
| 832 scope)); |
| 833 } |
| 834 |
771 void GCMDriverDesktop::SetAccountTokens( | 835 void GCMDriverDesktop::SetAccountTokens( |
772 const std::vector<GCMClient::AccountTokenInfo>& account_tokens) { | 836 const std::vector<GCMClient::AccountTokenInfo>& account_tokens) { |
773 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 837 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
774 | 838 |
775 account_mapper_->SetAccountTokens(account_tokens); | 839 account_mapper_->SetAccountTokens(account_tokens); |
776 | 840 |
777 io_thread_->PostTask( | 841 io_thread_->PostTask( |
778 FROM_HERE, | 842 FROM_HERE, |
779 base::Bind(&GCMDriverDesktop::IOWorker::SetAccountTokens, | 843 base::Bind(&GCMDriverDesktop::IOWorker::SetAccountTokens, |
780 base::Unretained(io_worker_.get()), | 844 base::Unretained(io_worker_.get()), |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
923 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 987 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
924 | 988 |
925 // Normally request_gcm_statistics_callback_ would not be null. | 989 // Normally request_gcm_statistics_callback_ would not be null. |
926 if (!request_gcm_statistics_callback_.is_null()) | 990 if (!request_gcm_statistics_callback_.is_null()) |
927 request_gcm_statistics_callback_.Run(stats); | 991 request_gcm_statistics_callback_.Run(stats); |
928 else | 992 else |
929 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; | 993 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; |
930 } | 994 } |
931 | 995 |
932 } // namespace gcm | 996 } // namespace gcm |
OLD | NEW |