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

Side by Side Diff: chrome/browser/local_discovery/privet_url_fetcher.cc

Issue 69393003: Add minimum timeout for transient errors (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/local_discovery/privet_http_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/local_discovery/privet_url_fetcher.h" 5 #include "chrome/browser/local_discovery/privet_url_fetcher.h"
6 6
7 #include <algorithm>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
9 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
10 #include "base/rand_util.h" 12 #include "base/rand_util.h"
11 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/local_discovery/privet_constants.h" 14 #include "chrome/browser/local_discovery/privet_constants.h"
13 #include "net/http/http_status_code.h" 15 #include "net/http/http_status_code.h"
14 #include "net/url_request/url_request_status.h" 16 #include "net/url_request/url_request_status.h"
15 17
16 namespace local_discovery { 18 namespace local_discovery {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 dictionary_value->HasKey(kPrivetKeyError)); 151 dictionary_value->HasKey(kPrivetKeyError));
150 } 152 }
151 153
152 void PrivetURLFetcher::ScheduleRetry(int timeout_seconds) { 154 void PrivetURLFetcher::ScheduleRetry(int timeout_seconds) {
153 double random_scaling_factor = 155 double random_scaling_factor =
154 1 + base::RandDouble() * kPrivetMaximumTimeRandomAddition; 156 1 + base::RandDouble() * kPrivetMaximumTimeRandomAddition;
155 157
156 int timeout_seconds_randomized = 158 int timeout_seconds_randomized =
157 static_cast<int>(timeout_seconds * random_scaling_factor); 159 static_cast<int>(timeout_seconds * random_scaling_factor);
158 160
161 timeout_seconds_randomized =
162 std::max(timeout_seconds_randomized, kPrivetMinimumTimeout);
163
159 base::MessageLoop::current()->PostDelayedTask( 164 base::MessageLoop::current()->PostDelayedTask(
160 FROM_HERE, 165 FROM_HERE,
161 base::Bind(&PrivetURLFetcher::Try, weak_factory_.GetWeakPtr()), 166 base::Bind(&PrivetURLFetcher::Try, weak_factory_.GetWeakPtr()),
162 base::TimeDelta::FromSeconds(timeout_seconds_randomized)); 167 base::TimeDelta::FromSeconds(timeout_seconds_randomized));
163 } 168 }
164 169
165 void PrivetURLFetcher::RequestTokenRefresh() { 170 void PrivetURLFetcher::RequestTokenRefresh() {
166 delegate_->OnNeedPrivetToken( 171 delegate_->OnNeedPrivetToken(
167 this, 172 this,
168 base::Bind(&PrivetURLFetcher::RefreshToken, weak_factory_.GetWeakPtr())); 173 base::Bind(&PrivetURLFetcher::RefreshToken, weak_factory_.GetWeakPtr()));
(...skipping 24 matching lines...) Expand all
193 198
194 scoped_ptr<PrivetURLFetcher> PrivetURLFetcherFactory::CreateURLFetcher( 199 scoped_ptr<PrivetURLFetcher> PrivetURLFetcherFactory::CreateURLFetcher(
195 const GURL& url, net::URLFetcher::RequestType request_type, 200 const GURL& url, net::URLFetcher::RequestType request_type,
196 PrivetURLFetcher::Delegate* delegate) const { 201 PrivetURLFetcher::Delegate* delegate) const {
197 return scoped_ptr<PrivetURLFetcher>( 202 return scoped_ptr<PrivetURLFetcher>(
198 new PrivetURLFetcher(token_, url, request_type, request_context_.get(), 203 new PrivetURLFetcher(token_, url, request_type, request_context_.get(),
199 delegate)); 204 delegate));
200 } 205 }
201 206
202 } // namespace local_discovery 207 } // namespace local_discovery
OLDNEW
« no previous file with comments | « chrome/browser/local_discovery/privet_http_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698