Index: content/browser/service_worker/service_worker_controllee_request_handler.cc |
diff --git a/content/browser/service_worker/service_worker_request_handler.cc b/content/browser/service_worker/service_worker_controllee_request_handler.cc |
similarity index 55% |
copy from content/browser/service_worker/service_worker_request_handler.cc |
copy to content/browser/service_worker/service_worker_controllee_request_handler.cc |
index 2e3c5c4623350cef1e8ead5bc3a06fc3afdd739b..148ce443174481e11b288cbd84d5374aa2bbea08 100644 |
--- a/content/browser/service_worker/service_worker_request_handler.cc |
+++ b/content/browser/service_worker/service_worker_controllee_request_handler.cc |
@@ -2,10 +2,9 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "content/browser/service_worker/service_worker_request_handler.h" |
+#include "content/browser/service_worker/service_worker_controllee_request_handler.h" |
#include "content/browser/service_worker/service_worker_context_core.h" |
-#include "content/browser/service_worker/service_worker_context_wrapper.h" |
#include "content/browser/service_worker/service_worker_provider_host.h" |
#include "content/browser/service_worker/service_worker_registration.h" |
#include "content/browser/service_worker/service_worker_url_request_job.h" |
@@ -15,76 +14,19 @@ |
namespace content { |
-namespace { |
- |
-int kUserDataKey; // Key value is not important. |
- |
-class ServiceWorkerRequestInterceptor |
- : public net::URLRequestJobFactory::ProtocolHandler { |
- public: |
- ServiceWorkerRequestInterceptor() {} |
- virtual ~ServiceWorkerRequestInterceptor() {} |
- virtual net::URLRequestJob* MaybeCreateJob( |
- net::URLRequest* request, |
- net::NetworkDelegate* network_delegate) const OVERRIDE { |
- ServiceWorkerRequestHandler* handler = |
- ServiceWorkerRequestHandler::GetHandler(request); |
- if (!handler) |
- return NULL; |
- return handler->MaybeCreateJob(request, network_delegate); |
- } |
- |
- private: |
- DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRequestInterceptor); |
-}; |
- |
-} // namespace |
- |
-void ServiceWorkerRequestHandler::InitializeHandler( |
- net::URLRequest* request, |
- ServiceWorkerContextWrapper* context_wrapper, |
- int process_id, |
- int provider_id, |
- ResourceType::Type resource_type) { |
- if (!ServiceWorkerUtils::IsFeatureEnabled()) |
- return; |
- |
- if (!context_wrapper || !context_wrapper->context() || |
- provider_id == kInvalidServiceWorkerProviderId) { |
- return; |
- } |
- |
- ServiceWorkerProviderHost* provider_host = |
- context_wrapper->context()->GetProviderHost(process_id, provider_id); |
- if (!provider_host) |
- return; |
- |
- if (!provider_host->ShouldHandleRequest(resource_type)) |
- return; |
- |
- scoped_ptr<ServiceWorkerRequestHandler> handler( |
- new ServiceWorkerRequestHandler(context_wrapper->context()->AsWeakPtr(), |
- provider_host->AsWeakPtr(), |
- resource_type)); |
- request->SetUserData(&kUserDataKey, handler.release()); |
-} |
- |
-ServiceWorkerRequestHandler* ServiceWorkerRequestHandler::GetHandler( |
- net::URLRequest* request) { |
- return reinterpret_cast<ServiceWorkerRequestHandler*>( |
- request->GetUserData(&kUserDataKey)); |
-} |
- |
-scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
-ServiceWorkerRequestHandler::CreateInterceptor() { |
- return make_scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>( |
- new ServiceWorkerRequestInterceptor); |
+ServiceWorkerControlleeRequestHandler::ServiceWorkerControlleeRequestHandler( |
+ base::WeakPtr<ServiceWorkerContextCore> context, |
+ base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
+ ResourceType::Type resource_type) |
+ : ServiceWorkerRequestHandler(context, provider_host, resource_type), |
+ weak_factory_(this) { |
} |
-ServiceWorkerRequestHandler::~ServiceWorkerRequestHandler() { |
+ServiceWorkerControlleeRequestHandler:: |
+ ~ServiceWorkerControlleeRequestHandler() { |
} |
-net::URLRequestJob* ServiceWorkerRequestHandler::MaybeCreateJob( |
+net::URLRequestJob* ServiceWorkerControlleeRequestHandler::MaybeCreateJob( |
net::URLRequest* request, |
net::NetworkDelegate* network_delegate) { |
if (!context_ || !provider_host_) { |
@@ -128,17 +70,8 @@ net::URLRequestJob* ServiceWorkerRequestHandler::MaybeCreateJob( |
return job_.get(); |
} |
-ServiceWorkerRequestHandler::ServiceWorkerRequestHandler( |
- base::WeakPtr<ServiceWorkerContextCore> context, |
- base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
- ResourceType::Type resource_type) |
- : context_(context), |
- provider_host_(provider_host), |
- resource_type_(resource_type), |
- weak_factory_(this) { |
-} |
- |
-void ServiceWorkerRequestHandler::PrepareForMainResource(const GURL& url) { |
+void ServiceWorkerControlleeRequestHandler::PrepareForMainResource( |
+ const GURL& url) { |
DCHECK(job_.get()); |
DCHECK(context_); |
// The corresponding provider_host may already have associate version in |
@@ -149,10 +82,11 @@ void ServiceWorkerRequestHandler::PrepareForMainResource(const GURL& url) { |
context_->storage()->FindRegistrationForDocument( |
url, |
base::Bind(&self::DidLookupRegistrationForMainResource, |
- weak_factory_.GetWeakPtr())); |
+ weak_factory_.GetWeakPtr())); |
} |
-void ServiceWorkerRequestHandler::DidLookupRegistrationForMainResource( |
+void |
+ServiceWorkerControlleeRequestHandler::DidLookupRegistrationForMainResource( |
ServiceWorkerStatusCode status, |
const scoped_refptr<ServiceWorkerRegistration>& registration) { |
DCHECK(job_.get()); |
@@ -161,13 +95,16 @@ void ServiceWorkerRequestHandler::DidLookupRegistrationForMainResource( |
job_->FallbackToNetwork(); |
return; |
} |
+ // TODO(michaeln): should SetPendingVersion() even if no active version so |
+ // so the versions in the pipeline (.installing, .waiting) show up in the |
+ // attribute values. |
DCHECK(registration); |
provider_host_->SetActiveVersion(registration->active_version()); |
provider_host_->SetPendingVersion(registration->pending_version()); |
job_->ForwardToServiceWorker(); |
} |
-void ServiceWorkerRequestHandler::PrepareForSubResource() { |
+void ServiceWorkerControlleeRequestHandler::PrepareForSubResource() { |
DCHECK(job_.get()); |
DCHECK(context_); |
DCHECK(provider_host_->active_version()); |