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

Side by Side Diff: webkit/appcache/appcache_url_request_job.cc

Issue 5545003: Fix webkit URLRequestJob subtypes to handle Kill() correctly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 10 years 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
« no previous file with comments | « webkit/appcache/appcache_url_request_job.h ('k') | webkit/blob/blob_url_request_job.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #include <vector> 5 #include <vector>
6 6
7 #include "webkit/appcache/appcache_url_request_job.h" 7 #include "webkit/appcache/appcache_url_request_job.h"
8 8
9 #include "base/compiler_specific.h"
9 #include "base/message_loop.h" 10 #include "base/message_loop.h"
10 #include "base/string_util.h" 11 #include "base/string_util.h"
11 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
12 #include "net/base/net_errors.h" 13 #include "net/base/net_errors.h"
13 #include "net/base/net_log.h" 14 #include "net/base/net_log.h"
14 #include "net/http/http_request_headers.h" 15 #include "net/http/http_request_headers.h"
15 #include "net/http/http_response_headers.h" 16 #include "net/http/http_response_headers.h"
16 #include "net/http/http_util.h" 17 #include "net/http/http_util.h"
17 #include "net/url_request/url_request.h" 18 #include "net/url_request/url_request.h"
18 #include "net/url_request/url_request_status.h" 19 #include "net/url_request/url_request_status.h"
19 20
20 namespace appcache { 21 namespace appcache {
21 22
22 AppCacheURLRequestJob::AppCacheURLRequestJob( 23 AppCacheURLRequestJob::AppCacheURLRequestJob(
23 net::URLRequest* request, AppCacheStorage* storage) 24 net::URLRequest* request, AppCacheStorage* storage)
24 : URLRequestJob(request), storage_(storage), 25 : URLRequestJob(request), storage_(storage),
25 has_been_started_(false), has_been_killed_(false), 26 has_been_started_(false), has_been_killed_(false),
26 delivery_type_(AWAITING_DELIVERY_ORDERS), 27 delivery_type_(AWAITING_DELIVERY_ORDERS),
27 cache_id_(kNoCacheId), is_fallback_(false), 28 cache_id_(kNoCacheId), is_fallback_(false),
28 cache_entry_not_found_(false), 29 cache_entry_not_found_(false),
29 ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_( 30 ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_(
30 this, &AppCacheURLRequestJob::OnReadComplete)) { 31 this, &AppCacheURLRequestJob::OnReadComplete)),
32 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
31 DCHECK(storage_); 33 DCHECK(storage_);
32 } 34 }
33 35
34 AppCacheURLRequestJob::~AppCacheURLRequestJob() { 36 AppCacheURLRequestJob::~AppCacheURLRequestJob() {
35 if (storage_) 37 if (storage_)
36 storage_->CancelDelegateCallbacks(this); 38 storage_->CancelDelegateCallbacks(this);
37 } 39 }
38 40
39 void AppCacheURLRequestJob::DeliverAppCachedResponse( 41 void AppCacheURLRequestJob::DeliverAppCachedResponse(
40 const GURL& manifest_url, int64 cache_id, const AppCacheEntry& entry, 42 const GURL& manifest_url, int64 cache_id, const AppCacheEntry& entry,
(...skipping 19 matching lines...) Expand all
60 DCHECK(!has_delivery_orders()); 62 DCHECK(!has_delivery_orders());
61 delivery_type_ = ERROR_DELIVERY; 63 delivery_type_ = ERROR_DELIVERY;
62 storage_ = NULL; // not needed 64 storage_ = NULL; // not needed
63 MaybeBeginDelivery(); 65 MaybeBeginDelivery();
64 } 66 }
65 67
66 void AppCacheURLRequestJob::MaybeBeginDelivery() { 68 void AppCacheURLRequestJob::MaybeBeginDelivery() {
67 if (has_been_started() && has_delivery_orders()) { 69 if (has_been_started() && has_delivery_orders()) {
68 // Start asynchronously so that all error reporting and data 70 // Start asynchronously so that all error reporting and data
69 // callbacks happen as they would for network requests. 71 // callbacks happen as they would for network requests.
70 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( 72 MessageLoop::current()->PostTask(
71 this, &AppCacheURLRequestJob::BeginDelivery)); 73 FROM_HERE,
74 method_factory_.NewRunnableMethod(
75 &AppCacheURLRequestJob::BeginDelivery));
72 } 76 }
73 } 77 }
74 78
75 void AppCacheURLRequestJob::BeginDelivery() { 79 void AppCacheURLRequestJob::BeginDelivery() {
76 DCHECK(has_delivery_orders() && has_been_started()); 80 DCHECK(has_delivery_orders() && has_been_started());
77 81
78 if (has_been_killed()) 82 if (has_been_killed())
michaeln 2010/12/06 22:51:38 I think the changes to this job subclass aren't ne
willchan no longer on Chromium 2010/12/07 00:52:38 Hm, I see. That's unfortunate that we still need
79 return; 83 return;
80 84
81 switch (delivery_type_) { 85 switch (delivery_type_) {
82 case NETWORK_DELIVERY: 86 case NETWORK_DELIVERY:
83 // To fallthru to the network, we restart the request which will 87 // To fallthru to the network, we restart the request which will
84 // cause a new job to be created to retrieve the resource from the 88 // cause a new job to be created to retrieve the resource from the
85 // network. Our caller is responsible for arranging to not re-intercept 89 // network. Our caller is responsible for arranging to not re-intercept
86 // the same request. 90 // the same request.
87 NotifyRestartRequired(); 91 NotifyRestartRequired();
88 break; 92 break;
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 207
204 void AppCacheURLRequestJob::Kill() { 208 void AppCacheURLRequestJob::Kill() {
205 if (!has_been_killed_) { 209 if (!has_been_killed_) {
206 has_been_killed_ = true; 210 has_been_killed_ = true;
207 reader_.reset(); 211 reader_.reset();
208 if (storage_) { 212 if (storage_) {
209 storage_->CancelDelegateCallbacks(this); 213 storage_->CancelDelegateCallbacks(this);
210 storage_ = NULL; 214 storage_ = NULL;
211 } 215 }
212 URLRequestJob::Kill(); 216 URLRequestJob::Kill();
217 method_factory_.RevokeAll();
213 } 218 }
214 } 219 }
215 220
216 net::LoadState AppCacheURLRequestJob::GetLoadState() const { 221 net::LoadState AppCacheURLRequestJob::GetLoadState() const {
217 if (!has_been_started()) 222 if (!has_been_started())
218 return net::LOAD_STATE_IDLE; 223 return net::LOAD_STATE_IDLE;
219 if (!has_delivery_orders()) 224 if (!has_delivery_orders())
220 return net::LOAD_STATE_WAITING_FOR_CACHE; 225 return net::LOAD_STATE_WAITING_FOR_CACHE;
221 if (delivery_type_ != APPCACHED_DELIVERY) 226 if (delivery_type_ != APPCACHED_DELIVERY)
222 return net::LOAD_STATE_IDLE; 227 return net::LOAD_STATE_IDLE;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 return; 276 return;
272 } 277 }
273 278
274 // If multiple ranges are requested, we play dumb and 279 // If multiple ranges are requested, we play dumb and
275 // return the entire response with 200 OK. 280 // return the entire response with 200 OK.
276 if (ranges.size() == 1U) 281 if (ranges.size() == 1U)
277 range_requested_ = ranges[0]; 282 range_requested_ = ranges[0];
278 } 283 }
279 284
280 } // namespace appcache 285 } // namespace appcache
281
OLDNEW
« no previous file with comments | « webkit/appcache/appcache_url_request_job.h ('k') | webkit/blob/blob_url_request_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698