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 #include "webkit/browser/appcache/appcache_update_job.h" | 5 #include "webkit/browser/appcache/appcache_update_job.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #include "net/base/io_buffer.h" | 13 #include "net/base/io_buffer.h" |
14 #include "net/base/load_flags.h" | 14 #include "net/base/load_flags.h" |
15 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
| 16 #include "net/base/request_priority.h" |
16 #include "net/http/http_request_headers.h" | 17 #include "net/http/http_request_headers.h" |
17 #include "net/http/http_response_headers.h" | 18 #include "net/http/http_response_headers.h" |
18 #include "net/url_request/url_request_context.h" | 19 #include "net/url_request/url_request_context.h" |
19 #include "webkit/browser/appcache/appcache_group.h" | 20 #include "webkit/browser/appcache/appcache_group.h" |
20 #include "webkit/browser/appcache/appcache_histograms.h" | 21 #include "webkit/browser/appcache/appcache_histograms.h" |
21 | 22 |
22 namespace appcache { | 23 namespace appcache { |
23 | 24 |
24 static const int kBufferSize = 32768; | 25 static const int kBufferSize = 32768; |
25 static const size_t kMaxConcurrentUrlFetches = 2; | 26 static const size_t kMaxConcurrentUrlFetches = 2; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 storage_checked(checked), | 85 storage_checked(checked), |
85 existing_response_info(info) { | 86 existing_response_info(info) { |
86 } | 87 } |
87 | 88 |
88 AppCacheUpdateJob::UrlToFetch::~UrlToFetch() { | 89 AppCacheUpdateJob::UrlToFetch::~UrlToFetch() { |
89 } | 90 } |
90 | 91 |
91 // Helper class to fetch resources. Depending on the fetch type, | 92 // Helper class to fetch resources. Depending on the fetch type, |
92 // can either fetch to an in-memory string or write the response | 93 // can either fetch to an in-memory string or write the response |
93 // data out to the disk cache. | 94 // data out to the disk cache. |
94 AppCacheUpdateJob::URLFetcher::URLFetcher( | 95 AppCacheUpdateJob::URLFetcher::URLFetcher(const GURL& url, |
95 const GURL& url, FetchType fetch_type, AppCacheUpdateJob* job) | 96 FetchType fetch_type, |
| 97 AppCacheUpdateJob* job) |
96 : url_(url), | 98 : url_(url), |
97 job_(job), | 99 job_(job), |
98 fetch_type_(fetch_type), | 100 fetch_type_(fetch_type), |
99 retry_503_attempts_(0), | 101 retry_503_attempts_(0), |
100 buffer_(new net::IOBuffer(kBufferSize)), | 102 buffer_(new net::IOBuffer(kBufferSize)), |
101 request_(job->service_->request_context()->CreateRequest(url, this)) { | 103 request_(job->service_->request_context() |
102 } | 104 ->CreateRequest(url, net::DEFAULT_PRIORITY, this)) {} |
103 | 105 |
104 AppCacheUpdateJob::URLFetcher::~URLFetcher() { | 106 AppCacheUpdateJob::URLFetcher::~URLFetcher() { |
105 } | 107 } |
106 | 108 |
107 void AppCacheUpdateJob::URLFetcher::Start() { | 109 void AppCacheUpdateJob::URLFetcher::Start() { |
108 request_->set_first_party_for_cookies(job_->manifest_url_); | 110 request_->set_first_party_for_cookies(job_->manifest_url_); |
109 request_->set_load_flags(request_->load_flags() | | 111 request_->set_load_flags(request_->load_flags() | |
110 net::LOAD_DISABLE_INTERCEPT); | 112 net::LOAD_DISABLE_INTERCEPT); |
111 if (existing_response_headers_.get()) | 113 if (existing_response_headers_.get()) |
112 AddConditionalHeaders(existing_response_headers_.get()); | 114 AddConditionalHeaders(existing_response_headers_.get()); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 | 282 |
281 delete this; | 283 delete this; |
282 } | 284 } |
283 | 285 |
284 bool AppCacheUpdateJob::URLFetcher::MaybeRetryRequest() { | 286 bool AppCacheUpdateJob::URLFetcher::MaybeRetryRequest() { |
285 if (retry_503_attempts_ >= kMax503Retries || | 287 if (retry_503_attempts_ >= kMax503Retries || |
286 !request_->response_headers()->HasHeaderValue("retry-after", "0")) { | 288 !request_->response_headers()->HasHeaderValue("retry-after", "0")) { |
287 return false; | 289 return false; |
288 } | 290 } |
289 ++retry_503_attempts_; | 291 ++retry_503_attempts_; |
290 request_.reset(job_->service_->request_context()->CreateRequest(url_, this)); | 292 request_ = job_->service_->request_context()->CreateRequest( |
| 293 url_, net::DEFAULT_PRIORITY, this); |
291 Start(); | 294 Start(); |
292 return true; | 295 return true; |
293 } | 296 } |
294 | 297 |
295 AppCacheUpdateJob::AppCacheUpdateJob(AppCacheService* service, | 298 AppCacheUpdateJob::AppCacheUpdateJob(AppCacheService* service, |
296 AppCacheGroup* group) | 299 AppCacheGroup* group) |
297 : service_(service), | 300 : service_(service), |
298 manifest_url_(group->manifest_url()), | 301 manifest_url_(group->manifest_url()), |
299 group_(group), | 302 group_(group), |
300 update_type_(UNKNOWN_TYPE), | 303 update_type_(UNKNOWN_TYPE), |
(...skipping 1063 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1364 | 1367 |
1365 // Break the connection with the group so the group cannot call delete | 1368 // Break the connection with the group so the group cannot call delete |
1366 // on this object after we've posted a task to delete ourselves. | 1369 // on this object after we've posted a task to delete ourselves. |
1367 group_->SetUpdateStatus(AppCacheGroup::IDLE); | 1370 group_->SetUpdateStatus(AppCacheGroup::IDLE); |
1368 group_ = NULL; | 1371 group_ = NULL; |
1369 | 1372 |
1370 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 1373 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
1371 } | 1374 } |
1372 | 1375 |
1373 } // namespace appcache | 1376 } // namespace appcache |
OLD | NEW |