| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/bind.h" | 9 #include "base/bind.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/google/google_url_tracker_factory.h" | 15 #include "chrome/browser/google/google_url_tracker_factory.h" |
| 16 #include "chrome/browser/google/google_util.h" | 16 #include "chrome/browser/google/google_util.h" |
| 17 #include "chrome/browser/infobars/infobar_tab_helper.h" | 17 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 18 #include "chrome/browser/prefs/pref_service.h" | 18 #include "chrome/browser/prefs/pref_service.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/search_engines/template_url.h" | 20 #include "chrome/browser/search_engines/template_url.h" |
| 21 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 21 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 22 #include "chrome/common/chrome_notification_types.h" | 22 #include "chrome/common/chrome_notification_types.h" |
| 23 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 24 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 25 #include "content/public/browser/navigation_controller.h" | 25 #include "content/public/browser/navigation_controller.h" |
| 26 #include "content/public/browser/navigation_entry.h" | 26 #include "content/public/browser/navigation_entry.h" |
| 27 #include "content/public/browser/notification_service.h" | 27 #include "content/public/browser/notification_service.h" |
| 28 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 29 #include "content/public/common/url_fetcher.h" | |
| 30 #include "grit/generated_resources.h" | 29 #include "grit/generated_resources.h" |
| 31 #include "net/base/load_flags.h" | 30 #include "net/base/load_flags.h" |
| 32 #include "net/base/net_util.h" | 31 #include "net/base/net_util.h" |
| 32 #include "net/url_request/url_fetcher.h" |
| 33 #include "net/url_request/url_request_context_getter.h" | 33 #include "net/url_request/url_request_context_getter.h" |
| 34 #include "net/url_request/url_request_status.h" | 34 #include "net/url_request/url_request_status.h" |
| 35 #include "ui/base/l10n/l10n_util.h" | 35 #include "ui/base/l10n/l10n_util.h" |
| 36 | 36 |
| 37 namespace { | 37 namespace { |
| 38 | 38 |
| 39 GoogleURLTrackerInfoBarDelegate* CreateInfoBar( | 39 GoogleURLTrackerInfoBarDelegate* CreateInfoBar( |
| 40 InfoBarTabHelper* infobar_helper, | 40 InfoBarTabHelper* infobar_helper, |
| 41 const GURL& search_url, | 41 const GURL& search_url, |
| 42 GoogleURLTracker* google_url_tracker, | 42 GoogleURLTracker* google_url_tracker, |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 if (CommandLine::ForCurrentProcess()->HasSwitch( | 276 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 277 switches::kDisableBackgroundNetworking)) | 277 switches::kDisableBackgroundNetworking)) |
| 278 return; | 278 return; |
| 279 | 279 |
| 280 std::string fetch_url = CommandLine::ForCurrentProcess()-> | 280 std::string fetch_url = CommandLine::ForCurrentProcess()-> |
| 281 GetSwitchValueASCII(switches::kGoogleSearchDomainCheckURL); | 281 GetSwitchValueASCII(switches::kGoogleSearchDomainCheckURL); |
| 282 if (fetch_url.empty()) | 282 if (fetch_url.empty()) |
| 283 fetch_url = kSearchDomainCheckURL; | 283 fetch_url = kSearchDomainCheckURL; |
| 284 | 284 |
| 285 already_fetched_ = true; | 285 already_fetched_ = true; |
| 286 fetcher_.reset(content::URLFetcher::Create(fetcher_id_, GURL(fetch_url), | 286 fetcher_.reset(net::URLFetcher::Create(fetcher_id_, GURL(fetch_url), |
| 287 net::URLFetcher::GET, this)); | 287 net::URLFetcher::GET, this)); |
| 288 ++fetcher_id_; | 288 ++fetcher_id_; |
| 289 // We don't want this fetch to set new entries in the cache or cookies, lest | 289 // We don't want this fetch to set new entries in the cache or cookies, lest |
| 290 // we alarm the user. | 290 // we alarm the user. |
| 291 fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE | | 291 fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE | |
| 292 net::LOAD_DO_NOT_SAVE_COOKIES); | 292 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 293 fetcher_->SetRequestContext(profile_->GetRequestContext()); | 293 fetcher_->SetRequestContext(profile_->GetRequestContext()); |
| 294 | 294 |
| 295 // Configure to max_retries at most kMaxRetries times for 5xx errors. | 295 // Configure to max_retries at most kMaxRetries times for 5xx errors. |
| 296 static const int kMaxRetries = 5; | 296 static const int kMaxRetries = 5; |
| 297 fetcher_->SetMaxRetries(kMaxRetries); | 297 fetcher_->SetMaxRetries(kMaxRetries); |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 | 509 |
| 510 void GoogleURLTracker::CloseAllInfoBars(bool redo_searches) { | 510 void GoogleURLTracker::CloseAllInfoBars(bool redo_searches) { |
| 511 // Close all infobars, whether they've been added to tabs or not. | 511 // Close all infobars, whether they've been added to tabs or not. |
| 512 while (!infobar_map_.empty()) | 512 while (!infobar_map_.empty()) |
| 513 infobar_map_.begin()->second->Close(redo_searches); | 513 infobar_map_.begin()->second->Close(redo_searches); |
| 514 | 514 |
| 515 // Any registered listeners for NAV_ENTRY_COMMITTED and TAB_CLOSED are now | 515 // Any registered listeners for NAV_ENTRY_COMMITTED and TAB_CLOSED are now |
| 516 // irrelevant as the associated infobars are gone. | 516 // irrelevant as the associated infobars are gone. |
| 517 registrar_.RemoveAll(); | 517 registrar_.RemoveAll(); |
| 518 } | 518 } |
| OLD | NEW |