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 content { | 21 namespace content { |
22 | 22 |
23 class ChromeBlobStorageContext; | |
23 class ServiceWorkerContextCore; | 24 class ServiceWorkerContextCore; |
24 class ServiceWorkerContextWrapper; | 25 class ServiceWorkerContextWrapper; |
25 class ServiceWorkerProviderHost; | 26 class ServiceWorkerProviderHost; |
26 | 27 |
27 // Abstract base class for routing network requests to ServiceWorkers. | 28 // Abstract base class for routing network requests to ServiceWorkers. |
28 // Created one per URLRequest and attached to each request. | 29 // Created one per URLRequest and attached to each request. |
29 class CONTENT_EXPORT ServiceWorkerRequestHandler | 30 class CONTENT_EXPORT ServiceWorkerRequestHandler |
30 : public base::SupportsUserData::Data { | 31 : public base::SupportsUserData::Data { |
31 public: | 32 public: |
32 // Attaches a newly created handler if the given |request| needs to | 33 // Attaches a newly created handler if the given |request| needs to |
33 // be handled by ServiceWorker. | 34 // be handled by ServiceWorker. |
34 // TODO(kinuko): While utilizing UserData to attach data to URLRequest | 35 // 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 | 36 // has some precedence, it might be better to attach this handler in a more |
36 // explicit way within content layer, e.g. have ResourceRequestInfoImpl | 37 // explicit way within content layer, e.g. have ResourceRequestInfoImpl |
37 // own it. | 38 // own it. |
38 static void InitializeHandler( | 39 static void InitializeHandler( |
39 net::URLRequest* request, | 40 net::URLRequest* request, |
40 ServiceWorkerContextWrapper* context_wrapper, | 41 ServiceWorkerContextWrapper* context_wrapper, |
41 int process_id, | 42 int process_id, |
42 int provider_id, | 43 int provider_id, |
43 ResourceType::Type resource_type); | 44 ResourceType::Type resource_type); |
michaeln
2014/05/22 03:26:22
BlobContext* blob_context
| |
44 | 45 |
45 // Returns the handler attached to |request|. This may return NULL | 46 // Returns the handler attached to |request|. This may return NULL |
46 // if no handler is attached. | 47 // if no handler is attached. |
47 static ServiceWorkerRequestHandler* GetHandler( | 48 static ServiceWorkerRequestHandler* GetHandler( |
48 net::URLRequest* request); | 49 net::URLRequest* request); |
49 | 50 |
50 // Creates a protocol interceptor for ServiceWorker. | 51 // Creates a protocol interceptor for ServiceWorker. |
51 static scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | 52 static scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
52 CreateInterceptor(); | 53 CreateInterceptor(ChromeBlobStorageContext* blob_storage_context); |
53 | 54 |
54 virtual ~ServiceWorkerRequestHandler(); | 55 virtual ~ServiceWorkerRequestHandler(); |
55 | 56 |
56 // Called via custom URLRequestJobFactory. | 57 // Called via custom URLRequestJobFactory. |
57 virtual net::URLRequestJob* MaybeCreateJob( | 58 virtual net::URLRequestJob* MaybeCreateJob( |
58 net::URLRequest* request, | 59 net::URLRequest* request, |
59 net::NetworkDelegate* network_delegate) = 0; | 60 net::NetworkDelegate* network_delegate, |
61 const scoped_refptr<ChromeBlobStorageContext>& blob_storage_context) = 0; | |
60 | 62 |
61 protected: | 63 protected: |
62 ServiceWorkerRequestHandler( | 64 ServiceWorkerRequestHandler( |
63 base::WeakPtr<ServiceWorkerContextCore> context, | 65 base::WeakPtr<ServiceWorkerContextCore> context, |
64 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | 66 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
65 ResourceType::Type resource_type); | 67 ResourceType::Type resource_type); |
66 | 68 |
67 base::WeakPtr<ServiceWorkerContextCore> context_; | 69 base::WeakPtr<ServiceWorkerContextCore> context_; |
68 base::WeakPtr<ServiceWorkerProviderHost> provider_host_; | 70 base::WeakPtr<ServiceWorkerProviderHost> provider_host_; |
69 ResourceType::Type resource_type_; | 71 ResourceType::Type resource_type_; |
70 | 72 |
michaeln
2014/05/22 03:26:22
base::WeakPtr<BlobStorageContext> blob_context_;
| |
71 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRequestHandler); | 73 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRequestHandler); |
72 }; | 74 }; |
73 | 75 |
74 } // namespace content | 76 } // namespace content |
75 | 77 |
76 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REQUEST_HANDLER_H_ | 78 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REQUEST_HANDLER_H_ |
OLD | NEW |