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 28 matching lines...) Expand all Loading... |
39 | 39 |
40 namespace storage { | 40 namespace storage { |
41 class BlobDataHandle; | 41 class BlobDataHandle; |
42 class BlobStorageContext; | 42 class BlobStorageContext; |
43 } | 43 } |
44 | 44 |
45 namespace content { | 45 namespace content { |
46 | 46 |
47 class ResourceContext; | 47 class ResourceContext; |
48 class ResourceRequestBodyImpl; | 48 class ResourceRequestBodyImpl; |
| 49 class ServiceWorkerBlobReader; |
49 class ServiceWorkerContextCore; | 50 class ServiceWorkerContextCore; |
50 class ServiceWorkerFetchDispatcher; | 51 class ServiceWorkerFetchDispatcher; |
51 class ServiceWorkerProviderHost; | 52 class ServiceWorkerProviderHost; |
52 class ServiceWorkerVersion; | 53 class ServiceWorkerVersion; |
53 class Stream; | 54 class Stream; |
54 | 55 |
55 class CONTENT_EXPORT ServiceWorkerURLRequestJob | 56 class CONTENT_EXPORT ServiceWorkerURLRequestJob |
56 : public net::URLRequestJob, | 57 : public net::URLRequestJob, |
57 public net::URLRequest::Delegate, | |
58 public StreamReadObserver, | 58 public StreamReadObserver, |
59 public StreamRegisterObserver { | 59 public StreamRegisterObserver { |
60 public: | 60 public: |
61 class CONTENT_EXPORT Delegate { | 61 class CONTENT_EXPORT Delegate { |
62 public: | 62 public: |
63 virtual ~Delegate() {} | 63 virtual ~Delegate() {} |
64 | 64 |
65 // Will be invoked before the request is restarted. The caller | 65 // Will be invoked before the request is restarted. The caller |
66 // can use this opportunity to grab state from the | 66 // can use this opportunity to grab state from the |
67 // ServiceWorkerURLRequestJob to determine how it should behave when the | 67 // ServiceWorkerURLRequestJob to determine how it should behave when the |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 void Kill() override; | 128 void Kill() override; |
129 net::LoadState GetLoadState() const override; | 129 net::LoadState GetLoadState() const override; |
130 bool GetCharset(std::string* charset) override; | 130 bool GetCharset(std::string* charset) override; |
131 bool GetMimeType(std::string* mime_type) const override; | 131 bool GetMimeType(std::string* mime_type) const override; |
132 void GetResponseInfo(net::HttpResponseInfo* info) override; | 132 void GetResponseInfo(net::HttpResponseInfo* info) override; |
133 void GetLoadTimingInfo(net::LoadTimingInfo* load_timing_info) const override; | 133 void GetLoadTimingInfo(net::LoadTimingInfo* load_timing_info) const override; |
134 int GetResponseCode() const override; | 134 int GetResponseCode() const override; |
135 void SetExtraRequestHeaders(const net::HttpRequestHeaders& headers) override; | 135 void SetExtraRequestHeaders(const net::HttpRequestHeaders& headers) override; |
136 int ReadRawData(net::IOBuffer* buf, int buf_size) override; | 136 int ReadRawData(net::IOBuffer* buf, int buf_size) override; |
137 | 137 |
138 // net::URLRequest::Delegate overrides that read the blob from the | |
139 // ServiceWorkerFetchResponse. | |
140 void OnReceivedRedirect(net::URLRequest* request, | |
141 const net::RedirectInfo& redirect_info, | |
142 bool* defer_redirect) override; | |
143 void OnAuthRequired(net::URLRequest* request, | |
144 net::AuthChallengeInfo* auth_info) override; | |
145 void OnCertificateRequested( | |
146 net::URLRequest* request, | |
147 net::SSLCertRequestInfo* cert_request_info) override; | |
148 void OnSSLCertificateError(net::URLRequest* request, | |
149 const net::SSLInfo& ssl_info, | |
150 bool fatal) override; | |
151 void OnResponseStarted(net::URLRequest* request) override; | |
152 void OnReadCompleted(net::URLRequest* request, int bytes_read) override; | |
153 | |
154 // StreamObserver override: | 138 // StreamObserver override: |
155 void OnDataAvailable(Stream* stream) override; | 139 void OnDataAvailable(Stream* stream) override; |
156 | 140 |
157 // StreamRegisterObserver override: | 141 // StreamRegisterObserver override: |
158 void OnStreamRegistered(Stream* stream) override; | 142 void OnStreamRegistered(Stream* stream) override; |
159 | 143 |
| 144 //---------------------------------------------------------------------------- |
| 145 // The following are intended for use by ServiceWorkerBlobReader. |
| 146 void OnResponseStarted(); |
| 147 void OnReadRawDataComplete(int bytes_read); |
| 148 void RecordResult(ServiceWorkerMetrics::URLRequestJobResult result); |
| 149 //---------------------------------------------------------------------------- |
| 150 |
160 base::WeakPtr<ServiceWorkerURLRequestJob> GetWeakPtr(); | 151 base::WeakPtr<ServiceWorkerURLRequestJob> GetWeakPtr(); |
161 | 152 |
162 private: | 153 private: |
163 class BlobConstructionWaiter; | 154 class BlobConstructionWaiter; |
164 | 155 |
165 enum ResponseType { | 156 enum ResponseType { |
166 NOT_DETERMINED, | 157 NOT_DETERMINED, |
167 FALLBACK_TO_NETWORK, | 158 FALLBACK_TO_NETWORK, |
168 FALLBACK_TO_RENDERER, // Use this when falling back with CORS check | 159 FALLBACK_TO_RENDERER, // Use this when falling back with CORS check |
169 FORWARD_TO_SERVICE_WORKER, | 160 FORWARD_TO_SERVICE_WORKER, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 // This can be called after StartRequest. | 210 // This can be called after StartRequest. |
220 void FinalizeFallbackToRenderer(); | 211 void FinalizeFallbackToRenderer(); |
221 | 212 |
222 // True if need to send back a response with fall_back_required set as true to | 213 // True if need to send back a response with fall_back_required set as true to |
223 // trigger subsequent network requests with CORS checking. | 214 // trigger subsequent network requests with CORS checking. |
224 bool IsFallbackToRendererNeeded() const; | 215 bool IsFallbackToRendererNeeded() const; |
225 | 216 |
226 // For UMA. | 217 // For UMA. |
227 void SetResponseBodyType(ResponseBodyType type); | 218 void SetResponseBodyType(ResponseBodyType type); |
228 bool ShouldRecordResult(); | 219 bool ShouldRecordResult(); |
229 void RecordResult(ServiceWorkerMetrics::URLRequestJobResult result); | |
230 void RecordStatusZeroResponseError( | 220 void RecordStatusZeroResponseError( |
231 blink::WebServiceWorkerResponseError error); | 221 blink::WebServiceWorkerResponseError error); |
232 | 222 |
233 // Releases the resources for streaming. | 223 // Releases the resources for streaming. |
234 void ClearStream(); | 224 void ClearStream(); |
235 | 225 |
236 const net::HttpResponseInfo* http_info() const; | 226 const net::HttpResponseInfo* http_info() const; |
237 | 227 |
238 // Invoke callbacks before invoking corresponding URLRequestJob methods. | 228 // Invoke callbacks before invoking corresponding URLRequestJob methods. |
239 void NotifyHeadersComplete(); | 229 void NotifyHeadersComplete(); |
(...skipping 28 matching lines...) Expand all Loading... |
268 // Headers that have not yet been committed to |http_response_info_|. | 258 // Headers that have not yet been committed to |http_response_info_|. |
269 scoped_refptr<net::HttpResponseHeaders> http_response_headers_; | 259 scoped_refptr<net::HttpResponseHeaders> http_response_headers_; |
270 GURL response_url_; | 260 GURL response_url_; |
271 blink::WebServiceWorkerResponseType service_worker_response_type_; | 261 blink::WebServiceWorkerResponseType service_worker_response_type_; |
272 | 262 |
273 // Used when response type is FORWARD_TO_SERVICE_WORKER. | 263 // Used when response type is FORWARD_TO_SERVICE_WORKER. |
274 std::unique_ptr<ServiceWorkerFetchDispatcher> fetch_dispatcher_; | 264 std::unique_ptr<ServiceWorkerFetchDispatcher> fetch_dispatcher_; |
275 std::string client_id_; | 265 std::string client_id_; |
276 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_; | 266 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_; |
277 const ResourceContext* resource_context_; | 267 const ResourceContext* resource_context_; |
278 std::unique_ptr<net::URLRequest> blob_request_; | 268 std::unique_ptr<ServiceWorkerBlobReader> blob_reader_; |
279 scoped_refptr<Stream> stream_; | 269 scoped_refptr<Stream> stream_; |
280 GURL waiting_stream_url_; | 270 GURL waiting_stream_url_; |
281 scoped_refptr<net::IOBuffer> stream_pending_buffer_; | 271 scoped_refptr<net::IOBuffer> stream_pending_buffer_; |
282 int stream_pending_buffer_size_; | 272 int stream_pending_buffer_size_; |
283 | 273 |
284 FetchRequestMode request_mode_; | 274 FetchRequestMode request_mode_; |
285 FetchCredentialsMode credentials_mode_; | 275 FetchCredentialsMode credentials_mode_; |
286 FetchRedirectMode redirect_mode_; | 276 FetchRedirectMode redirect_mode_; |
287 const ResourceType resource_type_; | 277 const ResourceType resource_type_; |
288 RequestContextType request_context_type_; | 278 RequestContextType request_context_type_; |
(...skipping 20 matching lines...) Expand all Loading... |
309 EmbeddedWorkerStatus initial_worker_status_ = EmbeddedWorkerStatus::STOPPED; | 299 EmbeddedWorkerStatus initial_worker_status_ = EmbeddedWorkerStatus::STOPPED; |
310 | 300 |
311 base::WeakPtrFactory<ServiceWorkerURLRequestJob> weak_factory_; | 301 base::WeakPtrFactory<ServiceWorkerURLRequestJob> weak_factory_; |
312 | 302 |
313 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerURLRequestJob); | 303 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerURLRequestJob); |
314 }; | 304 }; |
315 | 305 |
316 } // namespace content | 306 } // namespace content |
317 | 307 |
318 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_URL_REQUEST_JOB_H_ | 308 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_URL_REQUEST_JOB_H_ |
OLD | NEW |