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 "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 |
15 namespace content { | 16 namespace content { |
16 | 17 |
| 18 class ChromeBlobStorageContext; |
17 class ServiceWorkerContextCore; | 19 class ServiceWorkerContextCore; |
18 class ServiceWorkerFetchDispatcher; | 20 class ServiceWorkerFetchDispatcher; |
19 class ServiceWorkerProviderHost; | 21 class ServiceWorkerProviderHost; |
20 | 22 |
21 class CONTENT_EXPORT ServiceWorkerURLRequestJob | 23 class CONTENT_EXPORT ServiceWorkerURLRequestJob |
22 : public net::URLRequestJob { | 24 : public net::URLRequestJob, |
| 25 public net::URLRequest::Delegate { |
23 public: | 26 public: |
24 ServiceWorkerURLRequestJob( | 27 ServiceWorkerURLRequestJob( |
25 net::URLRequest* request, | 28 net::URLRequest* request, |
26 net::NetworkDelegate* network_delegate, | 29 net::NetworkDelegate* network_delegate, |
27 base::WeakPtr<ServiceWorkerProviderHost> provider_host); | 30 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
| 31 const scoped_refptr<ChromeBlobStorageContext> blob_storage_context); |
28 | 32 |
29 // Sets the response type. | 33 // Sets the response type. |
30 void FallbackToNetwork(); | 34 void FallbackToNetwork(); |
31 void ForwardToServiceWorker(); | 35 void ForwardToServiceWorker(); |
32 | 36 |
33 bool ShouldFallbackToNetwork() const { | 37 bool ShouldFallbackToNetwork() const { |
34 return response_type_ == FALLBACK_TO_NETWORK; | 38 return response_type_ == FALLBACK_TO_NETWORK; |
35 } | 39 } |
36 bool ShouldForwardToServiceWorker() const { | 40 bool ShouldForwardToServiceWorker() const { |
37 return response_type_ == FORWARD_TO_SERVICE_WORKER; | 41 return response_type_ == FORWARD_TO_SERVICE_WORKER; |
38 } | 42 } |
39 | 43 |
40 // net::URLRequestJob overrides: | 44 // net::URLRequestJob overrides: |
41 virtual void Start() OVERRIDE; | 45 virtual void Start() OVERRIDE; |
42 virtual void Kill() OVERRIDE; | 46 virtual void Kill() OVERRIDE; |
43 virtual net::LoadState GetLoadState() const OVERRIDE; | 47 virtual net::LoadState GetLoadState() const OVERRIDE; |
44 virtual bool GetCharset(std::string* charset) OVERRIDE; | 48 virtual bool GetCharset(std::string* charset) OVERRIDE; |
45 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; | 49 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; |
46 virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE; | 50 virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE; |
47 virtual int GetResponseCode() const OVERRIDE; | 51 virtual int GetResponseCode() const OVERRIDE; |
48 virtual void SetExtraRequestHeaders( | 52 virtual void SetExtraRequestHeaders( |
49 const net::HttpRequestHeaders& headers) OVERRIDE; | 53 const net::HttpRequestHeaders& headers) OVERRIDE; |
50 virtual bool ReadRawData(net::IOBuffer* buf, | 54 virtual bool ReadRawData(net::IOBuffer* buf, |
51 int buf_size, | 55 int buf_size, |
52 int *bytes_read) OVERRIDE; | 56 int *bytes_read) OVERRIDE; |
53 | 57 |
| 58 // net::URLRequest::Delegate overrides that read the blob from the |
| 59 // ServiceWorkerFetchResponse. |
| 60 virtual void OnReceivedRedirect(net::URLRequest* request, |
| 61 const GURL& new_url, |
| 62 bool* defer_redirect) OVERRIDE; |
| 63 virtual void OnAuthRequired(net::URLRequest* request, |
| 64 net::AuthChallengeInfo* auth_info) OVERRIDE; |
| 65 virtual void OnCertificateRequested( |
| 66 net::URLRequest* request, |
| 67 net::SSLCertRequestInfo* cert_request_info) OVERRIDE; |
| 68 virtual void OnSSLCertificateError(net::URLRequest* request, |
| 69 const net::SSLInfo& ssl_info, |
| 70 bool fatal) OVERRIDE; |
| 71 virtual void OnBeforeNetworkStart(net::URLRequest* request, |
| 72 bool* defer) OVERRIDE; |
| 73 virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE; |
| 74 virtual void OnReadCompleted(net::URLRequest* request, |
| 75 int bytes_read) OVERRIDE; |
| 76 |
54 const net::HttpResponseInfo* http_info() const; | 77 const net::HttpResponseInfo* http_info() const; |
55 | 78 |
56 protected: | 79 protected: |
57 virtual ~ServiceWorkerURLRequestJob(); | 80 virtual ~ServiceWorkerURLRequestJob(); |
58 | 81 |
59 private: | 82 private: |
60 enum ResponseType { | 83 enum ResponseType { |
61 NOT_DETERMINED, | 84 NOT_DETERMINED, |
62 FALLBACK_TO_NETWORK, | 85 FALLBACK_TO_NETWORK, |
63 FORWARD_TO_SERVICE_WORKER, | 86 FORWARD_TO_SERVICE_WORKER, |
(...skipping 15 matching lines...) Expand all Loading... |
79 | 102 |
80 ResponseType response_type_; | 103 ResponseType response_type_; |
81 bool is_started_; | 104 bool is_started_; |
82 | 105 |
83 net::HttpByteRange byte_range_; | 106 net::HttpByteRange byte_range_; |
84 scoped_ptr<net::HttpResponseInfo> range_response_info_; | 107 scoped_ptr<net::HttpResponseInfo> range_response_info_; |
85 scoped_ptr<net::HttpResponseInfo> http_response_info_; | 108 scoped_ptr<net::HttpResponseInfo> http_response_info_; |
86 | 109 |
87 // Used when response type is FORWARD_TO_SERVICE_WORKER. | 110 // Used when response type is FORWARD_TO_SERVICE_WORKER. |
88 scoped_ptr<ServiceWorkerFetchDispatcher> fetch_dispatcher_; | 111 scoped_ptr<ServiceWorkerFetchDispatcher> fetch_dispatcher_; |
| 112 scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; |
| 113 scoped_ptr<net::URLRequest> blob_request_; |
89 | 114 |
90 base::WeakPtrFactory<ServiceWorkerURLRequestJob> weak_factory_; | 115 base::WeakPtrFactory<ServiceWorkerURLRequestJob> weak_factory_; |
91 | 116 |
92 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerURLRequestJob); | 117 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerURLRequestJob); |
93 }; | 118 }; |
94 | 119 |
95 } // namespace content | 120 } // namespace content |
96 | 121 |
97 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_URL_REQUEST_JOB_H_ | 122 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_URL_REQUEST_JOB_H_ |
OLD | NEW |