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

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

Issue 8343018: More groundwork for flat file based response storage. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/compiler_specific.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
13 #include "net/base/net_errors.h" 13 #include "net/base/net_errors.h"
14 #include "net/base/net_log.h" 14 #include "net/base/net_log.h"
15 #include "net/http/http_request_headers.h" 15 #include "net/http/http_request_headers.h"
16 #include "net/http/http_response_headers.h" 16 #include "net/http/http_response_headers.h"
17 #include "net/http/http_util.h" 17 #include "net/http/http_util.h"
18 #include "net/url_request/url_request.h" 18 #include "net/url_request/url_request.h"
19 #include "net/url_request/url_request_status.h" 19 #include "net/url_request/url_request_status.h"
20 #include "webkit/appcache/appcache_service.h" 20 #include "webkit/appcache/appcache_service.h"
21 21
22 namespace appcache { 22 namespace appcache {
23 23
24 AppCacheURLRequestJob::AppCacheURLRequestJob( 24 AppCacheURLRequestJob::AppCacheURLRequestJob(
25 net::URLRequest* request, AppCacheStorage* storage) 25 net::URLRequest* request, AppCacheStorage* storage)
26 : net::URLRequestJob(request), storage_(storage), 26 : net::URLRequestJob(request), storage_(storage),
27 has_been_started_(false), has_been_killed_(false), 27 has_been_started_(false), has_been_killed_(false),
28 delivery_type_(AWAITING_DELIVERY_ORDERS), 28 delivery_type_(AWAITING_DELIVERY_ORDERS),
29 cache_id_(kNoCacheId), is_fallback_(false), 29 group_id_(0), cache_id_(kNoCacheId), is_fallback_(false),
30 cache_entry_not_found_(false), 30 cache_entry_not_found_(false),
31 ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_( 31 ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_(
32 this, &AppCacheURLRequestJob::OnReadComplete)), 32 this, &AppCacheURLRequestJob::OnReadComplete)),
33 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { 33 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
34 DCHECK(storage_); 34 DCHECK(storage_);
35 } 35 }
36 36
37 AppCacheURLRequestJob::~AppCacheURLRequestJob() { 37 AppCacheURLRequestJob::~AppCacheURLRequestJob() {
38 if (storage_) 38 if (storage_)
39 storage_->CancelDelegateCallbacks(this); 39 storage_->CancelDelegateCallbacks(this);
40 } 40 }
41 41
42 void AppCacheURLRequestJob::DeliverAppCachedResponse( 42 void AppCacheURLRequestJob::DeliverAppCachedResponse(
43 const GURL& manifest_url, int64 cache_id, const AppCacheEntry& entry, 43 const GURL& manifest_url, int64 group_id, int64 cache_id,
44 bool is_fallback) { 44 const AppCacheEntry& entry, bool is_fallback) {
45 DCHECK(!has_delivery_orders()); 45 DCHECK(!has_delivery_orders());
46 DCHECK(entry.has_response_id()); 46 DCHECK(entry.has_response_id());
47 delivery_type_ = APPCACHED_DELIVERY; 47 delivery_type_ = APPCACHED_DELIVERY;
48 manifest_url_ = manifest_url; 48 manifest_url_ = manifest_url;
49 group_id_ = group_id;
49 cache_id_ = cache_id; 50 cache_id_ = cache_id;
50 entry_ = entry; 51 entry_ = entry;
51 is_fallback_ = is_fallback; 52 is_fallback_ = is_fallback;
52 MaybeBeginDelivery(); 53 MaybeBeginDelivery();
53 } 54 }
54 55
55 void AppCacheURLRequestJob::DeliverNetworkResponse() { 56 void AppCacheURLRequestJob::DeliverNetworkResponse() {
56 DCHECK(!has_delivery_orders()); 57 DCHECK(!has_delivery_orders());
57 delivery_type_ = NETWORK_DELIVERY; 58 delivery_type_ = NETWORK_DELIVERY;
58 storage_ = NULL; // not needed 59 storage_ = NULL; // not needed
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, 99 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED,
99 net::ERR_FAILED)); 100 net::ERR_FAILED));
100 break; 101 break;
101 102
102 case APPCACHED_DELIVERY: 103 case APPCACHED_DELIVERY:
103 request()->net_log().AddEvent( 104 request()->net_log().AddEvent(
104 is_fallback_ ? 105 is_fallback_ ?
105 net::NetLog::TYPE_APPCACHE_DELIVERING_FALLBACK_RESPONSE : 106 net::NetLog::TYPE_APPCACHE_DELIVERING_FALLBACK_RESPONSE :
106 net::NetLog::TYPE_APPCACHE_DELIVERING_CACHED_RESPONSE, 107 net::NetLog::TYPE_APPCACHE_DELIVERING_CACHED_RESPONSE,
107 NULL); 108 NULL);
108 storage_->LoadResponseInfo(manifest_url_, entry_.response_id(), this); 109 storage_->LoadResponseInfo(
110 manifest_url_, group_id_, entry_.response_id(), this);
109 break; 111 break;
110 112
111 default: 113 default:
112 NOTREACHED(); 114 NOTREACHED();
113 break; 115 break;
114 } 116 }
115 } 117 }
116 118
117 void AppCacheURLRequestJob::OnResponseInfoLoaded( 119 void AppCacheURLRequestJob::OnResponseInfoLoaded(
118 AppCacheResponseInfo* response_info, int64 response_id) { 120 AppCacheResponseInfo* response_info, int64 response_id) {
119 DCHECK(is_delivering_appcache_response()); 121 DCHECK(is_delivering_appcache_response());
120 scoped_refptr<AppCacheURLRequestJob> protect(this); 122 scoped_refptr<AppCacheURLRequestJob> protect(this);
121 if (response_info) { 123 if (response_info) {
122 info_ = response_info; 124 info_ = response_info;
123 reader_.reset( 125 reader_.reset(storage_->CreateResponseReader(
124 storage_->CreateResponseReader(manifest_url_, entry_.response_id())); 126 manifest_url_, group_id_, entry_.response_id()));
125 127
126 if (is_range_request()) 128 if (is_range_request())
127 SetupRangeResponse(); 129 SetupRangeResponse();
128 130
129 NotifyHeadersComplete(); 131 NotifyHeadersComplete();
130 } else { 132 } else {
131 // A resource that is expected to be in the appcache is missing. 133 // A resource that is expected to be in the appcache is missing.
132 // See http://code.google.com/p/chromium/issues/detail?id=50657 134 // See http://code.google.com/p/chromium/issues/detail?id=50657
133 // Instead of failing the request, we restart the request. The retry 135 // Instead of failing the request, we restart the request. The retry
134 // attempt will fallthru to the network instead of trying to load 136 // attempt will fallthru to the network instead of trying to load
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 return; 282 return;
281 } 283 }
282 284
283 // If multiple ranges are requested, we play dumb and 285 // If multiple ranges are requested, we play dumb and
284 // return the entire response with 200 OK. 286 // return the entire response with 200 OK.
285 if (ranges.size() == 1U) 287 if (ranges.size() == 1U)
286 range_requested_ = ranges[0]; 288 range_requested_ = ranges[0];
287 } 289 }
288 290
289 } // namespace appcache 291 } // namespace appcache
OLDNEW
« no previous file with comments | « webkit/appcache/appcache_url_request_job.h ('k') | webkit/appcache/appcache_url_request_job_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698