diff options
author | battre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-15 17:26:54 +0000 |
---|---|---|
committer | battre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-15 17:26:54 +0000 |
commit | d2d63be523cbd238e11e160d904bcb351fdfb9e8 (patch) | |
tree | cb4162162d4586ca4e9fd974f9f3744ba78f1bae /chrome/browser/google | |
parent | 0997dbb61cacad042c452b37e03d4de5a0ed82bb (diff) | |
download | chromium_src-d2d63be523cbd238e11e160d904bcb351fdfb9e8.zip chromium_src-d2d63be523cbd238e11e160d904bcb351fdfb9e8.tar.gz chromium_src-d2d63be523cbd238e11e160d904bcb351fdfb9e8.tar.bz2 |
Extended: Add "system" URLRequestContext (not ready for use!)
This is an extension of http://codereview.chromium.org/6280018 that provides a proxy configuration which respects command line parameters and policies
BUG=67232,70732
TEST=Start chrome, observe two PROXY_CONFIG_CHANGED events in about:net-internals (if you are on a corporate network with PAC configurations), observe that everything behaves as usual. In particular the https://www.google.com/searchdomaincheck?format=domain&type=chrome request should not fail as it uses the new system URLRequestContext.
Review URL: http://codereview.chromium.org/6292017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78228 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/google')
-rw-r--r-- | chrome/browser/google/google_url_tracker.cc | 21 | ||||
-rw-r--r-- | chrome/browser/google/google_url_tracker.h | 4 | ||||
-rw-r--r-- | chrome/browser/google/google_url_tracker_unittest.cc | 34 |
3 files changed, 5 insertions, 54 deletions
diff --git a/chrome/browser/google/google_url_tracker.cc b/chrome/browser/google/google_url_tracker.cc index 206cf0e..2612d73 100644 --- a/chrome/browser/google/google_url_tracker.cc +++ b/chrome/browser/google/google_url_tracker.cc @@ -12,9 +12,9 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/prefs/pref_service.h" -#include "chrome/browser/profiles/profile.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/net/url_request_context_getter.h" #include "chrome/common/pref_names.h" #include "content/browser/tab_contents/navigation_controller.h" #include "content/browser/tab_contents/tab_contents.h" @@ -98,13 +98,9 @@ GoogleURLTracker::GoogleURLTracker() in_startup_sleep_(true), already_fetched_(false), need_to_fetch_(false), - request_context_available_(!!Profile::GetDefaultRequestContext()), need_to_prompt_(false), controller_(NULL), infobar_(NULL) { - registrar_.Add(this, NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE, - NotificationService::AllSources()); - net::NetworkChangeNotifier::AddIPAddressObserver(this); MessageLoop::current()->PostTask(FROM_HERE, @@ -181,8 +177,7 @@ void GoogleURLTracker::StartFetchIfDesirable() { // // See comments in header on the class, on RequestServerCheck(), and on the // various members here for more detail on exactly what the conditions are. - if (in_startup_sleep_ || already_fetched_ || !need_to_fetch_ || - !request_context_available_) + if (in_startup_sleep_ || already_fetched_ || !need_to_fetch_) return; if (CommandLine::ForCurrentProcess()->HasSwitch( @@ -193,12 +188,12 @@ void GoogleURLTracker::StartFetchIfDesirable() { fetcher_.reset(URLFetcher::Create(fetcher_id_, GURL(kSearchDomainCheckURL), URLFetcher::GET, this)); ++fetcher_id_; - // We don't want this fetch to affect existing state in the profile. For + // We don't want this fetch to affect existing state in local_state. For // example, if a user has no Google cookies, this automatic check should not // cause one to be set, lest we alarm the user. fetcher_->set_load_flags(net::LOAD_DISABLE_CACHE | net::LOAD_DO_NOT_SAVE_COOKIES); - fetcher_->set_request_context(Profile::GetDefaultRequestContext()); + fetcher_->set_request_context(g_browser_process->system_request_context()); // Configure to max_retries at most kMaxRetries times for 5xx errors. static const int kMaxRetries = 5; @@ -298,14 +293,6 @@ void GoogleURLTracker::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { switch (type.value) { - case NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE: - registrar_.Remove(this, - NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE, - NotificationService::AllSources()); - request_context_available_ = true; - StartFetchIfDesirable(); - break; - case NotificationType::NAV_ENTRY_PENDING: { NavigationController* controller = Source<NavigationController>(source).ptr(); diff --git a/chrome/browser/google/google_url_tracker.h b/chrome/browser/google/google_url_tracker.h index 0cf6d4e..4af8910 100644 --- a/chrome/browser/google/google_url_tracker.h +++ b/chrome/browser/google/google_url_tracker.h @@ -148,10 +148,6 @@ class GoogleURLTracker : public URLFetcher::Delegate, // bother to fetch anything. // Consumers should observe // NotificationType::GOOGLE_URL_UPDATED. - bool request_context_available_; - // True when the profile has been loaded and the - // default request context created, so we can - // actually do the fetch with the right data. bool need_to_prompt_; // True if the last fetched Google URL is not // matched with current user's default Google URL // nor the last prompted Google URL. diff --git a/chrome/browser/google/google_url_tracker_unittest.cc b/chrome/browser/google/google_url_tracker_unittest.cc index 149720b..b836a03 100644 --- a/chrome/browser/google/google_url_tracker_unittest.cc +++ b/chrome/browser/google/google_url_tracker_unittest.cc @@ -8,7 +8,6 @@ #include "base/message_loop.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/prefs/browser_prefs.h" -#include "chrome/browser/profiles/profile.h" #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" #include "chrome/common/net/test_url_fetcher_factory.h" #include "chrome/common/net/url_fetcher.h" @@ -16,7 +15,6 @@ #include "chrome/common/pref_names.h" #include "chrome/test/testing_browser_process.h" #include "chrome/test/testing_pref_service.h" -#include "chrome/test/testing_profile.h" #include "content/browser/browser_thread.h" #include "content/common/notification_service.h" #include "net/url_request/url_request.h" @@ -110,7 +108,6 @@ class GoogleURLTrackerTest : public testing::Test { virtual void SetUp(); virtual void TearDown(); - void CreateRequestContext(); TestURLFetcher* GetFetcherByID(int expected_id); void MockSearchDomainCheckResponse(int expected_id, const std::string& domain); @@ -137,31 +134,24 @@ class GoogleURLTrackerTest : public testing::Test { BrowserThread* io_thread_; scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; TestingPrefService local_state_; - scoped_ptr<TestingProfile> testing_profile_; TestURLFetcherFactory fetcher_factory_; NotificationRegistrar registrar_; - - URLRequestContextGetter* original_default_request_context_; }; GoogleURLTrackerTest::GoogleURLTrackerTest() : observer_(new TestNotificationObserver), message_loop_(NULL), - io_thread_(NULL), - original_default_request_context_(NULL) { + io_thread_(NULL) { } GoogleURLTrackerTest::~GoogleURLTrackerTest() { } void GoogleURLTrackerTest::SetUp() { - original_default_request_context_ = Profile::GetDefaultRequestContext(); - Profile::set_default_request_context(NULL); message_loop_ = new MessageLoop(MessageLoop::TYPE_IO); io_thread_ = new BrowserThread(BrowserThread::IO, message_loop_); network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); - testing_profile_.reset(new TestingProfile); browser::RegisterLocalState(&local_state_); TestingBrowserProcess* testing_browser_process = static_cast<TestingBrowserProcess*>(g_browser_process); @@ -182,20 +172,9 @@ void GoogleURLTrackerTest::TearDown() { static_cast<TestingBrowserProcess*>(g_browser_process); testing_browser_process->SetGoogleURLTracker(NULL); testing_browser_process->SetPrefService(NULL); - testing_profile_.reset(); network_change_notifier_.reset(); delete io_thread_; delete message_loop_; - Profile::set_default_request_context(original_default_request_context_); - original_default_request_context_ = NULL; -} - -void GoogleURLTrackerTest::CreateRequestContext() { - testing_profile_->CreateRequestContext(); - Profile::set_default_request_context(testing_profile_->GetRequestContext()); - NotificationService::current()->Notify( - NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE, - NotificationService::AllSources(), NotificationService::NoDetails()); } TestURLFetcher* GoogleURLTrackerTest::GetFetcherByID(int expected_id) { @@ -316,7 +295,6 @@ void GoogleURLTrackerTest::ExpectDefaultURLs() { // Tests ---------------------------------------------------------------------- TEST_F(GoogleURLTrackerTest, DontFetchWhenNoOneRequestsCheck) { - CreateRequestContext(); ExpectDefaultURLs(); FinishSleep(); // No one called RequestServerCheck() so nothing should have happened. @@ -326,7 +304,6 @@ TEST_F(GoogleURLTrackerTest, DontFetchWhenNoOneRequestsCheck) { } TEST_F(GoogleURLTrackerTest, UpdateOnFirstRun) { - CreateRequestContext(); RequestServerCheck(); EXPECT_FALSE(GetFetcherByID(0)); ExpectDefaultURLs(); @@ -341,7 +318,6 @@ TEST_F(GoogleURLTrackerTest, UpdateOnFirstRun) { } TEST_F(GoogleURLTrackerTest, DontUpdateWhenUnchanged) { - CreateRequestContext(); SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); RequestServerCheck(); @@ -360,7 +336,6 @@ TEST_F(GoogleURLTrackerTest, DontUpdateWhenUnchanged) { } TEST_F(GoogleURLTrackerTest, UpdatePromptedURLOnReturnToPreviousLocation) { - CreateRequestContext(); SetLastPromptedGoogleURL(GURL("http://www.google.co.jp/")); SetGoogleURL(GURL("http://www.google.co.uk/")); RequestServerCheck(); @@ -373,7 +348,6 @@ TEST_F(GoogleURLTrackerTest, UpdatePromptedURLOnReturnToPreviousLocation) { } TEST_F(GoogleURLTrackerTest, RefetchOnIPAddressChange) { - CreateRequestContext(); RequestServerCheck(); FinishSleep(); MockSearchDomainCheckResponse(0, ".google.co.uk"); @@ -391,7 +365,6 @@ TEST_F(GoogleURLTrackerTest, RefetchOnIPAddressChange) { } TEST_F(GoogleURLTrackerTest, DontRefetchWhenNoOneRequestsCheck) { - CreateRequestContext(); FinishSleep(); NotifyIPAddressChanged(); // No one called RequestServerCheck() so nothing should have happened. @@ -401,7 +374,6 @@ TEST_F(GoogleURLTrackerTest, DontRefetchWhenNoOneRequestsCheck) { } TEST_F(GoogleURLTrackerTest, FetchOnLateRequest) { - CreateRequestContext(); FinishSleep(); NotifyIPAddressChanged(); @@ -415,7 +387,6 @@ TEST_F(GoogleURLTrackerTest, FetchOnLateRequest) { } TEST_F(GoogleURLTrackerTest, SearchingDoesNothingIfNoNeedToPrompt) { - CreateRequestContext(); RequestServerCheck(); FinishSleep(); MockSearchDomainCheckResponse(0, ".google.co.uk"); @@ -435,7 +406,6 @@ TEST_F(GoogleURLTrackerTest, SearchingDoesNothingIfNoNeedToPrompt) { } TEST_F(GoogleURLTrackerTest, InfobarClosed) { - CreateRequestContext(); SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); RequestServerCheck(); FinishSleep(); @@ -454,7 +424,6 @@ TEST_F(GoogleURLTrackerTest, InfobarClosed) { } TEST_F(GoogleURLTrackerTest, InfobarRefused) { - CreateRequestContext(); SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); RequestServerCheck(); FinishSleep(); @@ -474,7 +443,6 @@ TEST_F(GoogleURLTrackerTest, InfobarRefused) { } TEST_F(GoogleURLTrackerTest, InfobarAccepted) { - CreateRequestContext(); SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); RequestServerCheck(); FinishSleep(); |