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

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

Issue 293083002: Add a blob field to ServiceWorkerFetchResponse and read the blob (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: michael's review Created 6 years, 7 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 | Annotate | Revision Log
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 "base/memory/weak_ptr.h" 8 #include "base/memory/weak_ptr.h"
9 #include "content/common/content_export.h" 9 #include "content/common/content_export.h"
10 #include "content/common/service_worker/service_worker_status_code.h" 10 #include "content/common/service_worker/service_worker_status_code.h"
11 #include "content/common/service_worker/service_worker_types.h" 11 #include "content/common/service_worker/service_worker_types.h"
12 #include "net/http/http_byte_range.h" 12 #include "net/http/http_byte_range.h"
13 #include "net/url_request/url_request.h"
13 #include "net/url_request/url_request_job.h" 14 #include "net/url_request/url_request_job.h"
14 15
16 namespace webkit_blob {
17 class BlobStorageContext;
18 }
19
15 namespace content { 20 namespace content {
16 21
17 class ServiceWorkerContextCore; 22 class ServiceWorkerContextCore;
18 class ServiceWorkerFetchDispatcher; 23 class ServiceWorkerFetchDispatcher;
19 class ServiceWorkerProviderHost; 24 class ServiceWorkerProviderHost;
20 25
21 class CONTENT_EXPORT ServiceWorkerURLRequestJob 26 class CONTENT_EXPORT ServiceWorkerURLRequestJob
22 : public net::URLRequestJob { 27 : public net::URLRequestJob,
28 public net::URLRequest::Delegate {
23 public: 29 public:
24 ServiceWorkerURLRequestJob( 30 ServiceWorkerURLRequestJob(
25 net::URLRequest* request, 31 net::URLRequest* request,
26 net::NetworkDelegate* network_delegate, 32 net::NetworkDelegate* network_delegate,
27 base::WeakPtr<ServiceWorkerProviderHost> provider_host); 33 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
34 base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context);
28 35
29 // Sets the response type. 36 // Sets the response type.
30 void FallbackToNetwork(); 37 void FallbackToNetwork();
31 void ForwardToServiceWorker(); 38 void ForwardToServiceWorker();
32 39
33 bool ShouldFallbackToNetwork() const { 40 bool ShouldFallbackToNetwork() const {
34 return response_type_ == FALLBACK_TO_NETWORK; 41 return response_type_ == FALLBACK_TO_NETWORK;
35 } 42 }
36 bool ShouldForwardToServiceWorker() const { 43 bool ShouldForwardToServiceWorker() const {
37 return response_type_ == FORWARD_TO_SERVICE_WORKER; 44 return response_type_ == FORWARD_TO_SERVICE_WORKER;
38 } 45 }
39 46
40 // net::URLRequestJob overrides: 47 // net::URLRequestJob overrides:
41 virtual void Start() OVERRIDE; 48 virtual void Start() OVERRIDE;
42 virtual void Kill() OVERRIDE; 49 virtual void Kill() OVERRIDE;
43 virtual net::LoadState GetLoadState() const OVERRIDE; 50 virtual net::LoadState GetLoadState() const OVERRIDE;
44 virtual bool GetCharset(std::string* charset) OVERRIDE; 51 virtual bool GetCharset(std::string* charset) OVERRIDE;
45 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; 52 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE;
46 virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE; 53 virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE;
47 virtual int GetResponseCode() const OVERRIDE; 54 virtual int GetResponseCode() const OVERRIDE;
48 virtual void SetExtraRequestHeaders( 55 virtual void SetExtraRequestHeaders(
49 const net::HttpRequestHeaders& headers) OVERRIDE; 56 const net::HttpRequestHeaders& headers) OVERRIDE;
50 virtual bool ReadRawData(net::IOBuffer* buf, 57 virtual bool ReadRawData(net::IOBuffer* buf,
51 int buf_size, 58 int buf_size,
52 int *bytes_read) OVERRIDE; 59 int *bytes_read) OVERRIDE;
53 60
61 // net::URLRequest::Delegate overrides that read the blob from the
62 // ServiceWorkerFetchResponse.
63 virtual void OnReceivedRedirect(net::URLRequest* request,
64 const GURL& new_url,
65 bool* defer_redirect) OVERRIDE;
66 virtual void OnAuthRequired(net::URLRequest* request,
67 net::AuthChallengeInfo* auth_info) OVERRIDE;
68 virtual void OnCertificateRequested(
69 net::URLRequest* request,
70 net::SSLCertRequestInfo* cert_request_info) OVERRIDE;
71 virtual void OnSSLCertificateError(net::URLRequest* request,
72 const net::SSLInfo& ssl_info,
73 bool fatal) OVERRIDE;
74 virtual void OnBeforeNetworkStart(net::URLRequest* request,
75 bool* defer) OVERRIDE;
76 virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE;
77 virtual void OnReadCompleted(net::URLRequest* request,
78 int bytes_read) OVERRIDE;
79
54 const net::HttpResponseInfo* http_info() const; 80 const net::HttpResponseInfo* http_info() const;
55 81
56 protected: 82 protected:
57 virtual ~ServiceWorkerURLRequestJob(); 83 virtual ~ServiceWorkerURLRequestJob();
58 84
59 private: 85 private:
60 enum ResponseType { 86 enum ResponseType {
61 NOT_DETERMINED, 87 NOT_DETERMINED,
62 FALLBACK_TO_NETWORK, 88 FALLBACK_TO_NETWORK,
63 FORWARD_TO_SERVICE_WORKER, 89 FORWARD_TO_SERVICE_WORKER,
64 }; 90 };
65 91
66 // We start processing the request if Start() is called AND response_type_ 92 // We start processing the request if Start() is called AND response_type_
67 // is determined. 93 // is determined.
68 void MaybeStartRequest(); 94 void MaybeStartRequest();
69 void StartRequest(); 95 void StartRequest();
70 96
71 // For FORWARD_TO_SERVICE_WORKER case. 97 // For FORWARD_TO_SERVICE_WORKER case.
72 void DidDispatchFetchEvent(ServiceWorkerStatusCode status, 98 void DidDispatchFetchEvent(ServiceWorkerStatusCode status,
73 ServiceWorkerFetchEventResult fetch_result, 99 ServiceWorkerFetchEventResult fetch_result,
74 const ServiceWorkerResponse& response); 100 const ServiceWorkerResponse& response);
75 101
102 // Populates |http_response_headers_| with info from |response|.
76 void CreateResponseHeader(const ServiceWorkerResponse& response); 103 void CreateResponseHeader(const ServiceWorkerResponse& response);
104 // Creates |http_response_info_| using |http_response_headers_| and calls
105 // NotifyHeadersComplete.
106 void CommitResponseHeader();
77 107
78 base::WeakPtr<ServiceWorkerProviderHost> provider_host_; 108 base::WeakPtr<ServiceWorkerProviderHost> provider_host_;
79 109
80 ResponseType response_type_; 110 ResponseType response_type_;
81 bool is_started_; 111 bool is_started_;
82 112
83 net::HttpByteRange byte_range_; 113 net::HttpByteRange byte_range_;
84 scoped_ptr<net::HttpResponseInfo> range_response_info_; 114 scoped_ptr<net::HttpResponseInfo> range_response_info_;
85 scoped_ptr<net::HttpResponseInfo> http_response_info_; 115 scoped_ptr<net::HttpResponseInfo> http_response_info_;
116 // Headers that have not yet been committed to |http_response_info_|.
117 scoped_refptr<net::HttpResponseHeaders> http_response_headers_;
86 118
87 // Used when response type is FORWARD_TO_SERVICE_WORKER. 119 // Used when response type is FORWARD_TO_SERVICE_WORKER.
88 scoped_ptr<ServiceWorkerFetchDispatcher> fetch_dispatcher_; 120 scoped_ptr<ServiceWorkerFetchDispatcher> fetch_dispatcher_;
121 base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context_;
122 scoped_ptr<net::URLRequest> blob_request_;
89 123
90 base::WeakPtrFactory<ServiceWorkerURLRequestJob> weak_factory_; 124 base::WeakPtrFactory<ServiceWorkerURLRequestJob> weak_factory_;
91 125
92 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerURLRequestJob); 126 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerURLRequestJob);
93 }; 127 };
94 128
95 } // namespace content 129 } // namespace content
96 130
97 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_URL_REQUEST_JOB_H_ 131 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_URL_REQUEST_JOB_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698