| 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/appcache/appcache_update_job.h" | 5 #include "webkit/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.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/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/http/http_request_headers.h" | 16 #include "net/http/http_request_headers.h" |
| 17 #include "net/http/http_response_headers.h" | 17 #include "net/http/http_response_headers.h" |
| 18 #include "net/url_request/url_request_context.h" |
| 18 #include "webkit/appcache/appcache_group.h" | 19 #include "webkit/appcache/appcache_group.h" |
| 19 #include "webkit/appcache/appcache_histograms.h" | 20 #include "webkit/appcache/appcache_histograms.h" |
| 20 | 21 |
| 21 namespace appcache { | 22 namespace appcache { |
| 22 | 23 |
| 23 static const int kBufferSize = 32768; | 24 static const int kBufferSize = 32768; |
| 24 static const size_t kMaxConcurrentUrlFetches = 2; | 25 static const size_t kMaxConcurrentUrlFetches = 2; |
| 25 static const int kMax503Retries = 3; | 26 static const int kMax503Retries = 3; |
| 26 | 27 |
| 27 // Helper class for collecting hosts per frontend when sending notifications | 28 // Helper class for collecting hosts per frontend when sending notifications |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 // Helper class to fetch resources. Depending on the fetch type, | 91 // Helper class to fetch resources. Depending on the fetch type, |
| 91 // can either fetch to an in-memory string or write the response | 92 // can either fetch to an in-memory string or write the response |
| 92 // data out to the disk cache. | 93 // data out to the disk cache. |
| 93 AppCacheUpdateJob::URLFetcher::URLFetcher( | 94 AppCacheUpdateJob::URLFetcher::URLFetcher( |
| 94 const GURL& url, FetchType fetch_type, AppCacheUpdateJob* job) | 95 const GURL& url, FetchType fetch_type, AppCacheUpdateJob* job) |
| 95 : url_(url), | 96 : url_(url), |
| 96 job_(job), | 97 job_(job), |
| 97 fetch_type_(fetch_type), | 98 fetch_type_(fetch_type), |
| 98 retry_503_attempts_(0), | 99 retry_503_attempts_(0), |
| 99 buffer_(new net::IOBuffer(kBufferSize)), | 100 buffer_(new net::IOBuffer(kBufferSize)), |
| 100 ALLOW_THIS_IN_INITIALIZER_LIST( | 101 ALLOW_THIS_IN_INITIALIZER_LIST(request_( |
| 101 request_(new net::URLRequest(url, | 102 job->service_->request_context()->CreateRequest(url, this))) { |
| 102 this, | |
| 103 job->service_->request_context()))) { | |
| 104 } | 103 } |
| 105 | 104 |
| 106 AppCacheUpdateJob::URLFetcher::~URLFetcher() { | 105 AppCacheUpdateJob::URLFetcher::~URLFetcher() { |
| 107 } | 106 } |
| 108 | 107 |
| 109 void AppCacheUpdateJob::URLFetcher::Start() { | 108 void AppCacheUpdateJob::URLFetcher::Start() { |
| 110 request_->set_first_party_for_cookies(job_->manifest_url_); | 109 request_->set_first_party_for_cookies(job_->manifest_url_); |
| 111 request_->set_load_flags(request_->load_flags() | | 110 request_->set_load_flags(request_->load_flags() | |
| 112 net::LOAD_DISABLE_INTERCEPT); | 111 net::LOAD_DISABLE_INTERCEPT); |
| 113 if (existing_response_headers_) | 112 if (existing_response_headers_) |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 | 280 |
| 282 delete this; | 281 delete this; |
| 283 } | 282 } |
| 284 | 283 |
| 285 bool AppCacheUpdateJob::URLFetcher::MaybeRetryRequest() { | 284 bool AppCacheUpdateJob::URLFetcher::MaybeRetryRequest() { |
| 286 if (retry_503_attempts_ >= kMax503Retries || | 285 if (retry_503_attempts_ >= kMax503Retries || |
| 287 !request_->response_headers()->HasHeaderValue("retry-after", "0")) { | 286 !request_->response_headers()->HasHeaderValue("retry-after", "0")) { |
| 288 return false; | 287 return false; |
| 289 } | 288 } |
| 290 ++retry_503_attempts_; | 289 ++retry_503_attempts_; |
| 291 request_.reset(new net::URLRequest(url_, | 290 request_.reset(job_->service_->request_context()->CreateRequest(url_, this)); |
| 292 this, | |
| 293 job_->service_->request_context())); | |
| 294 Start(); | 291 Start(); |
| 295 return true; | 292 return true; |
| 296 } | 293 } |
| 297 | 294 |
| 298 AppCacheUpdateJob::AppCacheUpdateJob(AppCacheService* service, | 295 AppCacheUpdateJob::AppCacheUpdateJob(AppCacheService* service, |
| 299 AppCacheGroup* group) | 296 AppCacheGroup* group) |
| 300 : service_(service), | 297 : service_(service), |
| 301 manifest_url_(group->manifest_url()), | 298 manifest_url_(group->manifest_url()), |
| 302 group_(group), | 299 group_(group), |
| 303 update_type_(UNKNOWN_TYPE), | 300 update_type_(UNKNOWN_TYPE), |
| (...skipping 1037 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1341 | 1338 |
| 1342 // Break the connection with the group so the group cannot call delete | 1339 // Break the connection with the group so the group cannot call delete |
| 1343 // on this object after we've posted a task to delete ourselves. | 1340 // on this object after we've posted a task to delete ourselves. |
| 1344 group_->SetUpdateStatus(AppCacheGroup::IDLE); | 1341 group_->SetUpdateStatus(AppCacheGroup::IDLE); |
| 1345 group_ = NULL; | 1342 group_ = NULL; |
| 1346 | 1343 |
| 1347 MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 1344 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 1348 } | 1345 } |
| 1349 | 1346 |
| 1350 } // namespace appcache | 1347 } // namespace appcache |
| OLD | NEW |