diff options
author | shalev@chromium.org <shalev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-24 01:06:58 +0000 |
---|---|---|
committer | shalev@chromium.org <shalev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-24 01:06:58 +0000 |
commit | 9f170464e1ab4f1f75802a391db76408bc8998f2 (patch) | |
tree | 50ecf1c9c893ab12c59ee653d57732572128b7ed /webkit/appcache | |
parent | 3dc4019ef862889073cf16e875050a512e93aa3a (diff) | |
download | chromium_src-9f170464e1ab4f1f75802a391db76408bc8998f2.zip chromium_src-9f170464e1ab4f1f75802a391db76408bc8998f2.tar.gz chromium_src-9f170464e1ab4f1f75802a391db76408bc8998f2.tar.bz2 |
Refactoring: ProtocolHandler::MaybeCreateJob and other functions take NetworkDelegate as argument
This change goes a long way to prepare for removing NetworkDelegate from URLRequestContext.
TBR=sky@chromium.org, michaeln@chromium.org, benjhayden@chromium.org, brettw@chromium.org, ben@chromium.org, davemoore@chromium.org, zelidrag@chromium.org, mnissler@chromium.org, thestig@chromium.org, asargent@chromium.org, jhawkins@chromium.org, bulach@chromium.org
BUG=crbug.com/142945
Review URL: https://chromiumcodereview.appspot.com/10855209
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@153133 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache')
-rw-r--r-- | webkit/appcache/appcache_interceptor.cc | 12 | ||||
-rw-r--r-- | webkit/appcache/appcache_interceptor.h | 8 | ||||
-rw-r--r-- | webkit/appcache/appcache_request_handler.cc | 29 | ||||
-rw-r--r-- | webkit/appcache/appcache_request_handler.h | 19 | ||||
-rw-r--r-- | webkit/appcache/appcache_request_handler_unittest.cc | 156 | ||||
-rw-r--r-- | webkit/appcache/appcache_update_job_unittest.cc | 46 | ||||
-rw-r--r-- | webkit/appcache/appcache_url_request_job.cc | 7 | ||||
-rw-r--r-- | webkit/appcache/appcache_url_request_job.h | 4 | ||||
-rw-r--r-- | webkit/appcache/appcache_url_request_job_unittest.cc | 33 | ||||
-rw-r--r-- | webkit/appcache/view_appcache_internals_job.cc | 54 | ||||
-rw-r--r-- | webkit/appcache/view_appcache_internals_job.h | 5 |
11 files changed, 246 insertions, 127 deletions
diff --git a/webkit/appcache/appcache_interceptor.cc b/webkit/appcache/appcache_interceptor.cc index f1be933..6342b93 100644 --- a/webkit/appcache/appcache_interceptor.cc +++ b/webkit/appcache/appcache_interceptor.cc @@ -71,28 +71,30 @@ AppCacheInterceptor::~AppCacheInterceptor() { } net::URLRequestJob* AppCacheInterceptor::MaybeIntercept( - net::URLRequest* request) { + net::URLRequest* request, net::NetworkDelegate* network_delegate) { AppCacheRequestHandler* handler = GetHandler(request); if (!handler) return NULL; - return handler->MaybeLoadResource(request); + return handler->MaybeLoadResource(request, network_delegate); } net::URLRequestJob* AppCacheInterceptor::MaybeInterceptRedirect( net::URLRequest* request, + net::NetworkDelegate* network_delegate, const GURL& location) { AppCacheRequestHandler* handler = GetHandler(request); if (!handler) return NULL; - return handler->MaybeLoadFallbackForRedirect(request, location); + return handler->MaybeLoadFallbackForRedirect( + request, network_delegate, location); } net::URLRequestJob* AppCacheInterceptor::MaybeInterceptResponse( - net::URLRequest* request) { + net::URLRequest* request, net::NetworkDelegate* network_delegate) { AppCacheRequestHandler* handler = GetHandler(request); if (!handler) return NULL; - return handler->MaybeLoadFallbackForResponse(request); + return handler->MaybeLoadFallbackForResponse(request, network_delegate); } } // namespace appcache diff --git a/webkit/appcache/appcache_interceptor.h b/webkit/appcache/appcache_interceptor.h index 9f6759a..1bbe121 100644 --- a/webkit/appcache/appcache_interceptor.h +++ b/webkit/appcache/appcache_interceptor.h @@ -44,11 +44,15 @@ class APPCACHE_EXPORT AppCacheInterceptor protected: // Override from net::URLRequest::Interceptor: - virtual net::URLRequestJob* MaybeIntercept(net::URLRequest* request) OVERRIDE; + virtual net::URLRequestJob* MaybeIntercept( + net::URLRequest* request, + net::NetworkDelegate* network_delegate) OVERRIDE; virtual net::URLRequestJob* MaybeInterceptResponse( - net::URLRequest* request) OVERRIDE; + net::URLRequest* request, + net::NetworkDelegate* network_delegate) OVERRIDE; virtual net::URLRequestJob* MaybeInterceptRedirect( net::URLRequest* request, + net::NetworkDelegate* network_delegate, const GURL& location) OVERRIDE; private: diff --git a/webkit/appcache/appcache_request_handler.cc b/webkit/appcache/appcache_request_handler.cc index 0f123a1..7673273 100644 --- a/webkit/appcache/appcache_request_handler.cc +++ b/webkit/appcache/appcache_request_handler.cc @@ -43,7 +43,7 @@ void AppCacheRequestHandler::GetExtraResponseInfo( } AppCacheURLRequestJob* AppCacheRequestHandler::MaybeLoadResource( - net::URLRequest* request) { + net::URLRequest* request, net::NetworkDelegate* network_delegate) { if (!host_ || !IsSchemeAndMethodSupported(request) || cache_entry_not_found_) return NULL; @@ -73,9 +73,9 @@ AppCacheURLRequestJob* AppCacheRequestHandler::MaybeLoadResource( found_network_namespace_ = false; if (is_main_resource()) - MaybeLoadMainResource(request); + MaybeLoadMainResource(request, network_delegate); else - MaybeLoadSubResource(request); + MaybeLoadSubResource(request, network_delegate); // If its been setup to deliver a network response, we can just delete // it now and return NULL instead to achieve that since it couldn't @@ -89,7 +89,9 @@ AppCacheURLRequestJob* AppCacheRequestHandler::MaybeLoadResource( } AppCacheURLRequestJob* AppCacheRequestHandler::MaybeLoadFallbackForRedirect( - net::URLRequest* request, const GURL& location) { + net::URLRequest* request, + net::NetworkDelegate* network_delegate, + const GURL& location) { if (!host_ || !IsSchemeAndMethodSupported(request) || cache_entry_not_found_) return NULL; if (is_main_resource()) @@ -102,13 +104,13 @@ AppCacheURLRequestJob* AppCacheRequestHandler::MaybeLoadFallbackForRedirect( if (found_fallback_entry_.has_response_id()) { // 6.9.6, step 4: If this results in a redirect to another origin, // get the resource of the fallback entry. - job_ = new AppCacheURLRequestJob(request, storage()); + job_ = new AppCacheURLRequestJob(request, network_delegate, storage()); DeliverAppCachedResponse( found_fallback_entry_, found_cache_id_, found_group_id_, found_manifest_url_, true, found_namespace_entry_url_); } else if (!found_network_namespace_) { // 6.9.6, step 6: Fail the resource load. - job_ = new AppCacheURLRequestJob(request, storage()); + job_ = new AppCacheURLRequestJob(request, network_delegate, storage()); DeliverErrorResponse(); } else { // 6.9.6 step 3 and 5: Fetch the resource normally. @@ -118,7 +120,7 @@ AppCacheURLRequestJob* AppCacheRequestHandler::MaybeLoadFallbackForRedirect( } AppCacheURLRequestJob* AppCacheRequestHandler::MaybeLoadFallbackForResponse( - net::URLRequest* request) { + net::URLRequest* request, net::NetworkDelegate* network_delegate) { if (!host_ || !IsSchemeAndMethodSupported(request) || cache_entry_not_found_) return NULL; if (!found_fallback_entry_.has_response_id()) @@ -154,7 +156,7 @@ AppCacheURLRequestJob* AppCacheRequestHandler::MaybeLoadFallbackForResponse( // 6.9.6, step 4: If this results in a 4xx or 5xx status code // or there were network errors, get the resource of the fallback entry. - job_ = new AppCacheURLRequestJob(request, storage()); + job_ = new AppCacheURLRequestJob(request, network_delegate, storage()); DeliverAppCachedResponse( found_fallback_entry_, found_cache_id_, found_group_id_, found_manifest_url_, true, found_namespace_entry_url_); @@ -199,7 +201,8 @@ void AppCacheRequestHandler::DeliverNetworkResponse() { // Main-resource handling ---------------------------------------------- -void AppCacheRequestHandler::MaybeLoadMainResource(net::URLRequest* request) { +void AppCacheRequestHandler::MaybeLoadMainResource( + net::URLRequest* request, net::NetworkDelegate* network_delegate) { DCHECK(!job_); DCHECK(host_); @@ -211,7 +214,7 @@ void AppCacheRequestHandler::MaybeLoadMainResource(net::URLRequest* request) { // We may have to wait for our storage query to complete, but // this query can also complete syncrhonously. - job_ = new AppCacheURLRequestJob(request, storage()); + job_ = new AppCacheURLRequestJob(request, network_delegate, storage()); storage()->FindResponseForMainRequest( request->url(), preferred_manifest_url, this); } @@ -277,14 +280,14 @@ void AppCacheRequestHandler::OnMainResponseFound( // Sub-resource handling ---------------------------------------------- void AppCacheRequestHandler::MaybeLoadSubResource( - net::URLRequest* request) { + net::URLRequest* request, net::NetworkDelegate* network_delegate) { DCHECK(!job_); if (host_->is_selection_pending()) { // We have to wait until cache selection is complete and the // selected cache is loaded. is_waiting_for_cache_selection_ = true; - job_ = new AppCacheURLRequestJob(request, storage()); + job_ = new AppCacheURLRequestJob(request, network_delegate, storage()); return; } @@ -293,7 +296,7 @@ void AppCacheRequestHandler::MaybeLoadSubResource( return; } - job_ = new AppCacheURLRequestJob(request, storage()); + job_ = new AppCacheURLRequestJob(request, network_delegate, storage()); ContinueMaybeLoadSubResource(); } diff --git a/webkit/appcache/appcache_request_handler.h b/webkit/appcache/appcache_request_handler.h index f7e8c23..bedd90d 100644 --- a/webkit/appcache/appcache_request_handler.h +++ b/webkit/appcache/appcache_request_handler.h @@ -13,6 +13,7 @@ #include "webkit/glue/resource_type.h" namespace net { +class NetworkDelegate; class URLRequest; class URLRequestJob; } // namespace net @@ -34,10 +35,14 @@ class APPCACHE_EXPORT AppCacheRequestHandler virtual ~AppCacheRequestHandler(); // These are called on each request intercept opportunity. - AppCacheURLRequestJob* MaybeLoadResource(net::URLRequest* request); - AppCacheURLRequestJob* MaybeLoadFallbackForRedirect(net::URLRequest* request, - const GURL& location); - AppCacheURLRequestJob* MaybeLoadFallbackForResponse(net::URLRequest* request); + AppCacheURLRequestJob* MaybeLoadResource( + net::URLRequest* request, net::NetworkDelegate* network_delegate); + AppCacheURLRequestJob* MaybeLoadFallbackForRedirect( + net::URLRequest* request, + net::NetworkDelegate* network_delegate, + const GURL& location); + AppCacheURLRequestJob* MaybeLoadFallbackForResponse( + net::URLRequest* request, net::NetworkDelegate* network_delegate); void GetExtraResponseInfo(int64* cache_id, GURL* manifest_url); @@ -74,7 +79,8 @@ class APPCACHE_EXPORT AppCacheRequestHandler // Main-resource loading ------------------------------------- // Frame and SharedWorker main resources are handled here. - void MaybeLoadMainResource(net::URLRequest* request); + void MaybeLoadMainResource(net::URLRequest* request, + net::NetworkDelegate* network_delegate); // AppCacheStorage::Delegate methods virtual void OnMainResponseFound( @@ -85,7 +91,8 @@ class APPCACHE_EXPORT AppCacheRequestHandler // Sub-resource loading ------------------------------------- // Dedicated worker and all manner of sub-resources are handled here. - void MaybeLoadSubResource(net::URLRequest* request); + void MaybeLoadSubResource(net::URLRequest* request, + net::NetworkDelegate* network_delegate); void ContinueMaybeLoadSubResource(); // AppCacheHost::Observer override diff --git a/webkit/appcache/appcache_request_handler_unittest.cc b/webkit/appcache/appcache_request_handler_unittest.cc index d537212..2abb0f4 100644 --- a/webkit/appcache/appcache_request_handler_unittest.cc +++ b/webkit/appcache/appcache_request_handler_unittest.cc @@ -74,14 +74,15 @@ class AppCacheRequestHandlerTest : public testing::Test { class MockURLRequestJob : public net::URLRequestJob { public: MockURLRequestJob(net::URLRequest* request, + net::NetworkDelegate* network_delegate, int response_code) - : net::URLRequestJob(request, request->context()->network_delegate()), + : net::URLRequestJob(request, network_delegate), response_code_(response_code), has_response_info_(false) {} MockURLRequestJob(net::URLRequest* request, + net::NetworkDelegate* network_delegate, const net::HttpResponseInfo& info) - : net::URLRequestJob(request, - request->context()->network_delegate()), + : net::URLRequestJob(request, network_delegate), response_code_(info.headers->response_code()), has_response_info_(true), response_info_(info) {} @@ -114,7 +115,8 @@ class AppCacheRequestHandlerTest : public testing::Test { } void SimulateResponseCode(int http_response_code) { - mock_factory_job_ = new MockURLRequestJob(this, http_response_code); + mock_factory_job_ = new MockURLRequestJob( + this, context()->network_delegate(), http_response_code); Start(); DCHECK(!mock_factory_job_); // All our simulation needs to satisfy are the following two DCHECKs @@ -123,7 +125,8 @@ class AppCacheRequestHandlerTest : public testing::Test { } void SimulateResponseInfo(const net::HttpResponseInfo& info) { - mock_factory_job_ = new MockURLRequestJob(this, info); + mock_factory_job_ = new MockURLRequestJob( + this, context()->network_delegate(), info); set_delegate(&delegate_); // needed to get the info back out Start(); DCHECK(!mock_factory_job_); @@ -132,8 +135,10 @@ class AppCacheRequestHandlerTest : public testing::Test { MockURLRequestDelegate delegate_; }; - static net::URLRequestJob* MockHttpJobFactory(net::URLRequest* request, - const std::string& scheme) { + static net::URLRequestJob* MockHttpJobFactory( + net::URLRequest* request, + net::NetworkDelegate* network_delegate, + const std::string& scheme) { if (mock_factory_job_) { net::URLRequestJob* temp = mock_factory_job_; mock_factory_job_ = NULL; @@ -142,6 +147,7 @@ class AppCacheRequestHandlerTest : public testing::Test { // Some of these tests trigger UpdateJobs which start URLRequests. // We short circuit those be returning error jobs. return new net::URLRequestErrorJob(request, + network_delegate, net::ERR_INTERNET_DISCONNECTED); } } @@ -246,7 +252,8 @@ class AppCacheRequestHandlerTest : public testing::Test { ResourceType::MAIN_FRAME)); EXPECT_TRUE(handler_.get()); - job_ = handler_->MaybeLoadResource(request_.get()); + job_ = handler_->MaybeLoadResource(request_.get(), + empty_context_.network_delegate()); EXPECT_TRUE(job_.get()); EXPECT_TRUE(job_->is_waiting()); @@ -267,9 +274,12 @@ class AppCacheRequestHandlerTest : public testing::Test { AppCacheURLRequestJob* fallback_job; fallback_job = handler_->MaybeLoadFallbackForRedirect( - request_.get(), GURL("http://blah/redirect")); + request_.get(), + request_->context()->network_delegate(), + GURL("http://blah/redirect")); EXPECT_FALSE(fallback_job); - fallback_job = handler_->MaybeLoadFallbackForResponse(request_.get()); + fallback_job = handler_->MaybeLoadFallbackForResponse( + request_.get(), request_->context()->network_delegate()); EXPECT_FALSE(fallback_job); EXPECT_TRUE(host_->preferred_manifest_url().is_empty()); @@ -294,7 +304,8 @@ class AppCacheRequestHandlerTest : public testing::Test { GURL(), AppCacheEntry(), 1, 2, GURL("http://blah/manifest/")); - job_ = handler_->MaybeLoadResource(request_.get()); + job_ = handler_->MaybeLoadResource(request_.get(), + empty_context_.network_delegate()); EXPECT_TRUE(job_.get()); EXPECT_TRUE(job_->is_waiting()); @@ -314,7 +325,8 @@ class AppCacheRequestHandlerTest : public testing::Test { EXPECT_EQ(2, handler_->found_group_id_); AppCacheURLRequestJob* fallback_job; - fallback_job = handler_->MaybeLoadFallbackForResponse(request_.get()); + fallback_job = handler_->MaybeLoadFallbackForResponse( + request_.get(), request_->context()->network_delegate()); EXPECT_FALSE(fallback_job); EXPECT_EQ(GURL("http://blah/manifest/"), @@ -341,7 +353,8 @@ class AppCacheRequestHandlerTest : public testing::Test { AppCacheEntry(AppCacheEntry::EXPLICIT, 1), 1, 2, GURL("http://blah/manifest/")); - job_ = handler_->MaybeLoadResource(request_.get()); + job_ = handler_->MaybeLoadResource(request_.get(), + empty_context_.network_delegate()); EXPECT_TRUE(job_.get()); EXPECT_TRUE(job_->is_waiting()); @@ -356,13 +369,15 @@ class AppCacheRequestHandlerTest : public testing::Test { // When the request is restarted, the existing job is dropped so a // real network job gets created. We expect NULL here which will cause // the net library to create a real job. - job_ = handler_->MaybeLoadResource(request_.get()); + job_ = handler_->MaybeLoadResource(request_.get(), + empty_context_.network_delegate()); EXPECT_FALSE(job_); // Simulate an http error of the real network job. request_->SimulateResponseCode(500); - job_ = handler_->MaybeLoadFallbackForResponse(request_.get()); + job_ = handler_->MaybeLoadFallbackForResponse( + request_.get(), request_->context()->network_delegate()); EXPECT_TRUE(job_); EXPECT_TRUE(job_->is_delivering_appcache_response()); @@ -399,7 +414,8 @@ class AppCacheRequestHandlerTest : public testing::Test { AppCacheEntry(AppCacheEntry::EXPLICIT, 1), 1, 2, GURL("http://blah/manifest/")); - job_ = handler_->MaybeLoadResource(request_.get()); + job_ = handler_->MaybeLoadResource(request_.get(), + empty_context_.network_delegate()); EXPECT_TRUE(job_.get()); EXPECT_TRUE(job_->is_waiting()); @@ -414,7 +430,8 @@ class AppCacheRequestHandlerTest : public testing::Test { // When the request is restarted, the existing job is dropped so a // real network job gets created. We expect NULL here which will cause // the net library to create a real job. - job_ = handler_->MaybeLoadResource(request_.get()); + job_ = handler_->MaybeLoadResource(request_.get(), + empty_context_.network_delegate()); EXPECT_FALSE(job_); // Simulate an http error of the real network job, but with custom @@ -428,7 +445,8 @@ class AppCacheRequestHandlerTest : public testing::Test { std::string(kOverrideHeaders, arraysize(kOverrideHeaders))); request_->SimulateResponseInfo(info); - job_ = handler_->MaybeLoadFallbackForResponse(request_.get()); + job_ = handler_->MaybeLoadFallbackForResponse( + request_.get(), request_->context()->network_delegate()); EXPECT_FALSE(job_); TestFinished(); @@ -460,15 +478,19 @@ class AppCacheRequestHandlerTest : public testing::Test { ResourceType::SUB_RESOURCE)); EXPECT_TRUE(handler_.get()); - job_ = handler_->MaybeLoadResource(request_.get()); + job_ = handler_->MaybeLoadResource(request_.get(), + empty_context_.network_delegate()); EXPECT_TRUE(job_.get()); EXPECT_TRUE(job_->is_delivering_error_response()); AppCacheURLRequestJob* fallback_job; fallback_job = handler_->MaybeLoadFallbackForRedirect( - request_.get(), GURL("http://blah/redirect")); + request_.get(), + empty_context_.network_delegate(), + GURL("http://blah/redirect")); EXPECT_FALSE(fallback_job); - fallback_job = handler_->MaybeLoadFallbackForResponse(request_.get()); + fallback_job = handler_->MaybeLoadFallbackForResponse( + request_.get(), empty_context_.network_delegate()); EXPECT_FALSE(fallback_job); TestFinished(); @@ -486,7 +508,8 @@ class AppCacheRequestHandlerTest : public testing::Test { handler_.reset(host_->CreateRequestHandler(request_.get(), ResourceType::SUB_RESOURCE)); EXPECT_TRUE(handler_.get()); - job_ = handler_->MaybeLoadResource(request_.get()); + job_ = handler_->MaybeLoadResource(request_.get(), + empty_context_.network_delegate()); EXPECT_TRUE(job_.get()); EXPECT_TRUE(job_->is_waiting()); @@ -496,9 +519,12 @@ class AppCacheRequestHandlerTest : public testing::Test { AppCacheURLRequestJob* fallback_job; fallback_job = handler_->MaybeLoadFallbackForRedirect( - request_.get(), GURL("http://blah/redirect")); + request_.get(), + empty_context_.network_delegate(), + GURL("http://blah/redirect")); EXPECT_FALSE(fallback_job); - fallback_job = handler_->MaybeLoadFallbackForResponse(request_.get()); + fallback_job = handler_->MaybeLoadFallbackForResponse( + request_.get(), empty_context_.network_delegate()); EXPECT_FALSE(fallback_job); TestFinished(); @@ -516,15 +542,19 @@ class AppCacheRequestHandlerTest : public testing::Test { handler_.reset(host_->CreateRequestHandler(request_.get(), ResourceType::SUB_RESOURCE)); EXPECT_TRUE(handler_.get()); - job_ = handler_->MaybeLoadResource(request_.get()); + job_ = handler_->MaybeLoadResource(request_.get(), + empty_context_.network_delegate()); EXPECT_TRUE(job_.get()); EXPECT_TRUE(job_->is_delivering_appcache_response()); AppCacheURLRequestJob* fallback_job; fallback_job = handler_->MaybeLoadFallbackForRedirect( - request_.get(), GURL("http://blah/redirect")); + request_.get(), + empty_context_.network_delegate(), + GURL("http://blah/redirect")); EXPECT_FALSE(fallback_job); - fallback_job = handler_->MaybeLoadFallbackForResponse(request_.get()); + fallback_job = handler_->MaybeLoadFallbackForResponse( + request_.get(), empty_context_.network_delegate()); EXPECT_FALSE(fallback_job); TestFinished(); @@ -544,16 +574,20 @@ class AppCacheRequestHandlerTest : public testing::Test { handler_.reset(host_->CreateRequestHandler(request_.get(), ResourceType::SUB_RESOURCE)); EXPECT_TRUE(handler_.get()); - job_ = handler_->MaybeLoadResource(request_.get()); + job_ = handler_->MaybeLoadResource(request_.get(), + empty_context_.network_delegate()); EXPECT_FALSE(job_.get()); job_ = handler_->MaybeLoadFallbackForRedirect( - request_.get(), GURL("http://not_blah/redirect")); + request_.get(), + empty_context_.network_delegate(), + GURL("http://not_blah/redirect")); EXPECT_TRUE(job_.get()); EXPECT_TRUE(job_->is_delivering_appcache_response()); AppCacheURLRequestJob* fallback_job; - fallback_job = handler_->MaybeLoadFallbackForResponse(request_.get()); + fallback_job = handler_->MaybeLoadFallbackForResponse( + request_.get(), empty_context_.network_delegate()); EXPECT_FALSE(fallback_job); TestFinished(); @@ -573,16 +607,20 @@ class AppCacheRequestHandlerTest : public testing::Test { handler_.reset(host_->CreateRequestHandler(request_.get(), ResourceType::SUB_RESOURCE)); EXPECT_TRUE(handler_.get()); - job_ = handler_->MaybeLoadResource(request_.get()); + job_ = handler_->MaybeLoadResource(request_.get(), + empty_context_.network_delegate()); EXPECT_FALSE(job_.get()); AppCacheURLRequestJob* fallback_job; fallback_job = handler_->MaybeLoadFallbackForRedirect( - request_.get(), GURL("http://blah/redirect")); + request_.get(), + empty_context_.network_delegate(), + GURL("http://blah/redirect")); EXPECT_FALSE(fallback_job); request_->SimulateResponseCode(200); - fallback_job = handler_->MaybeLoadFallbackForResponse(request_.get()); + fallback_job = handler_->MaybeLoadFallbackForResponse( + request_.get(), empty_context_.network_delegate()); EXPECT_FALSE(fallback_job); TestFinished(); @@ -603,14 +641,18 @@ class AppCacheRequestHandlerTest : public testing::Test { handler_.reset(host_->CreateRequestHandler(request_.get(), ResourceType::SUB_RESOURCE)); EXPECT_TRUE(handler_.get()); - job_ = handler_->MaybeLoadResource(request_.get()); + job_ = handler_->MaybeLoadResource(request_.get(), + empty_context_.network_delegate()); EXPECT_FALSE(job_.get()); AppCacheURLRequestJob* fallback_job; fallback_job = handler_->MaybeLoadFallbackForRedirect( - request_.get(), GURL("http://blah/redirect")); + request_.get(), + empty_context_.network_delegate(), + GURL("http://blah/redirect")); EXPECT_FALSE(fallback_job); - fallback_job = handler_->MaybeLoadFallbackForResponse(request_.get()); + fallback_job = handler_->MaybeLoadFallbackForResponse( + request_.get(), empty_context_.network_delegate()); EXPECT_FALSE(fallback_job); TestFinished(); @@ -632,10 +674,14 @@ class AppCacheRequestHandlerTest : public testing::Test { backend_impl_->UnregisterHost(1); host_ = NULL; - EXPECT_FALSE(handler_->MaybeLoadResource(request_.get())); + EXPECT_FALSE(handler_->MaybeLoadResource( + request_.get(), empty_context_.network_delegate())); EXPECT_FALSE(handler_->MaybeLoadFallbackForRedirect( - request_.get(), GURL("http://blah/redirect"))); - EXPECT_FALSE(handler_->MaybeLoadFallbackForResponse(request_.get())); + request_.get(), + empty_context_.network_delegate(), + GURL("http://blah/redirect"))); + EXPECT_FALSE(handler_->MaybeLoadFallbackForResponse( + request_.get(), empty_context_.network_delegate())); TestFinished(); } @@ -651,7 +697,8 @@ class AppCacheRequestHandlerTest : public testing::Test { ResourceType::SUB_RESOURCE)); EXPECT_TRUE(handler_.get()); - job_ = handler_->MaybeLoadResource(request_.get()); + job_ = handler_->MaybeLoadResource( + request_.get(), empty_context_.network_delegate()); EXPECT_TRUE(job_.get()); EXPECT_TRUE(job_->is_waiting()); @@ -659,10 +706,14 @@ class AppCacheRequestHandlerTest : public testing::Test { host_ = NULL; EXPECT_TRUE(job_->has_been_killed()); - EXPECT_FALSE(handler_->MaybeLoadResource(request_.get())); + EXPECT_FALSE(handler_->MaybeLoadResource( + request_.get(), empty_context_.network_delegate())); EXPECT_FALSE(handler_->MaybeLoadFallbackForRedirect( - request_.get(), GURL("http://blah/redirect"))); - EXPECT_FALSE(handler_->MaybeLoadFallbackForResponse(request_.get())); + request_.get(), + empty_context_.network_delegate(), + GURL("http://blah/redirect"))); + EXPECT_FALSE(handler_->MaybeLoadFallbackForResponse( + request_.get(), empty_context_.network_delegate())); TestFinished(); } @@ -678,10 +729,14 @@ class AppCacheRequestHandlerTest : public testing::Test { ResourceType::SUB_RESOURCE)); EXPECT_TRUE(handler_.get()); // we could redirect to http (conceivably) - EXPECT_FALSE(handler_->MaybeLoadResource(request_.get())); + EXPECT_FALSE(handler_->MaybeLoadResource( + request_.get(), empty_context_.network_delegate())); EXPECT_FALSE(handler_->MaybeLoadFallbackForRedirect( - request_.get(), GURL("ftp://blah/redirect"))); - EXPECT_FALSE(handler_->MaybeLoadFallbackForResponse(request_.get())); + request_.get(), + empty_context_.network_delegate(), + GURL("ftp://blah/redirect"))); + EXPECT_FALSE(handler_->MaybeLoadFallbackForResponse( + request_.get(), empty_context_.network_delegate())); TestFinished(); } @@ -694,7 +749,8 @@ class AppCacheRequestHandlerTest : public testing::Test { ResourceType::MAIN_FRAME)); EXPECT_TRUE(handler_.get()); - job_ = handler_->MaybeLoadResource(request_.get()); + job_ = handler_->MaybeLoadResource(request_.get(), + empty_context_.network_delegate()); EXPECT_TRUE(job_.get()); EXPECT_TRUE(job_->is_waiting()); EXPECT_FALSE(job_->has_been_started()); @@ -706,7 +762,8 @@ class AppCacheRequestHandlerTest : public testing::Test { request_->Cancel(); EXPECT_TRUE(job_->has_been_killed()); - EXPECT_FALSE(handler_->MaybeLoadFallbackForResponse(request_.get())); + EXPECT_FALSE(handler_->MaybeLoadFallbackForResponse( + request_.get(), empty_context_.network_delegate())); TestFinished(); } @@ -771,7 +828,8 @@ class AppCacheRequestHandlerTest : public testing::Test { GURL(), AppCacheEntry(), 1, 2, GURL("http://blah/manifest/")); - job_ = handler_->MaybeLoadResource(request_.get()); + job_ = handler_->MaybeLoadResource(request_.get(), + empty_context_.network_delegate()); EXPECT_TRUE(job_.get()); EXPECT_TRUE(job_->is_waiting()); diff --git a/webkit/appcache/appcache_update_job_unittest.cc b/webkit/appcache/appcache_update_job_unittest.cc index 123a563..73f8692 100644 --- a/webkit/appcache/appcache_update_job_unittest.cc +++ b/webkit/appcache/appcache_update_job_unittest.cc @@ -51,14 +51,16 @@ class MockHttpServer { return GURL("https://cross_origin_host/" + path); } - static net::URLRequestJob* JobFactory(net::URLRequest* request) { + static net::URLRequestJob* JobFactory( + net::URLRequest* request, net::NetworkDelegate* network_delegate) { if (request->url().host() != "mockhost" && request->url().host() != "cross_origin_host") - return new net::URLRequestErrorJob(request, -100); + return new net::URLRequestErrorJob(request, network_delegate, -100); std::string headers, body; GetMockResponse(request->url().path(), &headers, &body); - return new net::URLRequestTestJob(request, headers, body, true); + return new net::URLRequestTestJob( + request, network_delegate, headers, body, true); } private: @@ -194,8 +196,9 @@ class MockHttpServer { class MockHttpServerJobFactory : public net::URLRequestJobFactory::ProtocolHandler { public: - virtual net::URLRequestJob* MaybeCreateJob(net::URLRequest* request) const { - return MockHttpServer::JobFactory(request); + virtual net::URLRequestJob* MaybeCreateJob( + net::URLRequest* request, net::NetworkDelegate* network_delegate) const { + return MockHttpServer::JobFactory(request, network_delegate); } }; @@ -336,9 +339,11 @@ class MockFrontend : public AppCacheFrontend { // Helper factories to simulate redirected URL responses for tests. class RedirectFactory : public net::URLRequestJobFactory::ProtocolHandler { public: - virtual net::URLRequestJob* MaybeCreateJob(net::URLRequest* request) const { + virtual net::URLRequestJob* MaybeCreateJob( + net::URLRequest* request, net::NetworkDelegate* network_delegate) const { return new net::URLRequestTestJob( request, + network_delegate, net::URLRequestTestJob::test_redirect_headers(), net::URLRequestTestJob::test_data_1(), true); @@ -372,15 +377,18 @@ class RetryRequestTestJob : public net::URLRequestTestJob { expected_requests_ = 0; } - static net::URLRequestJob* RetryFactory(net::URLRequest* request) { + static net::URLRequestJob* RetryFactory( + net::URLRequest* request, net::NetworkDelegate* network_delegate) { ++num_requests_; if (num_retries_ > 0 && request->original_url() == kRetryUrl) { --num_retries_; return new RetryRequestTestJob( - request, RetryRequestTestJob::retry_headers(), 503); + request, network_delegate, RetryRequestTestJob::retry_headers(), 503); } else { return new RetryRequestTestJob( - request, RetryRequestTestJob::manifest_headers(), 200); + request, + network_delegate, + RetryRequestTestJob::manifest_headers(), 200); } } @@ -427,9 +435,11 @@ class RetryRequestTestJob : public net::URLRequestTestJob { } RetryRequestTestJob(net::URLRequest* request, + net::NetworkDelegate* network_delegate, const std::string& headers, int response_code) - : net::URLRequestTestJob(request, headers, data(), true), + : net::URLRequestTestJob( + request, network_delegate, headers, data(), true), response_code_(response_code) { } @@ -444,8 +454,9 @@ class RetryRequestTestJob : public net::URLRequestTestJob { class RetryRequestTestJobFactory : public net::URLRequestJobFactory::ProtocolHandler { public: - virtual net::URLRequestJob* MaybeCreateJob(net::URLRequest* request) const { - return RetryRequestTestJob::RetryFactory(request); + virtual net::URLRequestJob* MaybeCreateJob( + net::URLRequest* request, net::NetworkDelegate* network_delegate) const { + return RetryRequestTestJob::RetryFactory(request, network_delegate); } }; @@ -481,7 +492,8 @@ class HttpHeadersRequestTestJob : public net::URLRequestTestJob { already_checked_ = false; } - static net::URLRequestJob* IfModifiedSinceFactory(net::URLRequest* request) { + static net::URLRequestJob* IfModifiedSinceFactory( + net::URLRequest* request, net::NetworkDelegate* network_delegate) { if (!already_checked_) { already_checked_ = true; // only check once for a test const net::HttpRequestHeaders& extra_headers = @@ -497,7 +509,7 @@ class HttpHeadersRequestTestJob : public net::URLRequestTestJob { net::HttpRequestHeaders::kIfNoneMatch, &header_value) && header_value == expect_if_none_match_; } - return MockHttpServer::JobFactory(request); + return MockHttpServer::JobFactory(request, network_delegate); } protected: @@ -521,8 +533,10 @@ bool HttpHeadersRequestTestJob::already_checked_ = false; class IfModifiedSinceJobFactory : public net::URLRequestJobFactory::ProtocolHandler { public: - virtual net::URLRequestJob* MaybeCreateJob(net::URLRequest* request) const { - return HttpHeadersRequestTestJob::IfModifiedSinceFactory(request); + virtual net::URLRequestJob* MaybeCreateJob( + net::URLRequest* request, net::NetworkDelegate* network_delegate) const { + return HttpHeadersRequestTestJob::IfModifiedSinceFactory( + request, network_delegate); } }; diff --git a/webkit/appcache/appcache_url_request_job.cc b/webkit/appcache/appcache_url_request_job.cc index 2c8efa7..80c0b7d 100644 --- a/webkit/appcache/appcache_url_request_job.cc +++ b/webkit/appcache/appcache_url_request_job.cc @@ -18,15 +18,16 @@ #include "net/http/http_response_headers.h" #include "net/http/http_util.h" #include "net/url_request/url_request.h" -#include "net/url_request/url_request_context.h" #include "net/url_request/url_request_status.h" #include "webkit/appcache/appcache_service.h" namespace appcache { AppCacheURLRequestJob::AppCacheURLRequestJob( - net::URLRequest* request, AppCacheStorage* storage) - : net::URLRequestJob(request, request->context()->network_delegate()), + net::URLRequest* request, + net::NetworkDelegate* network_delegate, + AppCacheStorage* storage) + : net::URLRequestJob(request, network_delegate), storage_(storage), has_been_started_(false), has_been_killed_(false), delivery_type_(AWAITING_DELIVERY_ORDERS), diff --git a/webkit/appcache/appcache_url_request_job.h b/webkit/appcache/appcache_url_request_job.h index 2e11abc..38ee9bd 100644 --- a/webkit/appcache/appcache_url_request_job.h +++ b/webkit/appcache/appcache_url_request_job.h @@ -22,7 +22,9 @@ namespace appcache { class APPCACHE_EXPORT AppCacheURLRequestJob : public net::URLRequestJob, public AppCacheStorage::Delegate { public: - AppCacheURLRequestJob(net::URLRequest* request, AppCacheStorage* storage); + AppCacheURLRequestJob(net::URLRequest* request, + net::NetworkDelegate* network_delegate, + AppCacheStorage* storage); // Informs the job of what response it should deliver. Only one of these // methods should be called, and only once per job. A job will sit idle and diff --git a/webkit/appcache/appcache_url_request_job_unittest.cc b/webkit/appcache/appcache_url_request_job_unittest.cc index 1c2d1f1..9fa8ded 100644 --- a/webkit/appcache/appcache_url_request_job_unittest.cc +++ b/webkit/appcache/appcache_url_request_job_unittest.cc @@ -127,14 +127,17 @@ class AppCacheURLRequestJobTest : public testing::Test { bool kill_with_io_pending_; }; - static net::URLRequestJob* MockHttpJobFactory(net::URLRequest* request, - const std::string& scheme) { + static net::URLRequestJob* MockHttpJobFactory( + net::URLRequest* request, + net::NetworkDelegate* network_delegate, + const std::string& scheme) { if (mock_factory_job_) { net::URLRequestJob* temp = mock_factory_job_; mock_factory_job_ = NULL; return temp; } else { return new net::URLRequestErrorJob(request, + network_delegate, net::ERR_INTERNET_DISCONNECTED); } } @@ -375,7 +378,8 @@ class AppCacheURLRequestJobTest : public testing::Test { // Create an instance and see that it looks as expected. - job = new AppCacheURLRequestJob(&request, storage); + job = new AppCacheURLRequestJob( + &request, empty_context_.network_delegate(), storage); EXPECT_TRUE(job->is_waiting()); EXPECT_FALSE(job->is_delivering_appcache_response()); EXPECT_FALSE(job->is_delivering_network_response()); @@ -398,17 +402,20 @@ class AppCacheURLRequestJobTest : public testing::Test { // Create an instance, give it a delivery order and see that // it looks as expected. - job = new AppCacheURLRequestJob(&request, storage); + job = new AppCacheURLRequestJob( + &request, empty_context_.network_delegate(), storage); job->DeliverErrorResponse(); EXPECT_TRUE(job->is_delivering_error_response()); EXPECT_FALSE(job->has_been_started()); - job = new AppCacheURLRequestJob(&request, storage); + job = new AppCacheURLRequestJob( + &request, empty_context_.network_delegate(), storage); job->DeliverNetworkResponse(); EXPECT_TRUE(job->is_delivering_network_response()); EXPECT_FALSE(job->has_been_started()); - job = new AppCacheURLRequestJob(&request, storage); + job = new AppCacheURLRequestJob( + &request, empty_context_.network_delegate(), storage); const GURL kManifestUrl("http://blah/"); const int64 kCacheId(1); const int64 kGroupId(1); @@ -443,7 +450,8 @@ class AppCacheURLRequestJobTest : public testing::Test { // Setup to create an AppCacheURLRequestJob with orders to deliver // a network response. - mock_factory_job_ = new AppCacheURLRequestJob(request_.get(), storage); + mock_factory_job_ = new AppCacheURLRequestJob( + request_.get(), empty_context_.network_delegate(), storage); mock_factory_job_->DeliverNetworkResponse(); EXPECT_TRUE(mock_factory_job_->is_delivering_network_response()); EXPECT_FALSE(mock_factory_job_->has_been_started()); @@ -478,7 +486,8 @@ class AppCacheURLRequestJobTest : public testing::Test { // Setup to create an AppCacheURLRequestJob with orders to deliver // a network response. - mock_factory_job_ = new AppCacheURLRequestJob(request_.get(), storage); + mock_factory_job_ = new AppCacheURLRequestJob( + request_.get(), empty_context_.network_delegate(), storage); mock_factory_job_->DeliverErrorResponse(); EXPECT_TRUE(mock_factory_job_->is_delivering_error_response()); EXPECT_FALSE(mock_factory_job_->has_been_started()); @@ -528,8 +537,8 @@ class AppCacheURLRequestJobTest : public testing::Test { // Setup to create an AppCacheURLRequestJob with orders to deliver // a network response. - scoped_refptr<AppCacheURLRequestJob> job( - new AppCacheURLRequestJob(request_.get(), storage)); + scoped_refptr<AppCacheURLRequestJob> job(new AppCacheURLRequestJob( + request_.get(), empty_context_.network_delegate(), storage)); if (start_after_delivery_orders) { job->DeliverAppCachedResponse( @@ -646,8 +655,8 @@ class AppCacheURLRequestJobTest : public testing::Test { request_->SetExtraRequestHeaders(extra_headers); // Create job with orders to deliver an appcached entry. - scoped_refptr<AppCacheURLRequestJob> job( - new AppCacheURLRequestJob(request_.get(), storage)); + scoped_refptr<AppCacheURLRequestJob> job(new AppCacheURLRequestJob( + request_.get(), empty_context_.network_delegate(), storage)); job->DeliverAppCachedResponse( GURL(), 0, 111, AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_), diff --git a/webkit/appcache/view_appcache_internals_job.cc b/webkit/appcache/view_appcache_internals_job.cc index 94ee601..c33c7ae 100644 --- a/webkit/appcache/view_appcache_internals_job.cc +++ b/webkit/appcache/view_appcache_internals_job.cc @@ -311,8 +311,11 @@ GURL ClearQuery(const GURL& url) { // Simple base class for the job subclasses defined here. class BaseInternalsJob : public net::URLRequestSimpleJob { protected: - BaseInternalsJob(net::URLRequest* request, AppCacheService* service) - : URLRequestSimpleJob(request), appcache_service_(service) {} + BaseInternalsJob(net::URLRequest* request, + net::NetworkDelegate* network_delegate, + AppCacheService* service) + : URLRequestSimpleJob(request, network_delegate), + appcache_service_(service) {} virtual ~BaseInternalsJob() {} AppCacheService* appcache_service_; @@ -321,8 +324,10 @@ class BaseInternalsJob : public net::URLRequestSimpleJob { // Job that lists all appcaches in the system. class MainPageJob : public BaseInternalsJob { public: - MainPageJob(net::URLRequest* request, AppCacheService* service) - : BaseInternalsJob(request, service), + MainPageJob(net::URLRequest* request, + net::NetworkDelegate* network_delegate, + AppCacheService* service) + : BaseInternalsJob(request, network_delegate, service), ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { } @@ -383,8 +388,10 @@ class MainPageJob : public BaseInternalsJob { // Job that redirects back to the main appcache internals page. class RedirectToMainPageJob : public BaseInternalsJob { public: - RedirectToMainPageJob(net::URLRequest* request, AppCacheService* service) - : BaseInternalsJob(request, service) {} + RedirectToMainPageJob(net::URLRequest* request, + net::NetworkDelegate* network_delegate, + AppCacheService* service) + : BaseInternalsJob(request, network_delegate, service) {} virtual int GetData(std::string* mime_type, std::string* charset, @@ -407,9 +414,11 @@ class RedirectToMainPageJob : public BaseInternalsJob { class RemoveAppCacheJob : public RedirectToMainPageJob { public: RemoveAppCacheJob( - net::URLRequest* request, AppCacheService* service, + net::URLRequest* request, + net::NetworkDelegate* network_delegate, + AppCacheService* service, const GURL& manifest_url) - : RedirectToMainPageJob(request, service), + : RedirectToMainPageJob(request, network_delegate, service), manifest_url_(manifest_url), ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { } @@ -439,9 +448,11 @@ class ViewAppCacheJob : public BaseInternalsJob, public AppCacheStorage::Delegate { public: ViewAppCacheJob( - net::URLRequest* request, AppCacheService* service, + net::URLRequest* request, + net::NetworkDelegate* network_delegate, + AppCacheService* service, const GURL& manifest_url) - : BaseInternalsJob(request, service), + : BaseInternalsJob(request, network_delegate, service), manifest_url_(manifest_url) {} virtual void Start() { @@ -508,10 +519,13 @@ class ViewEntryJob : public BaseInternalsJob, public AppCacheStorage::Delegate { public: ViewEntryJob( - net::URLRequest* request, AppCacheService* service, - const GURL& manifest_url, const GURL& entry_url, + net::URLRequest* request, + net::NetworkDelegate* network_delegate, + AppCacheService* service, + const GURL& manifest_url, + const GURL& entry_url, int64 response_id, int64 group_id) - : BaseInternalsJob(request, service), + : BaseInternalsJob(request, network_delegate, service), manifest_url_(manifest_url), entry_url_(entry_url), response_id_(response_id), group_id_(group_id), amount_read_(0) { } @@ -599,20 +613,22 @@ class ViewEntryJob : public BaseInternalsJob, } // namespace net::URLRequestJob* ViewAppCacheInternalsJobFactory::CreateJobForRequest( - net::URLRequest* request, AppCacheService* service) { + net::URLRequest* request, + net::NetworkDelegate* network_delegate, + AppCacheService* service) { if (!request->url().has_query()) - return new MainPageJob(request, service); + return new MainPageJob(request, network_delegate, service); std::string command; std::string param; ParseQuery(request->url().query(), &command, ¶m); if (command == kRemoveCacheCommand) - return new RemoveAppCacheJob(request, service, + return new RemoveAppCacheJob(request, network_delegate, service, DecodeBase64URL(param)); if (command == kViewCacheCommand) - return new ViewAppCacheJob(request, service, + return new ViewAppCacheJob(request, network_delegate, service, DecodeBase64URL(param)); std::vector<std::string> tokens; @@ -621,13 +637,13 @@ net::URLRequestJob* ViewAppCacheInternalsJobFactory::CreateJobForRequest( if (command == kViewEntryCommand && Tokenize(param, "|", &tokens) == 4u && base::StringToInt64(tokens[2], &response_id) && base::StringToInt64(tokens[3], &group_id)) { - return new ViewEntryJob(request, service, + return new ViewEntryJob(request, network_delegate, service, DecodeBase64URL(tokens[0]), // manifest url DecodeBase64URL(tokens[1]), // entry url response_id, group_id); } - return new RedirectToMainPageJob(request, service); + return new RedirectToMainPageJob(request, network_delegate, service); } } // namespace appcache diff --git a/webkit/appcache/view_appcache_internals_job.h b/webkit/appcache/view_appcache_internals_job.h index 762a703..aad961f 100644 --- a/webkit/appcache/view_appcache_internals_job.h +++ b/webkit/appcache/view_appcache_internals_job.h @@ -9,6 +9,7 @@ #include "webkit/appcache/appcache_export.h" namespace net { +class NetworkDelegate; class URLRequest; class URLRequestJob; } @@ -20,7 +21,9 @@ class AppCacheService; class APPCACHE_EXPORT ViewAppCacheInternalsJobFactory { public: static net::URLRequestJob* CreateJobForRequest( - net::URLRequest* request, AppCacheService* service); + net::URLRequest* request, + net::NetworkDelegate* network_delegate, + AppCacheService* service); private: DISALLOW_IMPLICIT_CONSTRUCTORS(ViewAppCacheInternalsJobFactory); |