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

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

Issue 657703002: Revert of [GCM] Start GCMChannelStatusSyncer when GCM is disabled (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
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_channel_status_syncer.h" 5 #include "components/gcm_driver/gcm_channel_status_syncer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 return; 104 return;
105 105
106 ScheduleRequest(); 106 ScheduleRequest();
107 } 107 }
108 108
109 void GCMChannelStatusSyncer::Stop() { 109 void GCMChannelStatusSyncer::Stop() {
110 request_.reset(); 110 request_.reset();
111 weak_ptr_factory_.InvalidateWeakPtrs(); 111 weak_ptr_factory_.InvalidateWeakPtrs();
112 } 112 }
113 113
114 void GCMChannelStatusSyncer::OnRequestCompleted(bool update_received, 114 void GCMChannelStatusSyncer::OnRequestCompleted(bool enabled,
115 bool enabled,
116 int poll_interval_seconds) { 115 int poll_interval_seconds) {
117 DCHECK(request_); 116 DCHECK(request_);
118 request_.reset(); 117 request_.reset();
119 118
120 // Persist the current time as the last request complete time. 119 // Persist the current time as the last request complete time.
121 last_check_time_ = base::Time::Now(); 120 last_check_time_ = base::Time::Now();
122 prefs_->SetInt64(kGCMChannelLastCheckTime, 121 prefs_->SetInt64(kGCMChannelLastCheckTime,
123 last_check_time_.ToInternalValue()); 122 last_check_time_.ToInternalValue());
124 123
125 if (update_received) { 124 if (gcm_enabled_ != enabled) {
126 if (gcm_enabled_ != enabled) { 125 gcm_enabled_ = enabled;
127 gcm_enabled_ = enabled; 126 prefs_->SetBoolean(kGCMChannelStatus, enabled);
128 prefs_->SetBoolean(kGCMChannelStatus, enabled); 127 if (gcm_enabled_)
129 if (gcm_enabled_) 128 driver_->Enable();
130 driver_->Enable(); 129 else
131 else 130 driver_->Disable();
132 driver_->Disable(); 131 }
133 }
134 132
135 DCHECK_GE(poll_interval_seconds, 133 DCHECK_GE(poll_interval_seconds,
136 GCMChannelStatusRequest::min_poll_interval_seconds()); 134 GCMChannelStatusRequest::min_poll_interval_seconds());
137 if (poll_interval_seconds_ != poll_interval_seconds) { 135 if (poll_interval_seconds_ != poll_interval_seconds) {
138 poll_interval_seconds_ = poll_interval_seconds; 136 poll_interval_seconds_ = poll_interval_seconds;
139 prefs_->SetInteger(kGCMChannelPollIntervalSeconds, 137 prefs_->SetInteger(kGCMChannelPollIntervalSeconds, poll_interval_seconds_);
140 poll_interval_seconds_);
141 }
142 } 138 }
143 139
144 ScheduleRequest(); 140 ScheduleRequest();
145 } 141 }
146 142
147 void GCMChannelStatusSyncer::ScheduleRequest() { 143 void GCMChannelStatusSyncer::ScheduleRequest() {
148 current_request_delay_interval_ = GetRequestDelayInterval(); 144 current_request_delay_interval_ = GetRequestDelayInterval();
149 base::MessageLoop::current()->PostDelayedTask( 145 base::MessageLoop::current()->PostDelayedTask(
150 FROM_HERE, 146 FROM_HERE,
151 base::Bind(&GCMChannelStatusSyncer::StartRequest, 147 base::Bind(&GCMChannelStatusSyncer::StartRequest,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 delay_seconds = kFirstTimeDelaySeconds; 180 delay_seconds = kFirstTimeDelaySeconds;
185 } else { 181 } else {
186 // Otherwise, add a fuzzing variation to the delay. 182 // Otherwise, add a fuzzing variation to the delay.
187 delay_seconds += base::RandInt(0, kGCMChannelRequestTimeJitterSeconds); 183 delay_seconds += base::RandInt(0, kGCMChannelRequestTimeJitterSeconds);
188 } 184 }
189 185
190 return base::TimeDelta::FromSeconds(delay_seconds); 186 return base::TimeDelta::FromSeconds(delay_seconds);
191 } 187 }
192 188
193 } // namespace gcm 189 } // namespace gcm
OLDNEW
« no previous file with comments | « components/gcm_driver/gcm_channel_status_syncer.h ('k') | components/gcm_driver/gcm_driver_desktop.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698