diff options
author | battre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-16 14:47:21 +0000 |
---|---|---|
committer | battre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-16 14:47:21 +0000 |
commit | db0e86dde97e9b1ced5cba1c6a6c0cf29179db1b (patch) | |
tree | 05b12196fd6fb91c63e554029eccc87016f741fb /chrome | |
parent | b8dedffcd73166ff70163162a713a2c0407953d6 (diff) | |
download | chromium_src-db0e86dde97e9b1ced5cba1c6a6c0cf29179db1b.zip chromium_src-db0e86dde97e9b1ced5cba1c6a6c0cf29179db1b.tar.gz chromium_src-db0e86dde97e9b1ced5cba1c6a6c0cf29179db1b.tar.bz2 |
This is an extension of http://codereview.chromium.org/6280018 that provides a proxy configuration which respects command line parameters and policies
This was committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=78228, iyengar asked to commit again after fixing trunk.
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@78362 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
29 files changed, 382 insertions, 249 deletions
diff --git a/chrome/browser/browser_process.h b/chrome/browser/browser_process.h index d406eb0..6afb776 100644 --- a/chrome/browser/browser_process.h +++ b/chrome/browser/browser_process.h @@ -15,6 +15,7 @@ #include <vector> #include "base/basictypes.h" +#include "base/ref_counted.h" #include "ipc/ipc_message.h" class AutomationProviderList; @@ -40,6 +41,7 @@ class ResourceDispatcherHost; class SidebarManager; class TabCloseableStateWatcher; class ThumbnailGenerator; +class URLRequestContextGetter; class WatchDogThread; namespace base { @@ -47,6 +49,12 @@ class Thread; class WaitableEvent; } +#if defined(OS_CHROMEOS) +namespace chromeos { +class ProxyConfigServiceImpl; +} +#endif // defined(OS_CHROMEOS) + namespace printing { class PrintJobManager; class PrintPreviewTabController; @@ -82,6 +90,14 @@ 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 61dacf3..aff5fa7 100644 --- a/chrome/browser/browser_process_impl.cc +++ b/chrome/browser/browser_process_impl.cc @@ -54,6 +54,7 @@ #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" @@ -77,6 +78,10 @@ #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. @@ -438,6 +443,23 @@ 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 4967f59..b7412a4 100644 --- a/chrome/browser/browser_process_impl.h +++ b/chrome/browser/browser_process_impl.h @@ -63,6 +63,11 @@ 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(); @@ -275,6 +280,11 @@ 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 a078999..04fb5c5 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( - profile->GetChromeOSProxyConfigServiceImpl())); + g_browser_process->chromeos_proxy_config_service_impl())); 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 44a5166..99e50b03 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/chrome_url_request_context.cc::CreateProxyConfigService - // via ProfileImpl::GetChromeOSProxyConfigServiceImpl, and stored in Profile - // as a scoped_refptr (because it's RefCountedThreadSafe). + // 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). // // 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 - // WebUI::GetProfile::GetChromeOSProxyConfigServiceImpl to allow user to read + // BrowserProcess::chromeos_proxy_config_service_impl 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 78489a1..ccb3e44 100644 --- a/chrome/browser/chromeos/proxy_cros_settings_provider.cc +++ b/chrome/browser/chromeos/proxy_cros_settings_provider.cc @@ -7,8 +7,7 @@ #include "base/command_line.h" #include "base/string_util.h" #include "chrome/browser/browser_list.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/profiles/profile_manager.h" +#include "chrome/browser/browser_process.h" #include "chrome/common/chrome_switches.h" namespace chromeos { @@ -292,12 +291,7 @@ bool ProxyCrosSettingsProvider::HandlesSetting(const std::string& path) { chromeos::ProxyConfigServiceImpl* ProxyCrosSettingsProvider::GetConfigService() const { - Browser* browser = BrowserList::GetLastActive(); - // browser is NULL at OOBE/login stage. - Profile* profile = browser ? - browser->profile() : - ProfileManager::GetDefaultProfile(); - return profile->GetChromeOSProxyConfigServiceImpl(); + return g_browser_process->chromeos_proxy_config_service_impl(); } void ProxyCrosSettingsProvider::AppendPortIfValid( 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(); diff --git a/chrome/browser/intranet_redirect_detector.cc b/chrome/browser/intranet_redirect_detector.cc index d858a2f..2ac9ab5 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,11 +25,7 @@ IntranetRedirectDetector::IntranetRedirectDetector() : redirect_origin_(g_browser_process->local_state()->GetString( prefs::kLastKnownIntranetRedirectOrigin)), ALLOW_THIS_IN_INITIALIZER_LIST(fetcher_factory_(this)), - in_sleep_(true), - request_context_available_(Profile::GetDefaultRequestContext() != NULL) { - registrar_.Add(this, NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE, - NotificationService::AllSources()); - + in_sleep_(true) { // 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. @@ -70,16 +66,6 @@ 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) || @@ -98,7 +84,7 @@ void IntranetRedirectDetector::StartFetchesIfPossible() { // 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(Profile::GetDefaultRequestContext()); + fetcher->set_request_context(g_browser_process->system_request_context()); fetcher->Start(); fetchers_.insert(fetcher); } @@ -158,14 +144,6 @@ 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 e54566b2..3dfcb9c 100644 --- a/chrome/browser/intranet_redirect_detector.h +++ b/chrome/browser/intranet_redirect_detector.h @@ -37,7 +37,6 @@ 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 @@ -66,9 +65,6 @@ 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, @@ -77,15 +73,9 @@ 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_; @@ -93,10 +83,6 @@ 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 1978a0c..6ddad22 100644 --- a/chrome/browser/io_thread.cc +++ b/chrome/browser/io_thread.cc @@ -23,6 +23,8 @@ #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" @@ -39,6 +41,7 @@ #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" @@ -199,8 +202,64 @@ 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); @@ -233,9 +292,12 @@ 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(); @@ -302,6 +364,18 @@ 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(); @@ -401,6 +475,8 @@ void IOThread::CleanUp() { getter->ReleaseURLRequestContext(); } + system_url_request_context_getter_ = NULL; + // Step 2: Release objects that the net::URLRequestContext could have been // pointing to. @@ -427,12 +503,16 @@ 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(); @@ -532,3 +612,34 @@ 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 d3bf4e7..2c8362d 100644 --- a/chrome/browser/io_thread.h +++ b/chrome/browser/io_thread.h @@ -19,7 +19,10 @@ class ChromeNetLog; class ChromeURLRequestContextGetter; class ExtensionEventRouterForwarder; class ListValue; +class PrefProxyConfigTracker; class PrefService; +class SystemURLRequestContextGetter; +class URLRequestContextGetter; namespace chrome_browser_net { class ConnectInterceptor; @@ -33,6 +36,7 @@ class HostResolver; class HttpAuthHandlerFactory; class HttpTransactionFactory; class NetworkDelegate; +class ProxyConfigService; class ProxyScriptFetcher; class ProxyService; class SSLConfigService; @@ -58,6 +62,12 @@ 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; }; @@ -104,6 +114,9 @@ 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. @@ -114,11 +127,19 @@ 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, @@ -174,6 +195,12 @@ 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 e8b68be..11695b4 100644 --- a/chrome/browser/net/chrome_url_request_context.cc +++ b/chrome/browser/net/chrome_url_request_context.cc @@ -25,12 +25,6 @@ #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 490f06d..b0e7fc3 100644 --- a/chrome/browser/net/pref_proxy_config_service.h +++ b/chrome/browser/net/pref_proxy_config_service.h @@ -33,7 +33,6 @@ class PrefProxyConfigTracker }; explicit PrefProxyConfigTracker(PrefService* pref_service); - virtual ~PrefProxyConfigTracker(); // Observer manipulation is only valid on the IO thread. void AddObserver(Observer* observer); @@ -50,6 +49,9 @@ 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 new file mode 100644 index 0000000..bc74d71 --- /dev/null +++ b/chrome/browser/net/proxy_service_factory.cc @@ -0,0 +1,107 @@ +// 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 new file mode 100644 index 0000000..aa6796c --- /dev/null +++ b/chrome/browser/net/proxy_service_factory.h @@ -0,0 +1,39 @@ +// 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 26cacf1..5ce5ed7 100644 --- a/chrome/browser/profiles/off_the_record_profile_io_data.cc +++ b/chrome/browser/profiles/off_the_record_profile_io_data.cc @@ -15,6 +15,7 @@ #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/extensions/extension.h" #include "chrome/common/url_constants.h" #include "content/browser/browser_thread.h" @@ -156,7 +157,7 @@ void OffTheRecordProfileIOData::LazyInitializeInternal() const { main_request_context_->set_dns_cert_checker(dns_cert_checker_.get()); main_request_context_->set_proxy_service( - CreateProxyService( + ProxyServiceFactory::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 2ec2de4..6a0955d 100644 --- a/chrome/browser/profiles/profile.cc +++ b/chrome/browser/profiles/profile.cc @@ -613,11 +613,6 @@ 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 9b70f2c..236e0e5 100644 --- a/chrome/browser/profiles/profile.h +++ b/chrome/browser/profiles/profile.h @@ -15,13 +15,6 @@ namespace base { class Time; } -#if defined(OS_CHROMEOS) -namespace chromeos { -class EnterpriseExtensionObserver; -class ProxyConfigServiceImpl; -} -#endif - namespace fileapi { class FileSystemContext; class SandboxedFileSystemContext; @@ -543,16 +536,11 @@ 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 f09be25..b1fbf66 100644 --- a/chrome/browser/profiles/profile_impl.cc +++ b/chrome/browser/profiles/profile_impl.cc @@ -113,7 +113,6 @@ #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) @@ -1528,15 +1527,6 @@ 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 d870dea..9f6914d 100644 --- a/chrome/browser/profiles/profile_impl.h +++ b/chrome/browser/profiles/profile_impl.h @@ -26,8 +26,9 @@ class PrefService; #if defined(OS_CHROMEOS) namespace chromeos { -class Preferences; +class EnterpriseExtensionObserver; class LocaleChangeGuard; +class Preferences; } #endif @@ -143,7 +144,6 @@ 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) @@ -307,9 +307,6 @@ 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 68b853c..4ad854c 100644 --- a/chrome/browser/profiles/profile_impl_io_data.cc +++ b/chrome/browser/profiles/profile_impl_io_data.cc @@ -14,6 +14,7 @@ #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" @@ -214,7 +215,7 @@ void ProfileImplIOData::LazyInitializeInternal() const { media_request_context_->set_dns_cert_checker(dns_cert_checker_.get()); net::ProxyService* proxy_service = - CreateProxyService( + ProxyServiceFactory::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 3720f2d..de202c5 100644 --- a/chrome/browser/profiles/profile_io_data.cc +++ b/chrome/browser/profiles/profile_io_data.cc @@ -16,6 +16,8 @@ #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" @@ -27,12 +29,6 @@ #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 { // ---------------------------------------------------------------------------- @@ -173,7 +169,9 @@ void ProfileIOData::InitializeProfileParams(Profile* profile, params->prerender_manager = profile->GetPrerenderManager(); params->protocol_handler_registry = profile->GetProtocolHandlerRegistry(); - params->proxy_config_service.reset(CreateProxyConfigService(profile)); + params->proxy_config_service.reset( + ProxyServiceFactory::CreateProxyConfigService( + profile->GetProxyConfigTracker())); params->profile_id = profile->GetRuntimeId(); } @@ -270,88 +268,3 @@ 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 3a2bcd5..0aca926 100644 --- a/chrome/browser/profiles/profile_io_data.h +++ b/chrome/browser/profiles/profile_io_data.h @@ -125,12 +125,6 @@ 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 df6cbe7..eadddd4 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1351,6 +1351,8 @@ '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 9a4e72f..b8a030a 100644 --- a/chrome/test/testing_browser_process.cc +++ b/chrome/test/testing_browser_process.cc @@ -13,6 +13,7 @@ #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() @@ -113,6 +114,17 @@ 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 95895d7..05d37a6 100644 --- a/chrome/test/testing_browser_process.h +++ b/chrome/test/testing_browser_process.h @@ -80,6 +80,13 @@ 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 3ae70ba..7c3ae2bb 100644 --- a/chrome/test/testing_profile.h +++ b/chrome/test/testing_profile.h @@ -259,10 +259,6 @@ 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() { |