OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 WEBKIT_BROWSER_APPCACHE_APPCACHE_URL_REQUEST_JOB_H_ | 5 #ifndef WEBKIT_BROWSER_APPCACHE_APPCACHE_URL_REQUEST_JOB_H_ |
6 #define WEBKIT_BROWSER_APPCACHE_APPCACHE_URL_REQUEST_JOB_H_ | 6 #define WEBKIT_BROWSER_APPCACHE_APPCACHE_URL_REQUEST_JOB_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "net/http/http_byte_range.h" | 11 #include "net/http/http_byte_range.h" |
12 #include "net/url_request/url_request_job.h" | 12 #include "net/url_request/url_request_job.h" |
13 #include "webkit/browser/appcache/appcache_entry.h" | 13 #include "webkit/browser/appcache/appcache_entry.h" |
14 #include "webkit/browser/appcache/appcache_executable_handler.h" | 14 #include "webkit/browser/appcache/appcache_executable_handler.h" |
15 #include "webkit/browser/appcache/appcache_response.h" | 15 #include "webkit/browser/appcache/appcache_response.h" |
16 #include "webkit/browser/appcache/appcache_storage.h" | 16 #include "webkit/browser/appcache/appcache_storage.h" |
17 #include "webkit/browser/webkit_storage_browser_export.h" | 17 #include "webkit/browser/webkit_storage_browser_export.h" |
18 | 18 |
19 namespace net { | 19 namespace net { |
20 class GrowableIOBuffer; | 20 class GrowableIOBuffer; |
21 }; | 21 }; |
| 22 namespace webkit_blob { |
| 23 class BlobReader; |
| 24 }; |
22 | 25 |
23 namespace appcache { | 26 namespace appcache { |
24 | 27 |
25 class AppCacheHost; | 28 class AppCacheHost; |
26 | 29 |
27 // A net::URLRequestJob derivative that knows how to return a response stored | 30 // A net::URLRequestJob derivative that knows how to return a response stored |
28 // in the appcache. | 31 // in the appcache. |
29 class WEBKIT_STORAGE_BROWSER_EXPORT AppCacheURLRequestJob | 32 class WEBKIT_STORAGE_BROWSER_EXPORT AppCacheURLRequestJob |
30 : public net::URLRequestJob, | 33 : public net::URLRequestJob, |
31 public AppCacheStorage::Delegate { | 34 public AppCacheStorage::Delegate { |
(...skipping 21 matching lines...) Expand all Loading... |
53 } | 56 } |
54 | 57 |
55 bool is_delivering_network_response() const { | 58 bool is_delivering_network_response() const { |
56 return delivery_type_ == NETWORK_DELIVERY; | 59 return delivery_type_ == NETWORK_DELIVERY; |
57 } | 60 } |
58 | 61 |
59 bool is_delivering_error_response() const { | 62 bool is_delivering_error_response() const { |
60 return delivery_type_ == ERROR_DELIVERY; | 63 return delivery_type_ == ERROR_DELIVERY; |
61 } | 64 } |
62 | 65 |
| 66 bool is_delivering_synthesized_response() const { |
| 67 return delivery_type_ == SYNTHESIZED_DELIVERY; |
| 68 } |
| 69 |
63 // Accessors for the info about the appcached response, if any, | 70 // Accessors for the info about the appcached response, if any, |
64 // that this job has been instructed to deliver. These are only | 71 // that this job has been instructed to deliver. These are only |
65 // valid to call if is_delivering_appcache_response. | 72 // valid to call if is_delivering_appcache_response. |
66 const GURL& manifest_url() const { return manifest_url_; } | 73 const GURL& manifest_url() const { return manifest_url_; } |
67 int64 group_id() const { return group_id_; } | 74 int64 group_id() const { return group_id_; } |
68 int64 cache_id() const { return cache_id_; } | 75 int64 cache_id() const { return cache_id_; } |
69 const AppCacheEntry& entry() const { return entry_; } | 76 const AppCacheEntry& entry() const { return entry_; } |
70 | 77 |
71 // net::URLRequestJob's Kill method is made public so the users of this | 78 // net::URLRequestJob's Kill method is made public so the users of this |
72 // class in the appcache namespace can call it. | 79 // class in the appcache namespace can call it. |
73 virtual void Kill() OVERRIDE; | 80 virtual void Kill() OVERRIDE; |
74 | 81 |
75 // Returns true if the job has been started by the net library. | 82 // Returns true if the job has been started by the net library. |
76 bool has_been_started() const { | 83 bool has_been_started() const { |
77 return has_been_started_; | 84 return has_been_started_; |
78 } | 85 } |
79 | 86 |
80 // Returns true if the job has been killed. | 87 // Returns true if the job has been killed. |
81 bool has_been_killed() const { | 88 bool has_been_killed() const { |
82 return has_been_killed_; | 89 return has_been_killed_; |
83 } | 90 } |
84 | 91 |
85 // Returns true if the cache entry was not found in the disk cache. | 92 // Returns true if the cache entry was not found in the disk cache. |
86 bool cache_entry_not_found() const { | 93 bool cache_entry_not_found() const { |
87 return cache_entry_not_found_; | 94 return cache_entry_not_found_; |
88 } | 95 } |
89 | 96 |
| 97 // Executable handler hackery. |
| 98 void set_is_main_resource_load(bool is_main) { |
| 99 is_main_resource_load_ = is_main; |
| 100 } |
90 protected: | 101 protected: |
91 virtual ~AppCacheURLRequestJob(); | 102 virtual ~AppCacheURLRequestJob(); |
92 | 103 |
93 private: | 104 private: |
94 friend class AppCacheRequestHandlerTest; | 105 friend class AppCacheRequestHandlerTest; |
95 friend class AppCacheURLRequestJobTest; | 106 friend class AppCacheURLRequestJobTest; |
96 | 107 |
97 enum DeliveryType { | 108 enum DeliveryType { |
98 AWAITING_DELIVERY_ORDERS, | 109 AWAITING_DELIVERY_ORDERS, |
99 APPCACHED_DELIVERY, | 110 APPCACHED_DELIVERY, |
100 NETWORK_DELIVERY, | 111 NETWORK_DELIVERY, |
101 ERROR_DELIVERY | 112 ERROR_DELIVERY, |
| 113 SYNTHESIZED_DELIVERY |
102 }; | 114 }; |
103 | 115 |
104 // Returns true if one of the Deliver methods has been called. | 116 // Returns true if one of the Deliver methods has been called. |
105 bool has_delivery_orders() const { | 117 bool has_delivery_orders() const { |
106 return !is_waiting(); | 118 return !is_waiting(); |
107 } | 119 } |
108 | 120 |
109 void MaybeBeginDelivery(); | 121 void MaybeBeginDelivery(); |
110 void BeginDelivery(); | 122 void BeginDelivery(); |
111 | 123 |
112 // For executable response handling. | 124 // For executable response handling. |
113 void BeginExecutableHandlerDelivery(); | 125 void BeginExecutableHandlerDelivery(); |
114 void OnExecutableSourceLoaded(int result); | 126 void OnExecutableSourceLoaded(int result); |
115 void InvokeExecutableHandler(AppCacheExecutableHandler* handler); | 127 void InvokeExecutableHandler(AppCacheExecutableHandler* handler); |
116 void OnExecutableResponseCallback( | 128 void OnExecutableResponseCallback( |
117 const AppCacheExecutableHandler::Response& response); | 129 const AppCacheExecutableHandler::Response& response); |
118 void BeginErrorDelivery(const char* message); | 130 void BeginErrorDelivery(const char* message); |
| 131 void BeginSynthesizedDelivery(); |
119 | 132 |
120 // AppCacheStorage::Delegate methods | 133 // AppCacheStorage::Delegate methods |
121 virtual void OnResponseInfoLoaded( | 134 virtual void OnResponseInfoLoaded( |
122 AppCacheResponseInfo* response_info, int64 response_id) OVERRIDE; | 135 AppCacheResponseInfo* response_info, int64 response_id) OVERRIDE; |
123 virtual void OnCacheLoaded(AppCache* cache, int64 cache_id) OVERRIDE; | 136 virtual void OnCacheLoaded(AppCache* cache, int64 cache_id) OVERRIDE; |
124 | 137 |
125 const net::HttpResponseInfo* http_info() const; | 138 const net::HttpResponseInfo* http_info() const; |
126 bool is_range_request() const { return range_requested_.IsValid(); } | 139 bool is_range_request() const { return range_requested_.IsValid(); } |
127 void SetupRangeResponse(); | 140 void SetupRangeResponse(); |
128 | 141 |
129 // AppCacheResponseReader completion callback | 142 // AppCacheResponseReader completion callback |
130 void OnReadComplete(int result); | 143 void OnReadComplete(int result); |
131 | 144 |
132 // net::URLRequestJob methods, see url_request_job.h for doc comments | 145 // net::URLRequestJob methods, see url_request_job.h for doc comments |
133 virtual void Start() OVERRIDE; | 146 virtual void Start() OVERRIDE; |
134 virtual net::LoadState GetLoadState() const OVERRIDE; | 147 virtual net::LoadState GetLoadState() const OVERRIDE; |
135 virtual bool GetCharset(std::string* charset) OVERRIDE; | 148 virtual bool GetCharset(std::string* charset) OVERRIDE; |
136 virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE; | 149 virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE; |
137 virtual bool ReadRawData(net::IOBuffer* buf, | 150 virtual bool ReadRawData(net::IOBuffer* buf, |
138 int buf_size, | 151 int buf_size, |
139 int *bytes_read) OVERRIDE; | 152 int *bytes_read) OVERRIDE; |
140 | 153 |
| 154 bool ReadRawBlobData(net::IOBuffer* buf, |
| 155 int buf_size, |
| 156 int *bytes_read); |
| 157 void OnReadBlobDataComplete(int result); |
| 158 |
141 // Sets extra request headers for Job types that support request headers. | 159 // Sets extra request headers for Job types that support request headers. |
142 // This is how we get informed of range-requests. | 160 // This is how we get informed of range-requests. |
143 virtual void SetExtraRequestHeaders( | 161 virtual void SetExtraRequestHeaders( |
144 const net::HttpRequestHeaders& headers) OVERRIDE; | 162 const net::HttpRequestHeaders& headers) OVERRIDE; |
145 | 163 |
146 // FilterContext methods | 164 // FilterContext methods |
147 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; | 165 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; |
148 virtual int GetResponseCode() const OVERRIDE; | 166 virtual int GetResponseCode() const OVERRIDE; |
149 | 167 |
150 AppCacheHost* host_; | 168 AppCacheHost* host_; |
151 AppCacheStorage* storage_; | 169 AppCacheStorage* storage_; |
152 base::TimeTicks start_time_tick_; | 170 base::TimeTicks start_time_tick_; |
153 bool has_been_started_; | 171 bool has_been_started_; |
154 bool has_been_killed_; | 172 bool has_been_killed_; |
155 DeliveryType delivery_type_; | 173 DeliveryType delivery_type_; |
156 GURL manifest_url_; | 174 GURL manifest_url_; |
157 int64 group_id_; | 175 int64 group_id_; |
158 int64 cache_id_; | 176 int64 cache_id_; |
159 AppCacheEntry entry_; | 177 AppCacheEntry entry_; |
160 bool is_fallback_; | 178 bool is_fallback_; |
161 bool cache_entry_not_found_; | 179 bool cache_entry_not_found_; |
162 scoped_refptr<AppCacheResponseInfo> info_; | 180 scoped_refptr<AppCacheResponseInfo> info_; |
163 scoped_refptr<net::GrowableIOBuffer> handler_source_buffer_; | 181 scoped_refptr<net::GrowableIOBuffer> handler_source_buffer_; |
164 scoped_ptr<AppCacheResponseReader> handler_source_reader_; | 182 scoped_ptr<AppCacheResponseReader> handler_source_reader_; |
165 net::HttpByteRange range_requested_; | 183 net::HttpByteRange range_requested_; |
166 scoped_ptr<net::HttpResponseInfo> range_response_info_; | 184 scoped_ptr<net::HttpResponseInfo> range_response_info_; |
167 scoped_ptr<AppCacheResponseReader> reader_; | 185 scoped_ptr<AppCacheResponseReader> reader_; |
| 186 scoped_ptr<webkit_blob::BlobReader> blob_reader_; |
168 scoped_refptr<AppCache> cache_; | 187 scoped_refptr<AppCache> cache_; |
169 scoped_refptr<AppCacheGroup> group_; | 188 scoped_refptr<AppCacheGroup> group_; |
170 base::WeakPtrFactory<AppCacheURLRequestJob> weak_factory_; | 189 base::WeakPtrFactory<AppCacheURLRequestJob> weak_factory_; |
| 190 bool is_main_resource_load_; |
171 }; | 191 }; |
172 | 192 |
173 } // namespace appcache | 193 } // namespace appcache |
174 | 194 |
175 #endif // WEBKIT_BROWSER_APPCACHE_APPCACHE_REQUEST_HANDLER_H_ | 195 #endif // WEBKIT_BROWSER_APPCACHE_APPCACHE_REQUEST_HANDLER_H_ |
OLD | NEW |