Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: content/browser/service_worker/service_worker_url_request_job.h

Issue 2703343002: ServiceWorker: Use mojo's data pipe for respondWith(stream) (Closed)
Patch Set: Addressed comments from kinuko and haraken Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
11 #include <memory> 11 #include <memory>
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "base/memory/weak_ptr.h" 17 #include "base/memory/weak_ptr.h"
18 #include "base/optional.h" 18 #include "base/optional.h"
19 #include "base/time/time.h" 19 #include "base/time/time.h"
20 #include "content/browser/service_worker/embedded_worker_status.h" 20 #include "content/browser/service_worker/embedded_worker_status.h"
21 #include "content/browser/service_worker/service_worker_metrics.h" 21 #include "content/browser/service_worker/service_worker_metrics.h"
22 #include "content/common/content_export.h" 22 #include "content/common/content_export.h"
23 #include "content/common/service_worker/service_worker_event_dispatcher.mojom.h"
23 #include "content/common/service_worker/service_worker_status_code.h" 24 #include "content/common/service_worker/service_worker_status_code.h"
24 #include "content/common/service_worker/service_worker_types.h" 25 #include "content/common/service_worker/service_worker_types.h"
25 #include "content/public/common/request_context_frame_type.h" 26 #include "content/public/common/request_context_frame_type.h"
26 #include "content/public/common/request_context_type.h" 27 #include "content/public/common/request_context_type.h"
27 #include "content/public/common/resource_type.h" 28 #include "content/public/common/resource_type.h"
29 #include "mojo/public/cpp/system/data_pipe.h"
28 #include "net/http/http_byte_range.h" 30 #include "net/http/http_byte_range.h"
29 #include "net/url_request/url_request.h" 31 #include "net/url_request/url_request.h"
30 #include "net/url_request/url_request_job.h" 32 #include "net/url_request/url_request_job.h"
31 #include "net/url_request/url_request_status.h" 33 #include "net/url_request/url_request_status.h"
32 #include "storage/common/blob_storage/blob_storage_constants.h" 34 #include "storage/common/blob_storage/blob_storage_constants.h"
33 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerResponseType.h" 35 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerResponseType.h"
34 #include "url/gurl.h" 36 #include "url/gurl.h"
35 37
36 namespace net { 38 namespace net {
37 class IOBuffer; 39 class IOBuffer;
38 } // namespace net 40 } // namespace net
39 41
40 namespace storage { 42 namespace storage {
41 class BlobDataHandle; 43 class BlobDataHandle;
42 class BlobStorageContext; 44 class BlobStorageContext;
43 } // namespace storage 45 } // namespace storage
44 46
45 namespace content { 47 namespace content {
46 48
47 class ResourceContext; 49 class ResourceContext;
48 class ResourceRequestBodyImpl; 50 class ResourceRequestBodyImpl;
49 class ServiceWorkerBlobReader; 51 class ServiceWorkerBlobReader;
50 class ServiceWorkerStreamReader; 52 class ServiceWorkerDataPipeReader;
51 class ServiceWorkerFetchDispatcher; 53 class ServiceWorkerFetchDispatcher;
52 class ServiceWorkerVersion; 54 class ServiceWorkerVersion;
53 class Stream;
54 55
55 class CONTENT_EXPORT ServiceWorkerURLRequestJob : public net::URLRequestJob { 56 class CONTENT_EXPORT ServiceWorkerURLRequestJob : public net::URLRequestJob {
56 public: 57 public:
57 class CONTENT_EXPORT Delegate { 58 class CONTENT_EXPORT Delegate {
58 public: 59 public:
59 virtual ~Delegate() {} 60 virtual ~Delegate() {}
60 61
61 // Will be invoked before the request is restarted. The caller 62 // Will be invoked before the request is restarted. The caller
62 // can use this opportunity to grab state from the 63 // can use this opportunity to grab state from the
63 // ServiceWorkerURLRequestJob to determine how it should behave when the 64 // ServiceWorkerURLRequestJob to determine how it should behave when the
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 void Kill() override; 133 void Kill() override;
133 net::LoadState GetLoadState() const override; 134 net::LoadState GetLoadState() const override;
134 bool GetCharset(std::string* charset) override; 135 bool GetCharset(std::string* charset) override;
135 bool GetMimeType(std::string* mime_type) const override; 136 bool GetMimeType(std::string* mime_type) const override;
136 void GetResponseInfo(net::HttpResponseInfo* info) override; 137 void GetResponseInfo(net::HttpResponseInfo* info) override;
137 void GetLoadTimingInfo(net::LoadTimingInfo* load_timing_info) const override; 138 void GetLoadTimingInfo(net::LoadTimingInfo* load_timing_info) const override;
138 void SetExtraRequestHeaders(const net::HttpRequestHeaders& headers) override; 139 void SetExtraRequestHeaders(const net::HttpRequestHeaders& headers) override;
139 int ReadRawData(net::IOBuffer* buf, int buf_size) override; 140 int ReadRawData(net::IOBuffer* buf, int buf_size) override;
140 141
141 //---------------------------------------------------------------------------- 142 //----------------------------------------------------------------------------
142 // The following are intended for use by ServiceWorker(Blob|Stream)Reader. 143 // The following are intended for use by ServiceWorker(Blob|DataPipe)Reader.
143 void OnResponseStarted(); 144 virtual void OnResponseStarted();
144 void OnReadRawDataComplete(int bytes_read); 145 virtual void OnReadRawDataComplete(int bytes_read);
145 void RecordResult(ServiceWorkerMetrics::URLRequestJobResult result); 146 virtual void RecordResult(ServiceWorkerMetrics::URLRequestJobResult result);
146 //---------------------------------------------------------------------------- 147 //----------------------------------------------------------------------------
147 148
148 base::WeakPtr<ServiceWorkerURLRequestJob> GetWeakPtr(); 149 base::WeakPtr<ServiceWorkerURLRequestJob> GetWeakPtr();
149 150
150 private: 151 private:
151 class FileSizeResolver; 152 class FileSizeResolver;
152 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest, 153 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest,
153 LostActiveVersion); 154 LostActiveVersion);
154 155
155 enum ResponseType { 156 enum ResponseType {
(...skipping 24 matching lines...) Expand all
180 // This must not be called until all files in |body_| with unknown size have 181 // This must not be called until all files in |body_| with unknown size have
181 // their sizes populated. 182 // their sizes populated.
182 void CreateRequestBodyBlob(std::string* blob_uuid, uint64_t* blob_size); 183 void CreateRequestBodyBlob(std::string* blob_uuid, uint64_t* blob_size);
183 184
184 // For FORWARD_TO_SERVICE_WORKER case. 185 // For FORWARD_TO_SERVICE_WORKER case.
185 void DidPrepareFetchEvent(scoped_refptr<ServiceWorkerVersion> version); 186 void DidPrepareFetchEvent(scoped_refptr<ServiceWorkerVersion> version);
186 void DidDispatchFetchEvent( 187 void DidDispatchFetchEvent(
187 ServiceWorkerStatusCode status, 188 ServiceWorkerStatusCode status,
188 ServiceWorkerFetchEventResult fetch_result, 189 ServiceWorkerFetchEventResult fetch_result,
189 const ServiceWorkerResponse& response, 190 const ServiceWorkerResponse& response,
191 blink::mojom::ServiceWorkerStreamHandlePtr body_as_stream,
190 const scoped_refptr<ServiceWorkerVersion>& version); 192 const scoped_refptr<ServiceWorkerVersion>& version);
191 void SetResponse(const ServiceWorkerResponse& response); 193 void SetResponse(const ServiceWorkerResponse& response);
192 194
193 // Populates |http_response_headers_|. 195 // Populates |http_response_headers_|.
194 void CreateResponseHeader(int status_code, 196 void CreateResponseHeader(int status_code,
195 const std::string& status_text, 197 const std::string& status_text,
196 const ServiceWorkerHeaderMap& headers); 198 const ServiceWorkerHeaderMap& headers);
197 199
198 // Creates |http_response_info_| using |http_response_headers_| and calls 200 // Creates |http_response_info_| using |http_response_headers_| and calls
199 // NotifyHeadersComplete. 201 // NotifyHeadersComplete.
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 // Headers that have not yet been committed to |http_response_info_|. 297 // Headers that have not yet been committed to |http_response_info_|.
296 scoped_refptr<net::HttpResponseHeaders> http_response_headers_; 298 scoped_refptr<net::HttpResponseHeaders> http_response_headers_;
297 std::vector<GURL> response_url_list_; 299 std::vector<GURL> response_url_list_;
298 blink::WebServiceWorkerResponseType service_worker_response_type_; 300 blink::WebServiceWorkerResponseType service_worker_response_type_;
299 301
300 // Used when response type is FORWARD_TO_SERVICE_WORKER. 302 // Used when response type is FORWARD_TO_SERVICE_WORKER.
301 std::unique_ptr<ServiceWorkerFetchDispatcher> fetch_dispatcher_; 303 std::unique_ptr<ServiceWorkerFetchDispatcher> fetch_dispatcher_;
302 std::string client_id_; 304 std::string client_id_;
303 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_; 305 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_;
304 const ResourceContext* resource_context_; 306 const ResourceContext* resource_context_;
305 // Only one of |blob_reader_| and |stream_reader_| can be non-null. 307 // Only one of |blob_reader_| and |data_pipe_reader_| can be non-null.
306 std::unique_ptr<ServiceWorkerBlobReader> blob_reader_; 308 std::unique_ptr<ServiceWorkerBlobReader> blob_reader_;
307 std::unique_ptr<ServiceWorkerStreamReader> stream_reader_; 309 std::unique_ptr<ServiceWorkerDataPipeReader> data_pipe_reader_;
308 310
309 FetchRequestMode request_mode_; 311 FetchRequestMode request_mode_;
310 FetchCredentialsMode credentials_mode_; 312 FetchCredentialsMode credentials_mode_;
311 FetchRedirectMode redirect_mode_; 313 FetchRedirectMode redirect_mode_;
312 const ResourceType resource_type_; 314 const ResourceType resource_type_;
313 RequestContextType request_context_type_; 315 RequestContextType request_context_type_;
314 RequestContextFrameType frame_type_; 316 RequestContextFrameType frame_type_;
315 bool fall_back_required_; 317 bool fall_back_required_;
316 // ResourceRequestBody has a collection of BlobDataHandles attached to it 318 // ResourceRequestBody has a collection of BlobDataHandles attached to it
317 // using the userdata mechanism. So we have to keep it not to free the blobs. 319 // using the userdata mechanism. So we have to keep it not to free the blobs.
(...skipping 13 matching lines...) Expand all
331 std::unique_ptr<FileSizeResolver> file_size_resolver_; 333 std::unique_ptr<FileSizeResolver> file_size_resolver_;
332 334
333 base::WeakPtrFactory<ServiceWorkerURLRequestJob> weak_factory_; 335 base::WeakPtrFactory<ServiceWorkerURLRequestJob> weak_factory_;
334 336
335 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerURLRequestJob); 337 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerURLRequestJob);
336 }; 338 };
337 339
338 } // namespace content 340 } // namespace content
339 341
340 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_URL_REQUEST_JOB_H_ 342 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_URL_REQUEST_JOB_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698