| 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_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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 } | 64 } |
| 65 | 65 |
| 66 // static | 66 // static |
| 67 int GCMChannelStatusSyncer::first_time_delay_seconds() { | 67 int GCMChannelStatusSyncer::first_time_delay_seconds() { |
| 68 return kFirstTimeDelaySeconds; | 68 return kFirstTimeDelaySeconds; |
| 69 } | 69 } |
| 70 | 70 |
| 71 GCMChannelStatusSyncer::GCMChannelStatusSyncer( | 71 GCMChannelStatusSyncer::GCMChannelStatusSyncer( |
| 72 GCMDriver* driver, | 72 GCMDriver* driver, |
| 73 PrefService* prefs, | 73 PrefService* prefs, |
| 74 const std::string& channel_status_request_url, |
| 75 const std::string& user_agent, |
| 74 const scoped_refptr<net::URLRequestContextGetter>& request_context) | 76 const scoped_refptr<net::URLRequestContextGetter>& request_context) |
| 75 : driver_(driver), | 77 : driver_(driver), |
| 76 prefs_(prefs), | 78 prefs_(prefs), |
| 79 channel_status_request_url_(channel_status_request_url), |
| 80 user_agent_(user_agent), |
| 77 request_context_(request_context), | 81 request_context_(request_context), |
| 78 gcm_enabled_(true), | 82 gcm_enabled_(true), |
| 79 poll_interval_seconds_( | 83 poll_interval_seconds_( |
| 80 GCMChannelStatusRequest::default_poll_interval_seconds()), | 84 GCMChannelStatusRequest::default_poll_interval_seconds()), |
| 81 delay_removed_for_testing_(false), | 85 delay_removed_for_testing_(false), |
| 82 weak_ptr_factory_(this) { | 86 weak_ptr_factory_(this) { |
| 83 gcm_enabled_ = prefs_->GetBoolean(kGCMChannelStatus); | 87 gcm_enabled_ = prefs_->GetBoolean(kGCMChannelStatus); |
| 84 poll_interval_seconds_ = prefs_->GetInteger(kGCMChannelPollIntervalSeconds); | 88 poll_interval_seconds_ = prefs_->GetInteger(kGCMChannelPollIntervalSeconds); |
| 85 if (poll_interval_seconds_ < | 89 if (poll_interval_seconds_ < |
| 86 GCMChannelStatusRequest::min_poll_interval_seconds()) { | 90 GCMChannelStatusRequest::min_poll_interval_seconds()) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 base::Bind(&GCMChannelStatusSyncer::StartRequest, | 147 base::Bind(&GCMChannelStatusSyncer::StartRequest, |
| 144 weak_ptr_factory_.GetWeakPtr()), | 148 weak_ptr_factory_.GetWeakPtr()), |
| 145 current_request_delay_interval_); | 149 current_request_delay_interval_); |
| 146 } | 150 } |
| 147 | 151 |
| 148 void GCMChannelStatusSyncer::StartRequest() { | 152 void GCMChannelStatusSyncer::StartRequest() { |
| 149 DCHECK(!request_); | 153 DCHECK(!request_); |
| 150 | 154 |
| 151 request_.reset(new GCMChannelStatusRequest( | 155 request_.reset(new GCMChannelStatusRequest( |
| 152 request_context_, | 156 request_context_, |
| 157 channel_status_request_url_, |
| 158 user_agent_, |
| 153 base::Bind(&GCMChannelStatusSyncer::OnRequestCompleted, | 159 base::Bind(&GCMChannelStatusSyncer::OnRequestCompleted, |
| 154 weak_ptr_factory_.GetWeakPtr()))); | 160 weak_ptr_factory_.GetWeakPtr()))); |
| 155 request_->Start(); | 161 request_->Start(); |
| 156 } | 162 } |
| 157 | 163 |
| 158 base::TimeDelta GCMChannelStatusSyncer::GetRequestDelayInterval() const { | 164 base::TimeDelta GCMChannelStatusSyncer::GetRequestDelayInterval() const { |
| 159 // No delay during testing. | 165 // No delay during testing. |
| 160 if (delay_removed_for_testing_) | 166 if (delay_removed_for_testing_) |
| 161 return base::TimeDelta(); | 167 return base::TimeDelta(); |
| 162 | 168 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 174 delay_seconds = kFirstTimeDelaySeconds; | 180 delay_seconds = kFirstTimeDelaySeconds; |
| 175 } else { | 181 } else { |
| 176 // Otherwise, add a fuzzing variation to the delay. | 182 // Otherwise, add a fuzzing variation to the delay. |
| 177 delay_seconds += base::RandInt(0, kGCMChannelRequestTimeJitterSeconds); | 183 delay_seconds += base::RandInt(0, kGCMChannelRequestTimeJitterSeconds); |
| 178 } | 184 } |
| 179 | 185 |
| 180 return base::TimeDelta::FromSeconds(delay_seconds); | 186 return base::TimeDelta::FromSeconds(delay_seconds); |
| 181 } | 187 } |
| 182 | 188 |
| 183 } // namespace gcm | 189 } // namespace gcm |
| OLD | NEW |