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

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

Issue 653843003: [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_request.h" 5 #include "components/gcm_driver/gcm_channel_status_request.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "components/gcm_driver/gcm_backoff_policy.h" 9 #include "components/gcm_driver/gcm_backoff_policy.h"
10 #include "net/base/escape.h" 10 #include "net/base/escape.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 return false; 86 return false;
87 } 87 }
88 88
89 if (source->GetResponseCode() != net::HTTP_OK) { 89 if (source->GetResponseCode() != net::HTTP_OK) {
90 LOG(ERROR) << "GCM channel request failed. HTTP status: " 90 LOG(ERROR) << "GCM channel request failed. HTTP status: "
91 << source->GetResponseCode(); 91 << source->GetResponseCode();
92 return false; 92 return false;
93 } 93 }
94 94
95 std::string response_string; 95 std::string response_string;
96 if (!source->GetResponseAsString(&response_string) || 96 if (!source->GetResponseAsString(&response_string)) {
97 response_string.empty()) {
98 LOG(ERROR) << "GCM channel response failed to be retrieved."; 97 LOG(ERROR) << "GCM channel response failed to be retrieved.";
99 return false; 98 return false;
100 } 99 }
101 100
101 // Empty response means to keep the existing values.
102 if (response_string.empty()) {
103 callback_.Run(false, false, 0);
104 return true;
105 }
106
102 sync_pb::ExperimentStatusResponse response_proto; 107 sync_pb::ExperimentStatusResponse response_proto;
103 if (!response_proto.ParseFromString(response_string)) { 108 if (!response_proto.ParseFromString(response_string)) {
104 LOG(ERROR) << "GCM channel response failed to be parse as proto."; 109 LOG(ERROR) << "GCM channel response failed to be parse as proto.";
fgorski 2014/10/14 17:40:37 nit: parse -> parsed
jianli 2014/10/14 23:21:47 Done.
105 return false; 110 return false;
106 } 111 }
107 112
108 bool enabled = true; 113 bool enabled = true;
109 if (response_proto.experiment_size() == 1 && 114 if (response_proto.experiment_size() == 1 &&
110 response_proto.experiment(0).has_gcm_channel() && 115 response_proto.experiment(0).has_gcm_channel() &&
111 response_proto.experiment(0).gcm_channel().has_enabled()) { 116 response_proto.experiment(0).gcm_channel().has_enabled()) {
112 enabled = response_proto.experiment(0).gcm_channel().enabled(); 117 enabled = response_proto.experiment(0).gcm_channel().enabled();
113 } 118 }
114 119
115 int poll_interval_seconds; 120 int poll_interval_seconds;
116 if (response_proto.has_poll_interval_seconds()) 121 if (response_proto.has_poll_interval_seconds())
117 poll_interval_seconds = response_proto.poll_interval_seconds(); 122 poll_interval_seconds = response_proto.poll_interval_seconds();
118 else 123 else
119 poll_interval_seconds = kDefaultPollIntervalSeconds; 124 poll_interval_seconds = kDefaultPollIntervalSeconds;
120 if (poll_interval_seconds < kMinPollIntervalSeconds) 125 if (poll_interval_seconds < kMinPollIntervalSeconds)
121 poll_interval_seconds = kMinPollIntervalSeconds; 126 poll_interval_seconds = kMinPollIntervalSeconds;
122 127
123 callback_.Run(enabled, poll_interval_seconds); 128 callback_.Run(true, enabled, poll_interval_seconds);
124 129
125 return true; 130 return true;
126 } 131 }
127 132
128 void GCMChannelStatusRequest::RetryWithBackoff(bool update_backoff) { 133 void GCMChannelStatusRequest::RetryWithBackoff(bool update_backoff) {
129 if (update_backoff) { 134 if (update_backoff) {
130 url_fetcher_.reset(); 135 url_fetcher_.reset();
131 backoff_entry_.InformOfRequest(false); 136 backoff_entry_.InformOfRequest(false);
132 } 137 }
133 138
134 if (backoff_entry_.ShouldRejectRequest()) { 139 if (backoff_entry_.ShouldRejectRequest()) {
135 DVLOG(1) << "Delaying GCM channel request for " 140 DVLOG(1) << "Delaying GCM channel request for "
136 << backoff_entry_.GetTimeUntilRelease().InMilliseconds() 141 << backoff_entry_.GetTimeUntilRelease().InMilliseconds()
137 << " ms."; 142 << " ms.";
138 base::MessageLoop::current()->PostDelayedTask( 143 base::MessageLoop::current()->PostDelayedTask(
139 FROM_HERE, 144 FROM_HERE,
140 base::Bind(&GCMChannelStatusRequest::RetryWithBackoff, 145 base::Bind(&GCMChannelStatusRequest::RetryWithBackoff,
141 weak_ptr_factory_.GetWeakPtr(), 146 weak_ptr_factory_.GetWeakPtr(),
142 false), 147 false),
143 backoff_entry_.GetTimeUntilRelease()); 148 backoff_entry_.GetTimeUntilRelease());
144 return; 149 return;
145 } 150 }
146 151
147 Start(); 152 Start();
148 } 153 }
149 154
150 } // namespace gcm 155 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698