Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: components/gcm_driver/gcm_driver_desktop.cc

Issue 1124783002: [GCM] Wiring heartbeat interval calls to GCMDriver (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@store-heartbeat-gcm
Patch Set: Addressing final feedback and fixing formatting Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/gcm_driver/gcm_driver_desktop.h ('k') | google_apis/gcm/engine/gcm_store.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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(const std::string& scope,
398 int interval_ms) {
399 DCHECK(io_thread_->RunsTasksOnCurrentThread());
400 gcm_client_->AddHeartbeatInterval(scope, interval_ms);
401 }
402
403 void GCMDriverDesktop::IOWorker::RemoveHeartbeatInterval(
404 const std::string& scope) {
405 DCHECK(io_thread_->RunsTasksOnCurrentThread());
406 gcm_client_->RemoveHeartbeatInterval(scope);
407 }
408
395 GCMDriverDesktop::GCMDriverDesktop( 409 GCMDriverDesktop::GCMDriverDesktop(
396 scoped_ptr<GCMClientFactory> gcm_client_factory, 410 scoped_ptr<GCMClientFactory> gcm_client_factory,
397 const GCMClient::ChromeBuildInfo& chrome_build_info, 411 const GCMClient::ChromeBuildInfo& chrome_build_info,
398 const std::string& channel_status_request_url, 412 const std::string& channel_status_request_url,
399 const std::string& user_agent, 413 const std::string& user_agent,
400 PrefService* prefs, 414 PrefService* prefs,
401 const base::FilePath& store_path, 415 const base::FilePath& store_path,
402 const scoped_refptr<net::URLRequestContextGetter>& request_context, 416 const scoped_refptr<net::URLRequestContextGetter>& request_context,
403 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, 417 const scoped_refptr<base::SequencedTaskRunner>& ui_thread,
404 const scoped_refptr<base::SequencedTaskRunner>& io_thread, 418 const scoped_refptr<base::SequencedTaskRunner>& io_thread,
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 775
762 // The GCMClient is ready so we can go ahead and post this task to the 776 // The GCMClient is ready so we can go ahead and post this task to the
763 // IOWorker. 777 // IOWorker.
764 io_thread_->PostTask( 778 io_thread_->PostTask(
765 FROM_HERE, 779 FROM_HERE,
766 base::Bind(&GCMDriverDesktop::IOWorker::WakeFromSuspendForHeartbeat, 780 base::Bind(&GCMDriverDesktop::IOWorker::WakeFromSuspendForHeartbeat,
767 base::Unretained(io_worker_.get()), 781 base::Unretained(io_worker_.get()),
768 wake_from_suspend_enabled_)); 782 wake_from_suspend_enabled_));
769 } 783 }
770 784
785 void GCMDriverDesktop::AddHeartbeatInterval(const std::string& scope,
786 int interval_ms) {
787 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
788
789 // The GCM service has not been initialized.
790 if (!delayed_task_controller_)
791 return;
792
793 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) {
794 // The GCM service was initialized but has not started yet.
795 delayed_task_controller_->AddTask(
796 base::Bind(&GCMDriverDesktop::AddHeartbeatInterval,
797 weak_ptr_factory_.GetWeakPtr(), scope, interval_ms));
798 return;
799 }
800
801 io_thread_->PostTask(
802 FROM_HERE,
803 base::Bind(&GCMDriverDesktop::IOWorker::AddHeartbeatInterval,
804 base::Unretained(io_worker_.get()), scope, interval_ms));
805 }
806
807 void GCMDriverDesktop::RemoveHeartbeatInterval(const std::string& scope) {
808 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
809
810 // The GCM service has not been initialized.
811 if (!delayed_task_controller_)
812 return;
813
814 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) {
815 // The GCM service was initialized but has not started yet.
816 delayed_task_controller_->AddTask(
817 base::Bind(&GCMDriverDesktop::RemoveHeartbeatInterval,
818 weak_ptr_factory_.GetWeakPtr(), scope));
819 return;
820 }
821
822 io_thread_->PostTask(
823 FROM_HERE,
824 base::Bind(&GCMDriverDesktop::IOWorker::RemoveHeartbeatInterval,
825 base::Unretained(io_worker_.get()), scope));
826 }
827
771 void GCMDriverDesktop::SetAccountTokens( 828 void GCMDriverDesktop::SetAccountTokens(
772 const std::vector<GCMClient::AccountTokenInfo>& account_tokens) { 829 const std::vector<GCMClient::AccountTokenInfo>& account_tokens) {
773 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 830 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
774 831
775 account_mapper_->SetAccountTokens(account_tokens); 832 account_mapper_->SetAccountTokens(account_tokens);
776 833
777 io_thread_->PostTask( 834 io_thread_->PostTask(
778 FROM_HERE, 835 FROM_HERE,
779 base::Bind(&GCMDriverDesktop::IOWorker::SetAccountTokens, 836 base::Bind(&GCMDriverDesktop::IOWorker::SetAccountTokens,
780 base::Unretained(io_worker_.get()), 837 base::Unretained(io_worker_.get()),
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 980 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
924 981
925 // Normally request_gcm_statistics_callback_ would not be null. 982 // Normally request_gcm_statistics_callback_ would not be null.
926 if (!request_gcm_statistics_callback_.is_null()) 983 if (!request_gcm_statistics_callback_.is_null())
927 request_gcm_statistics_callback_.Run(stats); 984 request_gcm_statistics_callback_.Run(stats);
928 else 985 else
929 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; 986 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL.";
930 } 987 }
931 988
932 } // namespace gcm 989 } // namespace gcm
OLDNEW
« no previous file with comments | « components/gcm_driver/gcm_driver_desktop.h ('k') | google_apis/gcm/engine/gcm_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698