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

Side by Side Diff: components/gcm_driver/gcm_channel_status_request.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_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()) {
97 LOG(ERROR) << "GCM channel response failed to be retrieved."; 98 LOG(ERROR) << "GCM channel response failed to be retrieved.";
98 return false; 99 return false;
99 } 100 }
100 101
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
107 sync_pb::ExperimentStatusResponse response_proto; 102 sync_pb::ExperimentStatusResponse response_proto;
108 if (!response_proto.ParseFromString(response_string)) { 103 if (!response_proto.ParseFromString(response_string)) {
109 LOG(ERROR) << "GCM channel response failed to be parsed as proto."; 104 LOG(ERROR) << "GCM channel response failed to be parse as proto.";
110 return false; 105 return false;
111 } 106 }
112 107
113 bool enabled = true; 108 bool enabled = true;
114 if (response_proto.experiment_size() == 1 && 109 if (response_proto.experiment_size() == 1 &&
115 response_proto.experiment(0).has_gcm_channel() && 110 response_proto.experiment(0).has_gcm_channel() &&
116 response_proto.experiment(0).gcm_channel().has_enabled()) { 111 response_proto.experiment(0).gcm_channel().has_enabled()) {
117 enabled = response_proto.experiment(0).gcm_channel().enabled(); 112 enabled = response_proto.experiment(0).gcm_channel().enabled();
118 } 113 }
119 114
120 int poll_interval_seconds; 115 int poll_interval_seconds;
121 if (response_proto.has_poll_interval_seconds()) 116 if (response_proto.has_poll_interval_seconds())
122 poll_interval_seconds = response_proto.poll_interval_seconds(); 117 poll_interval_seconds = response_proto.poll_interval_seconds();
123 else 118 else
124 poll_interval_seconds = kDefaultPollIntervalSeconds; 119 poll_interval_seconds = kDefaultPollIntervalSeconds;
125 if (poll_interval_seconds < kMinPollIntervalSeconds) 120 if (poll_interval_seconds < kMinPollIntervalSeconds)
126 poll_interval_seconds = kMinPollIntervalSeconds; 121 poll_interval_seconds = kMinPollIntervalSeconds;
127 122
128 callback_.Run(true, enabled, poll_interval_seconds); 123 callback_.Run(enabled, poll_interval_seconds);
129 124
130 return true; 125 return true;
131 } 126 }
132 127
133 void GCMChannelStatusRequest::RetryWithBackoff(bool update_backoff) { 128 void GCMChannelStatusRequest::RetryWithBackoff(bool update_backoff) {
134 if (update_backoff) { 129 if (update_backoff) {
135 url_fetcher_.reset(); 130 url_fetcher_.reset();
136 backoff_entry_.InformOfRequest(false); 131 backoff_entry_.InformOfRequest(false);
137 } 132 }
138 133
139 if (backoff_entry_.ShouldRejectRequest()) { 134 if (backoff_entry_.ShouldRejectRequest()) {
140 DVLOG(1) << "Delaying GCM channel request for " 135 DVLOG(1) << "Delaying GCM channel request for "
141 << backoff_entry_.GetTimeUntilRelease().InMilliseconds() 136 << backoff_entry_.GetTimeUntilRelease().InMilliseconds()
142 << " ms."; 137 << " ms.";
143 base::MessageLoop::current()->PostDelayedTask( 138 base::MessageLoop::current()->PostDelayedTask(
144 FROM_HERE, 139 FROM_HERE,
145 base::Bind(&GCMChannelStatusRequest::RetryWithBackoff, 140 base::Bind(&GCMChannelStatusRequest::RetryWithBackoff,
146 weak_ptr_factory_.GetWeakPtr(), 141 weak_ptr_factory_.GetWeakPtr(),
147 false), 142 false),
148 backoff_entry_.GetTimeUntilRelease()); 143 backoff_entry_.GetTimeUntilRelease());
149 return; 144 return;
150 } 145 }
151 146
152 Start(); 147 Start();
153 } 148 }
154 149
155 } // namespace gcm 150 } // namespace gcm
OLDNEW
« no previous file with comments | « components/gcm_driver/gcm_channel_status_request.h ('k') | components/gcm_driver/gcm_channel_status_request_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698