| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REQUEST_HANDLER_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REQUEST_HANDLER_H_ |
| 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REQUEST_HANDLER_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REQUEST_HANDLER_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/supports_user_data.h" | 10 #include "base/supports_user_data.h" |
| 11 #include "content/common/content_export.h" | 11 #include "content/common/content_export.h" |
| 12 #include "content/common/service_worker/service_worker_status_code.h" | 12 #include "content/common/service_worker/service_worker_status_code.h" |
| 13 #include "net/url_request/url_request_job_factory.h" | 13 #include "net/url_request/url_request_job_factory.h" |
| 14 #include "webkit/common/resource_type.h" | 14 #include "webkit/common/resource_type.h" |
| 15 | 15 |
| 16 namespace net { | 16 namespace net { |
| 17 class NetworkDelegate; | 17 class NetworkDelegate; |
| 18 class URLRequest; | 18 class URLRequest; |
| 19 } | 19 } |
| 20 | 20 |
| 21 namespace webkit_blob { |
| 22 class BlobStorageContext; |
| 23 } |
| 24 |
| 21 namespace content { | 25 namespace content { |
| 22 | 26 |
| 27 class ChromeBlobStorageContext; |
| 23 class ServiceWorkerContextCore; | 28 class ServiceWorkerContextCore; |
| 24 class ServiceWorkerContextWrapper; | 29 class ServiceWorkerContextWrapper; |
| 25 class ServiceWorkerProviderHost; | 30 class ServiceWorkerProviderHost; |
| 26 | 31 |
| 27 // Abstract base class for routing network requests to ServiceWorkers. | 32 // Abstract base class for routing network requests to ServiceWorkers. |
| 28 // Created one per URLRequest and attached to each request. | 33 // Created one per URLRequest and attached to each request. |
| 29 class CONTENT_EXPORT ServiceWorkerRequestHandler | 34 class CONTENT_EXPORT ServiceWorkerRequestHandler |
| 30 : public base::SupportsUserData::Data { | 35 : public base::SupportsUserData::Data { |
| 31 public: | 36 public: |
| 32 // Attaches a newly created handler if the given |request| needs to | 37 // Attaches a newly created handler if the given |request| needs to |
| 33 // be handled by ServiceWorker. | 38 // be handled by ServiceWorker. |
| 34 // TODO(kinuko): While utilizing UserData to attach data to URLRequest | 39 // TODO(kinuko): While utilizing UserData to attach data to URLRequest |
| 35 // has some precedence, it might be better to attach this handler in a more | 40 // has some precedence, it might be better to attach this handler in a more |
| 36 // explicit way within content layer, e.g. have ResourceRequestInfoImpl | 41 // explicit way within content layer, e.g. have ResourceRequestInfoImpl |
| 37 // own it. | 42 // own it. |
| 38 static void InitializeHandler( | 43 static void InitializeHandler( |
| 39 net::URLRequest* request, | 44 net::URLRequest* request, |
| 40 ServiceWorkerContextWrapper* context_wrapper, | 45 ServiceWorkerContextWrapper* context_wrapper, |
| 46 webkit_blob::BlobStorageContext* blob_storage_context, |
| 41 int process_id, | 47 int process_id, |
| 42 int provider_id, | 48 int provider_id, |
| 43 ResourceType::Type resource_type); | 49 ResourceType::Type resource_type); |
| 44 | 50 |
| 45 // Returns the handler attached to |request|. This may return NULL | 51 // Returns the handler attached to |request|. This may return NULL |
| 46 // if no handler is attached. | 52 // if no handler is attached. |
| 47 static ServiceWorkerRequestHandler* GetHandler( | 53 static ServiceWorkerRequestHandler* GetHandler( |
| 48 net::URLRequest* request); | 54 net::URLRequest* request); |
| 49 | 55 |
| 50 // Creates a protocol interceptor for ServiceWorker. | 56 // Creates a protocol interceptor for ServiceWorker. |
| 51 static scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | 57 static scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 52 CreateInterceptor(); | 58 CreateInterceptor(); |
| 53 | 59 |
| 54 virtual ~ServiceWorkerRequestHandler(); | 60 virtual ~ServiceWorkerRequestHandler(); |
| 55 | 61 |
| 56 // Called via custom URLRequestJobFactory. | 62 // Called via custom URLRequestJobFactory. |
| 57 virtual net::URLRequestJob* MaybeCreateJob( | 63 virtual net::URLRequestJob* MaybeCreateJob( |
| 58 net::URLRequest* request, | 64 net::URLRequest* request, |
| 59 net::NetworkDelegate* network_delegate) = 0; | 65 net::NetworkDelegate* network_delegate) = 0; |
| 60 | 66 |
| 61 protected: | 67 protected: |
| 62 ServiceWorkerRequestHandler( | 68 ServiceWorkerRequestHandler( |
| 63 base::WeakPtr<ServiceWorkerContextCore> context, | 69 base::WeakPtr<ServiceWorkerContextCore> context, |
| 64 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | 70 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
| 71 base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context, |
| 65 ResourceType::Type resource_type); | 72 ResourceType::Type resource_type); |
| 66 | 73 |
| 67 base::WeakPtr<ServiceWorkerContextCore> context_; | 74 base::WeakPtr<ServiceWorkerContextCore> context_; |
| 68 base::WeakPtr<ServiceWorkerProviderHost> provider_host_; | 75 base::WeakPtr<ServiceWorkerProviderHost> provider_host_; |
| 76 base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context_; |
| 69 ResourceType::Type resource_type_; | 77 ResourceType::Type resource_type_; |
| 70 | 78 |
| 71 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRequestHandler); | 79 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRequestHandler); |
| 72 }; | 80 }; |
| 73 | 81 |
| 74 } // namespace content | 82 } // namespace content |
| 75 | 83 |
| 76 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REQUEST_HANDLER_H_ | 84 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REQUEST_HANDLER_H_ |
| OLD | NEW |