| 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_URL_REQUEST_JOB_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_URL_REQUEST_JOB_H_ |
| 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_URL_REQUEST_JOB_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_URL_REQUEST_JOB_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
| 13 #include "content/common/service_worker/service_worker_status_code.h" | 13 #include "content/common/service_worker/service_worker_status_code.h" |
| 14 #include "content/common/service_worker/service_worker_types.h" | 14 #include "content/common/service_worker/service_worker_types.h" |
| 15 #include "net/http/http_byte_range.h" | 15 #include "net/http/http_byte_range.h" |
| 16 #include "net/url_request/url_request.h" | 16 #include "net/url_request/url_request.h" |
| 17 #include "net/url_request/url_request_job.h" | 17 #include "net/url_request/url_request_job.h" |
| 18 | 18 |
| 19 namespace webkit_blob { | 19 namespace webkit_blob { |
| 20 class BlobDataHandle; |
| 20 class BlobStorageContext; | 21 class BlobStorageContext; |
| 21 } | 22 } |
| 22 | 23 |
| 23 namespace content { | 24 namespace content { |
| 24 | 25 |
| 26 class ResourceRequestBody; |
| 25 class ServiceWorkerContextCore; | 27 class ServiceWorkerContextCore; |
| 26 class ServiceWorkerFetchDispatcher; | 28 class ServiceWorkerFetchDispatcher; |
| 27 class ServiceWorkerProviderHost; | 29 class ServiceWorkerProviderHost; |
| 28 | 30 |
| 29 class CONTENT_EXPORT ServiceWorkerURLRequestJob | 31 class CONTENT_EXPORT ServiceWorkerURLRequestJob |
| 30 : public net::URLRequestJob, | 32 : public net::URLRequestJob, |
| 31 public net::URLRequest::Delegate { | 33 public net::URLRequest::Delegate { |
| 32 public: | 34 public: |
| 33 ServiceWorkerURLRequestJob( | 35 ServiceWorkerURLRequestJob( |
| 34 net::URLRequest* request, | 36 net::URLRequest* request, |
| 35 net::NetworkDelegate* network_delegate, | 37 net::NetworkDelegate* network_delegate, |
| 36 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | 38 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
| 37 base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context); | 39 base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context, |
| 40 scoped_refptr<ResourceRequestBody> body); |
| 38 | 41 |
| 39 // Sets the response type. | 42 // Sets the response type. |
| 40 void FallbackToNetwork(); | 43 void FallbackToNetwork(); |
| 41 void ForwardToServiceWorker(); | 44 void ForwardToServiceWorker(); |
| 42 | 45 |
| 43 bool ShouldFallbackToNetwork() const { | 46 bool ShouldFallbackToNetwork() const { |
| 44 return response_type_ == FALLBACK_TO_NETWORK; | 47 return response_type_ == FALLBACK_TO_NETWORK; |
| 45 } | 48 } |
| 46 bool ShouldForwardToServiceWorker() const { | 49 bool ShouldForwardToServiceWorker() const { |
| 47 return response_type_ == FORWARD_TO_SERVICE_WORKER; | 50 return response_type_ == FORWARD_TO_SERVICE_WORKER; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 NOT_DETERMINED, | 96 NOT_DETERMINED, |
| 94 FALLBACK_TO_NETWORK, | 97 FALLBACK_TO_NETWORK, |
| 95 FORWARD_TO_SERVICE_WORKER, | 98 FORWARD_TO_SERVICE_WORKER, |
| 96 }; | 99 }; |
| 97 | 100 |
| 98 // We start processing the request if Start() is called AND response_type_ | 101 // We start processing the request if Start() is called AND response_type_ |
| 99 // is determined. | 102 // is determined. |
| 100 void MaybeStartRequest(); | 103 void MaybeStartRequest(); |
| 101 void StartRequest(); | 104 void StartRequest(); |
| 102 | 105 |
| 106 // Creates ServiceWorkerFetchRequest from |request_| and |body_|. |
| 107 scoped_ptr<ServiceWorkerFetchRequest> CreateFetchRequest(); |
| 108 |
| 109 // Creates BlobDataHandle of the request body from |body_|. This handle |
| 110 // |request_body_blob_data_handle_| will be deleted when |
| 111 // ServiceWorkerURLRequestJob is deleted. |
| 112 bool CreateRequestBodyBlob(std::string* blob_uuid, uint64* blob_size); |
| 113 |
| 103 // For FORWARD_TO_SERVICE_WORKER case. | 114 // For FORWARD_TO_SERVICE_WORKER case. |
| 104 void DidDispatchFetchEvent(ServiceWorkerStatusCode status, | 115 void DidDispatchFetchEvent(ServiceWorkerStatusCode status, |
| 105 ServiceWorkerFetchEventResult fetch_result, | 116 ServiceWorkerFetchEventResult fetch_result, |
| 106 const ServiceWorkerResponse& response); | 117 const ServiceWorkerResponse& response); |
| 107 | 118 |
| 108 // Populates |http_response_headers_|. | 119 // Populates |http_response_headers_|. |
| 109 void CreateResponseHeader(int status_code, | 120 void CreateResponseHeader(int status_code, |
| 110 const std::string& status_text, | 121 const std::string& status_text, |
| 111 const std::map<std::string, std::string>& headers); | 122 const std::map<std::string, std::string>& headers); |
| 112 | 123 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 126 scoped_ptr<net::HttpResponseInfo> range_response_info_; | 137 scoped_ptr<net::HttpResponseInfo> range_response_info_; |
| 127 scoped_ptr<net::HttpResponseInfo> http_response_info_; | 138 scoped_ptr<net::HttpResponseInfo> http_response_info_; |
| 128 // Headers that have not yet been committed to |http_response_info_|. | 139 // Headers that have not yet been committed to |http_response_info_|. |
| 129 scoped_refptr<net::HttpResponseHeaders> http_response_headers_; | 140 scoped_refptr<net::HttpResponseHeaders> http_response_headers_; |
| 130 GURL response_url_; | 141 GURL response_url_; |
| 131 | 142 |
| 132 // Used when response type is FORWARD_TO_SERVICE_WORKER. | 143 // Used when response type is FORWARD_TO_SERVICE_WORKER. |
| 133 scoped_ptr<ServiceWorkerFetchDispatcher> fetch_dispatcher_; | 144 scoped_ptr<ServiceWorkerFetchDispatcher> fetch_dispatcher_; |
| 134 base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context_; | 145 base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context_; |
| 135 scoped_ptr<net::URLRequest> blob_request_; | 146 scoped_ptr<net::URLRequest> blob_request_; |
| 147 scoped_refptr<ResourceRequestBody> body_; |
| 148 scoped_ptr<webkit_blob::BlobDataHandle> request_body_blob_data_handle_; |
| 136 | 149 |
| 137 base::WeakPtrFactory<ServiceWorkerURLRequestJob> weak_factory_; | 150 base::WeakPtrFactory<ServiceWorkerURLRequestJob> weak_factory_; |
| 138 | 151 |
| 139 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerURLRequestJob); | 152 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerURLRequestJob); |
| 140 }; | 153 }; |
| 141 | 154 |
| 142 } // namespace content | 155 } // namespace content |
| 143 | 156 |
| 144 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_URL_REQUEST_JOB_H_ | 157 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_URL_REQUEST_JOB_H_ |
| OLD | NEW |