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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/gcm_driver/gcm_driver_desktop.cc
diff --git a/components/gcm_driver/gcm_driver_desktop.cc b/components/gcm_driver/gcm_driver_desktop.cc
index a711999f6bde014abee597a6d819b1232ab25865..dcc5cb21105185ad98763c49a81aa59483d0e3f7 100644
--- a/components/gcm_driver/gcm_driver_desktop.cc
+++ b/components/gcm_driver/gcm_driver_desktop.cc
@@ -91,6 +91,8 @@ class GCMDriverDesktop::IOWorker : public GCMClient::Delegate {
const std::string& instance_id_data);
void RemoveInstanceIDData(const std::string& app_id);
void GetInstanceIDData(const std::string& app_id);
+ void AddHeartbeatInterval(const std::string& scope, int interval_ms);
+ void RemoveHeartbeatInterval(const std::string& scope);
// For testing purpose. Can be called from UI thread. Use with care.
GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); }
@@ -392,6 +394,18 @@ void GCMDriverDesktop::IOWorker::WakeFromSuspendForHeartbeat(bool wake) {
#endif
}
+void GCMDriverDesktop::IOWorker::AddHeartbeatInterval(const std::string& scope,
+ int interval_ms) {
+ DCHECK(io_thread_->RunsTasksOnCurrentThread());
+ gcm_client_->AddHeartbeatInterval(scope, interval_ms);
+}
+
+void GCMDriverDesktop::IOWorker::RemoveHeartbeatInterval(
+ const std::string& scope) {
+ DCHECK(io_thread_->RunsTasksOnCurrentThread());
+ gcm_client_->RemoveHeartbeatInterval(scope);
+}
+
GCMDriverDesktop::GCMDriverDesktop(
scoped_ptr<GCMClientFactory> gcm_client_factory,
const GCMClient::ChromeBuildInfo& chrome_build_info,
@@ -768,6 +782,49 @@ void GCMDriverDesktop::WakeFromSuspendForHeartbeat(bool wake) {
wake_from_suspend_enabled_));
}
+void GCMDriverDesktop::AddHeartbeatInterval(const std::string& scope,
+ int interval_ms) {
+ DCHECK(ui_thread_->RunsTasksOnCurrentThread());
+
+ // The GCM service has not been initialized.
+ if (!delayed_task_controller_)
+ return;
+
+ if (!delayed_task_controller_->CanRunTaskWithoutDelay()) {
+ // The GCM service was initialized but has not started yet.
+ delayed_task_controller_->AddTask(
+ base::Bind(&GCMDriverDesktop::AddHeartbeatInterval,
+ weak_ptr_factory_.GetWeakPtr(), scope, interval_ms));
+ return;
+ }
+
+ io_thread_->PostTask(
+ FROM_HERE,
+ base::Bind(&GCMDriverDesktop::IOWorker::AddHeartbeatInterval,
+ base::Unretained(io_worker_.get()), scope, interval_ms));
+}
+
+void GCMDriverDesktop::RemoveHeartbeatInterval(const std::string& scope) {
+ DCHECK(ui_thread_->RunsTasksOnCurrentThread());
+
+ // The GCM service has not been initialized.
+ if (!delayed_task_controller_)
+ return;
+
+ if (!delayed_task_controller_->CanRunTaskWithoutDelay()) {
+ // The GCM service was initialized but has not started yet.
+ delayed_task_controller_->AddTask(
+ base::Bind(&GCMDriverDesktop::RemoveHeartbeatInterval,
+ weak_ptr_factory_.GetWeakPtr(), scope));
+ return;
+ }
+
+ io_thread_->PostTask(
+ FROM_HERE,
+ base::Bind(&GCMDriverDesktop::IOWorker::RemoveHeartbeatInterval,
+ base::Unretained(io_worker_.get()), scope));
+}
+
void GCMDriverDesktop::SetAccountTokens(
const std::vector<GCMClient::AccountTokenInfo>& account_tokens) {
DCHECK(ui_thread_->RunsTasksOnCurrentThread());
« 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