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

Side by Side Diff: chrome/browser/google/google_url_tracker.cc

Issue 4194001: Implement exponential back-off mechanism and enforce it at the URLRequestHttpJob level. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 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 | « no previous file | chrome/chrome_common.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/google/google_url_tracker.h" 5 #include "chrome/browser/google/google_url_tracker.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
14 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/prefs/pref_service.h" 15 #include "chrome/browser/prefs/pref_service.h"
16 #include "chrome/browser/profile.h" 16 #include "chrome/browser/profile.h"
17 #include "chrome/browser/search_engines/template_url.h" 17 #include "chrome/browser/search_engines/template_url.h"
18 #include "chrome/browser/tab_contents/navigation_controller.h" 18 #include "chrome/browser/tab_contents/navigation_controller.h"
19 #include "chrome/browser/tab_contents/tab_contents.h" 19 #include "chrome/browser/tab_contents/tab_contents.h"
20 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
21 #include "chrome/common/net/url_fetcher_protect.h"
22 #include "chrome/common/notification_service.h" 21 #include "chrome/common/notification_service.h"
23 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
24 #include "grit/generated_resources.h" 23 #include "grit/generated_resources.h"
25 #include "net/base/load_flags.h" 24 #include "net/base/load_flags.h"
26 #include "net/url_request/url_request_status.h" 25 #include "net/url_request/url_request_status.h"
27 26
28 namespace { 27 namespace {
29 28
30 InfoBarDelegate* CreateInfobar(TabContents* tab_contents, 29 InfoBarDelegate* CreateInfobar(TabContents* tab_contents,
31 GoogleURLTracker* google_url_tracker, 30 GoogleURLTracker* google_url_tracker,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 need_to_fetch_(false), 104 need_to_fetch_(false),
106 request_context_available_(!!Profile::GetDefaultRequestContext()), 105 request_context_available_(!!Profile::GetDefaultRequestContext()),
107 need_to_prompt_(false), 106 need_to_prompt_(false),
108 controller_(NULL), 107 controller_(NULL),
109 infobar_(NULL) { 108 infobar_(NULL) {
110 registrar_.Add(this, NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE, 109 registrar_.Add(this, NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE,
111 NotificationService::AllSources()); 110 NotificationService::AllSources());
112 111
113 net::NetworkChangeNotifier::AddObserver(this); 112 net::NetworkChangeNotifier::AddObserver(this);
114 113
115 // Configure to max_retries at most kMaxRetries times for 5xx errors.
116 URLFetcherProtectEntry* protect =
117 URLFetcherProtectManager::GetInstance()->Register(
118 GURL(kSearchDomainCheckURL).host());
119 static const int kMaxRetries = 5;
120 protect->SetMaxRetries(kMaxRetries);
121
122 MessageLoop::current()->PostTask(FROM_HERE, 114 MessageLoop::current()->PostTask(FROM_HERE,
123 runnable_method_factory_.NewRunnableMethod( 115 runnable_method_factory_.NewRunnableMethod(
124 &GoogleURLTracker::QueueWakeupTask)); 116 &GoogleURLTracker::QueueWakeupTask));
125 } 117 }
126 118
127 GoogleURLTracker::~GoogleURLTracker() { 119 GoogleURLTracker::~GoogleURLTracker() {
128 runnable_method_factory_.RevokeAll(); 120 runnable_method_factory_.RevokeAll();
129 net::NetworkChangeNotifier::RemoveObserver(this); 121 net::NetworkChangeNotifier::RemoveObserver(this);
130 } 122 }
131 123
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 already_fetched_ = true; 196 already_fetched_ = true;
205 fetcher_.reset(URLFetcher::Create(fetcher_id_, GURL(kSearchDomainCheckURL), 197 fetcher_.reset(URLFetcher::Create(fetcher_id_, GURL(kSearchDomainCheckURL),
206 URLFetcher::GET, this)); 198 URLFetcher::GET, this));
207 ++fetcher_id_; 199 ++fetcher_id_;
208 // We don't want this fetch to affect existing state in the profile. For 200 // We don't want this fetch to affect existing state in the profile. For
209 // example, if a user has no Google cookies, this automatic check should not 201 // example, if a user has no Google cookies, this automatic check should not
210 // cause one to be set, lest we alarm the user. 202 // cause one to be set, lest we alarm the user.
211 fetcher_->set_load_flags(net::LOAD_DISABLE_CACHE | 203 fetcher_->set_load_flags(net::LOAD_DISABLE_CACHE |
212 net::LOAD_DO_NOT_SAVE_COOKIES); 204 net::LOAD_DO_NOT_SAVE_COOKIES);
213 fetcher_->set_request_context(Profile::GetDefaultRequestContext()); 205 fetcher_->set_request_context(Profile::GetDefaultRequestContext());
206
207 // Configure to max_retries at most kMaxRetries times for 5xx errors.
208 static const int kMaxRetries = 5;
209 fetcher_->set_max_retries(kMaxRetries);
210
214 fetcher_->Start(); 211 fetcher_->Start();
215 } 212 }
216 213
217 void GoogleURLTracker::OnURLFetchComplete(const URLFetcher* source, 214 void GoogleURLTracker::OnURLFetchComplete(const URLFetcher* source,
218 const GURL& url, 215 const GURL& url,
219 const URLRequestStatus& status, 216 const URLRequestStatus& status,
220 int response_code, 217 int response_code,
221 const ResponseCookies& cookies, 218 const ResponseCookies& cookies,
222 const std::string& data) { 219 const std::string& data) {
223 // Delete the fetcher on this function's exit. 220 // Delete the fetcher on this function's exit.
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 } 371 }
375 372
376 void GoogleURLTracker::ShowGoogleURLInfoBarIfNecessary( 373 void GoogleURLTracker::ShowGoogleURLInfoBarIfNecessary(
377 TabContents* tab_contents) { 374 TabContents* tab_contents) {
378 if (!need_to_prompt_) 375 if (!need_to_prompt_)
379 return; 376 return;
380 DCHECK(!fetched_google_url_.is_empty()); 377 DCHECK(!fetched_google_url_.is_empty());
381 378
382 infobar_ = (*infobar_creator_)(tab_contents, this, fetched_google_url_); 379 infobar_ = (*infobar_creator_)(tab_contents, this, fetched_google_url_);
383 } 380 }
OLDNEW
« no previous file with comments | « no previous file | chrome/chrome_common.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698