diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-11 03:27:09 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-11 03:27:09 +0000 |
commit | ef2bf421b04de3134cd7c02aac40a5565ef24dd9 (patch) | |
tree | 5bf90cca0bd015c23e843614ebf2e9f99cb8cd99 | |
parent | 280e9b5d4b2fb0fe14824e526521710a658bce56 (diff) | |
download | chromium_src-ef2bf421b04de3134cd7c02aac40a5565ef24dd9.zip chromium_src-ef2bf421b04de3134cd7c02aac40a5565ef24dd9.tar.gz chromium_src-ef2bf421b04de3134cd7c02aac40a5565ef24dd9.tar.bz2 |
Stop refcounting URLRequestContext.
While doing so, fix a few issues with the code like ordering of URLRequestContext to ensure correct destruction order. Also fix const correctness in some places.
BUG=58859
TEST=none
TBR=willchan
Review URL: https://chromiumcodereview.appspot.com/10299002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@136497 0039d316-1c4b-4281-b951-d872f2087c98
83 files changed, 853 insertions, 891 deletions
diff --git a/chrome/browser/automation/automation_resource_message_filter.cc b/chrome/browser/automation/automation_resource_message_filter.cc index fe18281..f8706a2 100644 --- a/chrome/browser/automation/automation_resource_message_filter.cc +++ b/chrome/browser/automation/automation_resource_message_filter.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -53,7 +53,7 @@ AutomationResourceMessageFilter::AutomationDetails::~AutomationDetails() {} struct AutomationResourceMessageFilter::CookieCompletionInfo { scoped_refptr<BrowserMessageFilter> filter; - scoped_refptr<net::URLRequestContext> context; + net::URLRequestContext* context; int render_process_id; IPC::Message* reply_msg; scoped_refptr<AutomationResourceMessageFilter> automation_message_filter; diff --git a/chrome/browser/browsing_data_server_bound_cert_helper_unittest.cc b/chrome/browser/browsing_data_server_bound_cert_helper_unittest.cc index 1307ba6..37f7c7a 100644 --- a/chrome/browser/browsing_data_server_bound_cert_helper_unittest.cc +++ b/chrome/browser/browsing_data_server_bound_cert_helper_unittest.cc @@ -28,7 +28,7 @@ class BrowsingDataServerBoundCertHelperTest : public testing::Test { } void CreateCertsForTest() { - scoped_refptr<net::URLRequestContext> context = + net::URLRequestContext* context = testing_profile_->GetRequestContext()->GetURLRequestContext(); net::ServerBoundCertStore* cert_store = context->server_bound_cert_service()->GetCertStore(); diff --git a/chrome/browser/extensions/api/web_request/web_request_api_unittest.cc b/chrome/browser/extensions/api/web_request/web_request_api_unittest.cc index 127d561..f2e94be 100644 --- a/chrome/browser/extensions/api/web_request/web_request_api_unittest.cc +++ b/chrome/browser/extensions/api/web_request/web_request_api_unittest.cc @@ -127,7 +127,7 @@ class ExtensionWebRequestTest : public testing::Test { network_delegate_.reset(new ChromeNetworkDelegate( event_router_.get(), NULL, NULL, &profile_, CookieSettings::Factory::GetForProfile(&profile_), &enable_referrers_)); - context_ = new TestURLRequestContext(); + context_.reset(new TestURLRequestContext()); context_->set_network_delegate(network_delegate_.get()); } @@ -141,7 +141,7 @@ class ExtensionWebRequestTest : public testing::Test { scoped_refptr<ExtensionEventRouterForwarder> event_router_; scoped_refptr<ExtensionInfoMap> extension_info_map_; scoped_ptr<ChromeNetworkDelegate> network_delegate_; - scoped_refptr<TestURLRequestContext> context_; + scoped_ptr<TestURLRequestContext> context_; }; // Tests that we handle disagreements among extensions about responses to @@ -166,7 +166,7 @@ TEST_F(ExtensionWebRequestTest, BlockingEventPrecedenceRedirect) { GURL not_chosen_redirect_url("about:not_chosen"); net::URLRequest request(GURL("about:blank"), &delegate_); - request.set_context(context_); + request.set_context(context_.get()); { // onBeforeRequest will be dispatched twice initially. The second response - // the redirect - should win, since it has a later |install_time|. The @@ -221,7 +221,7 @@ TEST_F(ExtensionWebRequestTest, BlockingEventPrecedenceRedirect) { // Now test the same thing but the extensions answer in reverse order. net::URLRequest request2(GURL("about:blank"), &delegate_); - request2.set_context(context_); + request2.set_context(context_.get()); { ExtensionWebRequestEventRouter::EventResponse* response = NULL; @@ -295,7 +295,7 @@ TEST_F(ExtensionWebRequestTest, BlockingEventPrecedenceCancel) { GURL request_url("about:blank"); net::URLRequest request(request_url, &delegate_); - request.set_context(context_); + request.set_context(context_.get()); // onBeforeRequest will be dispatched twice. The second response - // the redirect - would win, since it has a later |install_time|, but @@ -363,7 +363,7 @@ TEST_F(ExtensionWebRequestTest, SimulateChancelWhileBlocked) { GURL request_url("about:blank"); net::URLRequest request(request_url, &delegate_); - request.set_context(context_); + request.set_context(context_.get()); ExtensionWebRequestEventRouter::EventResponse* response = NULL; @@ -444,7 +444,7 @@ class ExtensionWebRequestHeaderModificationTest : network_delegate_.reset(new ChromeNetworkDelegate( event_router_.get(), NULL, NULL, &profile_, CookieSettings::Factory::GetForProfile(&profile_), &enable_referrers_)); - context_ = new TestURLRequestContext(); + context_.reset(new TestURLRequestContext()); context_->set_network_delegate(network_delegate_.get()); } @@ -458,7 +458,7 @@ class ExtensionWebRequestHeaderModificationTest : scoped_refptr<ExtensionEventRouterForwarder> event_router_; scoped_refptr<ExtensionInfoMap> extension_info_map_; scoped_ptr<ChromeNetworkDelegate> network_delegate_; - scoped_refptr<TestURLRequestContext> context_; + scoped_ptr<TestURLRequestContext> context_; }; TEST_P(ExtensionWebRequestHeaderModificationTest, TestModifications) { @@ -489,7 +489,7 @@ TEST_P(ExtensionWebRequestHeaderModificationTest, TestModifications) { GURL request_url("http://doesnotexist/does_not_exist.html"); net::URLRequest request(request_url, &delegate_); - request.set_context(context_); + request.set_context(context_.get()); // Initialize headers available before extensions are notified of the // onBeforeSendHeaders event. diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc index b354e32..c371594 100644 --- a/chrome/browser/io_thread.cc +++ b/chrome/browser/io_thread.cc @@ -197,13 +197,13 @@ class LoggingNetworkChangeObserver DISALLOW_COPY_AND_ASSIGN(LoggingNetworkChangeObserver); }; -// Create a separate request context for PAC fetches to avoid reference cycles. +// TODO(willchan): Remove proxy script fetcher context since it's not necessary +// now that I got rid of refcounting URLRequestContexts. // See IOThread::Globals for details. -scoped_refptr<net::URLRequestContext> +net::URLRequestContext* ConstructProxyScriptFetcherContext(IOThread::Globals* globals, net::NetLog* net_log) { - scoped_refptr<net::URLRequestContext> context( - new URLRequestContextWithUserAgent); + net::URLRequestContext* context = new URLRequestContextWithUserAgent; context->set_net_log(net_log); context->set_host_resolver(globals->host_resolver.get()); context->set_cert_verifier(globals->cert_verifier.get()); @@ -226,11 +226,10 @@ ConstructProxyScriptFetcherContext(IOThread::Globals* globals, return context; } -scoped_refptr<net::URLRequestContext> +net::URLRequestContext* ConstructSystemRequestContext(IOThread::Globals* globals, net::NetLog* net_log) { - scoped_refptr<net::URLRequestContext> context( - new SystemURLRequestContext); + net::URLRequestContext* context = new SystemURLRequestContext; context->set_net_log(net_log); context->set_host_resolver(globals->host_resolver.get()); context->set_cert_verifier(globals->cert_verifier.get()); @@ -281,9 +280,9 @@ SystemURLRequestContextGetter::~SystemURLRequestContextGetter() {} net::URLRequestContext* SystemURLRequestContextGetter::GetURLRequestContext() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - DCHECK(io_thread_->globals()->system_request_context); + DCHECK(io_thread_->globals()->system_request_context.get()); - return io_thread_->globals()->system_request_context; + return io_thread_->globals()->system_request_context.get(); } scoped_refptr<base::MessageLoopProxy> @@ -456,8 +455,8 @@ void IOThread::Init() { } globals_->throttler_manager->set_net_log(net_log_); - globals_->proxy_script_fetcher_context = - ConstructProxyScriptFetcherContext(globals_, net_log_); + globals_->proxy_script_fetcher_context.reset( + ConstructProxyScriptFetcherContext(globals_, net_log_)); sdch_manager_ = new net::SdchManager(); @@ -602,7 +601,7 @@ void IOThread::InitSystemRequestContextOnIOThread() { globals_->system_proxy_service.reset( ProxyServiceFactory::CreateProxyService( net_log_, - globals_->proxy_script_fetcher_context, + globals_->proxy_script_fetcher_context.get(), system_proxy_config_service_.release(), command_line)); net::HttpNetworkSession::Params system_params; @@ -625,8 +624,8 @@ void IOThread::InitSystemRequestContextOnIOThread() { new net::HttpNetworkSession(system_params))); globals_->system_ftp_transaction_factory.reset( new net::FtpNetworkLayer(globals_->host_resolver.get())); - globals_->system_request_context = - ConstructSystemRequestContext(globals_, net_log_); + globals_->system_request_context.reset( + ConstructSystemRequestContext(globals_, net_log_)); sdch_manager_->set_sdch_fetcher( new SdchDictionaryFetcher(system_url_request_context_getter_.get())); diff --git a/chrome/browser/io_thread.h b/chrome/browser/io_thread.h index c288ccf..1390c2c 100644 --- a/chrome/browser/io_thread.h +++ b/chrome/browser/io_thread.h @@ -89,17 +89,17 @@ class IOThread : public content::BrowserThreadDelegate { proxy_script_fetcher_ftp_transaction_factory; scoped_ptr<net::URLRequestThrottlerManager> throttler_manager; scoped_ptr<net::URLSecurityManager> url_security_manager; - // We use a separate URLRequestContext for PAC fetches, in order to break - // the reference cycle: - // URLRequestContext=>PAC fetch=>URLRequest=>URLRequestContext. + // TODO(willchan): Remove proxy script fetcher context since it's not + // necessary now that I got rid of refcounting URLRequestContexts. + // // The first URLRequestContext is |system_url_request_context|. We introduce // |proxy_script_fetcher_context| for the second context. It has a direct // ProxyService, since we always directly connect to fetch the PAC script. - scoped_refptr<net::URLRequestContext> proxy_script_fetcher_context; + scoped_ptr<net::URLRequestContext> proxy_script_fetcher_context; scoped_ptr<net::ProxyService> system_proxy_service; scoped_ptr<net::HttpTransactionFactory> system_http_transaction_factory; scoped_ptr<net::FtpTransactionFactory> system_ftp_transaction_factory; - scoped_refptr<net::URLRequestContext> system_request_context; + scoped_ptr<net::URLRequestContext> system_request_context; SystemRequestContextLeakChecker system_request_context_leak_checker; // |system_cookie_store| and |system_server_bound_cert_service| are shared // between |proxy_script_fetcher_context| and |system_request_context|. diff --git a/chrome/browser/net/chrome_fraudulent_certificate_reporter_unittest.cc b/chrome/browser/net/chrome_fraudulent_certificate_reporter_unittest.cc index bafed99..c9a8fee 100644 --- a/chrome/browser/net/chrome_fraudulent_certificate_reporter_unittest.cc +++ b/chrome/browser/net/chrome_fraudulent_certificate_reporter_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -151,22 +151,22 @@ class MockReporter : public ChromeFraudulentCertificateReporter { }; static void DoReportIsSent() { - scoped_refptr<ChromeURLRequestContext> context = new ChromeURLRequestContext; - SendingTestReporter reporter(context.get()); + ChromeURLRequestContext context; + SendingTestReporter reporter(&context); SSLInfo info = GetGoodSSLInfo(); reporter.SendReport("mail.google.com", info, true); } static void DoReportIsNotSent() { - scoped_refptr<ChromeURLRequestContext> context = new ChromeURLRequestContext; - NotSendingTestReporter reporter(context.get()); + ChromeURLRequestContext context; + NotSendingTestReporter reporter(&context); SSLInfo info = GetBadSSLInfo(); reporter.SendReport("www.example.com", info, true); } static void DoMockReportIsSent() { - scoped_refptr<ChromeURLRequestContext> context = new ChromeURLRequestContext; - MockReporter reporter(context.get()); + ChromeURLRequestContext context; + MockReporter reporter(&context); SSLInfo info = GetGoodSSLInfo(); reporter.SendReport("mail.google.com", info, true); } @@ -201,4 +201,3 @@ TEST(ChromeFraudulentCertificateReporterTest, ReportIsNotSent) { } } // namespace chrome_browser_net - diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc index 96bdde4..80c0c8a 100644 --- a/chrome/browser/net/chrome_url_request_context.cc +++ b/chrome/browser/net/chrome_url_request_context.cc @@ -30,7 +30,7 @@ class ChromeURLRequestContextFactory { virtual ~ChromeURLRequestContextFactory() {} // Called to create a new instance (will only be called once). - virtual scoped_refptr<ChromeURLRequestContext> Create() = 0; + virtual ChromeURLRequestContext* Create() = 0; protected: DISALLOW_COPY_AND_ASSIGN(ChromeURLRequestContextFactory); @@ -48,7 +48,7 @@ class FactoryForMain : public ChromeURLRequestContextFactory { explicit FactoryForMain(const ProfileIOData* profile_io_data) : profile_io_data_(profile_io_data) {} - virtual scoped_refptr<ChromeURLRequestContext> Create() { + virtual ChromeURLRequestContext* Create() OVERRIDE { return profile_io_data_->GetMainRequestContext(); } @@ -62,7 +62,7 @@ class FactoryForExtensions : public ChromeURLRequestContextFactory { explicit FactoryForExtensions(const ProfileIOData* profile_io_data) : profile_io_data_(profile_io_data) {} - virtual scoped_refptr<ChromeURLRequestContext> Create() { + virtual ChromeURLRequestContext* Create() OVERRIDE { return profile_io_data_->GetExtensionsRequestContext(); } @@ -80,7 +80,7 @@ class FactoryForIsolatedApp : public ChromeURLRequestContextFactory { app_id_(app_id), main_request_context_getter_(main_context) {} - virtual scoped_refptr<ChromeURLRequestContext> Create() { + virtual ChromeURLRequestContext* Create() OVERRIDE { // We will copy most of the state from the main request context. return profile_io_data_->GetIsolatedAppRequestContext( main_request_context_getter_->GetIOContext(), app_id_); @@ -100,7 +100,7 @@ class FactoryForMedia : public ChromeURLRequestContextFactory { : profile_io_data_(profile_io_data) { } - virtual scoped_refptr<ChromeURLRequestContext> Create() { + virtual ChromeURLRequestContext* Create() OVERRIDE { return profile_io_data_->GetMediaRequestContext(); } @@ -315,7 +315,12 @@ void ChromeURLRequestContextGetter::OnClearSiteDataOnExitChange( // ---------------------------------------------------------------------------- ChromeURLRequestContext::ChromeURLRequestContext() - : is_incognito_(false) { + : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), + is_incognito_(false) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); +} + +ChromeURLRequestContext::~ChromeURLRequestContext() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); } @@ -338,10 +343,6 @@ void ChromeURLRequestContext::set_chrome_url_data_manager_backend( chrome_url_data_manager_backend_ = backend; } -ChromeURLRequestContext::~ChromeURLRequestContext() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); -} - const std::string& ChromeURLRequestContext::GetUserAgent( const GURL& url) const { return content::GetUserAgent(url); diff --git a/chrome/browser/net/chrome_url_request_context.h b/chrome/browser/net/chrome_url_request_context.h index be9f5e3..31a41d3 100644 --- a/chrome/browser/net/chrome_url_request_context.h +++ b/chrome/browser/net/chrome_url_request_context.h @@ -29,6 +29,11 @@ class ProfileIOData; class ChromeURLRequestContext : public net::URLRequestContext { public: ChromeURLRequestContext(); + virtual ~ChromeURLRequestContext(); + + base::WeakPtr<ChromeURLRequestContext> GetWeakPtr() { + return weak_factory_.GetWeakPtr(); + } // Copies the state from |other| into this context. void CopyFrom(ChromeURLRequestContext* other); @@ -56,10 +61,9 @@ class ChromeURLRequestContext : public net::URLRequestContext { // Callback for when the default charset changes. void OnDefaultCharsetChange(const std::string& default_charset); - protected: - virtual ~ChromeURLRequestContext(); - private: + base::WeakPtrFactory<ChromeURLRequestContext> weak_factory_; + // --------------------------------------------------------------------------- // Important: When adding any new members below, consider whether they need to // be added to CopyFrom. @@ -177,10 +181,10 @@ class ChromeURLRequestContextGetter : public net::URLRequestContextGetter, // Access only from the IO thread. scoped_ptr<ChromeURLRequestContextFactory> factory_; - // NULL if not yet initialized. Otherwise, it is the net::URLRequestContext + // NULL if not yet initialized. Otherwise, it is the ChromeURLRequestContext // instance that was lazily created by GetURLRequestContext(). // Access only from the IO thread. - base::WeakPtr<net::URLRequestContext> url_request_context_; + base::WeakPtr<ChromeURLRequestContext> url_request_context_; DISALLOW_COPY_AND_ASSIGN(ChromeURLRequestContextGetter); }; diff --git a/chrome/browser/net/connection_tester.cc b/chrome/browser/net/connection_tester.cc index ae5c07f..eb250def 100644 --- a/chrome/browser/net/connection_tester.cc +++ b/chrome/browser/net/connection_tester.cc @@ -53,6 +53,8 @@ class ExperimentURLRequestContext : public net::URLRequestContext { ALLOW_THIS_IN_INITIALIZER_LIST(storage_(this)), ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {} + virtual ~ExperimentURLRequestContext() {} + // Creates a proxy config service for |experiment|. On success returns net::OK // and fills |config_service| with a new pointer. Otherwise returns a network // error code. @@ -127,10 +129,6 @@ class ExperimentURLRequestContext : public net::URLRequestContext { return net::OK; } - protected: - virtual ~ExperimentURLRequestContext() { - } - private: // Creates a host resolver for |experiment|. On success returns net::OK and // fills |host_resolver| with a new pointer. Otherwise returns a network @@ -272,7 +270,7 @@ class ExperimentURLRequestContext : public net::URLRequestContext { #endif } - const scoped_refptr<net::URLRequestContext> proxy_request_context_; + net::URLRequestContext* const proxy_request_context_; net::URLRequestContextStorage storage_; base::WeakPtrFactory<ExperimentURLRequestContext> weak_factory_; }; @@ -296,7 +294,6 @@ class ConnectionTester::TestRunner : public net::URLRequest::Delegate { // after disk access has completed. void ProxyConfigServiceCreated( const Experiment& experiment, - scoped_refptr<ExperimentURLRequestContext> context, scoped_ptr<net::ProxyConfigService>* proxy_config_service, int status); // Starts running |experiment|. Notifies tester->OnExperimentCompleted() when @@ -321,6 +318,7 @@ class ConnectionTester::TestRunner : public net::URLRequest::Delegate { void OnExperimentCompletedWithResult(int result); ConnectionTester* tester_; + scoped_ptr<ExperimentURLRequestContext> request_context_; scoped_ptr<net::URLRequest> request_; base::WeakPtrFactory<TestRunner> weak_factory_; @@ -385,36 +383,35 @@ void ConnectionTester::TestRunner::OnExperimentCompletedWithResult(int result) { void ConnectionTester::TestRunner::ProxyConfigServiceCreated( const Experiment& experiment, - scoped_refptr<ExperimentURLRequestContext> context, scoped_ptr<net::ProxyConfigService>* proxy_config_service, int status) { if (status == net::OK) - status = context->Init(experiment, proxy_config_service); + status = request_context_->Init(experiment, proxy_config_service); if (status != net::OK) { tester_->OnExperimentCompleted(status); return; } // Fetch a request using the experimental context. request_.reset(new net::URLRequest(experiment.url, this)); - request_->set_context(context); + request_->set_context(request_context_.get()); request_->Start(); } void ConnectionTester::TestRunner::Run(const Experiment& experiment) { // Try to create a net::URLRequestContext for this experiment. - scoped_refptr<ExperimentURLRequestContext> context( + request_context_.reset( new ExperimentURLRequestContext(tester_->proxy_request_context_)); scoped_ptr<net::ProxyConfigService>* proxy_config_service = new scoped_ptr<net::ProxyConfigService>(); base::Callback<void(int)> config_service_callback = base::Bind( &TestRunner::ProxyConfigServiceCreated, weak_factory_.GetWeakPtr(), - experiment, context, base::Owned(proxy_config_service)); - int rv = context->CreateProxyConfigService( + experiment, base::Owned(proxy_config_service)); + int rv = request_context_->CreateProxyConfigService( experiment.proxy_settings_experiment, proxy_config_service, config_service_callback); if (rv != net::ERR_IO_PENDING) - ProxyConfigServiceCreated(experiment, context, proxy_config_service, rv); + ProxyConfigServiceCreated(experiment, proxy_config_service, rv); } // ConnectionTester ---------------------------------------------------------- diff --git a/chrome/browser/net/connection_tester.h b/chrome/browser/net/connection_tester.h index 903f0b5..74b8e5e 100644 --- a/chrome/browser/net/connection_tester.h +++ b/chrome/browser/net/connection_tester.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -174,7 +174,7 @@ class ConnectionTester { // of the list is the one currently in progress. ExperimentList remaining_experiments_; - const scoped_refptr<net::URLRequestContext> proxy_request_context_; + net::URLRequestContext* const proxy_request_context_; DISALLOW_COPY_AND_ASSIGN(ConnectionTester); }; diff --git a/chrome/browser/net/connection_tester_unittest.cc b/chrome/browser/net/connection_tester_unittest.cc index 3ecfa48..6dd99b3 100644 --- a/chrome/browser/net/connection_tester_unittest.cc +++ b/chrome/browser/net/connection_tester_unittest.cc @@ -113,8 +113,8 @@ class ConnectionTesterTest : public PlatformTest { scoped_refptr<net::SSLConfigService> ssl_config_service_; scoped_ptr<net::HttpTransactionFactory> http_transaction_factory_; net::HttpAuthHandlerRegistryFactory http_auth_handler_factory_; - scoped_refptr<net::URLRequestContext> proxy_script_fetcher_context_; net::HttpServerPropertiesImpl http_server_properties_impl_; + scoped_ptr<net::URLRequestContext> proxy_script_fetcher_context_; private: void InitializeRequestContext() { @@ -148,7 +148,7 @@ class ConnectionTesterTest : public PlatformTest { TEST_F(ConnectionTesterTest, RunAllTests) { ASSERT_TRUE(test_server_.Start()); - ConnectionTester tester(&test_delegate_, proxy_script_fetcher_context_); + ConnectionTester tester(&test_delegate_, proxy_script_fetcher_context_.get()); // Start the test suite on URL "echoall". // TODO(eroman): Is this URL right? @@ -173,7 +173,8 @@ TEST_F(ConnectionTesterTest, DeleteWhileInProgress) { ASSERT_TRUE(test_server_.Start()); scoped_ptr<ConnectionTester> tester( - new ConnectionTester(&test_delegate_, proxy_script_fetcher_context_)); + new ConnectionTester(&test_delegate_, + proxy_script_fetcher_context_.get())); // Start the test suite on URL "echoall". // TODO(eroman): Is this URL right? diff --git a/chrome/browser/net/http_pipelining_compatibility_client.cc b/chrome/browser/net/http_pipelining_compatibility_client.cc index 5ba8200..ae81dca 100644 --- a/chrome/browser/net/http_pipelining_compatibility_client.cc +++ b/chrome/browser/net/http_pipelining_compatibility_client.cc @@ -297,7 +297,7 @@ void HttpPipeliningCompatibilityClient::Start( http_transaction_factory_.reset( net::HttpNetworkLayer::CreateFactory(session.get())); - url_request_context_ = new net::URLRequestContext; + url_request_context_.reset(new net::URLRequestContext); url_request_context_->CopyFrom(url_request_context); url_request_context_->set_http_transaction_factory( http_transaction_factory_.get()); diff --git a/chrome/browser/net/http_pipelining_compatibility_client.h b/chrome/browser/net/http_pipelining_compatibility_client.h index b50f9d3..811dc7b 100644 --- a/chrome/browser/net/http_pipelining_compatibility_client.h +++ b/chrome/browser/net/http_pipelining_compatibility_client.h @@ -141,8 +141,8 @@ class HttpPipeliningCompatibilityClient virtual void ReportNetworkError(int request_id, int error_code) OVERRIDE; virtual void ReportResponseCode(int request_id, int response_code) OVERRIDE; - scoped_refptr<net::URLRequestContext> url_request_context_; scoped_ptr<net::HttpTransactionFactory> http_transaction_factory_; + scoped_ptr<net::URLRequestContext> url_request_context_; scoped_ptr<internal::PipelineTestRequest::Factory> factory_; ScopedVector<internal::PipelineTestRequest> requests_; scoped_ptr<internal::PipelineTestRequest> canary_request_; diff --git a/chrome/browser/policy/device_management_service.cc b/chrome/browser/policy/device_management_service.cc index aab92e1..3e15e96 100644 --- a/chrome/browser/policy/device_management_service.cc +++ b/chrome/browser/policy/device_management_service.cc @@ -186,10 +186,9 @@ const std::string& GetPlatformString() { class DeviceManagementRequestContext : public net::URLRequestContext { public: explicit DeviceManagementRequestContext(net::URLRequestContext* base_context); - - private: virtual ~DeviceManagementRequestContext(); + private: // Overridden from net::URLRequestContext: virtual const std::string& GetUserAgent(const GURL& url) const OVERRIDE; }; @@ -243,7 +242,7 @@ class DeviceManagementRequestContextGetter virtual ~DeviceManagementRequestContextGetter() {} private: - scoped_refptr<net::URLRequestContext> context_; + scoped_ptr<net::URLRequestContext> context_; scoped_refptr<net::URLRequestContextGetter> base_context_getter_; }; @@ -251,9 +250,9 @@ class DeviceManagementRequestContextGetter net::URLRequestContext* DeviceManagementRequestContextGetter::GetURLRequestContext() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - if (!context_) { - context_ = new DeviceManagementRequestContext( - base_context_getter_->GetURLRequestContext()); + if (!context_.get()) { + context_.reset(new DeviceManagementRequestContext( + base_context_getter_->GetURLRequestContext())); } return context_.get(); 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 e90b5ac..c33f78c 100644 --- a/chrome/browser/profiles/off_the_record_profile_io_data.cc +++ b/chrome/browser/profiles/off_the_record_profile_io_data.cc @@ -250,9 +250,9 @@ void OffTheRecordProfileIOData::LazyInitializeInternal( extensions_context->set_job_factory(job_factory()); } -scoped_refptr<ChromeURLRequestContext> +ChromeURLRequestContext* OffTheRecordProfileIOData::InitializeAppRequestContext( - scoped_refptr<ChromeURLRequestContext> main_context, + ChromeURLRequestContext* main_context, const std::string& app_id) const { AppRequestContext* context = new AppRequestContext; @@ -276,18 +276,18 @@ OffTheRecordProfileIOData::InitializeAppRequestContext( return context; } -scoped_refptr<ChromeURLRequestContext> +ChromeURLRequestContext* OffTheRecordProfileIOData::AcquireMediaRequestContext() const { NOTREACHED(); return NULL; } -scoped_refptr<ChromeURLRequestContext> +ChromeURLRequestContext* OffTheRecordProfileIOData::AcquireIsolatedAppRequestContext( - scoped_refptr<ChromeURLRequestContext> main_context, + ChromeURLRequestContext* main_context, const std::string& app_id) const { // We create per-app contexts on demand, unlike the others above. - scoped_refptr<ChromeURLRequestContext> app_request_context = + ChromeURLRequestContext* app_request_context = InitializeAppRequestContext(main_context, app_id); DCHECK(app_request_context); return app_request_context; diff --git a/chrome/browser/profiles/off_the_record_profile_io_data.h b/chrome/browser/profiles/off_the_record_profile_io_data.h index a23b8fb..2e119a0 100644 --- a/chrome/browser/profiles/off_the_record_profile_io_data.h +++ b/chrome/browser/profiles/off_the_record_profile_io_data.h @@ -98,14 +98,14 @@ class OffTheRecordProfileIOData : public ProfileIOData { virtual void LazyInitializeInternal( ProfileParams* profile_params) const OVERRIDE; - virtual scoped_refptr<ChromeURLRequestContext> InitializeAppRequestContext( - scoped_refptr<ChromeURLRequestContext> main_context, + virtual ChromeURLRequestContext* InitializeAppRequestContext( + ChromeURLRequestContext* main_context, const std::string& app_id) const OVERRIDE; - virtual scoped_refptr<ChromeURLRequestContext> + virtual ChromeURLRequestContext* AcquireMediaRequestContext() const OVERRIDE; - virtual scoped_refptr<ChromeURLRequestContext> + virtual ChromeURLRequestContext* AcquireIsolatedAppRequestContext( - scoped_refptr<ChromeURLRequestContext> main_context, + ChromeURLRequestContext* main_context, const std::string& app_id) const OVERRIDE; mutable scoped_ptr<net::HttpServerPropertiesImpl> http_server_properties_; diff --git a/chrome/browser/profiles/profile_impl_io_data.cc b/chrome/browser/profiles/profile_impl_io_data.cc index 12355f7..0f4c473 100644 --- a/chrome/browser/profiles/profile_impl_io_data.cc +++ b/chrome/browser/profiles/profile_impl_io_data.cc @@ -252,7 +252,7 @@ ProfileImplIOData::ProfileImplIOData() ProfileImplIOData::~ProfileImplIOData() { DestroyResourceContext(); - if (media_request_context_) + if (media_request_context_.get()) media_request_context_->AssertNoURLRequests(); } @@ -263,7 +263,7 @@ void ProfileImplIOData::LazyInitializeInternal( ChromeURLRequestContext* main_context = main_request_context(); ChromeURLRequestContext* extensions_context = extensions_request_context(); - media_request_context_ = new ChromeURLRequestContext; + media_request_context_.reset(new ChromeURLRequestContext); IOThread* const io_thread = profile_params->io_thread; IOThread::Globals* const io_thread_globals = io_thread->globals(); @@ -275,7 +275,7 @@ void ProfileImplIOData::LazyInitializeInternal( // Initialize context members. ApplyProfileParamsToContext(main_context); - ApplyProfileParamsToContext(media_request_context_); + ApplyProfileParamsToContext(media_request_context_.get()); ApplyProfileParamsToContext(extensions_context); if (http_server_properties_manager()) @@ -449,9 +449,9 @@ void ProfileImplIOData::LazyInitializeInternal( lazy_params_.reset(); } -scoped_refptr<ChromeURLRequestContext> +ChromeURLRequestContext* ProfileImplIOData::InitializeAppRequestContext( - scoped_refptr<ChromeURLRequestContext> main_context, + ChromeURLRequestContext* main_context, const std::string& app_id) const { AppRequestContext* context = new AppRequestContext; @@ -511,18 +511,18 @@ ProfileImplIOData::InitializeAppRequestContext( return context; } -scoped_refptr<ChromeURLRequestContext> +ChromeURLRequestContext* ProfileImplIOData::AcquireMediaRequestContext() const { - DCHECK(media_request_context_); - return media_request_context_; + DCHECK(media_request_context_.get()); + return media_request_context_.get(); } -scoped_refptr<ChromeURLRequestContext> +ChromeURLRequestContext* ProfileImplIOData::AcquireIsolatedAppRequestContext( - scoped_refptr<ChromeURLRequestContext> main_context, + ChromeURLRequestContext* main_context, const std::string& app_id) const { // We create per-app contexts on demand, unlike the others above. - scoped_refptr<ChromeURLRequestContext> app_request_context = + ChromeURLRequestContext* app_request_context = InitializeAppRequestContext(main_context, app_id); DCHECK(app_request_context); return app_request_context; diff --git a/chrome/browser/profiles/profile_impl_io_data.h b/chrome/browser/profiles/profile_impl_io_data.h index 4bda4a6..153e278 100644 --- a/chrome/browser/profiles/profile_impl_io_data.h +++ b/chrome/browser/profiles/profile_impl_io_data.h @@ -125,14 +125,14 @@ class ProfileImplIOData : public ProfileIOData { virtual void LazyInitializeInternal( ProfileParams* profile_params) const OVERRIDE; - virtual scoped_refptr<ChromeURLRequestContext> InitializeAppRequestContext( - scoped_refptr<ChromeURLRequestContext> main_context, + virtual ChromeURLRequestContext* InitializeAppRequestContext( + ChromeURLRequestContext* main_context, const std::string& app_id) const OVERRIDE; - virtual scoped_refptr<ChromeURLRequestContext> + virtual ChromeURLRequestContext* AcquireMediaRequestContext() const OVERRIDE; - virtual scoped_refptr<ChromeURLRequestContext> + virtual ChromeURLRequestContext* AcquireIsolatedAppRequestContext( - scoped_refptr<ChromeURLRequestContext> main_context, + ChromeURLRequestContext* main_context, const std::string& app_id) const OVERRIDE; // Clears the networking history since |time|. @@ -147,7 +147,7 @@ class ProfileImplIOData : public ProfileIOData { mutable scoped_ptr<chrome_browser_net::Predictor> predictor_; - mutable scoped_refptr<ChromeURLRequestContext> media_request_context_; + mutable scoped_ptr<ChromeURLRequestContext> media_request_context_; // Parameters needed for isolated apps. FilePath app_path_; diff --git a/chrome/browser/profiles/profile_io_data.cc b/chrome/browser/profiles/profile_io_data.cc index a9ca5bb..6ea6e86 100644 --- a/chrome/browser/profiles/profile_io_data.cc +++ b/chrome/browser/profiles/profile_io_data.cc @@ -272,13 +272,14 @@ ProfileIOData::~ProfileIOData() { if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - if (main_request_context_) + if (main_request_context_.get()) main_request_context_->AssertNoURLRequests(); - if (extensions_request_context_) + if (extensions_request_context_.get()) extensions_request_context_->AssertNoURLRequests(); for (AppRequestContextMap::iterator it = app_request_context_map_.begin(); it != app_request_context_map_.end(); ++it) { it->second->AssertNoURLRequests(); + delete it->second; } } @@ -328,33 +329,33 @@ ProfileIOData::GetChromeURLDataManagerBackend() const { return chrome_url_data_manager_backend_.get(); } -scoped_refptr<ChromeURLRequestContext> +ChromeURLRequestContext* ProfileIOData::GetMainRequestContext() const { LazyInitialize(); - return main_request_context_; + return main_request_context_.get(); } -scoped_refptr<ChromeURLRequestContext> +ChromeURLRequestContext* ProfileIOData::GetMediaRequestContext() const { LazyInitialize(); - scoped_refptr<ChromeURLRequestContext> context = + ChromeURLRequestContext* context = AcquireMediaRequestContext(); DCHECK(context); return context; } -scoped_refptr<ChromeURLRequestContext> +ChromeURLRequestContext* ProfileIOData::GetExtensionsRequestContext() const { LazyInitialize(); - return extensions_request_context_; + return extensions_request_context_.get(); } -scoped_refptr<ChromeURLRequestContext> +ChromeURLRequestContext* ProfileIOData::GetIsolatedAppRequestContext( - scoped_refptr<ChromeURLRequestContext> main_context, + ChromeURLRequestContext* main_context, const std::string& app_id) const { LazyInitialize(); - scoped_refptr<ChromeURLRequestContext> context; + ChromeURLRequestContext* context; if (ContainsKey(app_request_context_map_, app_id)) { context = app_request_context_map_[app_id]; } else { @@ -467,8 +468,8 @@ void ProfileIOData::LazyInitialize() const { const CommandLine& command_line = *CommandLine::ForCurrentProcess(); // Create the common request contexts. - main_request_context_ = new ChromeURLRequestContext; - extensions_request_context_ = new ChromeURLRequestContext; + main_request_context_.reset(new ChromeURLRequestContext); + extensions_request_context_.reset(new ChromeURLRequestContext); chrome_url_data_manager_backend_.reset(new ChromeURLDataManagerBackend); @@ -482,7 +483,7 @@ void ProfileIOData::LazyInitialize() const { fraudulent_certificate_reporter_.reset( new chrome_browser_net::ChromeFraudulentCertificateReporter( - main_request_context_)); + main_request_context_.get())); proxy_service_.reset( ProxyServiceFactory::CreateProxyService( @@ -545,7 +546,7 @@ void ProfileIOData::LazyInitialize() const { extension_info_map_ = profile_params_->extension_info_map; resource_context_->host_resolver_ = io_thread_globals->host_resolver.get(); - resource_context_->request_context_ = main_request_context_; + resource_context_->request_context_ = main_request_context_.get(); LazyInitializeInternal(profile_params_.get()); diff --git a/chrome/browser/profiles/profile_io_data.h b/chrome/browser/profiles/profile_io_data.h index bc10f01..f4702bb 100644 --- a/chrome/browser/profiles/profile_io_data.h +++ b/chrome/browser/profiles/profile_io_data.h @@ -74,11 +74,11 @@ class ProfileIOData { // These should only be called at most once each. Ownership is reversed when // they get called, from ProfileIOData owning ChromeURLRequestContext to vice // versa. - scoped_refptr<ChromeURLRequestContext> GetMainRequestContext() const; - scoped_refptr<ChromeURLRequestContext> GetMediaRequestContext() const; - scoped_refptr<ChromeURLRequestContext> GetExtensionsRequestContext() const; - scoped_refptr<ChromeURLRequestContext> GetIsolatedAppRequestContext( - scoped_refptr<ChromeURLRequestContext> main_context, + ChromeURLRequestContext* GetMainRequestContext() const; + ChromeURLRequestContext* GetMediaRequestContext() const; + ChromeURLRequestContext* GetExtensionsRequestContext() const; + ChromeURLRequestContext* GetIsolatedAppRequestContext( + ChromeURLRequestContext* main_context, const std::string& app_id) const; // These are useful when the Chrome layer is called from the content layer @@ -225,7 +225,7 @@ class ProfileIOData { chrome_browser_net::HttpServerPropertiesManager* manager) const; ChromeURLRequestContext* main_request_context() const { - return main_request_context_; + return main_request_context_.get(); } // Destroys the ResourceContext first, to cancel any URLRequests that are @@ -254,7 +254,7 @@ class ProfileIOData { net::URLRequestContext* request_context_; }; - typedef base::hash_map<std::string, scoped_refptr<ChromeURLRequestContext> > + typedef base::hash_map<std::string, ChromeURLRequestContext*> AppRequestContextMap; // -------------------------------------------- @@ -267,17 +267,17 @@ class ProfileIOData { // Does an on-demand initialization of a RequestContext for the given // isolated app. - virtual scoped_refptr<ChromeURLRequestContext> InitializeAppRequestContext( - scoped_refptr<ChromeURLRequestContext> main_context, + virtual ChromeURLRequestContext* InitializeAppRequestContext( + ChromeURLRequestContext* main_context, const std::string& app_id) const = 0; // These functions are used to transfer ownership of the lazily initialized // context from ProfileIOData to the URLRequestContextGetter. - virtual scoped_refptr<ChromeURLRequestContext> + virtual ChromeURLRequestContext* AcquireMediaRequestContext() const = 0; - virtual scoped_refptr<ChromeURLRequestContext> + virtual ChromeURLRequestContext* AcquireIsolatedAppRequestContext( - scoped_refptr<ChromeURLRequestContext> main_context, + ChromeURLRequestContext* main_context, const std::string& app_id) const = 0; // The order *DOES* matter for the majority of these member variables, so @@ -341,8 +341,8 @@ class ProfileIOData { // These are only valid in between LazyInitialize() and their accessor being // called. - mutable scoped_refptr<ChromeURLRequestContext> main_request_context_; - mutable scoped_refptr<ChromeURLRequestContext> extensions_request_context_; + mutable scoped_ptr<ChromeURLRequestContext> main_request_context_; + mutable scoped_ptr<ChromeURLRequestContext> extensions_request_context_; // One AppRequestContext per isolated app. mutable AppRequestContextMap app_request_context_map_; diff --git a/chrome/browser/safe_browsing/safe_browsing_service.cc b/chrome/browser/safe_browsing/safe_browsing_service.cc index 642bf38..6fea46f 100644 --- a/chrome/browser/safe_browsing/safe_browsing_service.cc +++ b/chrome/browser/safe_browsing/safe_browsing_service.cc @@ -145,9 +145,9 @@ SafeBrowsingURLRequestContextGetter::~SafeBrowsingURLRequestContextGetter() {} net::URLRequestContext* SafeBrowsingURLRequestContextGetter::GetURLRequestContext() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - DCHECK(sb_service_->url_request_context_); + DCHECK(sb_service_->url_request_context_.get()); - return sb_service_->url_request_context_; + return sb_service_->url_request_context_.get(); } scoped_refptr<base::MessageLoopProxy> @@ -614,7 +614,7 @@ void SafeBrowsingService::InitURLRequestContextOnIOThread( FilePath(BaseFilename().value() + kCookiesFile), false), NULL); - url_request_context_ = new SafeBrowsingURLRequestContext; + url_request_context_.reset(new SafeBrowsingURLRequestContext); // |system_url_request_context_getter| may be NULL during tests. if (system_url_request_context_getter) url_request_context_->CopyFrom( @@ -633,8 +633,7 @@ void SafeBrowsingService::DestroyURLRequestContextOnIOThread() { using base::debug::LeakTracker; LeakTracker<SafeBrowsingURLRequestContextGetter>::CheckForLeaks(); - DCHECK(url_request_context_.get()); - url_request_context_ = NULL; + url_request_context_.reset(); } void SafeBrowsingService::StartOnIOThread() { diff --git a/chrome/browser/safe_browsing/safe_browsing_service.h b/chrome/browser/safe_browsing/safe_browsing_service.h index 511a758..85eb5ef 100644 --- a/chrome/browser/safe_browsing/safe_browsing_service.h +++ b/chrome/browser/safe_browsing/safe_browsing_service.h @@ -514,7 +514,7 @@ class SafeBrowsingService url_request_context_getter_; // The SafeBrowsingURLRequestContext. - scoped_refptr<net::URLRequestContext> url_request_context_; + scoped_ptr<net::URLRequestContext> url_request_context_; // Handles interaction with SafeBrowsing servers. SafeBrowsingProtocolManager* protocol_manager_; diff --git a/chrome/browser/sync/glue/http_bridge.cc b/chrome/browser/sync/glue/http_bridge.cc index dc01ebf..e7a217f 100644 --- a/chrome/browser/sync/glue/http_bridge.cc +++ b/chrome/browser/sync/glue/http_bridge.cc @@ -35,10 +35,10 @@ HttpBridge::RequestContextGetter::~RequestContextGetter() {} net::URLRequestContext* HttpBridge::RequestContextGetter::GetURLRequestContext() { // Lazily create the context. - if (!context_) { + if (!context_.get()) { net::URLRequestContext* baseline_context = baseline_context_getter_->GetURLRequestContext(); - context_ = new RequestContext(baseline_context); + context_.reset(new RequestContext(baseline_context)); baseline_context_getter_ = NULL; } @@ -46,7 +46,7 @@ HttpBridge::RequestContextGetter::GetURLRequestContext() { if (is_user_agent_set()) context_->set_user_agent(user_agent_); - return context_; + return context_.get(); } scoped_refptr<base::MessageLoopProxy> diff --git a/chrome/browser/sync/glue/http_bridge.h b/chrome/browser/sync/glue/http_bridge.h index 3e7e98e..a26410d 100644 --- a/chrome/browser/sync/glue/http_bridge.h +++ b/chrome/browser/sync/glue/http_bridge.h @@ -51,6 +51,9 @@ class HttpBridge : public base::RefCountedThreadSafe<HttpBridge>, // currently active profile. explicit RequestContext(net::URLRequestContext* baseline_context); + // The destructor MUST be called on the IO thread. + virtual ~RequestContext(); + // Set the user agent for requests using this context. The default is // the browser's UA string. void set_user_agent(const std::string& ua) { user_agent_ = ua; } @@ -63,9 +66,6 @@ class HttpBridge : public base::RefCountedThreadSafe<HttpBridge>, } private: - // The destructor MUST be called on the IO thread. - virtual ~RequestContext(); - std::string user_agent_; net::URLRequestContext* baseline_context_; @@ -96,7 +96,7 @@ class HttpBridge : public base::RefCountedThreadSafe<HttpBridge>, scoped_refptr<net::URLRequestContextGetter> baseline_context_getter_; // Lazily initialized by GetURLRequestContext(). - scoped_refptr<RequestContext> context_; + scoped_ptr<RequestContext> context_; DISALLOW_COPY_AND_ASSIGN(RequestContextGetter); }; diff --git a/chrome/service/cloud_print/cloud_print_url_fetcher_unittest.cc b/chrome/service/cloud_print/cloud_print_url_fetcher_unittest.cc index 63589df..e0279a70 100644 --- a/chrome/service/cloud_print/cloud_print_url_fetcher_unittest.cc +++ b/chrome/service/cloud_print/cloud_print_url_fetcher_unittest.cc @@ -39,8 +39,8 @@ class TrackingTestURLRequestContextGetter } virtual TestURLRequestContext* GetURLRequestContext() OVERRIDE { - if (!context_) { - context_ = new TestURLRequestContext(true); + if (!context_.get()) { + context_.reset(new TestURLRequestContext(true)); context_->set_throttler_manager(throttler_manager_); context_->Init(); } @@ -55,7 +55,7 @@ class TrackingTestURLRequestContextGetter private: // Not owned here. net::URLRequestThrottlerManager* throttler_manager_; - scoped_refptr<TestURLRequestContext> context_; + scoped_ptr<TestURLRequestContext> context_; }; class TestCloudPrintURLFetcher : public CloudPrintURLFetcher { diff --git a/chrome/service/net/service_url_request_context.cc b/chrome/service/net/service_url_request_context.cc index 4fb2385..493a6f5 100644 --- a/chrome/service/net/service_url_request_context.cc +++ b/chrome/service/net/service_url_request_context.cc @@ -170,11 +170,11 @@ ServiceURLRequestContextGetter::ServiceURLRequestContextGetter() net::URLRequestContext* ServiceURLRequestContextGetter::GetURLRequestContext() { - if (!url_request_context_) - url_request_context_ = + if (!url_request_context_.get()) + url_request_context_.reset( new ServiceURLRequestContext(user_agent_, - proxy_config_service_.release()); - return url_request_context_; + proxy_config_service_.release())); + return url_request_context_.get(); } scoped_refptr<base::MessageLoopProxy> diff --git a/chrome/service/net/service_url_request_context.h b/chrome/service/net/service_url_request_context.h index 1578f23..ae2b547 100644 --- a/chrome/service/net/service_url_request_context.h +++ b/chrome/service/net/service_url_request_context.h @@ -40,12 +40,11 @@ class ServiceURLRequestContext : public net::URLRequestContext { const std::string& user_agent, net::ProxyConfigService* net_proxy_config_service); + virtual ~ServiceURLRequestContext(); + // Overridden from net::URLRequestContext: virtual const std::string& GetUserAgent(const GURL& url) const OVERRIDE; - protected: - virtual ~ServiceURLRequestContext(); - private: std::string user_agent_; net::URLRequestContextStorage storage_; @@ -70,9 +69,9 @@ class ServiceURLRequestContextGetter : public net::URLRequestContextGetter { virtual ~ServiceURLRequestContextGetter(); std::string user_agent_; - scoped_refptr<net::URLRequestContext> url_request_context_; scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; scoped_ptr<net::ProxyConfigService> proxy_config_service_; + scoped_ptr<net::URLRequestContext> url_request_context_; }; #endif // CHROME_SERVICE_NET_SERVICE_URL_REQUEST_CONTEXT_H_ diff --git a/chrome/test/base/testing_profile.cc b/chrome/test/base/testing_profile.cc index f30e199..ea850b2 100644 --- a/chrome/test/base/testing_profile.cc +++ b/chrome/test/base/testing_profile.cc @@ -99,7 +99,6 @@ class TestExtensionURLRequestContext : public net::URLRequestContext { set_cookie_store(cookie_monster); } - private: virtual ~TestExtensionURLRequestContext() {} }; @@ -107,8 +106,8 @@ class TestExtensionURLRequestContextGetter : public net::URLRequestContextGetter { public: virtual net::URLRequestContext* GetURLRequestContext() { - if (!context_) - context_ = new TestExtensionURLRequestContext(); + if (!context_.get()) + context_.reset(new TestExtensionURLRequestContext()); return context_.get(); } virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const { @@ -119,7 +118,7 @@ class TestExtensionURLRequestContextGetter virtual ~TestExtensionURLRequestContextGetter() {} private: - scoped_refptr<net::URLRequestContext> context_; + scoped_ptr<net::URLRequestContext> context_; }; ProfileKeyedService* CreateTestDesktopNotificationService(Profile* profile) { diff --git a/content/browser/browser_process_sub_thread.cc b/content/browser/browser_process_sub_thread.cc index c521af2..bab8ead 100644 --- a/content/browser/browser_process_sub_thread.cc +++ b/content/browser/browser_process_sub_thread.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -53,9 +53,6 @@ void BrowserProcessSubThread::CleanUp() { BrowserThreadImpl::CleanUp(); - if (BrowserThread::CurrentlyOn(BrowserThread::IO)) - IOThreadPostCleanUp(); - delete notification_service_; notification_service_ = NULL; @@ -81,9 +78,4 @@ void BrowserProcessSubThread::IOThreadPreCleanUp() { BrowserChildProcessHostImpl::TerminateAll(); } -void BrowserProcessSubThread::IOThreadPostCleanUp() { - // net::URLRequest instances must NOT outlive the IO thread. - base::debug::LeakTracker<net::URLRequest>::CheckForLeaks(); -} - } // namespace content diff --git a/content/browser/browser_process_sub_thread.h b/content/browser/browser_process_sub_thread.h index 18a3b0b..34bed4f 100644 --- a/content/browser/browser_process_sub_thread.h +++ b/content/browser/browser_process_sub_thread.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -36,9 +36,8 @@ class CONTENT_EXPORT BrowserProcessSubThread : public BrowserThreadImpl { private: // These methods encapsulate cleanup that needs to happen on the IO thread - // before/after we call the embedder's CleanUp function. + // before we call the embedder's CleanUp function. void IOThreadPreCleanUp(); - void IOThreadPostCleanUp(); // Each specialized thread has its own notification service. // Note: We don't use scoped_ptr because the destructor runs on the wrong diff --git a/content/browser/renderer_host/resource_dispatcher_host_unittest.cc b/content/browser/renderer_host/resource_dispatcher_host_unittest.cc index 0057934..b012ff3 100644 --- a/content/browser/renderer_host/resource_dispatcher_host_unittest.cc +++ b/content/browser/renderer_host/resource_dispatcher_host_unittest.cc @@ -377,6 +377,9 @@ class ResourceDispatcherHostTest : public testing::Test, ChildProcessSecurityPolicyImpl::GetInstance()->Remove(0); // Flush the message loop to make application verifiers happy. + if (ResourceDispatcherHostImpl::Get()) + ResourceDispatcherHostImpl::Get()->CancelRequestsForContext( + browser_context_->GetResourceContext()); browser_context_.reset(); message_loop_.RunAllPending(); } diff --git a/content/common/net/url_fetcher_impl_unittest.cc b/content/common/net/url_fetcher_impl_unittest.cc index ab4e870..33e6f34 100644 --- a/content/common/net/url_fetcher_impl_unittest.cc +++ b/content/common/net/url_fetcher_impl_unittest.cc @@ -59,13 +59,13 @@ class ThrottlingTestURLRequestContextGetter } virtual TestURLRequestContext* GetURLRequestContext() OVERRIDE { - return context_.get(); + return context_; } protected: virtual ~ThrottlingTestURLRequestContextGetter() {} - scoped_refptr<TestURLRequestContext> context_; + TestURLRequestContext* const context_; }; } // namespace @@ -122,7 +122,7 @@ class URLFetcherTest : public testing::Test, scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; URLFetcherImpl* fetcher_; - scoped_refptr<TestURLRequestContext> context_; + const scoped_ptr<TestURLRequestContext> context_; }; void URLFetcherTest::CreateFetcher(const GURL& url) { @@ -293,8 +293,8 @@ class CancelTestURLRequestContextGetter throttle_for_url_(throttle_for_url) { } virtual TestURLRequestContext* GetURLRequestContext() OVERRIDE { - if (!context_) { - context_ = new CancelTestURLRequestContext(); + if (!context_.get()) { + context_.reset(new CancelTestURLRequestContext()); DCHECK(context_->throttler_manager()); // Registers an entry for test url. The backoff time is calculated by: @@ -310,7 +310,7 @@ class CancelTestURLRequestContextGetter context_created_.Signal(); } - return context_; + return context_.get(); } virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const { return io_message_loop_proxy_; @@ -323,7 +323,7 @@ class CancelTestURLRequestContextGetter virtual ~CancelTestURLRequestContextGetter() {} private: - scoped_refptr<ThrottlingTestURLRequestContext> context_; + scoped_ptr<TestURLRequestContext> context_; scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; base::WaitableEvent context_created_; GURL throttle_for_url_; diff --git a/content/shell/shell_url_request_context_getter.cc b/content/shell/shell_url_request_context_getter.cc index e0438a2..64a4271 100644 --- a/content/shell/shell_url_request_context_getter.cc +++ b/content/shell/shell_url_request_context_getter.cc @@ -49,11 +49,12 @@ ShellURLRequestContextGetter::~ShellURLRequestContextGetter() { net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - if (!url_request_context_) { - url_request_context_ = new net::URLRequestContext(); + if (!url_request_context_.get()) { + url_request_context_.reset(new net::URLRequestContext()); network_delegate_.reset(new ShellNetworkDelegate); url_request_context_->set_network_delegate(network_delegate_.get()); - storage_.reset(new net::URLRequestContextStorage(url_request_context_)); + storage_.reset( + new net::URLRequestContextStorage(url_request_context_.get())); storage_->set_cookie_store(new net::CookieMonster(NULL, NULL)); storage_->set_server_bound_cert_service(new net::ServerBoundCertService( new net::DefaultServerBoundCertStore(NULL), @@ -106,7 +107,7 @@ net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() { storage_->set_job_factory(new net::URLRequestJobFactory); } - return url_request_context_; + return url_request_context_.get(); } scoped_refptr<base::MessageLoopProxy> diff --git a/content/shell/shell_url_request_context_getter.h b/content/shell/shell_url_request_context_getter.h index 4de8bb8..b97e876 100644 --- a/content/shell/shell_url_request_context_getter.h +++ b/content/shell/shell_url_request_context_getter.h @@ -46,10 +46,9 @@ class ShellURLRequestContextGetter : public net::URLRequestContextGetter { MessageLoop* file_loop_; scoped_ptr<net::ProxyConfigService> proxy_config_service_; - - scoped_refptr<net::URLRequestContext> url_request_context_; - scoped_ptr<net::URLRequestContextStorage> storage_; scoped_ptr<net::NetworkDelegate> network_delegate_; + scoped_ptr<net::URLRequestContextStorage> storage_; + scoped_ptr<net::URLRequestContext> url_request_context_; DISALLOW_COPY_AND_ASSIGN(ShellURLRequestContextGetter); }; diff --git a/content/test/mock_resource_context.cc b/content/test/mock_resource_context.cc index ee9a6f1..cd36901 100644 --- a/content/test/mock_resource_context.cc +++ b/content/test/mock_resource_context.cc @@ -13,10 +13,6 @@ MockResourceContext::MockResourceContext() : test_request_context_(new TestURLRequestContext) { } -MockResourceContext::MockResourceContext(net::URLRequestContext* context) - : test_request_context_(context) { -} - MockResourceContext::~MockResourceContext() {} net::HostResolver* MockResourceContext::GetHostResolver() { @@ -24,7 +20,7 @@ net::HostResolver* MockResourceContext::GetHostResolver() { } net::URLRequestContext* MockResourceContext::GetRequestContext() { - return test_request_context_; + return test_request_context_.get(); } } // namespace content diff --git a/content/test/mock_resource_context.h b/content/test/mock_resource_context.h index d25bcd6..6e8ed09 100644 --- a/content/test/mock_resource_context.h +++ b/content/test/mock_resource_context.h @@ -8,7 +8,7 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" -#include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" #include "content/public/browser/resource_context.h" namespace content { @@ -16,19 +16,14 @@ namespace content { class MockResourceContext : public ResourceContext { public: MockResourceContext(); - explicit MockResourceContext(net::URLRequestContext* context); virtual ~MockResourceContext(); - void set_request_context(net::URLRequestContext* context) { - test_request_context_ = context; - } - // ResourceContext implementation: virtual net::HostResolver* GetHostResolver() OVERRIDE; virtual net::URLRequestContext* GetRequestContext() OVERRIDE; private: - scoped_refptr<net::URLRequestContext> test_request_context_; + scoped_ptr<net::URLRequestContext> test_request_context_; DISALLOW_COPY_AND_ASSIGN(MockResourceContext); }; diff --git a/content/test/webrtc_audio_device_test.cc b/content/test/webrtc_audio_device_test.cc index c9e72ec6..4532595 100644 --- a/content/test/webrtc_audio_device_test.cc +++ b/content/test/webrtc_audio_device_test.cc @@ -81,11 +81,34 @@ class ReplaceContentClientRenderer { namespace { +class MockResourceContext : public content::ResourceContext { + public: + MockResourceContext() : test_request_context_(NULL) {} + virtual ~MockResourceContext() {} + + void set_request_context(net::URLRequestContext* request_context) { + test_request_context_ = request_context; + } + + // ResourceContext implementation: + virtual net::HostResolver* GetHostResolver() OVERRIDE { + return NULL; + } + virtual net::URLRequestContext* GetRequestContext() OVERRIDE { + return test_request_context_; + } + + private: + net::URLRequestContext* test_request_context_; + + DISALLOW_COPY_AND_ASSIGN(MockResourceContext); +}; + ACTION_P(QuitMessageLoop, loop_or_proxy) { loop_or_proxy->PostTask(FROM_HERE, MessageLoop::QuitClosure()); } -} // end namespace +} // namespace WebRTCAudioDeviceTest::WebRTCAudioDeviceTest() : render_thread_(NULL), audio_util_callback_(NULL), @@ -106,7 +129,7 @@ void WebRTCAudioDeviceTest::SetUp() { MessageLoop::current())); // Construct the resource context on the UI thread. - resource_context_.reset(new content::MockResourceContext(NULL)); + resource_context_.reset(new MockResourceContext); static const char kThreadName[] = "RenderThread"; ChildProcess::current()->io_message_loop()->PostTask(FROM_HERE, @@ -168,8 +191,10 @@ void WebRTCAudioDeviceTest::InitializeIOThread(const char* thread_name) { audio_manager_.reset(media::AudioManager::Create()); // Populate our resource context. - test_request_context_ = new TestURLRequestContext(); - resource_context_->set_request_context(test_request_context_.get()); + test_request_context_.reset(new TestURLRequestContext()); + MockResourceContext* resource_context = + static_cast<MockResourceContext*>(resource_context_.get()); + resource_context->set_request_context(test_request_context_.get()); media_observer_.reset(new MockMediaObserver()); has_input_devices_ = audio_manager_->HasAudioInputDevices(); @@ -183,7 +208,7 @@ void WebRTCAudioDeviceTest::UninitializeIOThread() { resource_context_.reset(); audio_manager_.reset(); - test_request_context_ = NULL; + test_request_context_.reset(); initialize_com_.reset(); } diff --git a/content/test/webrtc_audio_device_test.h b/content/test/webrtc_audio_device_test.h index e360f4f..1e136f2 100644 --- a/content/test/webrtc_audio_device_test.h +++ b/content/test/webrtc_audio_device_test.h @@ -170,8 +170,8 @@ class WebRTCAudioDeviceTest scoped_ptr<MockMediaObserver> media_observer_; scoped_ptr<media_stream::MediaStreamManager> media_stream_manager_; scoped_ptr<media::AudioManager> audio_manager_; - scoped_ptr<content::MockResourceContext> resource_context_; - scoped_refptr<net::URLRequestContext> test_request_context_; + scoped_ptr<net::URLRequestContext> test_request_context_; + scoped_ptr<content::ResourceContext> resource_context_; scoped_ptr<IPC::Channel> channel_; scoped_refptr<AudioRendererHost> audio_render_host_; scoped_refptr<AudioInputRendererHost> audio_input_renderer_host_; diff --git a/net/proxy/dhcp_proxy_script_adapter_fetcher_win_unittest.cc b/net/proxy/dhcp_proxy_script_adapter_fetcher_win_unittest.cc index 9c66d11..0c612eb 100644 --- a/net/proxy/dhcp_proxy_script_adapter_fetcher_win_unittest.cc +++ b/net/proxy/dhcp_proxy_script_adapter_fetcher_win_unittest.cc @@ -150,7 +150,7 @@ class FetcherClient { } TestCompletionCallback callback_; - scoped_refptr<URLRequestContext> url_request_context_; + scoped_ptr<URLRequestContext> url_request_context_; scoped_ptr<MockDhcpProxyScriptAdapterFetcher> fetcher_; string16 pac_text_; }; @@ -278,11 +278,10 @@ TEST(DhcpProxyScriptAdapterFetcher, MockDhcpRealFetch) { GURL configured_url = test_server.GetURL("files/downloadable.pac"); FetcherClient client; - scoped_refptr<URLRequestContext> url_request_context( - new TestURLRequestContext()); + TestURLRequestContext url_request_context; client.fetcher_.reset( new MockDhcpRealFetchProxyScriptAdapterFetcher( - url_request_context.get())); + &url_request_context)); client.fetcher_->configured_url_ = configured_url.spec(); client.RunTest(); client.WaitForResult(OK); diff --git a/net/proxy/dhcp_proxy_script_fetcher_factory_unittest.cc b/net/proxy/dhcp_proxy_script_fetcher_factory_unittest.cc index 97730bc..9eb7c67 100644 --- a/net/proxy/dhcp_proxy_script_fetcher_factory_unittest.cc +++ b/net/proxy/dhcp_proxy_script_fetcher_factory_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -22,8 +22,8 @@ TEST(DhcpProxyScriptFetcherFactoryTest, WindowsFetcherOnWindows) { DhcpProxyScriptFetcherFactory factory; factory.set_enabled(true); - scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); - scoped_ptr<DhcpProxyScriptFetcher> fetcher(factory.Create(context)); + scoped_ptr<TestURLRequestContext> context(new TestURLRequestContext()); + scoped_ptr<DhcpProxyScriptFetcher> fetcher(factory.Create(context.get())); EXPECT_EQ("win", fetcher->GetFetcherName()); } #endif // defined(OS_WIN) diff --git a/net/proxy/dhcp_proxy_script_fetcher_win_unittest.cc b/net/proxy/dhcp_proxy_script_fetcher_win_unittest.cc index 644b533..e05f7c1 100644 --- a/net/proxy/dhcp_proxy_script_fetcher_win_unittest.cc +++ b/net/proxy/dhcp_proxy_script_fetcher_win_unittest.cc @@ -48,7 +48,7 @@ TEST(DhcpProxyScriptFetcherWin, AdapterNamesAndPacURLFromDhcp) { class RealFetchTester { public: RealFetchTester() - : context_((new TestURLRequestContext())), + : context_(new TestURLRequestContext), fetcher_(new DhcpProxyScriptFetcherWin(context_.get())), finished_(false), on_completion_is_error_(false) { @@ -114,7 +114,7 @@ class RealFetchTester { base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(30)); } - scoped_refptr<URLRequestContext> context_; + scoped_ptr<URLRequestContext> context_; scoped_ptr<DhcpProxyScriptFetcherWin> fetcher_; bool finished_; string16 pac_text_; @@ -200,7 +200,7 @@ TEST(DhcpProxyScriptFetcherWin, RealFetchWithDeferredCancel) { // the cancel is called before they complete. RealFetchTester fetcher; fetcher.fetcher_.reset( - new DelayingDhcpProxyScriptFetcherWin(fetcher.context_)); + new DelayingDhcpProxyScriptFetcherWin(fetcher.context_.get())); fetcher.on_completion_is_error_ = true; fetcher.RunTestWithDeferredCancel(); fetcher.WaitUntilDone(); @@ -372,7 +372,7 @@ class FetcherClient { public: FetcherClient() : context_(new TestURLRequestContext), - fetcher_(context_), + fetcher_(context_.get()), finished_(false), result_(ERR_UNEXPECTED) { } @@ -411,7 +411,7 @@ public: fetcher_.ResetTestState(); } - scoped_refptr<URLRequestContext> context_; + scoped_ptr<URLRequestContext> context_; MockDhcpProxyScriptFetcherWin fetcher_; bool finished_; int result_; @@ -421,9 +421,9 @@ public: // We separate out each test's logic so that we can easily implement // the ReuseFetcher test at the bottom. void TestNormalCaseURLConfiguredOneAdapter(FetcherClient* client) { - scoped_refptr<URLRequestContext> context(new TestURLRequestContext); + TestURLRequestContext context; scoped_ptr<DummyDhcpProxyScriptAdapterFetcher> adapter_fetcher( - new DummyDhcpProxyScriptAdapterFetcher(context)); + new DummyDhcpProxyScriptAdapterFetcher(&context)); adapter_fetcher->Configure(true, OK, L"bingo", 1); client->fetcher_.PushBackAdapter("a", adapter_fetcher.release()); client->RunTest(); @@ -573,9 +573,9 @@ TEST(DhcpProxyScriptFetcherWin, ShortCircuitLessPreferredAdapters) { } void TestImmediateCancel(FetcherClient* client) { - scoped_refptr<URLRequestContext> context(new TestURLRequestContext); + TestURLRequestContext context; scoped_ptr<DummyDhcpProxyScriptAdapterFetcher> adapter_fetcher( - new DummyDhcpProxyScriptAdapterFetcher(context)); + new DummyDhcpProxyScriptAdapterFetcher(&context)); adapter_fetcher->Configure(true, OK, L"bingo", 1); client->fetcher_.PushBackAdapter("a", adapter_fetcher.release()); client->RunTest(); diff --git a/net/proxy/proxy_script_fetcher_impl.cc b/net/proxy/proxy_script_fetcher_impl.cc index 32f6542..d69200f 100644 --- a/net/proxy/proxy_script_fetcher_impl.cc +++ b/net/proxy/proxy_script_fetcher_impl.cc @@ -295,9 +295,6 @@ void ProxyScriptFetcherImpl::FetchCompleted() { int result_code = result_code_; CompletionCallback callback = callback_; - // Hold a reference to the URLRequestContext to prevent re-entrancy from - // ~URLRequestContext. - scoped_refptr<const URLRequestContext> context(cur_request_->context()); ResetCurRequestState(); callback.Run(result_code); diff --git a/net/proxy/proxy_script_fetcher_impl.h b/net/proxy/proxy_script_fetcher_impl.h index 3774748..119ace1 100644 --- a/net/proxy/proxy_script_fetcher_impl.h +++ b/net/proxy/proxy_script_fetcher_impl.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -85,7 +85,7 @@ class NET_EXPORT ProxyScriptFetcherImpl : public ProxyScriptFetcher, base::WeakPtrFactory<ProxyScriptFetcherImpl> weak_factory_; // The context used for making network requests. - URLRequestContext* url_request_context_; + URLRequestContext* const url_request_context_; // Buffer that URLRequest writes into. scoped_refptr<IOBuffer> buf_; diff --git a/net/proxy/proxy_script_fetcher_impl_unittest.cc b/net/proxy/proxy_script_fetcher_impl_unittest.cc index 45fcc07..dd95e7e 100644 --- a/net/proxy/proxy_script_fetcher_impl_unittest.cc +++ b/net/proxy/proxy_script_fetcher_impl_unittest.cc @@ -96,10 +96,10 @@ class RequestContext : public URLRequestContext { new CheckNoRevocationFlagSetInterceptor); } - private: - ~RequestContext() { + virtual ~RequestContext() { } + private: URLRequestContextStorage storage_; scoped_ptr<URLRequestJobFactory> url_request_job_factory_; }; @@ -197,22 +197,17 @@ class ProxyScriptFetcherImplTest : public PlatformTest { : test_server_(TestServer::TYPE_HTTP, net::TestServer::kLocalhost, FilePath(kDocRoot)) { - } - - // testing::Test overrides - virtual void SetUp() OVERRIDE { - context_ = new RequestContext; - context_->set_network_delegate(&network_delegate_); + context_.set_network_delegate(&network_delegate_); } protected: TestServer test_server_; BasicNetworkDelegate network_delegate_; - scoped_refptr<URLRequestContext> context_; + RequestContext context_; }; TEST_F(ProxyScriptFetcherImplTest, FileUrl) { - ProxyScriptFetcherImpl pac_fetcher(context_.get()); + ProxyScriptFetcherImpl pac_fetcher(&context_); { // Fetch a non-existent file. string16 text; @@ -239,7 +234,7 @@ TEST_F(ProxyScriptFetcherImplTest, FileUrl) { TEST_F(ProxyScriptFetcherImplTest, HttpMimeType) { ASSERT_TRUE(test_server_.Start()); - ProxyScriptFetcherImpl pac_fetcher(context_.get()); + ProxyScriptFetcherImpl pac_fetcher(&context_); { // Fetch a PAC with mime type "text/plain" GURL url(test_server_.GetURL("files/pac.txt")); @@ -273,7 +268,7 @@ TEST_F(ProxyScriptFetcherImplTest, HttpMimeType) { TEST_F(ProxyScriptFetcherImplTest, HttpStatusCode) { ASSERT_TRUE(test_server_.Start()); - ProxyScriptFetcherImpl pac_fetcher(context_.get()); + ProxyScriptFetcherImpl pac_fetcher(&context_); { // Fetch a PAC which gives a 500 -- FAIL GURL url(test_server_.GetURL("files/500.pac")); @@ -298,7 +293,7 @@ TEST_F(ProxyScriptFetcherImplTest, HttpStatusCode) { TEST_F(ProxyScriptFetcherImplTest, ContentDisposition) { ASSERT_TRUE(test_server_.Start()); - ProxyScriptFetcherImpl pac_fetcher(context_.get()); + ProxyScriptFetcherImpl pac_fetcher(&context_); // Fetch PAC scripts via HTTP with a Content-Disposition header -- should // have no effect. @@ -314,7 +309,7 @@ TEST_F(ProxyScriptFetcherImplTest, ContentDisposition) { TEST_F(ProxyScriptFetcherImplTest, NoCache) { ASSERT_TRUE(test_server_.Start()); - ProxyScriptFetcherImpl pac_fetcher(context_.get()); + ProxyScriptFetcherImpl pac_fetcher(&context_); // Fetch a PAC script whose HTTP headers make it cacheable for 1 hour. GURL url(test_server_.GetURL("files/cacheable_1hr.pac")); @@ -345,7 +340,7 @@ TEST_F(ProxyScriptFetcherImplTest, NoCache) { TEST_F(ProxyScriptFetcherImplTest, TooLarge) { ASSERT_TRUE(test_server_.Start()); - ProxyScriptFetcherImpl pac_fetcher(context_.get()); + ProxyScriptFetcherImpl pac_fetcher(&context_); // Set the maximum response size to 50 bytes. int prev_size = pac_fetcher.SetSizeConstraint(50); @@ -385,7 +380,7 @@ TEST_F(ProxyScriptFetcherImplTest, TooLarge) { TEST_F(ProxyScriptFetcherImplTest, Hang) { ASSERT_TRUE(test_server_.Start()); - ProxyScriptFetcherImpl pac_fetcher(context_.get()); + ProxyScriptFetcherImpl pac_fetcher(&context_); // Set the timeout period to 0.5 seconds. base::TimeDelta prev_timeout = pac_fetcher.SetTimeoutConstraint( @@ -393,7 +388,8 @@ TEST_F(ProxyScriptFetcherImplTest, Hang) { // Try fetching a URL which takes 1.2 seconds. We should abort the request // after 500 ms, and fail with a timeout error. - { GURL url(test_server_.GetURL("slow/proxy.pac?1.2")); + { + GURL url(test_server_.GetURL("slow/proxy.pac?1.2")); string16 text; TestCompletionCallback callback; int result = pac_fetcher.Fetch(url, &text, callback.callback()); @@ -422,7 +418,7 @@ TEST_F(ProxyScriptFetcherImplTest, Hang) { TEST_F(ProxyScriptFetcherImplTest, Encodings) { ASSERT_TRUE(test_server_.Start()); - ProxyScriptFetcherImpl pac_fetcher(context_.get()); + ProxyScriptFetcherImpl pac_fetcher(&context_); // Test a response that is gzip-encoded -- should get inflated. { @@ -449,7 +445,7 @@ TEST_F(ProxyScriptFetcherImplTest, Encodings) { } TEST_F(ProxyScriptFetcherImplTest, DataURLs) { - ProxyScriptFetcherImpl pac_fetcher(context_.get()); + ProxyScriptFetcherImpl pac_fetcher(&context_); const char kEncodedUrl[] = "data:application/x-ns-proxy-autoconfig;base64,ZnVuY3Rpb24gRmluZFByb3h5R" diff --git a/net/socket_stream/socket_stream.cc b/net/socket_stream/socket_stream.cc index fb8984e..4e0eac1 100644 --- a/net/socket_stream/socket_stream.cc +++ b/net/socket_stream/socket_stream.cc @@ -56,6 +56,7 @@ SocketStream::SocketStream(const GURL& url, Delegate* delegate) : delegate_(delegate), url_(url), max_pending_send_allowed_(kMaxPendingSendAllowed), + context_(NULL), next_state_(STATE_NONE), host_resolver_(NULL), cert_verifier_(NULL), @@ -101,8 +102,8 @@ bool SocketStream::is_secure() const { return url_.SchemeIs("wss"); } -void SocketStream::set_context(URLRequestContext* context) { - scoped_refptr<URLRequestContext> prev_context = context_; +void SocketStream::set_context(const URLRequestContext* context) { + const URLRequestContext* prev_context = context_; context_ = context; diff --git a/net/socket_stream/socket_stream.h b/net/socket_stream/socket_stream.h index c207d3b..2fa3683 100644 --- a/net/socket_stream/socket_stream.h +++ b/net/socket_stream/socket_stream.h @@ -138,8 +138,8 @@ class NET_EXPORT SocketStream Delegate* delegate() const { return delegate_; } int max_pending_send_allowed() const { return max_pending_send_allowed_; } - URLRequestContext* context() const { return context_.get(); } - void set_context(URLRequestContext* context); + const URLRequestContext* context() const { return context_; } + void set_context(const URLRequestContext* context); BoundNetLog* net_log() { return &net_log_; } @@ -321,7 +321,7 @@ class NET_EXPORT SocketStream GURL url_; int max_pending_send_allowed_; - scoped_refptr<URLRequestContext> context_; + const URLRequestContext* context_; UserDataMap user_data_; diff --git a/net/socket_stream/socket_stream_job.h b/net/socket_stream/socket_stream_job.h index 9e6c8f5..00510b2 100644 --- a/net/socket_stream/socket_stream_job.h +++ b/net/socket_stream/socket_stream_job.h @@ -50,10 +50,10 @@ class NET_EXPORT SocketStreamJob virtual SocketStream::UserData* GetUserData(const void* key) const; virtual void SetUserData(const void* key, SocketStream::UserData* data); - URLRequestContext* context() const { + const URLRequestContext* context() const { return socket_->context(); } - void set_context(URLRequestContext* context) { + void set_context(const URLRequestContext* context) { socket_->set_context(context); } diff --git a/net/socket_stream/socket_stream_unittest.cc b/net/socket_stream/socket_stream_unittest.cc index 25fc0a8..a7a0cc7 100644 --- a/net/socket_stream/socket_stream_unittest.cc +++ b/net/socket_stream/socket_stream_unittest.cc @@ -279,11 +279,12 @@ TEST_F(SocketStreamTest, CloseFlushPendingWrite) { base::Unretained(this))); MockHostResolver host_resolver; + TestURLRequestContext context; scoped_refptr<SocketStream> socket_stream( new SocketStream(GURL("ws://example.com/demo"), delegate.get())); - socket_stream->set_context(new TestURLRequestContext()); + socket_stream->set_context(&context); socket_stream->SetHostResolver(&host_resolver); MockWrite data_writes[] = { @@ -379,8 +380,10 @@ TEST_F(SocketStreamTest, BasicAuthProxy) { scoped_refptr<SocketStream> socket_stream( new SocketStream(GURL("ws://example.com/demo"), delegate.get())); - socket_stream->set_context(new TestURLRequestContext("myproxy:70")); MockHostResolver host_resolver; + TestURLRequestContext context("myproxy:70"); + + socket_stream->set_context(&context); socket_stream->SetHostResolver(&host_resolver); socket_stream->SetClientSocketFactory(&mock_socket_factory); @@ -416,11 +419,12 @@ TEST_F(SocketStreamTest, IOPending) { &SocketStreamTest::DoIOPending, base::Unretained(this))); MockHostResolver host_resolver; + TestURLRequestContext context; scoped_refptr<SocketStream> socket_stream( new SocketStream(GURL("ws://example.com/demo"), delegate.get())); - socket_stream->set_context(new TestURLRequestContext()); + socket_stream->set_context(&context); socket_stream->SetHostResolver(&host_resolver); MockWrite data_writes[] = { @@ -479,11 +483,12 @@ TEST_F(SocketStreamTest, SwitchToSpdy) { &SocketStreamTest::DoSwitchToSpdyTest, base::Unretained(this))); MockHostResolver host_resolver; + TestURLRequestContext context; scoped_refptr<SocketStream> socket_stream( new SocketStream(GURL("ws://example.com/demo"), delegate.get())); - socket_stream->set_context(new TestURLRequestContext()); + socket_stream->set_context(&context); socket_stream->SetHostResolver(&host_resolver); socket_stream->Connect(); @@ -508,11 +513,12 @@ TEST_F(SocketStreamTest, SwitchAfterPending) { &SocketStreamTest::DoIOPending, base::Unretained(this))); MockHostResolver host_resolver; + TestURLRequestContext context; scoped_refptr<SocketStream> socket_stream( new SocketStream(GURL("ws://example.com/demo"), delegate.get())); - socket_stream->set_context(new TestURLRequestContext()); + socket_stream->set_context(&context); socket_stream->SetHostResolver(&host_resolver); socket_stream->Connect(); @@ -556,6 +562,8 @@ TEST_F(SocketStreamTest, SecureProxyConnectError) { mock_socket_factory.AddSSLSocketDataProvider(&ssl); TestCompletionCallback test_callback; + MockHostResolver host_resolver; + TestURLRequestContext context("https://myproxy:70"); scoped_ptr<SocketStreamEventRecorder> delegate( new SocketStreamEventRecorder(test_callback.callback())); @@ -565,8 +573,7 @@ TEST_F(SocketStreamTest, SecureProxyConnectError) { scoped_refptr<SocketStream> socket_stream( new SocketStream(GURL("ws://example.com/demo"), delegate.get())); - socket_stream->set_context(new TestURLRequestContext("https://myproxy:70")); - MockHostResolver host_resolver; + socket_stream->set_context(&context); socket_stream->SetHostResolver(&host_resolver); socket_stream->SetClientSocketFactory(&mock_socket_factory); @@ -608,6 +615,8 @@ TEST_F(SocketStreamTest, SecureProxyConnect) { mock_socket_factory.AddSSLSocketDataProvider(&ssl); TestCompletionCallback test_callback; + MockHostResolver host_resolver; + TestURLRequestContext context("https://myproxy:70"); scoped_ptr<SocketStreamEventRecorder> delegate( new SocketStreamEventRecorder(test_callback.callback())); @@ -617,8 +626,7 @@ TEST_F(SocketStreamTest, SecureProxyConnect) { scoped_refptr<SocketStream> socket_stream( new SocketStream(GURL("ws://example.com/demo"), delegate.get())); - socket_stream->set_context(new TestURLRequestContext("https://myproxy:70")); - MockHostResolver host_resolver; + socket_stream->set_context(&context); socket_stream->SetHostResolver(&host_resolver); socket_stream->SetClientSocketFactory(&mock_socket_factory); diff --git a/net/spdy/spdy_network_transaction_spdy2_unittest.cc b/net/spdy/spdy_network_transaction_spdy2_unittest.cc index e8964163..c2e6fdf 100644 --- a/net/spdy/spdy_network_transaction_spdy2_unittest.cc +++ b/net/spdy/spdy_network_transaction_spdy2_unittest.cc @@ -2196,13 +2196,12 @@ TEST_P(SpdyNetworkTransactionSpdy2Test, RedirectGetRequest) { HttpStreamFactory::set_force_spdy_always(true); TestDelegate d; { + SpdyURLRequestContext spdy_url_request_context; net::URLRequest r(GURL("http://www.google.com/"), &d); - SpdyURLRequestContext* spdy_url_request_context = - new SpdyURLRequestContext(); - r.set_context(spdy_url_request_context); - spdy_url_request_context->socket_factory(). + r.set_context(&spdy_url_request_context); + spdy_url_request_context.socket_factory(). AddSocketDataProvider(data.get()); - spdy_url_request_context->socket_factory(). + spdy_url_request_context.socket_factory(). AddSocketDataProvider(data2.get()); d.set_quit_on_redirect(true); @@ -2452,12 +2451,11 @@ TEST_P(SpdyNetworkTransactionSpdy2Test, RedirectServerPush) { HttpStreamFactory::set_force_spdy_always(true); TestDelegate d; TestDelegate d2; - scoped_refptr<SpdyURLRequestContext> spdy_url_request_context( - new SpdyURLRequestContext()); + SpdyURLRequestContext spdy_url_request_context; { net::URLRequest r(GURL("http://www.google.com/"), &d); - r.set_context(spdy_url_request_context); - spdy_url_request_context->socket_factory(). + r.set_context(&spdy_url_request_context); + spdy_url_request_context.socket_factory(). AddSocketDataProvider(data.get()); r.Start(); @@ -2468,8 +2466,8 @@ TEST_P(SpdyNetworkTransactionSpdy2Test, RedirectServerPush) { EXPECT_EQ(contents, d.data_received()); net::URLRequest r2(GURL("http://www.google.com/foo.dat"), &d2); - r2.set_context(spdy_url_request_context); - spdy_url_request_context->socket_factory(). + r2.set_context(&spdy_url_request_context); + spdy_url_request_context.socket_factory(). AddSocketDataProvider(data2.get()); d2.set_quit_on_redirect(true); diff --git a/net/spdy/spdy_network_transaction_spdy3_unittest.cc b/net/spdy/spdy_network_transaction_spdy3_unittest.cc index 8854d55..70a53cc 100644 --- a/net/spdy/spdy_network_transaction_spdy3_unittest.cc +++ b/net/spdy/spdy_network_transaction_spdy3_unittest.cc @@ -2767,13 +2767,12 @@ TEST_P(SpdyNetworkTransactionSpdy3Test, RedirectGetRequest) { HttpStreamFactory::set_force_spdy_always(true); TestDelegate d; { + SpdyURLRequestContext spdy_url_request_context; net::URLRequest r(GURL("http://www.google.com/"), &d); - SpdyURLRequestContext* spdy_url_request_context = - new SpdyURLRequestContext(); - r.set_context(spdy_url_request_context); - spdy_url_request_context->socket_factory(). + r.set_context(&spdy_url_request_context); + spdy_url_request_context.socket_factory(). AddSocketDataProvider(data.get()); - spdy_url_request_context->socket_factory(). + spdy_url_request_context.socket_factory(). AddSocketDataProvider(data2.get()); d.set_quit_on_redirect(true); @@ -3025,12 +3024,11 @@ TEST_P(SpdyNetworkTransactionSpdy3Test, RedirectServerPush) { HttpStreamFactory::set_force_spdy_always(true); TestDelegate d; TestDelegate d2; - scoped_refptr<SpdyURLRequestContext> spdy_url_request_context( - new SpdyURLRequestContext()); + SpdyURLRequestContext spdy_url_request_context; { net::URLRequest r(GURL("http://www.google.com/"), &d); - r.set_context(spdy_url_request_context); - spdy_url_request_context->socket_factory(). + r.set_context(&spdy_url_request_context); + spdy_url_request_context.socket_factory(). AddSocketDataProvider(data.get()); r.Start(); @@ -3041,8 +3039,8 @@ TEST_P(SpdyNetworkTransactionSpdy3Test, RedirectServerPush) { EXPECT_EQ(contents, d.data_received()); net::URLRequest r2(GURL("http://www.google.com/foo.dat"), &d2); - r2.set_context(spdy_url_request_context); - spdy_url_request_context->socket_factory(). + r2.set_context(&spdy_url_request_context); + spdy_url_request_context.socket_factory(). AddSocketDataProvider(data2.get()); d2.set_quit_on_redirect(true); diff --git a/net/spdy/spdy_test_util_spdy2.h b/net/spdy/spdy_test_util_spdy2.h index f20e07e..03b70d87 100644 --- a/net/spdy/spdy_test_util_spdy2.h +++ b/net/spdy/spdy_test_util_spdy2.h @@ -373,12 +373,10 @@ class SpdySessionDependencies { class SpdyURLRequestContext : public URLRequestContext { public: SpdyURLRequestContext(); + virtual ~SpdyURLRequestContext(); MockClientSocketFactory& socket_factory() { return socket_factory_; } - protected: - virtual ~SpdyURLRequestContext(); - private: MockClientSocketFactory socket_factory_; net::URLRequestContextStorage storage_; diff --git a/net/spdy/spdy_test_util_spdy3.h b/net/spdy/spdy_test_util_spdy3.h index 2b11041..3e18077 100644 --- a/net/spdy/spdy_test_util_spdy3.h +++ b/net/spdy/spdy_test_util_spdy3.h @@ -374,12 +374,10 @@ class SpdySessionDependencies { class SpdyURLRequestContext : public URLRequestContext { public: SpdyURLRequestContext(); + virtual ~SpdyURLRequestContext(); MockClientSocketFactory& socket_factory() { return socket_factory_; } - protected: - virtual ~SpdyURLRequestContext(); - private: MockClientSocketFactory socket_factory_; net::URLRequestContextStorage storage_; diff --git a/net/test/spawner_communicator.cc b/net/test/spawner_communicator.cc index 8b454f0..65b700a 100644 --- a/net/test/spawner_communicator.cc +++ b/net/test/spawner_communicator.cc @@ -173,8 +173,8 @@ void SpawnerCommunicator::SendCommandAndWaitForResultOnIOThread( cur_request_->SetUserData(this, data); // Build the URLRequest. - scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); - cur_request_->set_context(context); + context_.reset(new TestURLRequestContext); + cur_request_->set_context(context_.get()); if (post_data.empty()) { cur_request_->set_method("GET"); } else { @@ -364,4 +364,3 @@ bool SpawnerCommunicator::StopServer() { } } // namespace net - diff --git a/net/test/spawner_communicator.h b/net/test/spawner_communicator.h index 42afb41..061324d 100644 --- a/net/test/spawner_communicator.h +++ b/net/test/spawner_communicator.h @@ -135,6 +135,8 @@ class SpawnerCommunicator : public net::URLRequest::Delegate { // outstanding tasks when |this| is deleted. base::WeakPtrFactory<SpawnerCommunicator> weak_factory_; + scoped_ptr<URLRequestContext> context_; + // The current (in progress) request, or NULL. scoped_ptr<URLRequest> cur_request_; @@ -147,4 +149,3 @@ class SpawnerCommunicator : public net::URLRequest::Delegate { } // namespace net #endif // NET_TEST_SPAWNER_COMMUNICATOR_H_ - diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc index 3947d69..c2c2c5e4 100644 --- a/net/url_request/url_request.cc +++ b/net/url_request/url_request.cc @@ -132,7 +132,8 @@ void URLRequest::Delegate::OnSSLCertificateError(URLRequest* request, // URLRequest URLRequest::URLRequest(const GURL& url, Delegate* delegate) - : url_chain_(1, url), + : context_(NULL), + url_chain_(1, url), method_("GET"), referrer_policy_(CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE), load_flags_(LOAD_NORMAL), @@ -721,7 +722,7 @@ int URLRequest::Redirect(const GURL& location, int http_status_code) { } const URLRequestContext* URLRequest::context() const { - return context_.get(); + return context_; } void URLRequest::set_context(const URLRequestContext* context) { @@ -738,7 +739,7 @@ void URLRequest::set_context(const URLRequestContext* context) { url_requests->insert(this); } - scoped_refptr<const URLRequestContext> prev_context = context_; + const URLRequestContext* prev_context = context_; context_ = context; diff --git a/net/url_request/url_request.h b/net/url_request/url_request.h index 72f6b95..df466d5 100644 --- a/net/url_request/url_request.h +++ b/net/url_request/url_request.h @@ -705,7 +705,7 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe), // Contextual information used for this request (can be NULL). This contains // most of the dependencies which are shared between requests (disk cache, // cookie store, socket pool, etc.) - scoped_refptr<const URLRequestContext> context_; + const URLRequestContext* context_; // Tracks the time spent in various load states throughout this request. BoundNetLog net_log_; diff --git a/net/url_request/url_request_context.cc b/net/url_request/url_request_context.cc index 08cf95a..aac6f2e 100644 --- a/net/url_request/url_request_context.cc +++ b/net/url_request/url_request_context.cc @@ -16,8 +16,7 @@ namespace net { URLRequestContext::URLRequestContext() - : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), - net_log_(NULL), + : net_log_(NULL), host_resolver_(NULL), cert_verifier_(NULL), server_bound_cert_service_(NULL), @@ -35,6 +34,10 @@ URLRequestContext::URLRequestContext() url_requests_(new std::set<const URLRequest*>) { } +URLRequestContext::~URLRequestContext() { + AssertNoURLRequests(); +} + void URLRequestContext::CopyFrom(URLRequestContext* other) { // Copy URLRequestContext parameters. set_net_log(other->net_log()); @@ -85,8 +88,4 @@ void URLRequestContext::AssertNoURLRequests() const { } } -URLRequestContext::~URLRequestContext() { - AssertNoURLRequests(); -} - } // namespace net diff --git a/net/url_request/url_request_context.h b/net/url_request/url_request_context.h index ca5c7b1..26261f2 100644 --- a/net/url_request/url_request_context.h +++ b/net/url_request/url_request_context.h @@ -44,14 +44,10 @@ class URLRequestThrottlerManager; // these member variables, since they may be shared. For the ones that aren't // shared, URLRequestContextStorage can be helpful in defining their storage. class NET_EXPORT URLRequestContext - : public base::RefCountedThreadSafe<URLRequestContext>, - NON_EXPORTED_BASE(public base::NonThreadSafe) { + : NON_EXPORTED_BASE(public base::NonThreadSafe) { public: URLRequestContext(); - - base::WeakPtr<URLRequestContext> GetWeakPtr() { - return weak_factory_.GetWeakPtr(); - } + virtual ~URLRequestContext(); // Copies the state from |other| into this context. void CopyFrom(URLRequestContext* other); @@ -111,7 +107,7 @@ class NET_EXPORT URLRequestContext // Gets the HTTP Authentication Handler Factory for this context. // The factory is only valid for the lifetime of this URLRequestContext - HttpAuthHandlerFactory* http_auth_handler_factory() { + HttpAuthHandlerFactory* http_auth_handler_factory() const { return http_auth_handler_factory_; } void set_http_auth_handler_factory(HttpAuthHandlerFactory* factory) { @@ -208,14 +204,7 @@ class NET_EXPORT URLRequestContext void AssertNoURLRequests() const; - protected: - friend class base::RefCountedThreadSafe<URLRequestContext>; - - virtual ~URLRequestContext(); - private: - base::WeakPtrFactory<URLRequestContext> weak_factory_; - // --------------------------------------------------------------------------- // Important: When adding any new members below, consider whether they need to // be added to CopyFrom. diff --git a/net/url_request/url_request_context_builder.cc b/net/url_request/url_request_context_builder.cc index 6547c2b..d4fab8a 100644 --- a/net/url_request/url_request_context_builder.cc +++ b/net/url_request/url_request_context_builder.cc @@ -179,7 +179,7 @@ void URLRequestContextBuilder::set_proxy_config_service( } #endif // defined(OS_LINUX) -scoped_refptr<URLRequestContext> URLRequestContextBuilder::Build() { +URLRequestContext* URLRequestContextBuilder::Build() { BasicURLRequestContext* context = new BasicURLRequestContext; URLRequestContextStorage* storage = context->storage(); diff --git a/net/url_request/url_request_context_builder.h b/net/url_request/url_request_context_builder.h index dbb521e..2f2b66d 100644 --- a/net/url_request/url_request_context_builder.h +++ b/net/url_request/url_request_context_builder.h @@ -91,7 +91,7 @@ class NET_EXPORT URLRequestContextBuilder { void EnableHttpCache(const HttpCacheParams& params); void DisableHttpCache(); - scoped_refptr<URLRequestContext> Build(); + URLRequestContext* Build(); private: std::string user_agent_; diff --git a/net/url_request/url_request_context_builder_unittest.cc b/net/url_request/url_request_context_builder_unittest.cc index 8fcb19c..2908c51 100644 --- a/net/url_request/url_request_context_builder_unittest.cc +++ b/net/url_request/url_request_context_builder_unittest.cc @@ -53,10 +53,10 @@ class URLRequestContextBuilderTest : public PlatformTest { TEST_F(URLRequestContextBuilderTest, DefaultSettings) { ASSERT_TRUE(test_server_.Start()); - scoped_refptr<URLRequestContext> context = builder_.Build(); + scoped_ptr<URLRequestContext> context(builder_.Build()); TestDelegate delegate; URLRequest request(test_server_.GetURL("echoheader?Foo"), &delegate); - request.set_context(context); + request.set_context(context.get()); request.set_method("GET"); request.SetExtraRequestHeaderByName("Foo", "Bar", false); request.Start(); @@ -68,10 +68,10 @@ TEST_F(URLRequestContextBuilderTest, UserAgent) { ASSERT_TRUE(test_server_.Start()); builder_.set_user_agent("Bar"); - scoped_refptr<URLRequestContext> context = builder_.Build(); + scoped_ptr<URLRequestContext> context(builder_.Build()); TestDelegate delegate; URLRequest request(test_server_.GetURL("echoheader?User-Agent"), &delegate); - request.set_context(context); + request.set_context(context.get()); request.set_method("GET"); request.Start(); MessageLoop::current()->Run(); diff --git a/net/url_request/url_request_ftp_job.cc b/net/url_request/url_request_ftp_job.cc index a07b94e..63dcc86 100644 --- a/net/url_request/url_request_ftp_job.cc +++ b/net/url_request/url_request_ftp_job.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -22,7 +22,6 @@ namespace net { URLRequestFtpJob::URLRequestFtpJob(URLRequest* request) : URLRequestJob(request), read_in_progress_(false), - context_(request->context()), ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { } diff --git a/net/url_request/url_request_ftp_job.h b/net/url_request/url_request_ftp_job.h index 5012386..05cbb33 100644 --- a/net/url_request/url_request_ftp_job.h +++ b/net/url_request/url_request_ftp_job.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -67,10 +67,6 @@ class URLRequestFtpJob : public URLRequestJob { scoped_refptr<AuthData> server_auth_; - // Keep a reference to the url request context to be sure it's not deleted - // before us. - scoped_refptr<const URLRequestContext> context_; - base::WeakPtrFactory<URLRequestFtpJob> weak_factory_; DISALLOW_COPY_AND_ASSIGN(URLRequestFtpJob); diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc index 1062563..1fd4f8b 100644 --- a/net/url_request/url_request_http_job.cc +++ b/net/url_request/url_request_http_job.cc @@ -252,7 +252,6 @@ void URLRequestHttpJob::DestroyTransaction() { DoneWithRequest(ABORTED); transaction_.reset(); response_info_ = NULL; - context_ = NULL; } void URLRequestHttpJob::StartTransaction() { @@ -327,9 +326,6 @@ void URLRequestHttpJob::StartTransactionInternal() { // Special error code for the exponential back-off module. rv = ERR_TEMPORARILY_THROTTLED; } - // Make sure the context is alive for the duration of the - // transaction. - context_ = request_->context(); } } @@ -663,14 +659,16 @@ void URLRequestHttpJob::OnStartCompleted(int result) { // Clear the IO_PENDING status SetStatus(URLRequestStatus()); + const URLRequestContext* context = request_->context(); + if (result == ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN && transaction_->GetResponseInfo() != NULL) { FraudulentCertificateReporter* reporter = - context_->fraudulent_certificate_reporter(); + context->fraudulent_certificate_reporter(); if (reporter != NULL) { const SSLInfo& ssl_info = transaction_->GetResponseInfo()->ssl_info; bool sni_available = SSLConfigService::IsSNIAvailable( - context_->ssl_config_service()); + context->ssl_config_service()); const std::string& host = request_->url().host(); reporter->SendReport(host, ssl_info, sni_available); @@ -679,11 +677,11 @@ void URLRequestHttpJob::OnStartCompleted(int result) { if (result == OK) { scoped_refptr<HttpResponseHeaders> headers = GetResponseHeaders(); - if (request_->context() && request_->context()->network_delegate()) { + if (context && context->network_delegate()) { // Note that |this| may not be deleted until // |on_headers_received_callback_| or // |NetworkDelegate::URLRequestDestroyed()| has been called. - int error = request_->context()->network_delegate()-> + int error = context->network_delegate()-> NotifyHeadersReceived(request_, on_headers_received_callback_, headers, &override_response_headers_); if (error != net::OK) { @@ -707,11 +705,12 @@ void URLRequestHttpJob::OnStartCompleted(int result) { // what we should do. TransportSecurityState::DomainState domain_state; + const URLRequestContext* context = request_->context(); const bool fatal = - context_->transport_security_state() && - context_->transport_security_state()->GetDomainState( + context->transport_security_state() && + context->transport_security_state()->GetDomainState( request_info_.url.host(), - SSLConfigService::IsSNIAvailable(context_->ssl_config_service()), + SSLConfigService::IsSNIAvailable(context->ssl_config_service()), &domain_state); NotifySSLCertificateError(transaction_->GetResponseInfo()->ssl_info, fatal); } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { diff --git a/net/url_request/url_request_http_job.h b/net/url_request/url_request_http_job.h index 836ddb6..3ff218f 100644 --- a/net/url_request/url_request_http_job.h +++ b/net/url_request/url_request_http_job.h @@ -93,10 +93,6 @@ class URLRequestHttpJob : public URLRequestJob { virtual HostPortPair GetSocketAddress() const OVERRIDE; virtual void NotifyURLRequestDestroyed() OVERRIDE; - // Keep a reference to the url request context to be sure it's not deleted - // before us. - scoped_refptr<const URLRequestContext> context_; - HttpRequestInfo request_info_; const HttpResponseInfo* response_info_; diff --git a/net/url_request/url_request_job_factory_unittest.cc b/net/url_request/url_request_job_factory_unittest.cc index 1273256..d385e7f 100644 --- a/net/url_request/url_request_job_factory_unittest.cc +++ b/net/url_request/url_request_job_factory_unittest.cc @@ -87,9 +87,9 @@ class DummyInterceptor : public URLRequestJobFactory::Interceptor { TEST(URLRequestJobFactoryTest, NoProtocolHandler) { TestDelegate delegate; - scoped_refptr<URLRequestContext> request_context(new TestURLRequestContext); + TestURLRequestContext request_context; TestURLRequest request(GURL("foo://bar"), &delegate); - request.set_context(request_context); + request.set_context(&request_context); request.Start(); MessageLoop::current()->Run(); @@ -99,12 +99,12 @@ TEST(URLRequestJobFactoryTest, NoProtocolHandler) { TEST(URLRequestJobFactoryTest, BasicProtocolHandler) { TestDelegate delegate; - scoped_refptr<URLRequestContext> request_context(new TestURLRequestContext); URLRequestJobFactory job_factory; - request_context->set_job_factory(&job_factory); + TestURLRequestContext request_context; + request_context.set_job_factory(&job_factory); job_factory.SetProtocolHandler("foo", new DummyProtocolHandler); TestURLRequest request(GURL("foo://bar"), &delegate); - request.set_context(request_context); + request.set_context(&request_context); request.Start(); MessageLoop::current()->Run(); @@ -113,21 +113,21 @@ TEST(URLRequestJobFactoryTest, BasicProtocolHandler) { } TEST(URLRequestJobFactoryTest, DeleteProtocolHandler) { - scoped_refptr<URLRequestContext> request_context(new TestURLRequestContext); URLRequestJobFactory job_factory; - request_context->set_job_factory(&job_factory); + TestURLRequestContext request_context; + request_context.set_job_factory(&job_factory); job_factory.SetProtocolHandler("foo", new DummyProtocolHandler); job_factory.SetProtocolHandler("foo", NULL); } TEST(URLRequestJobFactoryTest, BasicInterceptor) { TestDelegate delegate; - scoped_refptr<URLRequestContext> request_context(new TestURLRequestContext); URLRequestJobFactory job_factory; - request_context->set_job_factory(&job_factory); + TestURLRequestContext request_context; + request_context.set_job_factory(&job_factory); job_factory.AddInterceptor(new DummyInterceptor); TestURLRequest request(GURL("http://bar"), &delegate); - request.set_context(request_context); + request.set_context(&request_context); request.Start(); MessageLoop::current()->Run(); @@ -137,12 +137,12 @@ TEST(URLRequestJobFactoryTest, BasicInterceptor) { TEST(URLRequestJobFactoryTest, InterceptorNeedsValidSchemeStill) { TestDelegate delegate; - scoped_refptr<URLRequestContext> request_context(new TestURLRequestContext); URLRequestJobFactory job_factory; - request_context->set_job_factory(&job_factory); + TestURLRequestContext request_context; + request_context.set_job_factory(&job_factory); job_factory.AddInterceptor(new DummyInterceptor); TestURLRequest request(GURL("foo://bar"), &delegate); - request.set_context(request_context); + request.set_context(&request_context); request.Start(); MessageLoop::current()->Run(); @@ -152,13 +152,13 @@ TEST(URLRequestJobFactoryTest, InterceptorNeedsValidSchemeStill) { TEST(URLRequestJobFactoryTest, InterceptorOverridesProtocolHandler) { TestDelegate delegate; - scoped_refptr<URLRequestContext> request_context(new TestURLRequestContext); URLRequestJobFactory job_factory; - request_context->set_job_factory(&job_factory); + TestURLRequestContext request_context; + request_context.set_job_factory(&job_factory); job_factory.SetProtocolHandler("foo", new DummyProtocolHandler); job_factory.AddInterceptor(new DummyInterceptor); TestURLRequest request(GURL("foo://bar"), &delegate); - request.set_context(request_context); + request.set_context(&request_context); request.Start(); MessageLoop::current()->Run(); @@ -168,13 +168,13 @@ TEST(URLRequestJobFactoryTest, InterceptorOverridesProtocolHandler) { TEST(URLRequestJobFactoryTest, InterceptorDoesntInterceptUnknownProtocols) { TestDelegate delegate; - scoped_refptr<URLRequestContext> request_context(new TestURLRequestContext); URLRequestJobFactory job_factory; - request_context->set_job_factory(&job_factory); + TestURLRequestContext request_context; + request_context.set_job_factory(&job_factory); DummyInterceptor* interceptor = new DummyInterceptor; job_factory.AddInterceptor(interceptor); TestURLRequest request(GURL("foo://bar"), &delegate); - request.set_context(request_context); + request.set_context(&request_context); request.Start(); MessageLoop::current()->Run(); @@ -183,14 +183,14 @@ TEST(URLRequestJobFactoryTest, InterceptorDoesntInterceptUnknownProtocols) { TEST(URLRequestJobFactoryTest, InterceptorInterceptsHandledUnknownProtocols) { TestDelegate delegate; - scoped_refptr<URLRequestContext> request_context(new TestURLRequestContext); URLRequestJobFactory job_factory; - request_context->set_job_factory(&job_factory); + TestURLRequestContext request_context; + request_context.set_job_factory(&job_factory); DummyInterceptor* interceptor = new DummyInterceptor; interceptor->handle_all_protocols_ = true; job_factory.AddInterceptor(interceptor); TestURLRequest request(GURL("foo://bar"), &delegate); - request.set_context(request_context); + request.set_context(&request_context); request.Start(); MessageLoop::current()->Run(); diff --git a/net/url_request/url_request_job_unittest.cc b/net/url_request/url_request_job_unittest.cc index 017b98b..75d5c3b 100644 --- a/net/url_request/url_request_job_unittest.cc +++ b/net/url_request/url_request_job_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -39,15 +39,15 @@ const MockTransaction kGZip_Transaction = { } // namespace TEST(URLRequestJob, TransactionNotifiedWhenDone) { - TestDelegate d; - TestURLRequest req(GURL(kGZip_Transaction.url), &d); MockNetworkLayer network_layer; + TestURLRequestContext context; + context.set_http_transaction_factory(&network_layer); + TestDelegate d; + TestURLRequest req(GURL(kGZip_Transaction.url), &d); AddMockTransaction(&kGZip_Transaction); - scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); - context->set_http_transaction_factory(&network_layer); - req.set_context(context); + req.set_context(&context); req.set_method("GET"); req.Start(); @@ -59,17 +59,17 @@ TEST(URLRequestJob, TransactionNotifiedWhenDone) { } TEST(URLRequestJob, SyncTransactionNotifiedWhenDone) { - TestDelegate d; - TestURLRequest req(GURL(kGZip_Transaction.url), &d); MockNetworkLayer network_layer; + TestURLRequestContext context; + context.set_http_transaction_factory(&network_layer); + TestDelegate d; + TestURLRequest req(GURL(kGZip_Transaction.url), &d); MockTransaction transaction(kGZip_Transaction); transaction.test_mode = TEST_MODE_SYNC_ALL; AddMockTransaction(&transaction); - scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); - context->set_http_transaction_factory(&network_layer); - req.set_context(context); + req.set_context(&context); req.set_method("GET"); req.Start(); diff --git a/net/url_request/url_request_test_util.cc b/net/url_request/url_request_test_util.cc index 7a1bc7f..b81996c 100644 --- a/net/url_request/url_request_test_util.cc +++ b/net/url_request/url_request_test_util.cc @@ -162,11 +162,14 @@ void TestURLRequestContext::Init() { TestURLRequest::TestURLRequest(const GURL& url, Delegate* delegate) - : net::URLRequest(url, delegate) { - set_context(new TestURLRequestContext()); + : net::URLRequest(url, delegate), + context_(new TestURLRequestContext) { + set_context(context_.get()); } -TestURLRequest::~TestURLRequest() {} +TestURLRequest::~TestURLRequest() { + set_context(NULL); +} TestURLRequestContextGetter::TestURLRequestContextGetter( const scoped_refptr<base::MessageLoopProxy>& io_message_loop_proxy) @@ -177,8 +180,8 @@ TestURLRequestContextGetter::TestURLRequestContextGetter( TestURLRequestContextGetter::~TestURLRequestContextGetter() {} TestURLRequestContext* TestURLRequestContextGetter::GetURLRequestContext() { - if (!context_) - context_ = new TestURLRequestContext(); + if (!context_.get()) + context_.reset(new TestURLRequestContext); return context_.get(); } diff --git a/net/url_request/url_request_test_util.h b/net/url_request/url_request_test_util.h index 8c065cd..e1f72bb 100644 --- a/net/url_request/url_request_test_util.h +++ b/net/url_request/url_request_test_util.h @@ -58,6 +58,7 @@ class TestURLRequestContext : public net::URLRequestContext { explicit TestURLRequestContext(const std::string& proxy); TestURLRequestContext(const std::string& proxy, net::HostResolver* host_resolver); + virtual ~TestURLRequestContext(); // Configures the proxy server, must not be called after Init(). void SetProxyFromString(const std::string& proxy); @@ -65,9 +66,6 @@ class TestURLRequestContext : public net::URLRequestContext { void Init(); - protected: - virtual ~TestURLRequestContext(); - private: bool initialized_; net::URLRequestContextStorage context_storage_; @@ -93,7 +91,7 @@ class TestURLRequestContextGetter : public net::URLRequestContextGetter { private: const scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; - scoped_refptr<TestURLRequestContext> context_; + scoped_ptr<TestURLRequestContext> context_; }; //----------------------------------------------------------------------------- @@ -102,6 +100,9 @@ class TestURLRequest : public net::URLRequest { public: TestURLRequest(const GURL& url, Delegate* delegate); virtual ~TestURLRequest(); + + private: + const scoped_ptr<net::URLRequestContext> context_; }; //----------------------------------------------------------------------------- diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc index 25b2b0c..fc0645a 100644 --- a/net/url_request/url_request_unittest.cc +++ b/net/url_request/url_request_unittest.cc @@ -406,23 +406,23 @@ class TestJobInterceptor : public URLRequestJobFactory::Interceptor { // Inherit PlatformTest since we require the autorelease pool on Mac OS X.f class URLRequestTest : public PlatformTest { public: - URLRequestTest() : default_context_(new TestURLRequestContext(true)) { - default_context_->set_network_delegate(&default_network_delegate_); - default_context_->Init(); + URLRequestTest() : default_context_(true) { + default_context_.set_network_delegate(&default_network_delegate_); + default_context_.Init(); } // Adds the TestJobInterceptor to the default context. TestJobInterceptor* AddTestInterceptor() { TestJobInterceptor* interceptor = new TestJobInterceptor(); - default_context_->set_job_factory(&job_factory_); + default_context_.set_job_factory(&job_factory_); job_factory_.AddInterceptor(interceptor); return interceptor; } protected: TestNetworkDelegate default_network_delegate_; // must outlive URLRequest - scoped_refptr<TestURLRequestContext> default_context_; URLRequestJobFactory job_factory_; + TestURLRequestContext default_context_; }; class URLRequestTestHTTP : public URLRequestTest { @@ -446,8 +446,8 @@ class URLRequestTestHTTP : public URLRequestTest { bool include_data) { static const char kData[] = "hello world"; TestDelegate d; - TestURLRequest req(redirect_url, &d); - req.set_context(default_context_); + URLRequest req(redirect_url, &d); + req.set_context(&default_context_); req.set_method(request_method); if (include_data) { req.set_upload(CreateSimpleUploadData(kData).get()); @@ -493,7 +493,7 @@ class URLRequestTestHTTP : public URLRequestTest { for (int i = 0; i < kIterations; ++i) { TestDelegate d; URLRequest r(test_server_.GetURL("echo"), &d); - r.set_context(default_context_); + r.set_context(&default_context_); r.set_method(method.c_str()); r.AppendBytesToUpload(uploadBytes, kMsgSize); @@ -514,7 +514,7 @@ class URLRequestTestHTTP : public URLRequestTest { delete[] uploadBytes; } - void AddChunksToUpload(TestURLRequest* r) { + void AddChunksToUpload(URLRequest* r) { r->AppendChunkToUpload("a", 1, false); r->AppendChunkToUpload("bcd", 3, false); r->AppendChunkToUpload("this is a longer chunk than before.", 35, false); @@ -523,7 +523,7 @@ class URLRequestTestHTTP : public URLRequestTest { r->AppendChunkToUpload("2323", 4, true); } - void VerifyReceivedDataMatchesChunks(TestURLRequest* r, TestDelegate* d) { + void VerifyReceivedDataMatchesChunks(URLRequest* r, TestDelegate* d) { // This should match the chunks sent by AddChunksToUpload(). const char* expected_data = "abcdthis is a longer chunk than before.\r\n\r\n02323"; @@ -550,15 +550,15 @@ TEST_F(URLRequestTestHTTP, FLAKY_ProxyTunnelRedirectTest) { ASSERT_TRUE(test_server_.Start()); TestNetworkDelegate network_delegate; // must outlive URLRequest - scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); - context->SetProxyFromString(test_server_.host_port_pair().ToString()); - context->set_network_delegate(&network_delegate); - context->Init(); + TestURLRequestContext context(true); + context.SetProxyFromString(test_server_.host_port_pair().ToString()); + context.set_network_delegate(&network_delegate); + context.Init(); TestDelegate d; { URLRequest r(GURL("https://www.redirect.com/"), &d); - r.set_context(context); + r.set_context(&context); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -580,15 +580,15 @@ TEST_F(URLRequestTestHTTP, DISABLED_NetworkDelegateTunnelConnectionFailed) { ASSERT_TRUE(test_server_.Start()); TestNetworkDelegate network_delegate; // must outlive URLRequest - scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); - context->SetProxyFromString(test_server_.host_port_pair().ToString()); - context->set_network_delegate(&network_delegate); - context->Init(); + TestURLRequestContext context(true); + context.SetProxyFromString(test_server_.host_port_pair().ToString()); + context.set_network_delegate(&network_delegate); + context.Init(); TestDelegate d; { URLRequest r(GURL("https://www.redirect.com/"), &d); - r.set_context(context); + r.set_context(&context); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -613,14 +613,14 @@ TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequest) { BlockingNetworkDelegate network_delegate; network_delegate.set_callback_retval(ERR_EMPTY_RESPONSE); - scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); - context->SetProxyFromString(test_server_.host_port_pair().ToString()); - context->set_network_delegate(&network_delegate); - context->Init(); + TestURLRequestContext context(true); + context.SetProxyFromString(test_server_.host_port_pair().ToString()); + context.set_network_delegate(&network_delegate); + context.Init(); { - TestURLRequest r(test_server_.GetURL(""), &d); - r.set_context(context); + URLRequest r(test_server_.GetURL(""), &d); + r.set_context(&context); r.Start(); MessageLoop::current()->Run(); @@ -641,14 +641,14 @@ TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously) { BlockingNetworkDelegate network_delegate; network_delegate.set_retval(ERR_EMPTY_RESPONSE); - scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); - context->SetProxyFromString(test_server_.host_port_pair().ToString()); - context->set_network_delegate(&network_delegate); - context->Init(); + TestURLRequestContext context(true); + context.SetProxyFromString(test_server_.host_port_pair().ToString()); + context.set_network_delegate(&network_delegate); + context.Init(); { - TestURLRequest r(test_server_.GetURL(""), &d); - r.set_context(context); + URLRequest r(test_server_.GetURL(""), &d); + r.set_context(&context); r.Start(); MessageLoop::current()->Run(); @@ -671,15 +671,15 @@ TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequest) { GURL redirect_url(test_server_.GetURL("simple.html")); network_delegate.set_redirect_url(redirect_url); - scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); - context->SetProxyFromString(test_server_.host_port_pair().ToString()); - context->set_network_delegate(&network_delegate); - context->Init(); + TestURLRequestContext context(true); + context.SetProxyFromString(test_server_.host_port_pair().ToString()); + context.set_network_delegate(&network_delegate); + context.Init(); { GURL original_url(test_server_.GetURL("empty.html")); - TestURLRequest r(original_url, &d); - r.set_context(context); + URLRequest r(original_url, &d); + r.set_context(&context); r.Start(); MessageLoop::current()->Run(); @@ -706,15 +706,15 @@ TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequestSynchronously) { network_delegate.set_redirect_url(redirect_url); network_delegate.set_retval(OK); - scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); - context->SetProxyFromString(test_server_.host_port_pair().ToString()); - context->set_network_delegate(&network_delegate); - context->Init(); + TestURLRequestContext context(true); + context.SetProxyFromString(test_server_.host_port_pair().ToString()); + context.set_network_delegate(&network_delegate); + context.Init(); { GURL original_url(test_server_.GetURL("empty.html")); - TestURLRequest r(original_url, &d); - r.set_context(context); + URLRequest r(original_url, &d); + r.set_context(&context); r.Start(); MessageLoop::current()->Run(); @@ -741,14 +741,14 @@ TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequestPost) { GURL redirect_url(test_server_.GetURL("echo")); network_delegate.set_redirect_url(redirect_url); - scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); - context->set_network_delegate(&network_delegate); - context->Init(); + TestURLRequestContext context(true); + context.set_network_delegate(&network_delegate); + context.Init(); { GURL original_url(test_server_.GetURL("empty.html")); - TestURLRequest r(original_url, &d); - r.set_context(context); + URLRequest r(original_url, &d); + r.set_context(&context); r.set_method("POST"); r.set_upload(CreateSimpleUploadData(kData).get()); HttpRequestHeaders headers; @@ -783,16 +783,16 @@ TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncNoAction) { network_delegate.set_auth_retval( NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION); - scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); - context->set_network_delegate(&network_delegate); - context->Init(); + TestURLRequestContext context(true); + context.set_network_delegate(&network_delegate); + context.Init(); d.set_credentials(AuthCredentials(kUser, kSecret)); { GURL url(test_server_.GetURL("auth-basic")); - TestURLRequest r(url, &d); - r.set_context(context); + URLRequest r(url, &d); + r.set_context(&context); r.Start(); MessageLoop::current()->Run(); @@ -818,14 +818,14 @@ TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncSetAuth) { network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret)); - scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); - context->set_network_delegate(&network_delegate); - context->Init(); + TestURLRequestContext context(true); + context.set_network_delegate(&network_delegate); + context.Init(); { GURL url(test_server_.GetURL("auth-basic")); - TestURLRequest r(url, &d); - r.set_context(context); + URLRequest r(url, &d); + r.set_context(&context); r.Start(); MessageLoop::current()->Run(); @@ -849,14 +849,14 @@ TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncCancel) { network_delegate.set_auth_retval( NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); - scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); - context->set_network_delegate(&network_delegate); - context->Init(); + TestURLRequestContext context(true); + context.set_network_delegate(&network_delegate); + context.Init(); { GURL url(test_server_.GetURL("auth-basic")); - TestURLRequest r(url, &d); - r.set_context(context); + URLRequest r(url, &d); + r.set_context(&context); r.Start(); MessageLoop::current()->Run(); @@ -884,16 +884,16 @@ TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredAsyncNoAction) { network_delegate.set_auth_callback_retval( NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION); - scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); - context->set_network_delegate(&network_delegate); - context->Init(); + TestURLRequestContext context(true); + context.set_network_delegate(&network_delegate); + context.Init(); d.set_credentials(AuthCredentials(kUser, kSecret)); { GURL url(test_server_.GetURL("auth-basic")); - TestURLRequest r(url, &d); - r.set_context(context); + URLRequest r(url, &d); + r.set_context(&context); r.Start(); MessageLoop::current()->Run(); @@ -922,14 +922,14 @@ TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredAsyncSetAuth) { AuthCredentials auth_credentials(kUser, kSecret); network_delegate.set_auth_credentials(auth_credentials); - scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); - context->set_network_delegate(&network_delegate); - context->Init(); + TestURLRequestContext context(true); + context.set_network_delegate(&network_delegate); + context.Init(); { GURL url(test_server_.GetURL("auth-basic")); - TestURLRequest r(url, &d); - r.set_context(context); + URLRequest r(url, &d); + r.set_context(&context); r.Start(); MessageLoop::current()->Run(); @@ -956,14 +956,14 @@ TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredAsyncCancel) { network_delegate.set_auth_callback_retval( NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); - scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); - context->set_network_delegate(&network_delegate); - context->Init(); + TestURLRequestContext context(true); + context.set_network_delegate(&network_delegate); + context.Init(); { GURL url(test_server_.GetURL("auth-basic")); - TestURLRequest r(url, &d); - r.set_context(context); + URLRequest r(url, &d); + r.set_context(&context); r.Start(); MessageLoop::current()->Run(); @@ -988,13 +988,13 @@ TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting1) { network_delegate.BlockOn( BlockingNetworkDelegateWithManualCallback::ON_BEFORE_URL_REQUEST); - scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); - context->set_network_delegate(&network_delegate); - context->Init(); + TestURLRequestContext context(true); + context.set_network_delegate(&network_delegate); + context.Init(); { - TestURLRequest r(test_server_.GetURL(""), &d); - r.set_context(context); + URLRequest r(test_server_.GetURL(""), &d); + r.set_context(&context); r.Start(); network_delegate.WaitForState( @@ -1023,13 +1023,13 @@ TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting2) { network_delegate.BlockOn( BlockingNetworkDelegateWithManualCallback::ON_BEFORE_SEND_HEADERS); - scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); - context->set_network_delegate(&network_delegate); - context->Init(); + TestURLRequestContext context(true); + context.set_network_delegate(&network_delegate); + context.Init(); { - TestURLRequest r(test_server_.GetURL(""), &d); - r.set_context(context); + URLRequest r(test_server_.GetURL(""), &d); + r.set_context(&context); r.Start(); network_delegate.WaitForState( @@ -1058,13 +1058,13 @@ TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting3) { network_delegate.BlockOn( BlockingNetworkDelegateWithManualCallback::ON_HEADERS_RECEIVED); - scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); - context->set_network_delegate(&network_delegate); - context->Init(); + TestURLRequestContext context(true); + context.set_network_delegate(&network_delegate); + context.Init(); { - TestURLRequest r(test_server_.GetURL(""), &d); - r.set_context(context); + URLRequest r(test_server_.GetURL(""), &d); + r.set_context(&context); r.Start(); network_delegate.WaitForState( @@ -1093,13 +1093,13 @@ TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting4) { network_delegate.BlockOn( BlockingNetworkDelegateWithManualCallback::ON_AUTH_REQUIRED); - scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); - context->set_network_delegate(&network_delegate); - context->Init(); + TestURLRequestContext context(true); + context.set_network_delegate(&network_delegate); + context.Init(); { - TestURLRequest r(test_server_.GetURL("auth-basic"), &d); - r.set_context(context); + URLRequest r(test_server_.GetURL("auth-basic"), &d); + r.set_context(&context); r.Start(); network_delegate.WaitForState( @@ -1124,15 +1124,15 @@ TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) { ASSERT_TRUE(test_server_.Start()); TestNetworkDelegate network_delegate; // must outlive URLRequest - scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); - context->SetProxyFromString(test_server_.host_port_pair().ToString()); - context->set_network_delegate(&network_delegate); - context->Init(); + TestURLRequestContext context(true); + context.SetProxyFromString(test_server_.host_port_pair().ToString()); + context.set_network_delegate(&network_delegate); + context.Init(); TestDelegate d; { URLRequest r(GURL("https://www.server-auth.com/"), &d); - r.set_context(context); + r.set_context(&context); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -1149,8 +1149,8 @@ TEST_F(URLRequestTestHTTP, GetTest_NoCache) { TestDelegate d; { - TestURLRequest r(test_server_.GetURL(""), &d); - r.set_context(default_context_); + URLRequest r(test_server_.GetURL(""), &d); + r.set_context(&default_context_); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -1174,8 +1174,8 @@ TEST_F(URLRequestTestHTTP, GetTest) { TestDelegate d; { - TestURLRequest r(test_server_.GetURL(""), &d); - r.set_context(default_context_); + URLRequest r(test_server_.GetURL(""), &d); + r.set_context(&default_context_); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -1217,13 +1217,12 @@ TEST_F(URLRequestTestHTTP, GetZippedTest) { test_parameters[i]); TestNetworkDelegate network_delegate; // must outlive URLRequest - scoped_refptr<TestURLRequestContext> context( - new TestURLRequestContext(true)); - context->set_network_delegate(&network_delegate); - context->Init(); + TestURLRequestContext context(true); + context.set_network_delegate(&network_delegate); + context.Init(); - TestURLRequest r(test_server_.GetURL(test_file), &d); - r.set_context(context); + URLRequest r(test_server_.GetURL(test_file), &d); + r.set_context(&context); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -1261,9 +1260,9 @@ TEST_F(URLRequestTestHTTP, DISABLED_HTTPSToHTTPRedirectNoRefererTest) { // server should not be sent the referer. GURL http_destination = test_server_.GetURL(""); TestDelegate d; - TestURLRequest req(https_test_server.GetURL( + URLRequest req(https_test_server.GetURL( "server-redirect?" + http_destination.spec()), &d); - req.set_context(default_context_); + req.set_context(&default_context_); req.set_referrer("https://www.referrer.com/"); req.Start(); MessageLoop::current()->Run(); @@ -1283,8 +1282,8 @@ TEST_F(URLRequestTestHTTP, MultipleRedirectTest) { GURL original_url = test_server_.GetURL( "server-redirect?" + middle_redirect_url.spec()); TestDelegate d; - TestURLRequest req(original_url, &d); - req.set_context(default_context_); + URLRequest req(original_url, &d); + req.set_context(&default_context_); req.Start(); MessageLoop::current()->Run(); @@ -1300,15 +1299,15 @@ TEST_F(URLRequestTestHTTP, MultipleRedirectTest) { class HTTPSRequestTest : public testing::Test { public: - HTTPSRequestTest() : default_context_(new TestURLRequestContext(true)) { - default_context_->set_network_delegate(&default_network_delegate_); - default_context_->Init(); + HTTPSRequestTest() : default_context_(true) { + default_context_.set_network_delegate(&default_network_delegate_); + default_context_.Init(); } virtual ~HTTPSRequestTest() {} protected: TestNetworkDelegate default_network_delegate_; // must outlive URLRequest - scoped_refptr<TestURLRequestContext> default_context_; + TestURLRequestContext default_context_; }; // This test was disabled because it made chrome_frame_net_tests hang @@ -1321,8 +1320,8 @@ TEST_F(HTTPSRequestTest, DISABLED_HTTPSGetTest) { TestDelegate d; { - TestURLRequest r(test_server.GetURL(""), &d); - r.set_context(default_context_); + URLRequest r(test_server.GetURL(""), &d); + r.set_context(&default_context_); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -1351,8 +1350,8 @@ TEST_F(HTTPSRequestTest, HTTPSMismatchedTest) { TestDelegate d; { d.set_allow_certificate_errors(err_allowed); - TestURLRequest r(test_server.GetURL(""), &d); - r.set_context(default_context_); + URLRequest r(test_server.GetURL(""), &d); + r.set_context(&default_context_); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -1386,8 +1385,8 @@ TEST_F(HTTPSRequestTest, HTTPSExpiredTest) { TestDelegate d; { d.set_allow_certificate_errors(err_allowed); - TestURLRequest r(test_server.GetURL(""), &d); - r.set_context(default_context_); + URLRequest r(test_server.GetURL(""), &d); + r.set_context(&default_context_); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -1442,15 +1441,15 @@ static const char kOCSPTestCertPolicy[] = "1.3.6.1.4.1.11129.2.4.1"; class HTTPSOCSPTest : public HTTPSRequestTest { public: HTTPSOCSPTest() - : context_(new TestURLRequestContext(true)), + : context_(true), ev_test_policy_(EVRootCAMetadata::GetInstance(), kOCSPTestCertFingerprint, kOCSPTestCertPolicy) { } virtual void SetUp() OVERRIDE { - SetupContext(context_); - context_->Init(); + SetupContext(&context_); + context_.Init(); scoped_refptr<net::X509Certificate> root_cert = ImportCertFromFile(GetTestCertsDirectory(), "ocsp-test-root.pem"); @@ -1458,7 +1457,7 @@ class HTTPSOCSPTest : public HTTPSRequestTest { test_root_.reset(new ScopedTestRoot(root_cert)); #if defined(USE_NSS) - SetURLRequestContextForNSSHttpIO(context_.get()); + SetURLRequestContextForNSSHttpIO(&context_); EnsureNSSHttpIOInit(); #endif } @@ -1472,7 +1471,7 @@ class HTTPSOCSPTest : public HTTPSRequestTest { TestDelegate d; d.set_allow_certificate_errors(true); URLRequest r(test_server.GetURL(""), &d); - r.set_context(context_.get()); + r.set_context(&context_); r.Start(); MessageLoop::current()->Run(); @@ -1498,7 +1497,7 @@ class HTTPSOCSPTest : public HTTPSRequestTest { } scoped_ptr<ScopedTestRoot> test_root_; - scoped_refptr<TestURLRequestContext> context_; + TestURLRequestContext context_; ScopedTestEVPolicy ev_test_policy_; }; @@ -1735,11 +1734,11 @@ TEST_F(HTTPSRequestTest, SSLv3Fallback) { ASSERT_TRUE(test_server.Start()); TestDelegate d; - scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); - context->Init(); + TestURLRequestContext context(true); + context.Init(); d.set_allow_certificate_errors(true); URLRequest r(test_server.GetURL(""), &d); - r.set_context(context.get()); + r.set_context(&context); r.Start(); MessageLoop::current()->Run(); @@ -1767,18 +1766,18 @@ TEST_F(HTTPSRequestTest, HTTPSPreloadedHSTSTest) { MockHostResolver host_resolver; host_resolver.rules()->AddRule("www.google.com", "127.0.0.1"); TestNetworkDelegate network_delegate; // must outlive URLRequest - scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); - context->set_network_delegate(&network_delegate); - context->set_host_resolver(&host_resolver); + TestURLRequestContext context(true); + context.set_network_delegate(&network_delegate); + context.set_host_resolver(&host_resolver); TransportSecurityState transport_security_state; - context->set_transport_security_state(&transport_security_state); - context->Init(); + context.set_transport_security_state(&transport_security_state); + context.Init(); TestDelegate d; - TestURLRequest r(GURL(StringPrintf("https://www.google.com:%d", + URLRequest r(GURL(StringPrintf("https://www.google.com:%d", test_server.host_port_pair().port())), &d); - r.set_context(context); + r.set_context(&context); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -1810,21 +1809,21 @@ TEST_F(HTTPSRequestTest, HTTPSErrorsNoClobberTSSTest) { MockHostResolver host_resolver; host_resolver.rules()->AddRule("www.google.com", "127.0.0.1"); TestNetworkDelegate network_delegate; // must outlive URLRequest - scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); - context->set_network_delegate(&network_delegate); - context->set_host_resolver(&host_resolver); + TestURLRequestContext context(true); + context.set_network_delegate(&network_delegate); + context.set_host_resolver(&host_resolver); TransportSecurityState transport_security_state; TransportSecurityState::DomainState domain_state; EXPECT_TRUE(transport_security_state.GetDomainState("www.google.com", true, &domain_state)); - context->set_transport_security_state(&transport_security_state); - context->Init(); + context.set_transport_security_state(&transport_security_state); + context.Init(); TestDelegate d; - TestURLRequest r(GURL(StringPrintf("https://www.google.com:%d", + URLRequest r(GURL(StringPrintf("https://www.google.com:%d", test_server.host_port_pair().port())), &d); - r.set_context(context); + r.set_context(&context); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -1886,8 +1885,8 @@ TEST_F(HTTPSRequestTest, ClientAuthTest) { SSLClientAuthTestDelegate d; { - TestURLRequest r(test_server.GetURL(""), &d); - r.set_context(default_context_); + URLRequest r(test_server.GetURL(""), &d); + r.set_context(&default_context_); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -1924,8 +1923,8 @@ TEST_F(HTTPSRequestTest, ResumeTest) { { TestDelegate d; - TestURLRequest r(test_server.GetURL("ssl-session-cache"), &d); - r.set_context(default_context_); + URLRequest r(test_server.GetURL("ssl-session-cache"), &d); + r.set_context(&default_context_); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -1935,13 +1934,13 @@ TEST_F(HTTPSRequestTest, ResumeTest) { EXPECT_EQ(1, d.response_started_count()); } - reinterpret_cast<HttpCache*>(default_context_->http_transaction_factory())-> + reinterpret_cast<HttpCache*>(default_context_.http_transaction_factory())-> CloseAllConnections(); { TestDelegate d; - TestURLRequest r(test_server.GetURL("ssl-session-cache"), &d); - r.set_context(default_context_); + URLRequest r(test_server.GetURL("ssl-session-cache"), &d); + r.set_context(&default_context_); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -1991,8 +1990,8 @@ TEST_F(HTTPSRequestTest, SSLSessionCacheShardTest) { { TestDelegate d; - TestURLRequest r(test_server.GetURL("ssl-session-cache"), &d); - r.set_context(default_context_); + URLRequest r(test_server.GetURL("ssl-session-cache"), &d); + r.set_context(&default_context_); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -2004,26 +2003,26 @@ TEST_F(HTTPSRequestTest, SSLSessionCacheShardTest) { // Now create a new HttpCache with a different ssl_session_cache_shard value. HttpNetworkSession::Params params; - params.host_resolver = default_context_->host_resolver(); - params.cert_verifier = default_context_->cert_verifier(); - params.proxy_service = default_context_->proxy_service(); - params.ssl_config_service = default_context_->ssl_config_service(); + params.host_resolver = default_context_.host_resolver(); + params.cert_verifier = default_context_.cert_verifier(); + params.proxy_service = default_context_.proxy_service(); + params.ssl_config_service = default_context_.ssl_config_service(); params.http_auth_handler_factory = - default_context_->http_auth_handler_factory(); - params.network_delegate = default_context_->network_delegate(); - params.http_server_properties = default_context_->http_server_properties(); + default_context_.http_auth_handler_factory(); + params.network_delegate = default_context_.network_delegate(); + params.http_server_properties = default_context_.http_server_properties(); params.ssl_session_cache_shard = "alternate"; scoped_ptr<net::HttpCache> cache(new net::HttpCache( new net::HttpNetworkSession(params), net::HttpCache::DefaultBackend::InMemory(0))); - default_context_->set_http_transaction_factory(cache.get()); + default_context_.set_http_transaction_factory(cache.get()); { TestDelegate d; - TestURLRequest r(test_server.GetURL("ssl-session-cache"), &d); - r.set_context(default_context_); + URLRequest r(test_server.GetURL("ssl-session-cache"), &d); + r.set_context(&default_context_); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -2060,8 +2059,8 @@ TEST_F(HTTPSRequestTest, SSLSessionCacheShardTest) { TEST_F(URLRequestTestHTTP, CancelTest) { TestDelegate d; { - TestURLRequest r(GURL("http://www.google.com/"), &d); - r.set_context(default_context_); + URLRequest r(GURL("http://www.google.com/"), &d); + r.set_context(&default_context_); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -2083,8 +2082,8 @@ TEST_F(URLRequestTestHTTP, CancelTest2) { TestDelegate d; { - TestURLRequest r(test_server_.GetURL(""), &d); - r.set_context(default_context_); + URLRequest r(test_server_.GetURL(""), &d); + r.set_context(&default_context_); d.set_cancel_in_response_started(true); @@ -2105,8 +2104,8 @@ TEST_F(URLRequestTestHTTP, CancelTest3) { TestDelegate d; { - TestURLRequest r(test_server_.GetURL(""), &d); - r.set_context(default_context_); + URLRequest r(test_server_.GetURL(""), &d); + r.set_context(&default_context_); d.set_cancel_in_received_data(true); @@ -2130,8 +2129,8 @@ TEST_F(URLRequestTestHTTP, CancelTest4) { TestDelegate d; { - TestURLRequest r(test_server_.GetURL(""), &d); - r.set_context(default_context_); + URLRequest r(test_server_.GetURL(""), &d); + r.set_context(&default_context_); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -2158,7 +2157,7 @@ TEST_F(URLRequestTestHTTP, CancelTest5) { { TestDelegate d; URLRequest r(test_server_.GetURL("cachetime"), &d); - r.set_context(default_context_); + r.set_context(&default_context_); r.Start(); MessageLoop::current()->Run(); EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); @@ -2168,7 +2167,7 @@ TEST_F(URLRequestTestHTTP, CancelTest5) { { TestDelegate d; URLRequest r(test_server_.GetURL("cachetime"), &d); - r.set_context(default_context_); + r.set_context(&default_context_); r.Start(); r.Cancel(); MessageLoop::current()->Run(); @@ -2195,8 +2194,8 @@ TEST_F(URLRequestTestHTTP, PostEmptyTest) { TestDelegate d; { - TestURLRequest r(test_server_.GetURL("echo"), &d); - r.set_context(default_context_); + URLRequest r(test_server_.GetURL("echo"), &d); + r.set_context(&default_context_); r.set_method("POST"); r.Start(); @@ -2217,8 +2216,8 @@ TEST_F(URLRequestTestHTTP, PostFileTest) { TestDelegate d; { - TestURLRequest r(test_server_.GetURL("echo"), &d); - r.set_context(default_context_); + URLRequest r(test_server_.GetURL("echo"), &d); + r.set_context(&default_context_); r.set_method("POST"); FilePath dir; @@ -2271,8 +2270,8 @@ TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) { TestDelegate d; { - TestURLRequest r(test_server_.GetURL("echo"), &d); - r.set_context(default_context_); + URLRequest r(test_server_.GetURL("echo"), &d); + r.set_context(&default_context_); r.EnableChunkedUpload(); r.set_method("POST"); AddChunksToUpload(&r); @@ -2290,8 +2289,8 @@ TEST_F(URLRequestTestHTTP, TestPostChunkedDataAfterStart) { TestDelegate d; { - TestURLRequest r(test_server_.GetURL("echo"), &d); - r.set_context(default_context_); + URLRequest r(test_server_.GetURL("echo"), &d); + r.set_context(&default_context_); r.EnableChunkedUpload(); r.set_method("POST"); r.Start(); @@ -2308,8 +2307,8 @@ TEST_F(URLRequestTestHTTP, TestPostChunkedDataAfterStart) { TEST_F(URLRequestTest, AboutBlankTest) { TestDelegate d; { - TestURLRequest r(GURL("about:blank"), &d); - r.set_context(default_context_); + URLRequest r(GURL("about:blank"), &d); + r.set_context(&default_context_); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -2328,7 +2327,7 @@ TEST_F(URLRequestTest, DataURLImageTest) { TestDelegate d; { // Use our nice little Chrome logo. - TestURLRequest r(GURL( + URLRequest r(GURL( "data:image/png;base64," "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAADVklEQVQ4jX2TfUwUBBjG3" "w1y+HGcd9dxhXR8T4awOccJGgOSWclHImznLkTlSw0DDQXkrmgYgbUYnlQTqQxIEVxitD" @@ -2349,7 +2348,7 @@ TEST_F(URLRequestTest, DataURLImageTest) { "moRWRNZr/F1KfVMjW+IKEnv2FwZfKdzt0BQR6lClcZR0EfEXEfv/G6W9iLiIyCoReV5En" "hORIBHx+ufPj/gLB/zGI/G4Bk0AAAAASUVORK5CYII="), &d); - r.set_context(default_context_); + r.set_context(&default_context_); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -2371,8 +2370,8 @@ TEST_F(URLRequestTest, FileTest) { TestDelegate d; { - TestURLRequest r(app_url, &d); - r.set_context(default_context_); + URLRequest r(app_url, &d); + r.set_context(&default_context_); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -2412,8 +2411,8 @@ TEST_F(URLRequestTest, FileTestFullSpecifiedRange) { TestDelegate d; { - TestURLRequest r(temp_url, &d); - r.set_context(default_context_); + URLRequest r(temp_url, &d); + r.set_context(&default_context_); HttpRequestHeaders headers; headers.SetHeader(HttpRequestHeaders::kRange, @@ -2457,8 +2456,8 @@ TEST_F(URLRequestTest, FileTestHalfSpecifiedRange) { TestDelegate d; { - TestURLRequest r(temp_url, &d); - r.set_context(default_context_); + URLRequest r(temp_url, &d); + r.set_context(&default_context_); HttpRequestHeaders headers; headers.SetHeader(HttpRequestHeaders::kRange, @@ -2495,8 +2494,8 @@ TEST_F(URLRequestTest, FileTestMultipleRanges) { TestDelegate d; { - TestURLRequest r(temp_url, &d); - r.set_context(default_context_); + URLRequest r(temp_url, &d); + r.set_context(&default_context_); HttpRequestHeaders headers; headers.SetHeader(HttpRequestHeaders::kRange, @@ -2515,8 +2514,8 @@ TEST_F(URLRequestTest, FileTestMultipleRanges) { TEST_F(URLRequestTest, InvalidUrlTest) { TestDelegate d; { - TestURLRequest r(GURL("invalid url"), &d); - r.set_context(default_context_); + URLRequest r(GURL("invalid url"), &d); + r.set_context(&default_context_); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -2530,8 +2529,8 @@ TEST_F(URLRequestTestHTTP, ResponseHeadersTest) { ASSERT_TRUE(test_server_.Start()); TestDelegate d; - TestURLRequest req(test_server_.GetURL("files/with-headers.html"), &d); - req.set_context(default_context_); + URLRequest req(test_server_.GetURL("files/with-headers.html"), &d); + req.set_context(&default_context_); req.Start(); MessageLoop::current()->Run(); @@ -2592,8 +2591,8 @@ TEST_F(URLRequestTest, ResolveShortcutTest) { TestDelegate d; { - TestURLRequest r(FilePathToFileURL(FilePath(lnk_path)), &d); - r.set_context(default_context_); + URLRequest r(FilePathToFileURL(FilePath(lnk_path)), &d); + r.set_context(&default_context_); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -2630,9 +2629,9 @@ TEST_F(URLRequestTestHTTP, ContentTypeNormalizationTest) { ASSERT_TRUE(test_server_.Start()); TestDelegate d; - TestURLRequest req(test_server_.GetURL( + URLRequest req(test_server_.GetURL( "files/content-type-normalization.html"), &d); - req.set_context(default_context_); + req.set_context(&default_context_); req.Start(); MessageLoop::current()->Run(); @@ -2657,8 +2656,8 @@ TEST_F(URLRequestTest, FileDirCancelTest) { file_path = file_path.Append(FILE_PATH_LITERAL("net")); file_path = file_path.Append(FILE_PATH_LITERAL("data")); - TestURLRequest req(FilePathToFileURL(file_path), &d); - req.set_context(default_context_); + URLRequest req(FilePathToFileURL(file_path), &d); + req.set_context(&default_context_); req.Start(); EXPECT_TRUE(req.is_pending()); @@ -2683,8 +2682,8 @@ TEST_F(URLRequestTest, FileDirRedirectNoCrash) { path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); TestDelegate d; - TestURLRequest req(FilePathToFileURL(path), &d); - req.set_context(default_context_); + URLRequest req(FilePathToFileURL(path), &d); + req.set_context(&default_context_); req.Start(); MessageLoop::current()->Run(); @@ -2698,8 +2697,8 @@ TEST_F(URLRequestTest, FileDirRedirectNoCrash) { // Don't accept the url "file:///" on windows. See http://crbug.com/1474. TEST_F(URLRequestTest, FileDirRedirectSingleSlash) { TestDelegate d; - TestURLRequest req(GURL("file:///"), &d); - req.set_context(default_context_); + URLRequest req(GURL("file:///"), &d); + req.set_context(&default_context_); req.Start(); MessageLoop::current()->Run(); @@ -2712,9 +2711,9 @@ TEST_F(URLRequestTestHTTP, RestrictRedirects) { ASSERT_TRUE(test_server_.Start()); TestDelegate d; - TestURLRequest req(test_server_.GetURL( + URLRequest req(test_server_.GetURL( "files/redirect-to-file.html"), &d); - req.set_context(default_context_); + req.set_context(&default_context_); req.Start(); MessageLoop::current()->Run(); @@ -2726,9 +2725,9 @@ TEST_F(URLRequestTestHTTP, RedirectToInvalidURL) { ASSERT_TRUE(test_server_.Start()); TestDelegate d; - TestURLRequest req(test_server_.GetURL( + URLRequest req(test_server_.GetURL( "files/redirect-to-invalid-url.html"), &d); - req.set_context(default_context_); + req.set_context(&default_context_); req.Start(); MessageLoop::current()->Run(); @@ -2740,8 +2739,8 @@ TEST_F(URLRequestTestHTTP, NoUserPassInReferrer) { ASSERT_TRUE(test_server_.Start()); TestDelegate d; - TestURLRequest req(test_server_.GetURL("echoheader?Referer"), &d); - req.set_context(default_context_); + URLRequest req(test_server_.GetURL("echoheader?Referer"), &d); + req.set_context(&default_context_); req.set_referrer("http://user:pass@foo.com/"); req.Start(); MessageLoop::current()->Run(); @@ -2755,8 +2754,8 @@ TEST_F(URLRequestTestHTTP, CancelRedirect) { TestDelegate d; { d.set_cancel_in_received_redirect(true); - TestURLRequest req(test_server_.GetURL("files/redirect-test.html"), &d); - req.set_context(default_context_); + URLRequest req(test_server_.GetURL("files/redirect-test.html"), &d); + req.set_context(&default_context_); req.Start(); MessageLoop::current()->Run(); @@ -2773,8 +2772,8 @@ TEST_F(URLRequestTestHTTP, DeferredRedirect) { TestDelegate d; { d.set_quit_on_redirect(true); - TestURLRequest req(test_server_.GetURL("files/redirect-test.html"), &d); - req.set_context(default_context_); + URLRequest req(test_server_.GetURL("files/redirect-test.html"), &d); + req.set_context(&default_context_); req.Start(); MessageLoop::current()->Run(); @@ -2806,8 +2805,8 @@ TEST_F(URLRequestTestHTTP, CancelDeferredRedirect) { TestDelegate d; { d.set_quit_on_redirect(true); - TestURLRequest req(test_server_.GetURL("files/redirect-test.html"), &d); - req.set_context(default_context_); + URLRequest req(test_server_.GetURL("files/redirect-test.html"), &d); + req.set_context(&default_context_); req.Start(); MessageLoop::current()->Run(); @@ -2830,7 +2829,7 @@ TEST_F(URLRequestTestHTTP, VaryHeader) { { TestDelegate d; URLRequest req(test_server_.GetURL("echoheadercache?foo"), &d); - req.set_context(default_context_); + req.set_context(&default_context_); HttpRequestHeaders headers; headers.SetHeader("foo", "1"); req.SetExtraRequestHeaders(headers); @@ -2842,7 +2841,7 @@ TEST_F(URLRequestTestHTTP, VaryHeader) { { TestDelegate d; URLRequest req(test_server_.GetURL("echoheadercache?foo"), &d); - req.set_context(default_context_); + req.set_context(&default_context_); HttpRequestHeaders headers; headers.SetHeader("foo", "1"); req.SetExtraRequestHeaders(headers); @@ -2856,7 +2855,7 @@ TEST_F(URLRequestTestHTTP, VaryHeader) { { TestDelegate d; URLRequest req(test_server_.GetURL("echoheadercache?foo"), &d); - req.set_context(default_context_); + req.set_context(&default_context_); HttpRequestHeaders headers; headers.SetHeader("foo", "2"); req.SetExtraRequestHeaders(headers); @@ -2876,7 +2875,7 @@ TEST_F(URLRequestTestHTTP, BasicAuth) { d.set_credentials(AuthCredentials(kUser, kSecret)); URLRequest r(test_server_.GetURL("auth-basic"), &d); - r.set_context(default_context_); + r.set_context(&default_context_); r.Start(); MessageLoop::current()->Run(); @@ -2892,7 +2891,7 @@ TEST_F(URLRequestTestHTTP, BasicAuth) { d.set_credentials(AuthCredentials(kUser, kSecret)); URLRequest r(test_server_.GetURL("auth-basic"), &d); - r.set_context(default_context_); + r.set_context(&default_context_); r.set_load_flags(LOAD_VALIDATE_CACHE); r.Start(); @@ -2917,16 +2916,15 @@ TEST_F(URLRequestTestHTTP, BasicAuthWithCookies) { // Verify that when the transaction is restarted, it includes the new cookie. { TestNetworkDelegate network_delegate; // must outlive URLRequest - scoped_refptr<TestURLRequestContext> context( - new TestURLRequestContext(true)); - context->set_network_delegate(&network_delegate); - context->Init(); + TestURLRequestContext context(true); + context.set_network_delegate(&network_delegate); + context.Init(); TestDelegate d; d.set_credentials(AuthCredentials(kUser, kSecret)); URLRequest r(url_requiring_auth, &d); - r.set_context(context); + r.set_context(&context); r.Start(); MessageLoop::current()->Run(); @@ -2943,19 +2941,19 @@ TEST_F(URLRequestTest, DelayedCookieCallback) { LocalHttpTestServer test_server; ASSERT_TRUE(test_server.Start()); - scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); + TestURLRequestContext context; scoped_refptr<DelayedCookieMonster> delayed_cm = new DelayedCookieMonster(); scoped_refptr<CookieStore> cookie_store = delayed_cm; - context->set_cookie_store(delayed_cm); + context.set_cookie_store(delayed_cm); // Set up a cookie. { TestNetworkDelegate network_delegate; - context->set_network_delegate(&network_delegate); + context.set_network_delegate(&network_delegate); TestDelegate d; URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); - req.set_context(context); + req.set_context(&context); req.Start(); MessageLoop::current()->Run(); EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); @@ -2966,10 +2964,10 @@ TEST_F(URLRequestTest, DelayedCookieCallback) { // Verify that the cookie is set. { TestNetworkDelegate network_delegate; - context->set_network_delegate(&network_delegate); + context.set_network_delegate(&network_delegate); TestDelegate d; - TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); - req.set_context(context); + URLRequest req(test_server.GetURL("echoheader?Cookie"), &d); + req.set_context(&context); req.Start(); MessageLoop::current()->Run(); @@ -2987,10 +2985,10 @@ TEST_F(URLRequestTest, DoNotSendCookies) { // Set up a cookie. { TestNetworkDelegate network_delegate; - default_context_->set_network_delegate(&network_delegate); + default_context_.set_network_delegate(&network_delegate); TestDelegate d; URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); - req.set_context(default_context_); + req.set_context(&default_context_); req.Start(); MessageLoop::current()->Run(); EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); @@ -3000,10 +2998,10 @@ TEST_F(URLRequestTest, DoNotSendCookies) { // Verify that the cookie is set. { TestNetworkDelegate network_delegate; - default_context_->set_network_delegate(&network_delegate); + default_context_.set_network_delegate(&network_delegate); TestDelegate d; - TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); - req.set_context(default_context_); + URLRequest req(test_server.GetURL("echoheader?Cookie"), &d); + req.set_context(&default_context_); req.Start(); MessageLoop::current()->Run(); @@ -3016,11 +3014,11 @@ TEST_F(URLRequestTest, DoNotSendCookies) { // Verify that the cookie isn't sent when LOAD_DO_NOT_SEND_COOKIES is set. { TestNetworkDelegate network_delegate; - default_context_->set_network_delegate(&network_delegate); + default_context_.set_network_delegate(&network_delegate); TestDelegate d; - TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); + URLRequest req(test_server.GetURL("echoheader?Cookie"), &d); req.set_load_flags(LOAD_DO_NOT_SEND_COOKIES); - req.set_context(default_context_); + req.set_context(&default_context_); req.Start(); MessageLoop::current()->Run(); @@ -3032,7 +3030,7 @@ TEST_F(URLRequestTest, DoNotSendCookies) { EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); } - default_context_->set_network_delegate(&default_network_delegate_); + default_context_.set_network_delegate(&default_network_delegate_); } TEST_F(URLRequestTest, DoNotSaveCookies) { @@ -3042,10 +3040,10 @@ TEST_F(URLRequestTest, DoNotSaveCookies) { // Set up a cookie. { TestNetworkDelegate network_delegate; - default_context_->set_network_delegate(&network_delegate); + default_context_.set_network_delegate(&network_delegate); TestDelegate d; URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), &d); - req.set_context(default_context_); + req.set_context(&default_context_); req.Start(); MessageLoop::current()->Run(); @@ -3057,12 +3055,12 @@ TEST_F(URLRequestTest, DoNotSaveCookies) { // Try to set-up another cookie and update the previous cookie. { TestNetworkDelegate network_delegate; - default_context_->set_network_delegate(&network_delegate); + default_context_.set_network_delegate(&network_delegate); TestDelegate d; URLRequest req(test_server.GetURL( "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); req.set_load_flags(LOAD_DO_NOT_SAVE_COOKIES); - req.set_context(default_context_); + req.set_context(&default_context_); req.Start(); MessageLoop::current()->Run(); @@ -3076,10 +3074,10 @@ TEST_F(URLRequestTest, DoNotSaveCookies) { // Verify the cookies weren't saved or updated. { TestNetworkDelegate network_delegate; - default_context_->set_network_delegate(&network_delegate); + default_context_.set_network_delegate(&network_delegate); TestDelegate d; - TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); - req.set_context(default_context_); + URLRequest req(test_server.GetURL("echoheader?Cookie"), &d); + req.set_context(&default_context_); req.Start(); MessageLoop::current()->Run(); @@ -3093,7 +3091,7 @@ TEST_F(URLRequestTest, DoNotSaveCookies) { EXPECT_EQ(0, network_delegate.set_cookie_count()); } - default_context_->set_network_delegate(&default_network_delegate_); + default_context_.set_network_delegate(&default_network_delegate_); } TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { @@ -3103,10 +3101,10 @@ TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { // Set up a cookie. { TestNetworkDelegate network_delegate; - default_context_->set_network_delegate(&network_delegate); + default_context_.set_network_delegate(&network_delegate); TestDelegate d; URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); - req.set_context(default_context_); + req.set_context(&default_context_); req.Start(); MessageLoop::current()->Run(); @@ -3117,10 +3115,10 @@ TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { // Verify that the cookie is set. { TestNetworkDelegate network_delegate; - default_context_->set_network_delegate(&network_delegate); + default_context_.set_network_delegate(&network_delegate); TestDelegate d; - TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); - req.set_context(default_context_); + URLRequest req(test_server.GetURL("echoheader?Cookie"), &d); + req.set_context(&default_context_); req.Start(); MessageLoop::current()->Run(); @@ -3134,11 +3132,11 @@ TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { // Verify that the cookie isn't sent. { TestNetworkDelegate network_delegate; - default_context_->set_network_delegate(&network_delegate); + default_context_.set_network_delegate(&network_delegate); TestDelegate d; network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); - TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); - req.set_context(default_context_); + URLRequest req(test_server.GetURL("echoheader?Cookie"), &d); + req.set_context(&default_context_); req.Start(); MessageLoop::current()->Run(); @@ -3149,7 +3147,7 @@ TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); } - default_context_->set_network_delegate(&default_network_delegate_); + default_context_.set_network_delegate(&default_network_delegate_); } TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { @@ -3159,10 +3157,10 @@ TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { // Set up a cookie. { TestNetworkDelegate network_delegate; - default_context_->set_network_delegate(&network_delegate); + default_context_.set_network_delegate(&network_delegate); TestDelegate d; URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), &d); - req.set_context(default_context_); + req.set_context(&default_context_); req.Start(); MessageLoop::current()->Run(); @@ -3173,12 +3171,12 @@ TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { // Try to set-up another cookie and update the previous cookie. { TestNetworkDelegate network_delegate; - default_context_->set_network_delegate(&network_delegate); + default_context_.set_network_delegate(&network_delegate); TestDelegate d; network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); URLRequest req(test_server.GetURL( "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); - req.set_context(default_context_); + req.set_context(&default_context_); req.Start(); MessageLoop::current()->Run(); @@ -3191,10 +3189,10 @@ TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { // Verify the cookies weren't saved or updated. { TestNetworkDelegate network_delegate; - default_context_->set_network_delegate(&network_delegate); + default_context_.set_network_delegate(&network_delegate); TestDelegate d; - TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); - req.set_context(default_context_); + URLRequest req(test_server.GetURL("echoheader?Cookie"), &d); + req.set_context(&default_context_); req.Start(); MessageLoop::current()->Run(); @@ -3207,7 +3205,7 @@ TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); } - default_context_->set_network_delegate(&default_network_delegate_); + default_context_.set_network_delegate(&default_network_delegate_); } TEST_F(URLRequestTest, DoNotSaveEmptyCookies) { @@ -3217,10 +3215,10 @@ TEST_F(URLRequestTest, DoNotSaveEmptyCookies) { // Set up an empty cookie. { TestNetworkDelegate network_delegate; - default_context_->set_network_delegate(&network_delegate); + default_context_.set_network_delegate(&network_delegate); TestDelegate d; URLRequest req(test_server.GetURL("set-cookie"), &d); - req.set_context(default_context_); + req.set_context(&default_context_); req.Start(); MessageLoop::current()->Run(); @@ -3229,7 +3227,7 @@ TEST_F(URLRequestTest, DoNotSaveEmptyCookies) { EXPECT_EQ(0, network_delegate.set_cookie_count()); } - default_context_->set_network_delegate(&default_network_delegate_); + default_context_.set_network_delegate(&default_network_delegate_); } TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { @@ -3239,10 +3237,10 @@ TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { // Set up a cookie. { TestNetworkDelegate network_delegate; - default_context_->set_network_delegate(&network_delegate); + default_context_.set_network_delegate(&network_delegate); TestDelegate d; URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); - req.set_context(default_context_); + req.set_context(&default_context_); req.Start(); MessageLoop::current()->Run(); @@ -3253,10 +3251,10 @@ TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { // Verify that the cookie is set. { TestNetworkDelegate network_delegate; - default_context_->set_network_delegate(&network_delegate); + default_context_.set_network_delegate(&network_delegate); TestDelegate d; - TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); - req.set_context(default_context_); + URLRequest req(test_server.GetURL("echoheader?Cookie"), &d); + req.set_context(&default_context_); req.Start(); MessageLoop::current()->Run(); @@ -3270,11 +3268,11 @@ TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { // Verify that the cookie isn't sent. { TestNetworkDelegate network_delegate; - default_context_->set_network_delegate(&network_delegate); + default_context_.set_network_delegate(&network_delegate); TestDelegate d; network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); - TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); - req.set_context(default_context_); + URLRequest req(test_server.GetURL("echoheader?Cookie"), &d); + req.set_context(&default_context_); req.Start(); MessageLoop::current()->Run(); @@ -3285,7 +3283,7 @@ TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); } - default_context_->set_network_delegate(&default_network_delegate_); + default_context_.set_network_delegate(&default_network_delegate_); } TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { @@ -3295,10 +3293,10 @@ TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { // Set up a cookie. { TestNetworkDelegate network_delegate; - default_context_->set_network_delegate(&network_delegate); + default_context_.set_network_delegate(&network_delegate); TestDelegate d; URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), &d); - req.set_context(default_context_); + req.set_context(&default_context_); req.Start(); MessageLoop::current()->Run(); @@ -3309,12 +3307,12 @@ TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { // Try to set-up another cookie and update the previous cookie. { TestNetworkDelegate network_delegate; - default_context_->set_network_delegate(&network_delegate); + default_context_.set_network_delegate(&network_delegate); TestDelegate d; network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); URLRequest req(test_server.GetURL( "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); - req.set_context(default_context_); + req.set_context(&default_context_); req.Start(); MessageLoop::current()->Run(); @@ -3326,10 +3324,10 @@ TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { // Verify the cookies weren't saved or updated. { TestNetworkDelegate network_delegate; - default_context_->set_network_delegate(&network_delegate); + default_context_.set_network_delegate(&network_delegate); TestDelegate d; - TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); - req.set_context(default_context_); + URLRequest req(test_server.GetURL("echoheader?Cookie"), &d); + req.set_context(&default_context_); req.Start(); MessageLoop::current()->Run(); @@ -3342,7 +3340,7 @@ TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); } - default_context_->set_network_delegate(&default_network_delegate_); + default_context_.set_network_delegate(&default_network_delegate_); } void CheckCookiePolicyCallback(bool* was_run, const CookieList& cookies) { @@ -3359,12 +3357,12 @@ TEST_F(URLRequestTest, CookiePolicy_ForceSession) { // Set up a cookie. { TestNetworkDelegate network_delegate; - default_context_->set_network_delegate(&network_delegate); + default_context_.set_network_delegate(&network_delegate); TestDelegate d; network_delegate.set_cookie_options(TestNetworkDelegate::FORCE_SESSION); URLRequest req(test_server.GetURL( "set-cookie?A=1;expires=\"Fri, 05 Feb 2010 23:42:01 GMT\""), &d); - req.set_context(default_context_); + req.set_context(&default_context_); req.Start(); // Triggers an asynchronous cookie policy check. MessageLoop::current()->Run(); @@ -3372,11 +3370,11 @@ TEST_F(URLRequestTest, CookiePolicy_ForceSession) { EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); } - default_context_->set_network_delegate(&default_network_delegate_); + default_context_.set_network_delegate(&default_network_delegate_); // Now, check the cookie store. bool was_run = false; - default_context_->cookie_store()->GetCookieMonster()->GetAllCookiesAsync( + default_context_.cookie_store()->GetCookieMonster()->GetAllCookiesAsync( base::Bind(&CheckCookiePolicyCallback, &was_run)); MessageLoop::current()->RunAllPending(); DCHECK(was_run); @@ -3392,8 +3390,8 @@ TEST_F(URLRequestTestHTTP, Post302RedirectGet) { const char kData[] = "hello world"; TestDelegate d; - TestURLRequest req(test_server_.GetURL("files/redirect-to-echoall"), &d); - req.set_context(default_context_); + URLRequest req(test_server_.GetURL("files/redirect-to-echoall"), &d); + req.set_context(&default_context_); req.set_method("POST"); req.set_upload(CreateSimpleUploadData(kData)); @@ -3479,8 +3477,8 @@ TEST_F(URLRequestTestHTTP, InterceptPost302RedirectGet) { const char kData[] = "hello world"; TestDelegate d; - TestURLRequest req(test_server_.GetURL("empty.html"), &d); - req.set_context(default_context_); + URLRequest req(test_server_.GetURL("empty.html"), &d); + req.set_context(&default_context_); req.set_method("POST"); req.set_upload(CreateSimpleUploadData(kData).get()); HttpRequestHeaders headers; @@ -3503,8 +3501,8 @@ TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) { const char kData[] = "hello world"; TestDelegate d; - TestURLRequest req(test_server_.GetURL("empty.html"), &d); - req.set_context(default_context_); + URLRequest req(test_server_.GetURL("empty.html"), &d); + req.set_context(&default_context_); req.set_method("POST"); req.set_upload(CreateSimpleUploadData(kData).get()); HttpRequestHeaders headers; @@ -3723,8 +3721,8 @@ TEST_F(URLRequestTest, Intercept) { interceptor.main_data_ = TestInterceptor::ok_data(); TestDelegate d; - TestURLRequest req(GURL("http://test_intercept/foo"), &d); - req.set_context(default_context_); + URLRequest req(GURL("http://test_intercept/foo"), &d); + req.set_context(&default_context_); base::SupportsUserData::Data* user_data0 = new base::SupportsUserData::Data(); base::SupportsUserData::Data* user_data1 = new base::SupportsUserData::Data(); base::SupportsUserData::Data* user_data2 = new base::SupportsUserData::Data(); @@ -3765,8 +3763,8 @@ TEST_F(URLRequestTest, InterceptRedirect) { interceptor.redirect_data_ = TestInterceptor::ok_data(); TestDelegate d; - TestURLRequest req(GURL("http://test_intercept/foo"), &d); - req.set_context(default_context_); + URLRequest req(GURL("http://test_intercept/foo"), &d); + req.set_context(&default_context_); req.set_method("GET"); req.Start(); MessageLoop::current()->Run(); @@ -3799,8 +3797,8 @@ TEST_F(URLRequestTest, InterceptServerError) { interceptor.final_data_ = TestInterceptor::ok_data(); TestDelegate d; - TestURLRequest req(GURL("http://test_intercept/foo"), &d); - req.set_context(default_context_); + URLRequest req(GURL("http://test_intercept/foo"), &d); + req.set_context(&default_context_); req.set_method("GET"); req.Start(); MessageLoop::current()->Run(); @@ -3829,8 +3827,8 @@ TEST_F(URLRequestTest, InterceptNetworkError) { interceptor.final_data_ = TestInterceptor::ok_data(); TestDelegate d; - TestURLRequest req(GURL("http://test_intercept/foo"), &d); - req.set_context(default_context_); + URLRequest req(GURL("http://test_intercept/foo"), &d); + req.set_context(&default_context_); req.set_method("GET"); req.Start(); MessageLoop::current()->Run(); @@ -3859,8 +3857,8 @@ TEST_F(URLRequestTest, InterceptRestartRequired) { interceptor.main_data_ = TestInterceptor::ok_data(); TestDelegate d; - TestURLRequest req(GURL("http://test_intercept/foo"), &d); - req.set_context(default_context_); + URLRequest req(GURL("http://test_intercept/foo"), &d); + req.set_context(&default_context_); req.set_method("GET"); req.Start(); MessageLoop::current()->Run(); @@ -3891,8 +3889,8 @@ TEST_F(URLRequestTest, InterceptRespectsCancelMain) { interceptor.final_data_ = TestInterceptor::ok_data(); TestDelegate d; - TestURLRequest req(GURL("http://test_intercept/foo"), &d); - req.set_context(default_context_); + URLRequest req(GURL("http://test_intercept/foo"), &d); + req.set_context(&default_context_); req.set_method("GET"); req.Start(); MessageLoop::current()->Run(); @@ -3923,8 +3921,8 @@ TEST_F(URLRequestTest, InterceptRespectsCancelRedirect) { interceptor.final_data_ = TestInterceptor::ok_data(); TestDelegate d; - TestURLRequest req(GURL("http://test_intercept/foo"), &d); - req.set_context(default_context_); + URLRequest req(GURL("http://test_intercept/foo"), &d); + req.set_context(&default_context_); req.set_method("GET"); req.Start(); MessageLoop::current()->Run(); @@ -3949,8 +3947,8 @@ TEST_F(URLRequestTest, InterceptRespectsCancelFinal) { interceptor.cancel_final_request_ = true; TestDelegate d; - TestURLRequest req(GURL("http://test_intercept/foo"), &d); - req.set_context(default_context_); + URLRequest req(GURL("http://test_intercept/foo"), &d); + req.set_context(&default_context_); req.set_method("GET"); req.Start(); MessageLoop::current()->Run(); @@ -3976,8 +3974,8 @@ TEST_F(URLRequestTest, InterceptRespectsCancelInRestart) { interceptor.final_data_ = TestInterceptor::ok_data(); TestDelegate d; - TestURLRequest req(GURL("http://test_intercept/foo"), &d); - req.set_context(default_context_); + URLRequest req(GURL("http://test_intercept/foo"), &d); + req.set_context(&default_context_); req.set_method("GET"); req.Start(); MessageLoop::current()->Run(); @@ -4007,15 +4005,15 @@ TEST_F(URLRequestTest, NetworkDelegateProxyError) { host_resolver.rules()->AddSimulatedFailure("*"); TestNetworkDelegate network_delegate; // must outlive URLRequests - scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); - context->set_network_delegate(&network_delegate); - context->SetProxyFromString("myproxy:70"); - context->set_host_resolver(&host_resolver); - context->Init(); + TestURLRequestContext context(true); + context.set_network_delegate(&network_delegate); + context.SetProxyFromString("myproxy:70"); + context.set_host_resolver(&host_resolver); + context.Init(); TestDelegate d; - TestURLRequest req(GURL("http://example.com"), &d); - req.set_context(context); + URLRequest req(GURL("http://example.com"), &d); + req.set_context(&context); req.set_method("GET"); req.Start(); @@ -4041,9 +4039,9 @@ TEST_F(URLRequestTest, DoNotOverrideReferrer) { // only the latter shall be respected. { TestDelegate d; - TestURLRequest req(test_server.GetURL("echoheader?Referer"), &d); + URLRequest req(test_server.GetURL("echoheader?Referer"), &d); req.set_referrer("http://foo.com/"); - req.set_context(default_context_); + req.set_context(&default_context_); HttpRequestHeaders headers; headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); @@ -4059,8 +4057,8 @@ TEST_F(URLRequestTest, DoNotOverrideReferrer) { // shall be sent in the header. { TestDelegate d; - TestURLRequest req(test_server.GetURL("echoheader?Referer"), &d); - req.set_context(default_context_); + URLRequest req(test_server.GetURL("echoheader?Referer"), &d); + req.set_context(&default_context_); HttpRequestHeaders headers; headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); @@ -4078,9 +4076,8 @@ TEST_F(URLRequestTest, DoNotOverrideReferrer) { // content is empty. TEST_F(URLRequestTest, RequestCompletionForEmptyResponse) { TestDelegate d; - TestURLRequest req(GURL("data:,"), &d); - req.set_context(new TestURLRequestContext()); - req.set_context(default_context_); + URLRequest req(GURL("data:,"), &d); + req.set_context(&default_context_); req.Start(); MessageLoop::current()->Run(); EXPECT_EQ("", d.data_received()); @@ -4103,8 +4100,8 @@ TEST_F(URLRequestTestFTP, DISABLED_FTPDirectoryListing) { TestDelegate d; { - TestURLRequest r(test_server_.GetURL("/"), &d); - r.set_context(default_context_); + URLRequest r(test_server_.GetURL("/"), &d); + r.set_context(&default_context_); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -4130,8 +4127,8 @@ TEST_F(URLRequestTestFTP, DISABLED_FTPGetTestAnonymous) { app_path = app_path.AppendASCII("LICENSE"); TestDelegate d; { - TestURLRequest r(test_server_.GetURL("/LICENSE"), &d); - r.set_context(default_context_); + URLRequest r(test_server_.GetURL("/LICENSE"), &d); + r.set_context(&default_context_); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -4160,10 +4157,10 @@ TEST_F(URLRequestTestFTP, DISABLED_FTPGetTest) { app_path = app_path.AppendASCII("LICENSE"); TestDelegate d; { - TestURLRequest r( + URLRequest r( test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "chrome"), &d); - r.set_context(default_context_); + r.set_context(&default_context_); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -4192,12 +4189,12 @@ TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongPassword) { app_path = app_path.AppendASCII("LICENSE"); TestDelegate d; { - TestURLRequest r( + URLRequest r( test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "wrong_password"), &d); - r.set_context(default_context_); + r.set_context(&default_context_); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -4225,12 +4222,12 @@ TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongPasswordRestart) { // the initial login with wrong credentials will fail. d.set_credentials(AuthCredentials(kChrome, kChrome)); { - TestURLRequest r( + URLRequest r( test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "wrong_password"), &d); - r.set_context(default_context_); + r.set_context(&default_context_); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -4255,12 +4252,12 @@ TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongUser) { app_path = app_path.AppendASCII("LICENSE"); TestDelegate d; { - TestURLRequest r( + URLRequest r( test_server_.GetURLWithUserAndPassword("/LICENSE", "wrong_user", "chrome"), &d); - r.set_context(default_context_); + r.set_context(&default_context_); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -4288,12 +4285,12 @@ TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongUserRestart) { // the initial login with wrong credentials will fail. d.set_credentials(AuthCredentials(kChrome, kChrome)); { - TestURLRequest r( + URLRequest r( test_server_.GetURLWithUserAndPassword("/LICENSE", "wrong_user", "chrome"), &d); - r.set_context(default_context_); + r.set_context(&default_context_); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -4320,12 +4317,12 @@ TEST_F(URLRequestTestFTP, DISABLED_FTPCacheURLCredentials) { scoped_ptr<TestDelegate> d(new TestDelegate); { // Pass correct login identity in the URL. - TestURLRequest r( + URLRequest r( test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "chrome"), d.get()); - r.set_context(default_context_); + r.set_context(&default_context_); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -4343,8 +4340,8 @@ TEST_F(URLRequestTestFTP, DISABLED_FTPCacheURLCredentials) { d.reset(new TestDelegate); { // This request should use cached identity from previous request. - TestURLRequest r(test_server_.GetURL("/LICENSE"), d.get()); - r.set_context(default_context_); + URLRequest r(test_server_.GetURL("/LICENSE"), d.get()); + r.set_context(&default_context_); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -4373,12 +4370,12 @@ TEST_F(URLRequestTestFTP, DISABLED_FTPCacheLoginBoxCredentials) { // the initial login with wrong credentials will fail. d->set_credentials(AuthCredentials(kChrome, kChrome)); { - TestURLRequest r( + URLRequest r( test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "wrong_password"), d.get()); - r.set_context(default_context_); + r.set_context(&default_context_); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -4399,8 +4396,8 @@ TEST_F(URLRequestTestFTP, DISABLED_FTPCacheLoginBoxCredentials) { { // Don't pass wrong credentials in the URL, they would override valid cached // ones. - TestURLRequest r(test_server_.GetURL("/LICENSE"), d.get()); - r.set_context(default_context_); + URLRequest r(test_server_.GetURL("/LICENSE"), d.get()); + r.set_context(&default_context_); r.Start(); EXPECT_TRUE(r.is_pending()); @@ -4421,14 +4418,14 @@ TEST_F(URLRequestTestHTTP, DefaultAcceptLanguage) { ASSERT_TRUE(test_server_.Start()); TestNetworkDelegate network_delegate; // must outlive URLRequests - scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); - context->set_network_delegate(&network_delegate); - context->set_accept_language("en"); - context->Init(); + TestURLRequestContext context(true); + context.set_network_delegate(&network_delegate); + context.set_accept_language("en"); + context.Init(); TestDelegate d; - TestURLRequest req(test_server_.GetURL("echoheader?Accept-Language"), &d); - req.set_context(context); + URLRequest req(test_server_.GetURL("echoheader?Accept-Language"), &d); + req.set_context(&context); req.Start(); MessageLoop::current()->Run(); EXPECT_EQ("en", d.data_received()); @@ -4439,16 +4436,16 @@ TEST_F(URLRequestTestHTTP, EmptyAcceptLanguage) { ASSERT_TRUE(test_server_.Start()); TestNetworkDelegate network_delegate; // must outlive URLRequests - scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); - context->set_network_delegate(&network_delegate); - context->Init(); + TestURLRequestContext context(true); + context.set_network_delegate(&network_delegate); + context.Init(); // We override the language after initialization because empty entries // get overridden by Init(). - context->set_accept_language(""); + context.set_accept_language(""); TestDelegate d; - TestURLRequest req(test_server_.GetURL("echoheader?Accept-Language"), &d); - req.set_context(context); + URLRequest req(test_server_.GetURL("echoheader?Accept-Language"), &d); + req.set_context(&context); req.Start(); MessageLoop::current()->Run(); EXPECT_EQ("None", d.data_received()); @@ -4460,8 +4457,8 @@ TEST_F(URLRequestTestHTTP, OverrideAcceptLanguage) { ASSERT_TRUE(test_server_.Start()); TestDelegate d; - TestURLRequest req(test_server_.GetURL("echoheader?Accept-Language"), &d); - req.set_context(default_context_); + URLRequest req(test_server_.GetURL("echoheader?Accept-Language"), &d); + req.set_context(&default_context_); HttpRequestHeaders headers; headers.SetHeader(HttpRequestHeaders::kAcceptLanguage, "ru"); req.SetExtraRequestHeaders(headers); @@ -4475,8 +4472,8 @@ TEST_F(URLRequestTestHTTP, DefaultAcceptEncoding) { ASSERT_TRUE(test_server_.Start()); TestDelegate d; - TestURLRequest req(test_server_.GetURL("echoheader?Accept-Encoding"), &d); - req.set_context(default_context_); + URLRequest req(test_server_.GetURL("echoheader?Accept-Encoding"), &d); + req.set_context(&default_context_); HttpRequestHeaders headers; req.SetExtraRequestHeaders(headers); req.Start(); @@ -4490,8 +4487,8 @@ TEST_F(URLRequestTestHTTP, OverrideAcceptEncoding) { ASSERT_TRUE(test_server_.Start()); TestDelegate d; - TestURLRequest req(test_server_.GetURL("echoheader?Accept-Encoding"), &d); - req.set_context(default_context_); + URLRequest req(test_server_.GetURL("echoheader?Accept-Encoding"), &d); + req.set_context(&default_context_); HttpRequestHeaders headers; headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, "identity"); req.SetExtraRequestHeaders(headers); @@ -4506,14 +4503,14 @@ TEST_F(URLRequestTestHTTP, DefaultAcceptCharset) { ASSERT_TRUE(test_server_.Start()); TestNetworkDelegate network_delegate; // must outlive URLRequests - scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); - context->set_network_delegate(&network_delegate); - context->set_accept_charset("en"); - context->Init(); + TestURLRequestContext context(true); + context.set_network_delegate(&network_delegate); + context.set_accept_charset("en"); + context.Init(); TestDelegate d; - TestURLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), &d); - req.set_context(context); + URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), &d); + req.set_context(&context); req.Start(); MessageLoop::current()->Run(); EXPECT_EQ("en", d.data_received()); @@ -4524,16 +4521,16 @@ TEST_F(URLRequestTestHTTP, EmptyAcceptCharset) { ASSERT_TRUE(test_server_.Start()); TestNetworkDelegate network_delegate; // must outlive URLRequests - scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); - context->set_network_delegate(&network_delegate); - context->Init(); + TestURLRequestContext context(true); + context.set_network_delegate(&network_delegate); + context.Init(); // We override the accepted charset after initialization because empty // entries get overridden otherwise. - context->set_accept_charset(""); + context.set_accept_charset(""); TestDelegate d; - TestURLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), &d); - req.set_context(context); + URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), &d); + req.set_context(&context); req.Start(); MessageLoop::current()->Run(); EXPECT_EQ("None", d.data_received()); @@ -4545,8 +4542,8 @@ TEST_F(URLRequestTestHTTP, OverrideAcceptCharset) { ASSERT_TRUE(test_server_.Start()); TestDelegate d; - TestURLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), &d); - req.set_context(default_context_); + URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), &d); + req.set_context(&default_context_); HttpRequestHeaders headers; headers.SetHeader(HttpRequestHeaders::kAcceptCharset, "koi-8r"); req.SetExtraRequestHeaders(headers); @@ -4560,8 +4557,8 @@ TEST_F(URLRequestTestHTTP, DefaultUserAgent) { ASSERT_TRUE(test_server_.Start()); TestDelegate d; - TestURLRequest req(test_server_.GetURL("echoheader?User-Agent"), &d); - req.set_context(default_context_); + URLRequest req(test_server_.GetURL("echoheader?User-Agent"), &d); + req.set_context(&default_context_); req.Start(); MessageLoop::current()->Run(); EXPECT_EQ(req.context()->GetUserAgent(req.url()), d.data_received()); @@ -4573,8 +4570,8 @@ TEST_F(URLRequestTestHTTP, OverrideUserAgent) { ASSERT_TRUE(test_server_.Start()); TestDelegate d; - TestURLRequest req(test_server_.GetURL("echoheader?User-Agent"), &d); - req.set_context(default_context_); + URLRequest req(test_server_.GetURL("echoheader?User-Agent"), &d); + req.set_context(&default_context_); HttpRequestHeaders headers; headers.SetHeader(HttpRequestHeaders::kUserAgent, "Lynx (textmode)"); req.SetExtraRequestHeaders(headers); diff --git a/net/url_request/view_cache_helper.cc b/net/url_request/view_cache_helper.cc index 4dab89d..fde3442 100644 --- a/net/url_request/view_cache_helper.cc +++ b/net/url_request/view_cache_helper.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -41,7 +41,8 @@ std::string FormatEntryInfo(disk_cache::Entry* entry, } // namespace. ViewCacheHelper::ViewCacheHelper() - : disk_cache_(NULL), + : context_(NULL), + disk_cache_(NULL), entry_(NULL), iter_(NULL), buf_len_(0), diff --git a/net/url_request/view_cache_helper.h b/net/url_request/view_cache_helper.h index 2723d332..bd95401 100644 --- a/net/url_request/view_cache_helper.h +++ b/net/url_request/view_cache_helper.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -100,7 +100,7 @@ class NET_EXPORT ViewCacheHelper { // Called to signal completion of asynchronous IO. void OnIOComplete(int result); - scoped_refptr<const URLRequestContext> context_; + const URLRequestContext* context_; disk_cache::Backend* disk_cache_; disk_cache::Entry* entry_; void* iter_; diff --git a/net/url_request/view_cache_helper_unittest.cc b/net/url_request/view_cache_helper_unittest.cc index dbb813d..754ebe0 100644 --- a/net/url_request/view_cache_helper_unittest.cc +++ b/net/url_request/view_cache_helper_unittest.cc @@ -19,13 +19,11 @@ namespace { class TestURLRequestContext : public URLRequestContext { public: TestURLRequestContext(); + virtual ~TestURLRequestContext() {} // Gets a pointer to the cache backend. disk_cache::Backend* GetBackend(); - protected: - virtual ~TestURLRequestContext() {} - private: HttpCache cache_; }; @@ -104,25 +102,25 @@ void FillCache(URLRequestContext* context) { } // namespace. TEST(ViewCacheHelper, EmptyCache) { - scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); + TestURLRequestContext context; ViewCacheHelper helper; TestCompletionCallback cb; std::string prefix, data; - int rv = helper.GetContentsHTML(context, prefix, &data, cb.callback()); + int rv = helper.GetContentsHTML(&context, prefix, &data, cb.callback()); EXPECT_EQ(OK, cb.GetResult(rv)); EXPECT_FALSE(data.empty()); } TEST(ViewCacheHelper, ListContents) { - scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); + TestURLRequestContext context; ViewCacheHelper helper; - FillCache(context); + FillCache(&context); std::string prefix, data; TestCompletionCallback cb; - int rv = helper.GetContentsHTML(context, prefix, &data, cb.callback()); + int rv = helper.GetContentsHTML(&context, prefix, &data, cb.callback()); EXPECT_EQ(OK, cb.GetResult(rv)); EXPECT_EQ(0U, data.find("<html>")); @@ -137,14 +135,14 @@ TEST(ViewCacheHelper, ListContents) { } TEST(ViewCacheHelper, DumpEntry) { - scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); + TestURLRequestContext context; ViewCacheHelper helper; - FillCache(context); + FillCache(&context); std::string data; TestCompletionCallback cb; - int rv = helper.GetEntryInfoHTML("second", context, &data, cb.callback()); + int rv = helper.GetEntryInfoHTML("second", &context, &data, cb.callback()); EXPECT_EQ(OK, cb.GetResult(rv)); EXPECT_EQ(0U, data.find("<html>")); @@ -162,15 +160,15 @@ TEST(ViewCacheHelper, DumpEntry) { // Makes sure the links are correct. TEST(ViewCacheHelper, Prefix) { - scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); + TestURLRequestContext context; ViewCacheHelper helper; - FillCache(context); + FillCache(&context); std::string key, data; std::string prefix("prefix:"); TestCompletionCallback cb; - int rv = helper.GetContentsHTML(context, prefix, &data, cb.callback()); + int rv = helper.GetContentsHTML(&context, prefix, &data, cb.callback()); EXPECT_EQ(OK, cb.GetResult(rv)); EXPECT_EQ(0U, data.find("<html>")); @@ -181,13 +179,13 @@ TEST(ViewCacheHelper, Prefix) { } TEST(ViewCacheHelper, TruncatedFlag) { - scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); + TestURLRequestContext context; ViewCacheHelper helper; net::TestCompletionCallback cb; disk_cache::Backend* cache; int rv = - context->http_transaction_factory()->GetCache()->GetBackend( + context.http_transaction_factory()->GetCache()->GetBackend( &cache, cb.callback()); ASSERT_EQ(OK, cb.GetResult(rv)); @@ -203,7 +201,7 @@ TEST(ViewCacheHelper, TruncatedFlag) { std::string data; TestCompletionCallback cb1; - rv = helper.GetEntryInfoHTML(key, context, &data, cb1.callback()); + rv = helper.GetEntryInfoHTML(key, &context, &data, cb1.callback()); EXPECT_EQ(OK, cb1.GetResult(rv)); EXPECT_NE(std::string::npos, data.find("RESPONSE_INFO_TRUNCATED")); diff --git a/net/websockets/websocket_job_spdy2_unittest.cc b/net/websockets/websocket_job_spdy2_unittest.cc index 506056b..0aea40f 100644 --- a/net/websockets/websocket_job_spdy2_unittest.cc +++ b/net/websockets/websocket_job_spdy2_unittest.cc @@ -258,8 +258,6 @@ class MockURLRequestContext : public net::URLRequestContext { transport_security_state_.EnableHost("upgrademe.com", state); } - protected: - friend class base::RefCountedThreadSafe<MockURLRequestContext>; virtual ~MockURLRequestContext() {} private: @@ -337,11 +335,11 @@ class WebSocketJobSpdy2Test : public PlatformTest { SpdySession::set_default_protocol(kProtoSPDY2); stream_type_ = STREAM_INVALID; cookie_store_ = new MockCookieStore; - context_ = new MockURLRequestContext(cookie_store_.get()); + context_.reset(new MockURLRequestContext(cookie_store_.get())); } virtual void TearDown() OVERRIDE { cookie_store_ = NULL; - context_ = NULL; + context_.reset(); websocket_ = NULL; socket_ = NULL; } @@ -455,7 +453,7 @@ class WebSocketJobSpdy2Test : public PlatformTest { StreamType stream_type_; scoped_refptr<MockCookieStore> cookie_store_; - scoped_refptr<MockURLRequestContext> context_; + scoped_ptr<MockURLRequestContext> context_; scoped_refptr<WebSocketJob> websocket_; scoped_refptr<SocketStream> socket_; scoped_ptr<MockClientSocketFactory> socket_factory_; diff --git a/net/websockets/websocket_job_spdy3_unittest.cc b/net/websockets/websocket_job_spdy3_unittest.cc index e993289..c40ac79 100644 --- a/net/websockets/websocket_job_spdy3_unittest.cc +++ b/net/websockets/websocket_job_spdy3_unittest.cc @@ -262,8 +262,6 @@ class MockURLRequestContext : public net::URLRequestContext { transport_security_state_.EnableHost("upgrademe.com", state); } - protected: - friend class base::RefCountedThreadSafe<MockURLRequestContext>; virtual ~MockURLRequestContext() {} private: @@ -336,11 +334,11 @@ class WebSocketJobSpdy3Test : public PlatformTest { SpdySession::set_default_protocol(kProtoSPDY3); stream_type_ = STREAM_INVALID; cookie_store_ = new MockCookieStore; - context_ = new MockURLRequestContext(cookie_store_.get()); + context_.reset(new MockURLRequestContext(cookie_store_.get())); } virtual void TearDown() { cookie_store_ = NULL; - context_ = NULL; + context_.reset(); websocket_ = NULL; socket_ = NULL; } @@ -454,7 +452,6 @@ class WebSocketJobSpdy3Test : public PlatformTest { StreamType stream_type_; scoped_refptr<MockCookieStore> cookie_store_; - scoped_refptr<MockURLRequestContext> context_; scoped_refptr<WebSocketJob> websocket_; scoped_refptr<SocketStream> socket_; scoped_ptr<MockClientSocketFactory> socket_factory_; @@ -464,6 +461,7 @@ class WebSocketJobSpdy3Test : public PlatformTest { scoped_ptr<net::ProxyService> proxy_service_; scoped_ptr<net::MockHostResolver> host_resolver_; scoped_ptr<MockHttpTransactionFactory> http_factory_; + scoped_ptr<MockURLRequestContext> context_; static const char kHandshakeRequestWithoutCookie[]; static const char kHandshakeRequestWithCookie[]; diff --git a/net/websockets/websocket_throttle_unittest.cc b/net/websockets/websocket_throttle_unittest.cc index 734a9f9..af3e022 100644 --- a/net/websockets/websocket_throttle_unittest.cc +++ b/net/websockets/websocket_throttle_unittest.cc @@ -59,7 +59,7 @@ class WebSocketThrottleTest : public PlatformTest { }; TEST_F(WebSocketThrottleTest, Throttle) { - scoped_refptr<URLRequestContext> context(new TestURLRequestContext); + TestURLRequestContext context; DummySocketStreamDelegate delegate; // TODO(toyoshim): We need to consider both spdy-enabled and spdy-disabled // configuration. @@ -73,7 +73,7 @@ TEST_F(WebSocketThrottleTest, Throttle) { scoped_refptr<WebSocketJob> w1(new WebSocketJob(&delegate)); scoped_refptr<SocketStream> s1( new SocketStream(GURL("ws://host1/"), w1.get())); - s1->set_context(context.get()); + s1->set_context(&context); w1->InitSocketStream(s1.get()); WebSocketThrottleTest::MockSocketStreamConnect(s1, addr); @@ -94,7 +94,7 @@ TEST_F(WebSocketThrottleTest, Throttle) { scoped_refptr<WebSocketJob> w2(new WebSocketJob(&delegate)); scoped_refptr<SocketStream> s2( new SocketStream(GURL("ws://host2/"), w2.get())); - s2->set_context(context.get()); + s2->set_context(&context); w2->InitSocketStream(s2.get()); WebSocketThrottleTest::MockSocketStreamConnect(s2, addr); @@ -115,7 +115,7 @@ TEST_F(WebSocketThrottleTest, Throttle) { scoped_refptr<WebSocketJob> w3(new WebSocketJob(&delegate)); scoped_refptr<SocketStream> s3( new SocketStream(GURL("ws://host3/"), w3.get())); - s3->set_context(context.get()); + s3->set_context(&context); w3->InitSocketStream(s3.get()); WebSocketThrottleTest::MockSocketStreamConnect(s3, addr); @@ -136,7 +136,7 @@ TEST_F(WebSocketThrottleTest, Throttle) { scoped_refptr<WebSocketJob> w4(new WebSocketJob(&delegate)); scoped_refptr<SocketStream> s4( new SocketStream(GURL("ws://host4/"), w4.get())); - s4->set_context(context.get()); + s4->set_context(&context); w4->InitSocketStream(s4.get()); WebSocketThrottleTest::MockSocketStreamConnect(s4, addr); @@ -156,7 +156,7 @@ TEST_F(WebSocketThrottleTest, Throttle) { scoped_refptr<WebSocketJob> w5(new WebSocketJob(&delegate)); scoped_refptr<SocketStream> s5( new SocketStream(GURL("ws://host5/"), w5.get())); - s5->set_context(context.get()); + s5->set_context(&context); w5->InitSocketStream(s5.get()); WebSocketThrottleTest::MockSocketStreamConnect(s5, addr); @@ -176,7 +176,7 @@ TEST_F(WebSocketThrottleTest, Throttle) { scoped_refptr<WebSocketJob> w6(new WebSocketJob(&delegate)); scoped_refptr<SocketStream> s6( new SocketStream(GURL("ws://host6/"), w6.get())); - s6->set_context(context.get()); + s6->set_context(&context); w6->InitSocketStream(s6.get()); WebSocketThrottleTest::MockSocketStreamConnect(s6, addr); @@ -278,7 +278,7 @@ TEST_F(WebSocketThrottleTest, Throttle) { } TEST_F(WebSocketThrottleTest, NoThrottleForDuplicateAddress) { - scoped_refptr<URLRequestContext> context(new TestURLRequestContext); + TestURLRequestContext context; DummySocketStreamDelegate delegate; WebSocketJob::set_websocket_over_spdy_enabled(true); @@ -289,7 +289,7 @@ TEST_F(WebSocketThrottleTest, NoThrottleForDuplicateAddress) { scoped_refptr<WebSocketJob> w1(new WebSocketJob(&delegate)); scoped_refptr<SocketStream> s1( new SocketStream(GURL("ws://localhost/"), w1.get())); - s1->set_context(context.get()); + s1->set_context(&context); w1->InitSocketStream(s1.get()); WebSocketThrottleTest::MockSocketStreamConnect(s1, addr); diff --git a/remoting/host/url_request_context.cc b/remoting/host/url_request_context.cc index 901dc09..9d12a29 100644 --- a/remoting/host/url_request_context.cc +++ b/remoting/host/url_request_context.cc @@ -122,11 +122,11 @@ URLRequestContextGetter::URLRequestContextGetter( } net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { - if (!url_request_context_) { - url_request_context_ = - new URLRequestContext(proxy_config_service_.Pass()); + if (!url_request_context_.get()) { + url_request_context_.reset( + new URLRequestContext(proxy_config_service_.Pass())); } - return url_request_context_; + return url_request_context_.get(); } scoped_refptr<base::MessageLoopProxy> diff --git a/remoting/host/url_request_context.h b/remoting/host/url_request_context.h index 5c0c6ee..d1f2cd3 100644 --- a/remoting/host/url_request_context.h +++ b/remoting/host/url_request_context.h @@ -52,9 +52,9 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { virtual ~URLRequestContextGetter(); private: - scoped_refptr<net::URLRequestContext> url_request_context_; scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; scoped_ptr<net::ProxyConfigService> proxy_config_service_; + scoped_ptr<net::URLRequestContext> url_request_context_; DISALLOW_COPY_AND_ASSIGN(URLRequestContextGetter); }; diff --git a/webkit/appcache/appcache_update_job_unittest.cc b/webkit/appcache/appcache_update_job_unittest.cc index 604eaf1..123a563 100644 --- a/webkit/appcache/appcache_update_job_unittest.cc +++ b/webkit/appcache/appcache_update_job_unittest.cc @@ -536,8 +536,8 @@ class IOThread : public base::Thread { Stop(); } - const scoped_refptr<net::URLRequestContext>& request_context() { - return request_context_; + net::URLRequestContext* request_context() { + return request_context_.get(); } void SetNewJobFactory(net::URLRequestJobFactory* job_factory) { @@ -550,18 +550,18 @@ class IOThread : public base::Thread { job_factory_.reset(new net::URLRequestJobFactory); job_factory_->SetProtocolHandler("http", new MockHttpServerJobFactory); job_factory_->SetProtocolHandler("https", new MockHttpServerJobFactory); - request_context_ = new TestURLRequestContext(); + request_context_.reset(new TestURLRequestContext()); request_context_->set_job_factory(job_factory_.get()); } virtual void CleanUp() { - request_context_ = NULL; + request_context_.reset(); job_factory_.reset(); } private: scoped_ptr<net::URLRequestJobFactory> job_factory_; - scoped_refptr<net::URLRequestContext> request_context_; + scoped_ptr<net::URLRequestContext> request_context_; }; class AppCacheUpdateJobTest : public testing::Test, diff --git a/webkit/fileapi/file_system_operation_write_unittest.cc b/webkit/fileapi/file_system_operation_write_unittest.cc index 5ba14c5..2af53ec 100644 --- a/webkit/fileapi/file_system_operation_write_unittest.cc +++ b/webkit/fileapi/file_system_operation_write_unittest.cc @@ -154,13 +154,12 @@ class TestURLRequestContext : public net::URLRequestContext { TestURLRequestContext() : blob_storage_controller_(new webkit_blob::BlobStorageController) {} + virtual ~TestURLRequestContext() {} + webkit_blob::BlobStorageController* blob_storage_controller() const { return blob_storage_controller_.get(); } - protected: - virtual ~TestURLRequestContext() {} - private: scoped_ptr<webkit_blob::BlobStorageController> blob_storage_controller_; }; @@ -211,16 +210,15 @@ TEST_F(FileSystemOperationWriteTest, TestWriteSuccess) { scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); blob_data->AppendData("Hello, world!\n"); - scoped_refptr<TestURLRequestContext> url_request_context( - new TestURLRequestContext()); - url_request_context->blob_storage_controller()->AddFinishedBlob( + TestURLRequestContext url_request_context; + url_request_context.blob_storage_controller()->AddFinishedBlob( blob_url, blob_data); - operation()->Write(url_request_context, URLForPath(virtual_path_), blob_url, + operation()->Write(&url_request_context, URLForPath(virtual_path_), blob_url, 0, RecordWriteCallback()); MessageLoop::current()->Run(); - url_request_context->blob_storage_controller()->RemoveBlob(blob_url); + url_request_context.blob_storage_controller()->RemoveBlob(blob_url); EXPECT_EQ(14, bytes_written()); EXPECT_EQ(base::PLATFORM_FILE_OK, status()); @@ -232,16 +230,15 @@ TEST_F(FileSystemOperationWriteTest, TestWriteZero) { scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); blob_data->AppendData(""); - scoped_refptr<TestURLRequestContext> url_request_context( - new TestURLRequestContext()); - url_request_context->blob_storage_controller()->AddFinishedBlob( + TestURLRequestContext url_request_context; + url_request_context.blob_storage_controller()->AddFinishedBlob( blob_url, blob_data); - operation()->Write(url_request_context, URLForPath(virtual_path_), + operation()->Write(&url_request_context, URLForPath(virtual_path_), blob_url, 0, RecordWriteCallback()); MessageLoop::current()->Run(); - url_request_context->blob_storage_controller()->RemoveBlob(blob_url); + url_request_context.blob_storage_controller()->RemoveBlob(blob_url); EXPECT_EQ(0, bytes_written()); EXPECT_EQ(base::PLATFORM_FILE_OK, status()); @@ -249,10 +246,9 @@ TEST_F(FileSystemOperationWriteTest, TestWriteZero) { } TEST_F(FileSystemOperationWriteTest, TestWriteInvalidBlobUrl) { - scoped_refptr<TestURLRequestContext> url_request_context( - new TestURLRequestContext()); + TestURLRequestContext url_request_context; - operation()->Write(url_request_context, URLForPath(virtual_path_), + operation()->Write(&url_request_context, URLForPath(virtual_path_), GURL("blob:invalid"), 0, RecordWriteCallback()); MessageLoop::current()->Run(); @@ -266,17 +262,16 @@ TEST_F(FileSystemOperationWriteTest, TestWriteInvalidFile) { scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); blob_data->AppendData("It\'ll not be written."); - scoped_refptr<TestURLRequestContext> url_request_context( - new TestURLRequestContext()); - url_request_context->blob_storage_controller()->AddFinishedBlob( + TestURLRequestContext url_request_context; + url_request_context.blob_storage_controller()->AddFinishedBlob( blob_url, blob_data); - operation()->Write(url_request_context, + operation()->Write(&url_request_context, URLForPath(FilePath(FILE_PATH_LITERAL("nonexist"))), blob_url, 0, RecordWriteCallback()); MessageLoop::current()->Run(); - url_request_context->blob_storage_controller()->RemoveBlob(blob_url); + url_request_context.blob_storage_controller()->RemoveBlob(blob_url); EXPECT_EQ(0, bytes_written()); EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); @@ -294,16 +289,15 @@ TEST_F(FileSystemOperationWriteTest, TestWriteDir) { scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); blob_data->AppendData("It\'ll not be written, too."); - scoped_refptr<TestURLRequestContext> url_request_context( - new TestURLRequestContext()); - url_request_context->blob_storage_controller()->AddFinishedBlob( + TestURLRequestContext url_request_context; + url_request_context.blob_storage_controller()->AddFinishedBlob( blob_url, blob_data); - operation()->Write(url_request_context, URLForPath(virtual_subdir_path), + operation()->Write(&url_request_context, URLForPath(virtual_subdir_path), blob_url, 0, RecordWriteCallback()); MessageLoop::current()->Run(); - url_request_context->blob_storage_controller()->RemoveBlob(blob_url); + url_request_context.blob_storage_controller()->RemoveBlob(blob_url); EXPECT_EQ(0, bytes_written()); EXPECT_EQ(base::PLATFORM_FILE_ERROR_ACCESS_DENIED, status()); @@ -315,17 +309,16 @@ TEST_F(FileSystemOperationWriteTest, TestWriteFailureByQuota) { scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); blob_data->AppendData("Hello, world!\n"); - scoped_refptr<TestURLRequestContext> url_request_context( - new TestURLRequestContext()); - url_request_context->blob_storage_controller()->AddFinishedBlob( + TestURLRequestContext url_request_context; + url_request_context.blob_storage_controller()->AddFinishedBlob( blob_url, blob_data); quota_manager_->set_quota(10); - operation()->Write(url_request_context, URLForPath(virtual_path_), blob_url, + operation()->Write(&url_request_context, URLForPath(virtual_path_), blob_url, 0, RecordWriteCallback()); MessageLoop::current()->Run(); - url_request_context->blob_storage_controller()->RemoveBlob(blob_url); + url_request_context.blob_storage_controller()->RemoveBlob(blob_url); EXPECT_EQ(10, bytes_written()); EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); @@ -337,13 +330,12 @@ TEST_F(FileSystemOperationWriteTest, TestImmediateCancelSuccessfulWrite) { scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); blob_data->AppendData("Hello, world!\n"); - scoped_refptr<TestURLRequestContext> url_request_context( - new TestURLRequestContext()); - url_request_context->blob_storage_controller()->AddFinishedBlob( + TestURLRequestContext url_request_context; + url_request_context.blob_storage_controller()->AddFinishedBlob( blob_url, blob_data); FileSystemOperationInterface* write_operation = operation(); - write_operation->Write(url_request_context, URLForPath(virtual_path_), + write_operation->Write(&url_request_context, URLForPath(virtual_path_), blob_url, 0, RecordWriteCallback()); write_operation->Cancel(RecordCancelCallback()); // We use RunAllPendings() instead of Run() here, because we won't dispatch @@ -351,7 +343,7 @@ TEST_F(FileSystemOperationWriteTest, TestImmediateCancelSuccessfulWrite) { // to run another write cycle. MessageLoop::current()->RunAllPending(); - url_request_context->blob_storage_controller()->RemoveBlob(blob_url); + url_request_context.blob_storage_controller()->RemoveBlob(blob_url); // Issued Cancel() before receiving any response from Write(), // so nothing should have happen. @@ -366,13 +358,12 @@ TEST_F(FileSystemOperationWriteTest, TestImmediateCancelFailingWrite) { scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); blob_data->AppendData("It\'ll not be written."); - scoped_refptr<TestURLRequestContext> url_request_context( - new TestURLRequestContext()); - url_request_context->blob_storage_controller()->AddFinishedBlob( + TestURLRequestContext url_request_context; + url_request_context.blob_storage_controller()->AddFinishedBlob( blob_url, blob_data); FileSystemOperationInterface* write_operation = operation(); - write_operation->Write(url_request_context, + write_operation->Write(&url_request_context, URLForPath(FilePath(FILE_PATH_LITERAL("nonexist"))), blob_url, 0, RecordWriteCallback()); write_operation->Cancel(RecordCancelCallback()); @@ -381,7 +372,7 @@ TEST_F(FileSystemOperationWriteTest, TestImmediateCancelFailingWrite) { // to run another write cycle. MessageLoop::current()->RunAllPending(); - url_request_context->blob_storage_controller()->RemoveBlob(blob_url); + url_request_context.blob_storage_controller()->RemoveBlob(blob_url); // Issued Cancel() before receiving any response from Write(), // so nothing should have happen. diff --git a/webkit/tools/test_shell/simple_resource_loader_bridge.cc b/webkit/tools/test_shell/simple_resource_loader_bridge.cc index 074580d..450cbee 100644 --- a/webkit/tools/test_shell/simple_resource_loader_bridge.cc +++ b/webkit/tools/test_shell/simple_resource_loader_bridge.cc @@ -217,8 +217,6 @@ class IOThread : public base::Thread { g_request_context = new TestShellRequestContext(); } - g_request_context->AddRef(); - g_network_delegate = new TestShellNetworkDelegate(); g_request_context->set_network_delegate(g_network_delegate); @@ -241,7 +239,7 @@ class IOThread : public base::Thread { if (g_request_context) { g_request_context->set_network_delegate(NULL); - g_request_context->Release(); + delete g_request_context; g_request_context = NULL; } diff --git a/webkit/tools/test_shell/simple_socket_stream_bridge.cc b/webkit/tools/test_shell/simple_socket_stream_bridge.cc index 0d52ea2..05c9e74d 100644 --- a/webkit/tools/test_shell/simple_socket_stream_bridge.cc +++ b/webkit/tools/test_shell/simple_socket_stream_bridge.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -223,14 +223,11 @@ void WebSocketStreamHandleBridgeImpl::DoOnClose() { void SimpleSocketStreamBridge::InitializeOnIOThread( net::URLRequestContext* request_context) { g_io_thread = MessageLoop::current(); - if ((g_request_context = request_context)) - g_request_context->AddRef(); + g_request_context = request_context; } void SimpleSocketStreamBridge::Cleanup() { g_io_thread = NULL; - if (g_request_context) - g_request_context->Release(); g_request_context = NULL; } diff --git a/webkit/tools/test_shell/test_shell_request_context.h b/webkit/tools/test_shell/test_shell_request_context.h index 0eb29cf..946248f 100644 --- a/webkit/tools/test_shell/test_shell_request_context.h +++ b/webkit/tools/test_shell/test_shell_request_context.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -32,6 +32,8 @@ class TestShellRequestContext : public net::URLRequestContext { net::HttpCache::Mode cache_mode, bool no_proxy); + virtual ~TestShellRequestContext(); + virtual const std::string& GetUserAgent(const GURL& url) const OVERRIDE; webkit_blob::BlobStorageController* blob_storage_controller() const { @@ -43,8 +45,6 @@ class TestShellRequestContext : public net::URLRequestContext { } private: - virtual ~TestShellRequestContext(); - void Init(const FilePath& cache_path, net::HttpCache::Mode cache_mode, bool no_proxy); |