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 |
| 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, |
(...skipping 15 matching lines...) Expand all Loading... |
79 | 105 |
80 ResponseType response_type_; | 106 ResponseType response_type_; |
81 bool is_started_; | 107 bool is_started_; |
82 | 108 |
83 net::HttpByteRange byte_range_; | 109 net::HttpByteRange byte_range_; |
84 scoped_ptr<net::HttpResponseInfo> range_response_info_; | 110 scoped_ptr<net::HttpResponseInfo> range_response_info_; |
85 scoped_ptr<net::HttpResponseInfo> http_response_info_; | 111 scoped_ptr<net::HttpResponseInfo> http_response_info_; |
86 | 112 |
87 // Used when response type is FORWARD_TO_SERVICE_WORKER. | 113 // Used when response type is FORWARD_TO_SERVICE_WORKER. |
88 scoped_ptr<ServiceWorkerFetchDispatcher> fetch_dispatcher_; | 114 scoped_ptr<ServiceWorkerFetchDispatcher> fetch_dispatcher_; |
| 115 base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context_; |
| 116 scoped_ptr<net::URLRequest> blob_request_; |
89 | 117 |
90 base::WeakPtrFactory<ServiceWorkerURLRequestJob> weak_factory_; | 118 base::WeakPtrFactory<ServiceWorkerURLRequestJob> weak_factory_; |
91 | 119 |
92 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerURLRequestJob); | 120 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerURLRequestJob); |
93 }; | 121 }; |
94 | 122 |
95 } // namespace content | 123 } // namespace content |
96 | 124 |
97 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_URL_REQUEST_JOB_H_ | 125 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_URL_REQUEST_JOB_H_ |
OLD | NEW |