| OLD | NEW |
| 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/infobar_delegate.h" | 18 #include "chrome/browser/tab_contents/infobar_delegate.h" |
| 19 #include "chrome/browser/tab_contents/navigation_controller.h" | 19 #include "chrome/browser/tab_contents/navigation_controller.h" |
| 20 #include "chrome/browser/tab_contents/tab_contents.h" | 20 #include "chrome/browser/tab_contents/tab_contents.h" |
| 21 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 22 #include "chrome/common/net/url_fetcher_protect.h" | |
| 23 #include "chrome/common/notification_service.h" | 22 #include "chrome/common/notification_service.h" |
| 24 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 25 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
| 26 #include "net/base/load_flags.h" | 25 #include "net/base/load_flags.h" |
| 27 #include "net/url_request/url_request_status.h" | 26 #include "net/url_request/url_request_status.h" |
| 28 | 27 |
| 29 const char GoogleURLTracker::kDefaultGoogleHomepage[] = | 28 const char GoogleURLTracker::kDefaultGoogleHomepage[] = |
| 30 "http://www.google.com/"; | 29 "http://www.google.com/"; |
| 31 const char GoogleURLTracker::kSearchDomainCheckURL[] = | 30 const char GoogleURLTracker::kSearchDomainCheckURL[] = |
| 32 "https://www.google.com/searchdomaincheck?format=domain&type=chrome"; | 31 "https://www.google.com/searchdomaincheck?format=domain&type=chrome"; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 request_context_available_(!!Profile::GetDefaultRequestContext()), | 108 request_context_available_(!!Profile::GetDefaultRequestContext()), |
| 110 need_to_prompt_(false), | 109 need_to_prompt_(false), |
| 111 controller_(NULL), | 110 controller_(NULL), |
| 112 infobar_factory_(new InfoBarDelegateFactory), | 111 infobar_factory_(new InfoBarDelegateFactory), |
| 113 infobar_(NULL) { | 112 infobar_(NULL) { |
| 114 registrar_.Add(this, NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE, | 113 registrar_.Add(this, NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE, |
| 115 NotificationService::AllSources()); | 114 NotificationService::AllSources()); |
| 116 | 115 |
| 117 net::NetworkChangeNotifier::AddObserver(this); | 116 net::NetworkChangeNotifier::AddObserver(this); |
| 118 | 117 |
| 119 // Configure to max_retries at most kMaxRetries times for 5xx errors. | |
| 120 URLFetcherProtectEntry* protect = | |
| 121 URLFetcherProtectManager::GetInstance()->Register( | |
| 122 GURL(kSearchDomainCheckURL).host()); | |
| 123 static const int kMaxRetries = 5; | |
| 124 protect->SetMaxRetries(kMaxRetries); | |
| 125 | |
| 126 // Because this function can be called during startup, when kicking off a URL | 118 // Because this function can be called during startup, when kicking off a URL |
| 127 // fetch can eat up 20 ms of time, we delay five seconds, which is hopefully | 119 // fetch can eat up 20 ms of time, we delay five seconds, which is hopefully |
| 128 // long enough to be after startup, but still get results back quickly. | 120 // long enough to be after startup, but still get results back quickly. |
| 129 // Ideally, instead of this timer, we'd do something like "check if the | 121 // Ideally, instead of this timer, we'd do something like "check if the |
| 130 // browser is starting up, and if so, come back later", but there is currently | 122 // browser is starting up, and if so, come back later", but there is currently |
| 131 // no function to do this. | 123 // no function to do this. |
| 132 static const int kStartFetchDelayMS = 5000; | 124 static const int kStartFetchDelayMS = 5000; |
| 133 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 125 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 134 runnable_method_factory_.NewRunnableMethod( | 126 runnable_method_factory_.NewRunnableMethod( |
| 135 &GoogleURLTracker::FinishSleep), | 127 &GoogleURLTracker::FinishSleep), |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 already_fetched_ = true; | 189 already_fetched_ = true; |
| 198 fetcher_.reset(URLFetcher::Create(fetcher_id_, GURL(kSearchDomainCheckURL), | 190 fetcher_.reset(URLFetcher::Create(fetcher_id_, GURL(kSearchDomainCheckURL), |
| 199 URLFetcher::GET, this)); | 191 URLFetcher::GET, this)); |
| 200 ++fetcher_id_; | 192 ++fetcher_id_; |
| 201 // We don't want this fetch to affect existing state in the profile. For | 193 // We don't want this fetch to affect existing state in the profile. For |
| 202 // example, if a user has no Google cookies, this automatic check should not | 194 // example, if a user has no Google cookies, this automatic check should not |
| 203 // cause one to be set, lest we alarm the user. | 195 // cause one to be set, lest we alarm the user. |
| 204 fetcher_->set_load_flags(net::LOAD_DISABLE_CACHE | | 196 fetcher_->set_load_flags(net::LOAD_DISABLE_CACHE | |
| 205 net::LOAD_DO_NOT_SAVE_COOKIES); | 197 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 206 fetcher_->set_request_context(Profile::GetDefaultRequestContext()); | 198 fetcher_->set_request_context(Profile::GetDefaultRequestContext()); |
| 199 |
| 200 // Configure to max_retries at most kMaxRetries times for 5xx errors. |
| 201 static const int kMaxRetries = 5; |
| 202 fetcher_->set_max_retries(kMaxRetries); |
| 203 |
| 207 fetcher_->Start(); | 204 fetcher_->Start(); |
| 208 } | 205 } |
| 209 | 206 |
| 210 void GoogleURLTracker::OnURLFetchComplete(const URLFetcher* source, | 207 void GoogleURLTracker::OnURLFetchComplete(const URLFetcher* source, |
| 211 const GURL& url, | 208 const GURL& url, |
| 212 const URLRequestStatus& status, | 209 const URLRequestStatus& status, |
| 213 int response_code, | 210 int response_code, |
| 214 const ResponseCookies& cookies, | 211 const ResponseCookies& cookies, |
| 215 const std::string& data) { | 212 const std::string& data) { |
| 216 // Delete the fetcher on this function's exit. | 213 // Delete the fetcher on this function's exit. |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 TabContents* tab_contents) { | 352 TabContents* tab_contents) { |
| 356 if (!need_to_prompt_) | 353 if (!need_to_prompt_) |
| 357 return; | 354 return; |
| 358 DCHECK(!fetched_google_url_.is_empty()); | 355 DCHECK(!fetched_google_url_.is_empty()); |
| 359 DCHECK(infobar_factory_.get()); | 356 DCHECK(infobar_factory_.get()); |
| 360 | 357 |
| 361 infobar_ = infobar_factory_->CreateInfoBar(tab_contents, | 358 infobar_ = infobar_factory_->CreateInfoBar(tab_contents, |
| 362 this, | 359 this, |
| 363 fetched_google_url_); | 360 fetched_google_url_); |
| 364 } | 361 } |
| OLD | NEW |