diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-15 18:31:03 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-15 18:31:03 +0000 |
commit | 004ec925e3f71aeba2acd1461741ccddd92eeedc (patch) | |
tree | e58efd0fc8f7b2baec92cde9d95fd8617d86d32d /chrome | |
parent | 53f4636020e46d0ca54a60b1ecbbdcb677651c80 (diff) | |
download | chromium_src-004ec925e3f71aeba2acd1461741ccddd92eeedc.zip chromium_src-004ec925e3f71aeba2acd1461741ccddd92eeedc.tar.gz chromium_src-004ec925e3f71aeba2acd1461741ccddd92eeedc.tar.bz2 |
Revert 78228 - 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
TBR=battre@chromium.org
Review URL: http://codereview.chromium.org/6693023
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78240 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
29 files changed, 249 insertions, 382 deletions
diff --git a/chrome/browser/browser_process.h b/chrome/browser/browser_process.h index 6afb776..d406eb0 100644 --- a/chrome/browser/browser_process.h +++ b/chrome/browser/browser_process.h @@ -15,7 +15,6 @@ #include <vector> #include "base/basictypes.h" -#include "base/ref_counted.h" #include "ipc/ipc_message.h" class AutomationProviderList; @@ -41,7 +40,6 @@ class ResourceDispatcherHost; class SidebarManager; class TabCloseableStateWatcher; class ThumbnailGenerator; -class URLRequestContextGetter; class WatchDogThread; namespace base { @@ -49,12 +47,6 @@ class Thread; class WaitableEvent; } -#if defined(OS_CHROMEOS) -namespace chromeos { -class ProxyConfigServiceImpl; -} -#endif // defined(OS_CHROMEOS) - namespace printing { class PrintJobManager; class PrintPreviewTabController; @@ -90,14 +82,6 @@ class BrowserProcess { virtual DevToolsManager* devtools_manager() = 0; virtual SidebarManager* sidebar_manager() = 0; virtual ui::Clipboard* clipboard() = 0; - virtual URLRequestContextGetter* system_request_context() = 0; - -#if defined(OS_CHROMEOS) - // Returns ChromeOS's ProxyConfigServiceImpl, creating if not yet created. - virtual chromeos::ProxyConfigServiceImpl* - chromeos_proxy_config_service_impl() = 0; -#endif // defined(OS_CHROMEOS) - virtual ExtensionEventRouterForwarder* extension_event_router_forwarder() = 0; diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc index aff5fa7..61dacf3 100644 --- a/chrome/browser/browser_process_impl.cc +++ b/chrome/browser/browser_process_impl.cc @@ -54,7 +54,6 @@ #include "chrome/common/extensions/extension_l10n_util.h" #include "chrome/common/extensions/extension_resource.h" #include "chrome/common/json_pref_store.h" -#include "chrome/common/net/url_request_context_getter.h" #include "chrome/common/pref_names.h" #include "chrome/common/switch_utils.h" #include "chrome/common/url_constants.h" @@ -78,10 +77,6 @@ #include "content/common/child_process_messages.h" #endif -#if defined(OS_CHROMEOS) -#include "chrome/browser/chromeos/proxy_config_service_impl.h" -#endif // defined(OS_CHROMEOS) - #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) // How often to check if the persistent instance of Chrome needs to restart // to install an update. @@ -443,23 +438,6 @@ ui::Clipboard* BrowserProcessImpl::clipboard() { return clipboard_.get(); } -URLRequestContextGetter* BrowserProcessImpl::system_request_context() { - DCHECK(CalledOnValidThread()); - return io_thread()->system_url_request_context_getter(); -} - -#if defined(OS_CHROMEOS) -chromeos::ProxyConfigServiceImpl* -BrowserProcessImpl::chromeos_proxy_config_service_impl() { - DCHECK(CalledOnValidThread()); - if (!chromeos_proxy_config_service_impl_) { - chromeos_proxy_config_service_impl_ = - new chromeos::ProxyConfigServiceImpl(); - } - return chromeos_proxy_config_service_impl_; -} -#endif // defined(OS_CHROMEOS) - ExtensionEventRouterForwarder* BrowserProcessImpl::extension_event_router_forwarder() { return extension_event_router_forwarder_.get(); diff --git a/chrome/browser/browser_process_impl.h b/chrome/browser/browser_process_impl.h index b7412a4..4967f59 100644 --- a/chrome/browser/browser_process_impl.h +++ b/chrome/browser/browser_process_impl.h @@ -63,11 +63,6 @@ class BrowserProcessImpl : public BrowserProcess, virtual DevToolsManager* devtools_manager(); virtual SidebarManager* sidebar_manager(); virtual ui::Clipboard* clipboard(); - virtual URLRequestContextGetter* system_request_context(); -#if defined(OS_CHROMEOS) - virtual chromeos::ProxyConfigServiceImpl* - chromeos_proxy_config_service_impl(); -#endif // defined(OS_CHROMEOS) virtual ExtensionEventRouterForwarder* extension_event_router_forwarder(); virtual NotificationUIManager* notification_ui_manager(); virtual policy::BrowserPolicyConnector* browser_policy_connector(); @@ -280,11 +275,6 @@ class BrowserProcessImpl : public BrowserProcess, void RestartPersistentInstance(); #endif // defined(OS_WIN) || defined(OS_LINUX) -#if defined(OS_CHROMEOS) - scoped_refptr<chromeos::ProxyConfigServiceImpl> - chromeos_proxy_config_service_impl_; -#endif - DISALLOW_COPY_AND_ASSIGN(BrowserProcessImpl); }; diff --git a/chrome/browser/chromeos/login/login_utils.cc b/chrome/browser/chromeos/login/login_utils.cc index 04fb5c5..a078999 100644 --- a/chrome/browser/chromeos/login/login_utils.cc +++ b/chrome/browser/chromeos/login/login_utils.cc @@ -260,7 +260,7 @@ void LoginUtilsImpl::CompleteLogin( new PrefProxyConfigService( profile->GetProxyConfigTracker(), new chromeos::ProxyConfigService( - g_browser_process->chromeos_proxy_config_service_impl())); + profile->GetChromeOSProxyConfigServiceImpl())); BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, new ResetDefaultProxyConfigServiceTask( proxy_config_service)); diff --git a/chrome/browser/chromeos/proxy_config_service_impl.h b/chrome/browser/chromeos/proxy_config_service_impl.h index 99e50b03..44a5166 100644 --- a/chrome/browser/chromeos/proxy_config_service_impl.h +++ b/chrome/browser/chromeos/proxy_config_service_impl.h @@ -39,9 +39,9 @@ class ProxyConfigServiceImpl public SignedSettings::Delegate<std::string> { public: // ProxyConfigServiceImpl is created on the UI thread in - // chrome/browser/net/proxy_service_factory.cc::CreateProxyConfigService - // via BrowserProcess::chromeos_proxy_config_service_impl, and stored in - // g_browser_process as a scoped_refptr (because it's RefCountedThreadSafe). + // chrome/browser/net/chrome_url_request_context.cc::CreateProxyConfigService + // via ProfileImpl::GetChromeOSProxyConfigServiceImpl, and stored in Profile + // as a scoped_refptr (because it's RefCountedThreadSafe). // // Past that point, it can be accessed from the IO or UI threads. // @@ -50,7 +50,7 @@ class ProxyConfigServiceImpl // (GetLatestProxyConfig, AddObserver, RemoveObserver). // // From the UI thread, it is accessed via - // BrowserProcess::chromeos_proxy_config_service_impl to allow user to read + // WebUI::GetProfile::GetChromeOSProxyConfigServiceImpl to allow user to read // or modify the proxy configuration via UIGetProxyConfig or // UISetProxyConfigTo* respectively. // The new modified proxy config is posted to the IO thread through diff --git a/chrome/browser/chromeos/proxy_cros_settings_provider.cc b/chrome/browser/chromeos/proxy_cros_settings_provider.cc index ccb3e44..78489a1 100644 --- a/chrome/browser/chromeos/proxy_cros_settings_provider.cc +++ b/chrome/browser/chromeos/proxy_cros_settings_provider.cc @@ -7,7 +7,8 @@ #include "base/command_line.h" #include "base/string_util.h" #include "chrome/browser/browser_list.h" -#include "chrome/browser/browser_process.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/profiles/profile_manager.h" #include "chrome/common/chrome_switches.h" namespace chromeos { @@ -291,7 +292,12 @@ bool ProxyCrosSettingsProvider::HandlesSetting(const std::string& path) { chromeos::ProxyConfigServiceImpl* ProxyCrosSettingsProvider::GetConfigService() const { - return g_browser_process->chromeos_proxy_config_service_impl(); + Browser* browser = BrowserList::GetLastActive(); + // browser is NULL at OOBE/login stage. + Profile* profile = browser ? + browser->profile() : + ProfileManager::GetDefaultProfile(); + return profile->GetChromeOSProxyConfigServiceImpl(); } void ProxyCrosSettingsProvider::AppendPortIfValid( diff --git a/chrome/browser/google/google_url_tracker.cc b/chrome/browser/google/google_url_tracker.cc index 2612d73..206cf0e 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,9 +98,13 @@ 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, @@ -177,7 +181,8 @@ 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_) + if (in_startup_sleep_ || already_fetched_ || !need_to_fetch_ || + !request_context_available_) return; if (CommandLine::ForCurrentProcess()->HasSwitch( @@ -188,12 +193,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 local_state. For + // We don't want this fetch to affect existing state in the profile. 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(g_browser_process->system_request_context()); + fetcher_->set_request_context(Profile::GetDefaultRequestContext()); // Configure to max_retries at most kMaxRetries times for 5xx errors. static const int kMaxRetries = 5; @@ -293,6 +298,14 @@ 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 4af8910..0cf6d4e 100644 --- a/chrome/browser/google/google_url_tracker.h +++ b/chrome/browser/google/google_url_tracker.h @@ -148,6 +148,10 @@ 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 b836a03..149720b 100644 --- a/chrome/browser/google/google_url_tracker_unittest.cc +++ b/chrome/browser/google/google_url_tracker_unittest.cc @@ -8,6 +8,7 @@ #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" @@ -15,6 +16,7 @@ #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" @@ -108,6 +110,7 @@ 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); @@ -134,24 +137,31 @@ 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) { + io_thread_(NULL), + original_default_request_context_(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); @@ -172,9 +182,20 @@ 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) { @@ -295,6 +316,7 @@ void GoogleURLTrackerTest::ExpectDefaultURLs() { // Tests ---------------------------------------------------------------------- TEST_F(GoogleURLTrackerTest, DontFetchWhenNoOneRequestsCheck) { + CreateRequestContext(); ExpectDefaultURLs(); FinishSleep(); // No one called RequestServerCheck() so nothing should have happened. @@ -304,6 +326,7 @@ TEST_F(GoogleURLTrackerTest, DontFetchWhenNoOneRequestsCheck) { } TEST_F(GoogleURLTrackerTest, UpdateOnFirstRun) { + CreateRequestContext(); RequestServerCheck(); EXPECT_FALSE(GetFetcherByID(0)); ExpectDefaultURLs(); @@ -318,6 +341,7 @@ TEST_F(GoogleURLTrackerTest, UpdateOnFirstRun) { } TEST_F(GoogleURLTrackerTest, DontUpdateWhenUnchanged) { + CreateRequestContext(); SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); RequestServerCheck(); @@ -336,6 +360,7 @@ TEST_F(GoogleURLTrackerTest, DontUpdateWhenUnchanged) { } TEST_F(GoogleURLTrackerTest, UpdatePromptedURLOnReturnToPreviousLocation) { + CreateRequestContext(); SetLastPromptedGoogleURL(GURL("http://www.google.co.jp/")); SetGoogleURL(GURL("http://www.google.co.uk/")); RequestServerCheck(); @@ -348,6 +373,7 @@ TEST_F(GoogleURLTrackerTest, UpdatePromptedURLOnReturnToPreviousLocation) { } TEST_F(GoogleURLTrackerTest, RefetchOnIPAddressChange) { + CreateRequestContext(); RequestServerCheck(); FinishSleep(); MockSearchDomainCheckResponse(0, ".google.co.uk"); @@ -365,6 +391,7 @@ TEST_F(GoogleURLTrackerTest, RefetchOnIPAddressChange) { } TEST_F(GoogleURLTrackerTest, DontRefetchWhenNoOneRequestsCheck) { + CreateRequestContext(); FinishSleep(); NotifyIPAddressChanged(); // No one called RequestServerCheck() so nothing should have happened. @@ -374,6 +401,7 @@ TEST_F(GoogleURLTrackerTest, DontRefetchWhenNoOneRequestsCheck) { } TEST_F(GoogleURLTrackerTest, FetchOnLateRequest) { + CreateRequestContext(); FinishSleep(); NotifyIPAddressChanged(); @@ -387,6 +415,7 @@ TEST_F(GoogleURLTrackerTest, FetchOnLateRequest) { } TEST_F(GoogleURLTrackerTest, SearchingDoesNothingIfNoNeedToPrompt) { + CreateRequestContext(); RequestServerCheck(); FinishSleep(); MockSearchDomainCheckResponse(0, ".google.co.uk"); @@ -406,6 +435,7 @@ TEST_F(GoogleURLTrackerTest, SearchingDoesNothingIfNoNeedToPrompt) { } TEST_F(GoogleURLTrackerTest, InfobarClosed) { + CreateRequestContext(); SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); RequestServerCheck(); FinishSleep(); @@ -424,6 +454,7 @@ TEST_F(GoogleURLTrackerTest, InfobarClosed) { } TEST_F(GoogleURLTrackerTest, InfobarRefused) { + CreateRequestContext(); SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); RequestServerCheck(); FinishSleep(); @@ -443,6 +474,7 @@ TEST_F(GoogleURLTrackerTest, InfobarRefused) { } TEST_F(GoogleURLTrackerTest, InfobarAccepted) { + CreateRequestContext(); SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); RequestServerCheck(); FinishSleep(); diff --git a/chrome/browser/intranet_redirect_detector.cc b/chrome/browser/intranet_redirect_detector.cc index 2ac9ab5..d858a2f 100644 --- a/chrome/browser/intranet_redirect_detector.cc +++ b/chrome/browser/intranet_redirect_detector.cc @@ -10,8 +10,8 @@ #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/common/chrome_switches.h" -#include "chrome/common/net/url_request_context_getter.h" #include "chrome/common/pref_names.h" #include "content/common/notification_service.h" #include "net/base/load_flags.h" @@ -25,7 +25,11 @@ IntranetRedirectDetector::IntranetRedirectDetector() : redirect_origin_(g_browser_process->local_state()->GetString( prefs::kLastKnownIntranetRedirectOrigin)), ALLOW_THIS_IN_INITIALIZER_LIST(fetcher_factory_(this)), - in_sleep_(true) { + in_sleep_(true), + request_context_available_(Profile::GetDefaultRequestContext() != NULL) { + registrar_.Add(this, NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE, + NotificationService::AllSources()); + // Because this function can be called during startup, when kicking off a URL // fetch can eat up 20 ms of time, we delay seven seconds, which is hopefully // long enough to be after startup, but still get results back quickly. @@ -66,6 +70,16 @@ void IntranetRedirectDetector::FinishSleep() { STLDeleteElements(&fetchers_); resulting_origins_.clear(); + StartFetchesIfPossible(); +} + +void IntranetRedirectDetector::StartFetchesIfPossible() { + // Bail if a fetch isn't appropriate right now. This function will be called + // again each time one of the preconditions changes, so we'll fetch + // immediately once all of them are met. + if (in_sleep_ || !request_context_available_) + return; + // The detector is not needed in Chrome Frame since we have no omnibox there. const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); if (cmd_line->HasSwitch(switches::kDisableBackgroundNetworking) || @@ -84,7 +98,7 @@ void IntranetRedirectDetector::FinishSleep() { // We don't want these fetches to affect existing state in the profile. fetcher->set_load_flags(net::LOAD_DISABLE_CACHE | net::LOAD_DO_NOT_SAVE_COOKIES); - fetcher->set_request_context(g_browser_process->system_request_context()); + fetcher->set_request_context(Profile::GetDefaultRequestContext()); fetcher->Start(); fetchers_.insert(fetcher); } @@ -144,6 +158,14 @@ void IntranetRedirectDetector::OnURLFetchComplete( redirect_origin_.spec() : std::string()); } +void IntranetRedirectDetector::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + DCHECK_EQ(NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE, type.value); + request_context_available_ = true; + StartFetchesIfPossible(); +} + void IntranetRedirectDetector::OnIPAddressChanged() { // If a request is already scheduled, do not scheduled yet another one. if (in_sleep_) diff --git a/chrome/browser/intranet_redirect_detector.h b/chrome/browser/intranet_redirect_detector.h index 3dfcb9c..e54566b2 100644 --- a/chrome/browser/intranet_redirect_detector.h +++ b/chrome/browser/intranet_redirect_detector.h @@ -37,6 +37,7 @@ class PrefService; // redirection is in place, the returned GURL will be empty. class IntranetRedirectDetector : public URLFetcher::Delegate, + public NotificationObserver, public net::NetworkChangeNotifier::IPAddressObserver { public: // Only the main browser process loop should call this, when setting up @@ -65,6 +66,9 @@ class IntranetRedirectDetector // switch sleep has finished. Runs any pending fetch. void FinishSleep(); + // Starts the fetches to determine the redirect URL if we can currently do so. + void StartFetchesIfPossible(); + // URLFetcher::Delegate virtual void OnURLFetchComplete(const URLFetcher* source, const GURL& url, @@ -73,9 +77,15 @@ class IntranetRedirectDetector const ResponseCookies& cookies, const std::string& data); + // NotificationObserver + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + // NetworkChangeNotifier::IPAddressObserver virtual void OnIPAddressChanged(); + NotificationRegistrar registrar_; GURL redirect_origin_; ScopedRunnableMethodFactory<IntranetRedirectDetector> fetcher_factory_; Fetchers fetchers_; @@ -83,6 +93,10 @@ class IntranetRedirectDetector bool in_sleep_; // True if we're in the seven-second "no fetching" period // that begins at browser start, or the one-second "no // fetching" period that begins after network switches. + 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. DISALLOW_COPY_AND_ASSIGN(IntranetRedirectDetector); }; diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc index 6ddad22..1978a0c 100644 --- a/chrome/browser/io_thread.cc +++ b/chrome/browser/io_thread.cc @@ -23,8 +23,6 @@ #include "chrome/browser/net/connect_interceptor.h" #include "chrome/browser/net/passive_log_collector.h" #include "chrome/browser/net/predictor_api.h" -#include "chrome/browser/net/pref_proxy_config_service.h" -#include "chrome/browser/net/proxy_service_factory.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/net/raw_host_resolver_proc.h" @@ -41,7 +39,6 @@ #include "net/base/host_resolver_impl.h" #include "net/base/mapped_host_resolver.h" #include "net/base/net_util.h" -#include "net/proxy/proxy_config_service.h" #include "net/http/http_auth_filter.h" #include "net/http/http_auth_handler_factory.h" #include "net/http/http_network_layer.h" @@ -202,64 +199,8 @@ ConstructProxyScriptFetcherContext(IOThread::Globals* globals, return context; } -scoped_refptr<net::URLRequestContext> -ConstructSystemRequestContext(IOThread::Globals* globals, - net::NetLog* net_log) { - scoped_refptr<net::URLRequestContext> context(new net::URLRequestContext); - context->set_net_log(net_log); - context->set_host_resolver(globals->host_resolver.get()); - context->set_cert_verifier(globals->cert_verifier.get()); - context->set_dnsrr_resolver(globals->dnsrr_resolver.get()); - context->set_http_auth_handler_factory( - globals->http_auth_handler_factory.get()); - context->set_proxy_service(globals->system_proxy_service.get()); - context->set_http_transaction_factory( - globals->system_http_transaction_factory.get()); - // In-memory cookie store. - context->set_cookie_store(new net::CookieMonster(NULL, NULL)); - return context; -} - } // namespace -class SystemURLRequestContextGetter : public URLRequestContextGetter { - public: - explicit SystemURLRequestContextGetter(IOThread* io_thread); - virtual ~SystemURLRequestContextGetter(); - - // Implementation for UrlRequestContextGetter. - virtual net::URLRequestContext* GetURLRequestContext(); - virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const; - - private: - IOThread* const io_thread_; // Weak pointer, owned by BrowserProcess. - scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; - - base::debug::LeakTracker<SystemURLRequestContextGetter> leak_tracker_; -}; - -SystemURLRequestContextGetter::SystemURLRequestContextGetter( - IOThread* io_thread) - : io_thread_(io_thread), - io_message_loop_proxy_(io_thread->message_loop_proxy()) { -} - -SystemURLRequestContextGetter::~SystemURLRequestContextGetter() {} - -net::URLRequestContext* SystemURLRequestContextGetter::GetURLRequestContext() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - - if (!io_thread_->globals()->system_request_context) - io_thread_->InitSystemRequestContext(); - - return io_thread_->globals()->system_request_context; -} - -scoped_refptr<base::MessageLoopProxy> -SystemURLRequestContextGetter::GetIOMessageLoopProxy() const { - return io_message_loop_proxy_; -} - // The IOThread object must outlive any tasks posted to the IO thread before the // Quit task. DISABLE_RUNNABLE_METHOD_REFCOUNT(IOThread); @@ -292,12 +233,9 @@ IOThread::IOThread( auth_delegate_whitelist_ = local_state->GetString( prefs::kAuthNegotiateDelegateWhitelist); gssapi_library_name_ = local_state->GetString(prefs::kGSSAPILibraryName); - pref_proxy_config_tracker_ = new PrefProxyConfigTracker(local_state); } IOThread::~IOThread() { - if (pref_proxy_config_tracker_) - pref_proxy_config_tracker_->DetachFromPrefService(); // We cannot rely on our base class to stop the thread since we want our // CleanUp function to run. Stop(); @@ -364,18 +302,6 @@ void IOThread::ChangedToOnTheRecord() { &IOThread::ChangedToOnTheRecordOnIOThread)); } -URLRequestContextGetter* IOThread::system_url_request_context_getter() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (!system_url_request_context_getter_) { - system_proxy_config_service_.reset( - ProxyServiceFactory::CreateProxyConfigService( - pref_proxy_config_tracker_)); - system_url_request_context_getter_ = - new SystemURLRequestContextGetter(this); - } - return system_url_request_context_getter_; -} - void IOThread::ClearNetworkingHistory() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); ClearHostCache(); @@ -475,8 +401,6 @@ void IOThread::CleanUp() { getter->ReleaseURLRequestContext(); } - system_url_request_context_getter_ = NULL; - // Step 2: Release objects that the net::URLRequestContext could have been // pointing to. @@ -503,16 +427,12 @@ void IOThread::CleanUp() { globals_->host_resolver.get()->GetAsHostResolverImpl()->Shutdown(); } - system_proxy_config_service_.reset(); - delete globals_; globals_ = NULL; // net::URLRequest instances must NOT outlive the IO thread. base::debug::LeakTracker<net::URLRequest>::CheckForLeaks(); - base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks(); - // This will delete the |notification_service_|. Make sure it's done after // anything else can reference it. BrowserProcessSubThread::CleanUp(); @@ -612,34 +532,3 @@ void IOThread::ClearHostCache() { host_cache->clear(); } } - -void IOThread::InitSystemRequestContext() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - DCHECK(!globals_->system_proxy_service); - DCHECK(system_proxy_config_service_.get()); - - const CommandLine& command_line = *CommandLine::ForCurrentProcess(); - globals_->system_proxy_service = - ProxyServiceFactory::CreateProxyService( - net_log_, - globals_->proxy_script_fetcher_context, - system_proxy_config_service_.release(), - command_line); - net::HttpNetworkSession::Params system_params; - system_params.host_resolver = globals_->host_resolver.get(); - system_params.cert_verifier = globals_->cert_verifier.get(); - system_params.dnsrr_resolver = globals_->dnsrr_resolver.get(); - system_params.dns_cert_checker = NULL; - system_params.ssl_host_info_factory = NULL; - system_params.proxy_service = globals_->system_proxy_service.get(); - system_params.ssl_config_service = globals_->ssl_config_service.get(); - system_params.http_auth_handler_factory = - globals_->http_auth_handler_factory.get(); - system_params.network_delegate = globals_->system_network_delegate.get(); - system_params.net_log = net_log_; - globals_->system_http_transaction_factory.reset( - new net::HttpNetworkLayer( - new net::HttpNetworkSession(system_params))); - globals_->system_request_context = - ConstructSystemRequestContext(globals_, net_log_); -} diff --git a/chrome/browser/io_thread.h b/chrome/browser/io_thread.h index 2c8362d..d3bf4e7 100644 --- a/chrome/browser/io_thread.h +++ b/chrome/browser/io_thread.h @@ -19,10 +19,7 @@ class ChromeNetLog; class ChromeURLRequestContextGetter; class ExtensionEventRouterForwarder; class ListValue; -class PrefProxyConfigTracker; class PrefService; -class SystemURLRequestContextGetter; -class URLRequestContextGetter; namespace chrome_browser_net { class ConnectInterceptor; @@ -36,7 +33,6 @@ class HostResolver; class HttpAuthHandlerFactory; class HttpTransactionFactory; class NetworkDelegate; -class ProxyConfigService; class ProxyScriptFetcher; class ProxyService; class SSLConfigService; @@ -62,12 +58,6 @@ class IOThread : public BrowserProcessSubThread { proxy_script_fetcher_http_transaction_factory; scoped_ptr<net::URLSecurityManager> url_security_manager; scoped_refptr<net::URLRequestContext> proxy_script_fetcher_context; - scoped_ptr<net::HttpTransactionFactory> system_http_transaction_factory; - scoped_refptr<net::ProxyService> system_proxy_service; - // NOTE(willchan): This request context is unusable until a system - // SSLConfigService is provided that doesn't rely on - // Profiles. Do NOT use this yet. - scoped_refptr<net::URLRequestContext> system_request_context; scoped_refptr<ExtensionEventRouterForwarder> extension_event_router_forwarder; }; @@ -114,9 +104,6 @@ class IOThread : public BrowserProcessSubThread { // Handles changing to On The Record mode, discarding confidential data. void ChangedToOnTheRecord(); - // Returns a getter for the URLRequestContext. Only called on the UI thread. - URLRequestContextGetter* system_url_request_context_getter(); - // Clear all network stack history, including the host cache, as well as // speculative data about subresources of visited sites, and startup-time // navigations. @@ -127,19 +114,11 @@ class IOThread : public BrowserProcessSubThread { virtual void CleanUp(); private: - // Provide SystemURLRequestContextGetter with access to - // InitSystemRequestContext(). - friend class SystemURLRequestContextGetter; - static void RegisterPrefs(PrefService* local_state); net::HttpAuthHandlerFactory* CreateDefaultAuthHandlerFactory( net::HostResolver* resolver); - // Lazy initialization of system request context for - // SystemURLRequestContextGetter. To be called on IO thread. - void InitSystemRequestContext(); - void InitNetworkPredictorOnIOThread( bool prefetching_enabled, base::TimeDelta max_dns_queue_delay, @@ -195,12 +174,6 @@ class IOThread : public BrowserProcessSubThread { chrome_browser_net::ConnectInterceptor* speculative_interceptor_; chrome_browser_net::Predictor* predictor_; - scoped_ptr<net::ProxyConfigService> system_proxy_config_service_; - - scoped_refptr<PrefProxyConfigTracker> pref_proxy_config_tracker_; - - scoped_refptr<URLRequestContextGetter> system_url_request_context_getter_; - // Keeps track of all live ChromeURLRequestContextGetters, so the // ChromeURLRequestContexts can be released during // IOThread::CleanUp(). diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc index 32a1f5d..e4c9794 100644 --- a/chrome/browser/net/chrome_url_request_context.cc +++ b/chrome/browser/net/chrome_url_request_context.cc @@ -25,6 +25,12 @@ #include "net/ocsp/nss_ocsp.h" #endif +#if defined(OS_CHROMEOS) +#include "chrome/browser/chromeos/cros/cros_library.h" +#include "chrome/browser/chromeos/cros/libcros_service_library.h" +#include "chrome/browser/chromeos/proxy_config_service.h" +#endif // defined(OS_CHROMEOS) + class ChromeURLRequestContextFactory { public: ChromeURLRequestContextFactory() {} diff --git a/chrome/browser/net/pref_proxy_config_service.h b/chrome/browser/net/pref_proxy_config_service.h index b0e7fc3..490f06d 100644 --- a/chrome/browser/net/pref_proxy_config_service.h +++ b/chrome/browser/net/pref_proxy_config_service.h @@ -33,6 +33,7 @@ class PrefProxyConfigTracker }; explicit PrefProxyConfigTracker(PrefService* pref_service); + virtual ~PrefProxyConfigTracker(); // Observer manipulation is only valid on the IO thread. void AddObserver(Observer* observer); @@ -49,9 +50,6 @@ class PrefProxyConfigTracker void DetachFromPrefService(); private: - friend class base::RefCountedThreadSafe<PrefProxyConfigTracker>; - virtual ~PrefProxyConfigTracker(); - // NotificationObserver implementation: virtual void Observe(NotificationType type, const NotificationSource& source, diff --git a/chrome/browser/net/proxy_service_factory.cc b/chrome/browser/net/proxy_service_factory.cc deleted file mode 100644 index bc74d71..0000000 --- a/chrome/browser/net/proxy_service_factory.cc +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/net/proxy_service_factory.h" - -#include "base/command_line.h" -#include "base/string_number_conversions.h" -#include "chrome/browser/browser_process.h" -#include "chrome/browser/net/pref_proxy_config_service.h" -#include "chrome/browser/io_thread.h" -#include "chrome/common/chrome_switches.h" -#include "content/browser/browser_thread.h" -#include "net/base/net_log.h" -#include "net/proxy/proxy_config_service.h" -#include "net/proxy/proxy_script_fetcher_impl.h" -#include "net/url_request/url_request_context.h" - -#if defined(OS_CHROMEOS) -#include "chrome/browser/chromeos/cros/cros_library.h" -#include "chrome/browser/chromeos/cros/libcros_service_library.h" -#include "chrome/browser/chromeos/proxy_config_service.h" -#endif // defined(OS_CHROMEOS) - -// static -net::ProxyConfigService* ProxyServiceFactory::CreateProxyConfigService( - PrefProxyConfigTracker* proxy_config_tracker) { - // The linux gconf-based proxy settings getter relies on being initialized - // from the UI thread. - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - - // Create a baseline service that provides proxy configuration in case nothing - // is configured through prefs (Note: prefs include command line and - // configuration policy). - net::ProxyConfigService* base_service = NULL; - - // TODO(port): the IO and FILE message loops are only used by Linux. Can - // that code be moved to chrome/browser instead of being in net, so that it - // can use BrowserThread instead of raw MessageLoop pointers? See bug 25354. -#if defined(OS_CHROMEOS) - base_service = new chromeos::ProxyConfigService( - g_browser_process->chromeos_proxy_config_service_impl()); -#else - base_service = net::ProxyService::CreateSystemProxyConfigService( - g_browser_process->io_thread()->message_loop(), - g_browser_process->file_thread()->message_loop()); -#endif // defined(OS_CHROMEOS) - - return new PrefProxyConfigService(proxy_config_tracker, base_service); -} - -// static -net::ProxyService* ProxyServiceFactory::CreateProxyService( - net::NetLog* net_log, - net::URLRequestContext* context, - net::ProxyConfigService* proxy_config_service, - const CommandLine& command_line) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - - bool use_v8 = !command_line.HasSwitch(switches::kWinHttpProxyResolver); - if (use_v8 && command_line.HasSwitch(switches::kSingleProcess)) { - // See the note about V8 multithreading in net/proxy/proxy_resolver_v8.h - // to understand why we have this limitation. - LOG(ERROR) << "Cannot use V8 Proxy resolver in single process mode."; - use_v8 = false; // Fallback to non-v8 implementation. - } - - size_t num_pac_threads = 0u; // Use default number of threads. - - // Check the command line for an override on the number of proxy resolver - // threads to use. - if (command_line.HasSwitch(switches::kNumPacThreads)) { - std::string s = command_line.GetSwitchValueASCII(switches::kNumPacThreads); - - // Parse the switch (it should be a positive integer formatted as decimal). - int n; - if (base::StringToInt(s, &n) && n > 0) { - num_pac_threads = static_cast<size_t>(n); - } else { - LOG(ERROR) << "Invalid switch for number of PAC threads: " << s; - } - } - - net::ProxyService* proxy_service; - if (use_v8) { - proxy_service = net::ProxyService::CreateUsingV8ProxyResolver( - proxy_config_service, - num_pac_threads, - new net::ProxyScriptFetcherImpl(context), - context->host_resolver(), - net_log); - } else { - proxy_service = net::ProxyService::CreateUsingSystemProxyResolver( - proxy_config_service, - num_pac_threads, - net_log); - } - -#if defined(OS_CHROMEOS) - if (chromeos::CrosLibrary::Get()->EnsureLoaded()) { - chromeos::CrosLibrary::Get()->GetLibCrosServiceLibrary()-> - RegisterNetworkProxyHandler(proxy_service); - } -#endif // defined(OS_CHROMEOS) - - return proxy_service; -} diff --git a/chrome/browser/net/proxy_service_factory.h b/chrome/browser/net/proxy_service_factory.h deleted file mode 100644 index aa6796c..0000000 --- a/chrome/browser/net/proxy_service_factory.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_NET_PROXY_SERVICE_FACTORY_H_ -#define CHROME_BROWSER_NET_PROXY_SERVICE_FACTORY_H_ -#pragma once - -#include "base/basictypes.h" - -class CommandLine; -class PrefProxyConfigTracker; - -namespace net { -class NetLog; -class ProxyConfigService; -class ProxyService; -class URLRequestContext; -} // namespace net - -class ProxyServiceFactory { - public: - // Creates a ProxyConfigService that delivers the system preferences - // (or the respective ChromeOS equivalent). - static net::ProxyConfigService* CreateProxyConfigService( - PrefProxyConfigTracker* proxy_config_tracker); - - // Create a proxy service according to the options on command line. - static net::ProxyService* CreateProxyService( - net::NetLog* net_log, - net::URLRequestContext* context, - net::ProxyConfigService* proxy_config_service, - const CommandLine& command_line); - - private: - DISALLOW_IMPLICIT_CONSTRUCTORS(ProxyServiceFactory); -}; - -#endif // CHROME_BROWSER_NET_PROXY_SERVICE_FACTORY_H_ diff --git a/chrome/browser/profiles/off_the_record_profile_io_data.cc b/chrome/browser/profiles/off_the_record_profile_io_data.cc index b228a70..2be3631 100644 --- a/chrome/browser/profiles/off_the_record_profile_io_data.cc +++ b/chrome/browser/profiles/off_the_record_profile_io_data.cc @@ -14,7 +14,6 @@ #include "chrome/browser/net/chrome_net_log.h" #include "chrome/browser/net/chrome_network_delegate.h" #include "chrome/browser/net/chrome_url_request_context.h" -#include "chrome/browser/net/proxy_service_factory.h" #include "chrome/common/url_constants.h" #include "content/browser/browser_thread.h" #include "net/ftp/ftp_network_layer.h" @@ -124,7 +123,7 @@ void OffTheRecordProfileIOData::LazyInitializeInternal() const { main_request_context_->set_dns_cert_checker(dns_cert_checker_.get()); main_request_context_->set_proxy_service( - ProxyServiceFactory::CreateProxyService( + CreateProxyService( io_thread->net_log(), io_thread_globals->proxy_script_fetcher_context.get(), lazy_params_->profile_params.proxy_config_service.release(), diff --git a/chrome/browser/profiles/profile.cc b/chrome/browser/profiles/profile.cc index 65e9d21..b56e449 100644 --- a/chrome/browser/profiles/profile.cc +++ b/chrome/browser/profiles/profile.cc @@ -596,6 +596,11 @@ class OffTheRecordProfileImpl : public Profile, } #if defined(OS_CHROMEOS) + virtual chromeos::ProxyConfigServiceImpl* + GetChromeOSProxyConfigServiceImpl() { + return profile_->GetChromeOSProxyConfigServiceImpl(); + } + virtual void SetupChromeOSEnterpriseExtensionObserver() { profile_->SetupChromeOSEnterpriseExtensionObserver(); } diff --git a/chrome/browser/profiles/profile.h b/chrome/browser/profiles/profile.h index d94351c..15d3b09 100644 --- a/chrome/browser/profiles/profile.h +++ b/chrome/browser/profiles/profile.h @@ -15,6 +15,13 @@ namespace base { class Time; } +#if defined(OS_CHROMEOS) +namespace chromeos { +class EnterpriseExtensionObserver; +class ProxyConfigServiceImpl; +} +#endif + namespace fileapi { class FileSystemContext; class SandboxedFileSystemContext; @@ -523,11 +530,16 @@ class Profile { // Called after login. virtual void OnLogin() = 0; + // Returns ChromeOS's ProxyConfigServiceImpl, creating if not yet created. + virtual chromeos::ProxyConfigServiceImpl* + GetChromeOSProxyConfigServiceImpl() = 0; + // Creates ChromeOS's EnterpriseExtensionListener. virtual void SetupChromeOSEnterpriseExtensionObserver() = 0; // Initializes Chrome OS's preferences. virtual void InitChromeOSPreferences() = 0; + #endif // defined(OS_CHROMEOS) // Returns the helper object that provides the proxy configuration service diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc index d13621f..d973c1f 100644 --- a/chrome/browser/profiles/profile_impl.cc +++ b/chrome/browser/profiles/profile_impl.cc @@ -113,6 +113,7 @@ #include "chrome/browser/password_manager/password_store_mac.h" #elif defined(OS_CHROMEOS) #include "chrome/browser/chromeos/enterprise_extension_observer.h" +#include "chrome/browser/chromeos/proxy_config_service_impl.h" #elif defined(OS_POSIX) && !defined(OS_CHROMEOS) #include "base/nix/xdg_util.h" #if defined(USE_GNOME_KEYRING) @@ -1506,6 +1507,15 @@ void ProfileImpl::OnLogin() { locale_change_guard_.reset(new chromeos::LocaleChangeGuard(this)); } +chromeos::ProxyConfigServiceImpl* + ProfileImpl::GetChromeOSProxyConfigServiceImpl() { + if (!chromeos_proxy_config_service_impl_) { + chromeos_proxy_config_service_impl_ = + new chromeos::ProxyConfigServiceImpl(); + } + return chromeos_proxy_config_service_impl_; +} + void ProfileImpl::SetupChromeOSEnterpriseExtensionObserver() { DCHECK(!chromeos_enterprise_extension_observer_.get()); chromeos_enterprise_extension_observer_.reset( diff --git a/chrome/browser/profiles/profile_impl.h b/chrome/browser/profiles/profile_impl.h index afe62ae..4544601 100644 --- a/chrome/browser/profiles/profile_impl.h +++ b/chrome/browser/profiles/profile_impl.h @@ -26,9 +26,8 @@ class PrefService; #if defined(OS_CHROMEOS) namespace chromeos { -class EnterpriseExtensionObserver; -class LocaleChangeGuard; class Preferences; +class LocaleChangeGuard; } #endif @@ -140,6 +139,7 @@ class ProfileImpl : public Profile, #if defined(OS_CHROMEOS) virtual void ChangeAppLocale(const std::string& locale, AppLocaleChangedVia); virtual void OnLogin(); + virtual chromeos::ProxyConfigServiceImpl* GetChromeOSProxyConfigServiceImpl(); virtual void SetupChromeOSEnterpriseExtensionObserver(); virtual void InitChromeOSPreferences(); #endif // defined(OS_CHROMEOS) @@ -303,6 +303,9 @@ class ProfileImpl : public Profile, #if defined(OS_CHROMEOS) scoped_ptr<chromeos::Preferences> chromeos_preferences_; + scoped_refptr<chromeos::ProxyConfigServiceImpl> + chromeos_proxy_config_service_impl_; + scoped_ptr<chromeos::EnterpriseExtensionObserver> chromeos_enterprise_extension_observer_; diff --git a/chrome/browser/profiles/profile_impl_io_data.cc b/chrome/browser/profiles/profile_impl_io_data.cc index eaef474..faffcfb 100644 --- a/chrome/browser/profiles/profile_impl_io_data.cc +++ b/chrome/browser/profiles/profile_impl_io_data.cc @@ -12,7 +12,6 @@ #include "chrome/browser/net/chrome_dns_cert_provenance_checker_factory.h" #include "chrome/browser/net/chrome_net_log.h" #include "chrome/browser/net/chrome_network_delegate.h" -#include "chrome/browser/net/proxy_service_factory.h" #include "chrome/browser/net/sqlite_persistent_cookie_store.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_switches.h" @@ -174,7 +173,7 @@ void ProfileImplIOData::LazyInitializeInternal() const { media_request_context_->set_dns_cert_checker(dns_cert_checker_.get()); net::ProxyService* proxy_service = - ProxyServiceFactory::CreateProxyService( + CreateProxyService( io_thread->net_log(), io_thread_globals->proxy_script_fetcher_context.get(), lazy_params_->profile_params.proxy_config_service.release(), diff --git a/chrome/browser/profiles/profile_io_data.cc b/chrome/browser/profiles/profile_io_data.cc index 167e333..b784c40 100644 --- a/chrome/browser/profiles/profile_io_data.cc +++ b/chrome/browser/profiles/profile_io_data.cc @@ -16,8 +16,6 @@ #include "chrome/browser/io_thread.h" #include "chrome/browser/net/chrome_cookie_notification_details.h" #include "chrome/browser/net/pref_proxy_config_service.h" -#include "chrome/browser/net/proxy_service_factory.h" -#include "chrome/browser/profiles/profile.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/chrome_switches.h" @@ -29,6 +27,12 @@ #include "net/proxy/proxy_script_fetcher_impl.h" #include "net/proxy/proxy_service.h" +#if defined(OS_CHROMEOS) +#include "chrome/browser/chromeos/cros/cros_library.h" +#include "chrome/browser/chromeos/cros/libcros_service_library.h" +#include "chrome/browser/chromeos/proxy_config_service.h" +#endif // defined(OS_CHROMEOS) + namespace { // ---------------------------------------------------------------------------- @@ -169,9 +173,7 @@ void ProfileIOData::InitializeProfileParams(Profile* profile, params->prerender_manager = profile->GetPrerenderManager(); params->protocol_handler_registry = profile->GetProtocolHandlerRegistry(); - params->proxy_config_service.reset( - ProxyServiceFactory::CreateProxyConfigService( - profile->GetProxyConfigTracker())); + params->proxy_config_service.reset(CreateProxyConfigService(profile)); params->profile_id = profile->GetRuntimeId(); } @@ -257,3 +259,88 @@ void ProfileIOData::ApplyProfileParamsToContext( context->set_extension_info_map(profile_params.extension_info_map); context->set_prerender_manager(profile_params.prerender_manager); } + +// static +net::ProxyConfigService* ProfileIOData::CreateProxyConfigService( + Profile* profile) { + // The linux gconf-based proxy settings getter relies on being initialized + // from the UI thread. + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + + // Create a baseline service that provides proxy configuration in case nothing + // is configured through prefs (Note: prefs include command line and + // configuration policy). + net::ProxyConfigService* base_service = NULL; + + // TODO(port): the IO and FILE message loops are only used by Linux. Can + // that code be moved to chrome/browser instead of being in net, so that it + // can use BrowserThread instead of raw MessageLoop pointers? See bug 25354. +#if defined(OS_CHROMEOS) + base_service = new chromeos::ProxyConfigService( + profile->GetChromeOSProxyConfigServiceImpl()); +#else + base_service = net::ProxyService::CreateSystemProxyConfigService( + g_browser_process->io_thread()->message_loop(), + g_browser_process->file_thread()->message_loop()); +#endif // defined(OS_CHROMEOS) + + return new PrefProxyConfigService(profile->GetProxyConfigTracker(), + base_service); +} + +// static +net::ProxyService* ProfileIOData::CreateProxyService( + net::NetLog* net_log, + net::URLRequestContext* context, + net::ProxyConfigService* proxy_config_service, + const CommandLine& command_line) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + + bool use_v8 = !command_line.HasSwitch(switches::kWinHttpProxyResolver); + if (use_v8 && command_line.HasSwitch(switches::kSingleProcess)) { + // See the note about V8 multithreading in net/proxy/proxy_resolver_v8.h + // to understand why we have this limitation. + LOG(ERROR) << "Cannot use V8 Proxy resolver in single process mode."; + use_v8 = false; // Fallback to non-v8 implementation. + } + + size_t num_pac_threads = 0u; // Use default number of threads. + + // Check the command line for an override on the number of proxy resolver + // threads to use. + if (command_line.HasSwitch(switches::kNumPacThreads)) { + std::string s = command_line.GetSwitchValueASCII(switches::kNumPacThreads); + + // Parse the switch (it should be a positive integer formatted as decimal). + int n; + if (base::StringToInt(s, &n) && n > 0) { + num_pac_threads = static_cast<size_t>(n); + } else { + LOG(ERROR) << "Invalid switch for number of PAC threads: " << s; + } + } + + net::ProxyService* proxy_service; + if (use_v8) { + proxy_service = net::ProxyService::CreateUsingV8ProxyResolver( + proxy_config_service, + num_pac_threads, + new net::ProxyScriptFetcherImpl(context), + context->host_resolver(), + net_log); + } else { + proxy_service = net::ProxyService::CreateUsingSystemProxyResolver( + proxy_config_service, + num_pac_threads, + net_log); + } + +#if defined(OS_CHROMEOS) + if (chromeos::CrosLibrary::Get()->EnsureLoaded()) { + chromeos::CrosLibrary::Get()->GetLibCrosServiceLibrary()-> + RegisterNetworkProxyHandler(proxy_service); + } +#endif // defined(OS_CHROMEOS) + + return proxy_service; +} diff --git a/chrome/browser/profiles/profile_io_data.h b/chrome/browser/profiles/profile_io_data.h index c37629b..705ca3a 100644 --- a/chrome/browser/profiles/profile_io_data.h +++ b/chrome/browser/profiles/profile_io_data.h @@ -122,6 +122,12 @@ class ProfileIOData : public base::RefCountedThreadSafe<ProfileIOData> { static void InitializeProfileParams(Profile* profile, ProfileParams* params); static void ApplyProfileParamsToContext(const ProfileParams& profile_params, ChromeURLRequestContext* context); + static net::ProxyConfigService* CreateProxyConfigService(Profile* profile); + static net::ProxyService* CreateProxyService( + net::NetLog* net_log, + net::URLRequestContext* context, + net::ProxyConfigService* proxy_config_service, + const CommandLine& command_line); // Lazy initializes the ProfileIOData object the first time a request context // is requested. The lazy logic is implemented here. The actual initialization diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 25c7c88..db4ed20 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1348,8 +1348,6 @@ 'browser/net/predictor_api.h', 'browser/net/pref_proxy_config_service.cc', 'browser/net/pref_proxy_config_service.h', - 'browser/net/proxy_service_factory.cc', - 'browser/net/proxy_service_factory.h', 'browser/net/quoted_printable.cc', 'browser/net/quoted_printable.h', 'browser/net/referrer.cc', diff --git a/chrome/test/testing_browser_process.cc b/chrome/test/testing_browser_process.cc index b8a030a..9a4e72f 100644 --- a/chrome/test/testing_browser_process.cc +++ b/chrome/test/testing_browser_process.cc @@ -13,7 +13,6 @@ #include "chrome/browser/policy/dummy_configuration_policy_provider.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile_manager.h" -#include "chrome/common/net/url_request_context_getter.h" #include "ui/base/clipboard/clipboard.h" TestingBrowserProcess::TestingBrowserProcess() @@ -114,17 +113,6 @@ TestingBrowserProcess::safe_browsing_detection_service() { return NULL; } -URLRequestContextGetter* TestingBrowserProcess::system_request_context() { - return NULL; -} - -#if defined(OS_CHROMEOS) -chromeos::ProxyConfigServiceImpl* -TestingBrowserProcess::chromeos_proxy_config_service_impl() { - return NULL; -} -#endif // defined(OS_CHROMEOS) - ui::Clipboard* TestingBrowserProcess::clipboard() { if (!clipboard_.get()) { // Note that we need a MessageLoop for the next call to work. diff --git a/chrome/test/testing_browser_process.h b/chrome/test/testing_browser_process.h index 05d37a6..95895d7 100644 --- a/chrome/test/testing_browser_process.h +++ b/chrome/test/testing_browser_process.h @@ -80,13 +80,6 @@ class TestingBrowserProcess : public BrowserProcess { virtual safe_browsing::ClientSideDetectionService* safe_browsing_detection_service(); - virtual URLRequestContextGetter* system_request_context(); - -#if defined(OS_CHROMEOS) - virtual chromeos::ProxyConfigServiceImpl* - chromeos_proxy_config_service_impl(); -#endif // defined(OS_CHROMEOS) - virtual ui::Clipboard* clipboard(); virtual ExtensionEventRouterForwarder* extension_event_router_forwarder(); diff --git a/chrome/test/testing_profile.h b/chrome/test/testing_profile.h index acea619..49063b5 100644 --- a/chrome/test/testing_profile.h +++ b/chrome/test/testing_profile.h @@ -255,6 +255,10 @@ class TestingProfile : public Profile { virtual FilePath last_selected_directory(); virtual void set_last_selected_directory(const FilePath& path); #if defined(OS_CHROMEOS) + virtual chromeos::ProxyConfigServiceImpl* + GetChromeOSProxyConfigServiceImpl() { + return NULL; + } virtual void SetupChromeOSEnterpriseExtensionObserver() { } virtual void InitChromeOSPreferences() { |