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 <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 //---------------------------------------------------------------------------- | 134 //---------------------------------------------------------------------------- |
135 // The following are intended for use by ServiceWorker(Blob|Stream)Reader. | 135 // The following are intended for use by ServiceWorker(Blob|Stream)Reader. |
136 void OnResponseStarted(); | 136 void OnResponseStarted(); |
137 void OnReadRawDataComplete(int bytes_read); | 137 void OnReadRawDataComplete(int bytes_read); |
138 void RecordResult(ServiceWorkerMetrics::URLRequestJobResult result); | 138 void RecordResult(ServiceWorkerMetrics::URLRequestJobResult result); |
139 //---------------------------------------------------------------------------- | 139 //---------------------------------------------------------------------------- |
140 | 140 |
141 base::WeakPtr<ServiceWorkerURLRequestJob> GetWeakPtr(); | 141 base::WeakPtr<ServiceWorkerURLRequestJob> GetWeakPtr(); |
142 | 142 |
143 private: | 143 private: |
144 class BlobConstructionWaiter; | 144 class FileSizeResolver; |
145 | 145 |
146 enum ResponseType { | 146 enum ResponseType { |
147 NOT_DETERMINED, | 147 NOT_DETERMINED, |
148 FALLBACK_TO_NETWORK, | 148 FALLBACK_TO_NETWORK, |
149 FALLBACK_TO_RENDERER, // Use this when falling back with CORS check | 149 FALLBACK_TO_RENDERER, // Use this when falling back with CORS check |
150 FORWARD_TO_SERVICE_WORKER, | 150 FORWARD_TO_SERVICE_WORKER, |
151 }; | 151 }; |
152 | 152 |
153 enum ResponseBodyType { | 153 enum ResponseBodyType { |
154 UNKNOWN, | 154 UNKNOWN, |
155 BLOB, | 155 BLOB, |
156 STREAM, | 156 STREAM, |
157 }; | 157 }; |
158 | 158 |
159 // We start processing the request if Start() is called AND response_type_ | 159 // We start processing the request if Start() is called AND response_type_ |
160 // is determined. | 160 // is determined. |
161 void MaybeStartRequest(); | 161 void MaybeStartRequest(); |
162 void StartRequest(); | 162 void StartRequest(); |
163 | 163 |
164 // Creates ServiceWorkerFetchRequest from |request_| and |body_|. | 164 // Creates ServiceWorkerFetchRequest from |request_| and |body_|. |
165 std::unique_ptr<ServiceWorkerFetchRequest> CreateFetchRequest(); | 165 std::unique_ptr<ServiceWorkerFetchRequest> CreateFetchRequest(); |
166 | 166 |
167 // Creates BlobDataHandle of the request body from |body_|. This handle | 167 // Creates BlobDataHandle of the request body from |body_|. This handle |
168 // |request_body_blob_data_handle_| will be deleted when | 168 // |request_body_blob_data_handle_| will be deleted when |
169 // ServiceWorkerURLRequestJob is deleted. | 169 // ServiceWorkerURLRequestJob is deleted. |
170 // This must not be called until all blobs in |body_| finished construction. | 170 // This must not be called until all files in |body_| with unknown size have |
| 171 // their sizes populated. |
171 void CreateRequestBodyBlob(std::string* blob_uuid, uint64_t* blob_size); | 172 void CreateRequestBodyBlob(std::string* blob_uuid, uint64_t* blob_size); |
172 | 173 |
173 // For FORWARD_TO_SERVICE_WORKER case. | 174 // For FORWARD_TO_SERVICE_WORKER case. |
174 void DidPrepareFetchEvent(scoped_refptr<ServiceWorkerVersion> version); | 175 void DidPrepareFetchEvent(scoped_refptr<ServiceWorkerVersion> version); |
175 void DidDispatchFetchEvent( | 176 void DidDispatchFetchEvent( |
176 ServiceWorkerStatusCode status, | 177 ServiceWorkerStatusCode status, |
177 ServiceWorkerFetchEventResult fetch_result, | 178 ServiceWorkerFetchEventResult fetch_result, |
178 const ServiceWorkerResponse& response, | 179 const ServiceWorkerResponse& response, |
179 const scoped_refptr<ServiceWorkerVersion>& version); | 180 const scoped_refptr<ServiceWorkerVersion>& version); |
180 void SetResponse(const ServiceWorkerResponse& response); | 181 void SetResponse(const ServiceWorkerResponse& response); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 void NotifyHeadersComplete(); | 217 void NotifyHeadersComplete(); |
217 void NotifyStartError(net::URLRequestStatus status); | 218 void NotifyStartError(net::URLRequestStatus status); |
218 void NotifyRestartRequired(); | 219 void NotifyRestartRequired(); |
219 | 220 |
220 // Wrapper that gathers parameters to |on_start_completed_callback_| and then | 221 // Wrapper that gathers parameters to |on_start_completed_callback_| and then |
221 // calls it. | 222 // calls it. |
222 void OnStartCompleted() const; | 223 void OnStartCompleted() const; |
223 | 224 |
224 bool IsMainResourceLoad() const; | 225 bool IsMainResourceLoad() const; |
225 | 226 |
226 // For waiting for request body blobs to finish construction. | 227 // For waiting for files sizes of request body files with unknown sizes. |
227 bool HasRequestBody(); | 228 bool HasRequestBody(); |
228 void RequestBodyBlobsCompleted(bool success); | 229 void RequestBodyFileSizesResolved(bool success); |
229 | 230 |
230 // Not owned. | 231 // Not owned. |
231 Delegate* delegate_; | 232 Delegate* delegate_; |
232 | 233 |
233 // Timing info to show on the popup in Devtools' Network tab. | 234 // Timing info to show on the popup in Devtools' Network tab. |
234 net::LoadTimingInfo load_timing_info_; | 235 net::LoadTimingInfo load_timing_info_; |
235 base::TimeTicks worker_start_time_; | 236 base::TimeTicks worker_start_time_; |
236 base::TimeTicks worker_ready_time_; | 237 base::TimeTicks worker_ready_time_; |
237 base::Time response_time_; | 238 base::Time response_time_; |
238 | 239 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 ServiceWorkerFetchType fetch_type_; | 271 ServiceWorkerFetchType fetch_type_; |
271 | 272 |
272 ResponseBodyType response_body_type_ = UNKNOWN; | 273 ResponseBodyType response_body_type_ = UNKNOWN; |
273 bool did_record_result_ = false; | 274 bool did_record_result_ = false; |
274 | 275 |
275 bool response_is_in_cache_storage_ = false; | 276 bool response_is_in_cache_storage_ = false; |
276 std::string response_cache_storage_cache_name_; | 277 std::string response_cache_storage_cache_name_; |
277 | 278 |
278 ServiceWorkerHeaderList cors_exposed_header_names_; | 279 ServiceWorkerHeaderList cors_exposed_header_names_; |
279 | 280 |
280 std::unique_ptr<BlobConstructionWaiter> blob_construction_waiter_; | 281 std::unique_ptr<FileSizeResolver> file_size_resolver_; |
281 | 282 |
282 bool worker_already_activated_ = false; | 283 bool worker_already_activated_ = false; |
283 EmbeddedWorkerStatus initial_worker_status_ = EmbeddedWorkerStatus::STOPPED; | 284 EmbeddedWorkerStatus initial_worker_status_ = EmbeddedWorkerStatus::STOPPED; |
284 | 285 |
285 base::WeakPtrFactory<ServiceWorkerURLRequestJob> weak_factory_; | 286 base::WeakPtrFactory<ServiceWorkerURLRequestJob> weak_factory_; |
286 | 287 |
287 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerURLRequestJob); | 288 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerURLRequestJob); |
288 }; | 289 }; |
289 | 290 |
290 } // namespace content | 291 } // namespace content |
291 | 292 |
292 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_URL_REQUEST_JOB_H_ | 293 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_URL_REQUEST_JOB_H_ |
OLD | NEW |