Chromium Code Reviews| 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 "content/browser/appcache/appcache_update_job.h" | 5 #include "content/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/location.h" | 10 #include "base/location.h" |
| 11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "content/browser/appcache/appcache_group.h" | 15 #include "content/browser/appcache/appcache_group.h" |
| 16 #include "content/browser/appcache/appcache_histograms.h" | 16 #include "content/browser/appcache/appcache_histograms.h" |
| 17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 #include "net/base/io_buffer.h" | 18 #include "net/base/io_buffer.h" |
| 19 #include "net/base/load_flags.h" | 19 #include "net/base/load_flags.h" |
| 20 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
| 21 #include "net/base/request_priority.h" | 21 #include "net/base/request_priority.h" |
| 22 #include "net/http/http_request_headers.h" | 22 #include "net/http/http_request_headers.h" |
| 23 #include "net/http/http_response_headers.h" | 23 #include "net/http/http_response_headers.h" |
| 24 #include "net/traffic_annotation/network_traffic_annotation.h" | |
| 24 #include "net/url_request/url_request_context.h" | 25 #include "net/url_request/url_request_context.h" |
| 25 #include "url/origin.h" | 26 #include "url/origin.h" |
| 26 | 27 |
| 27 namespace content { | 28 namespace content { |
| 28 | 29 |
| 29 namespace { | 30 namespace { |
| 30 | 31 |
| 31 const int kBufferSize = 32768; | 32 const int kBufferSize = 32768; |
| 32 const size_t kMaxConcurrentUrlFetches = 2; | 33 const size_t kMaxConcurrentUrlFetches = 2; |
| 33 const int kMax503Retries = 3; | 34 const int kMax503Retries = 3; |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 62 return details.reason == APPCACHE_SIGNATURE_ERROR; | 63 return details.reason == APPCACHE_SIGNATURE_ERROR; |
| 63 | 64 |
| 64 default: | 65 default: |
| 65 NOTREACHED(); | 66 NOTREACHED(); |
| 66 return true; | 67 return true; |
| 67 } | 68 } |
| 68 } | 69 } |
| 69 | 70 |
| 70 void EmptyCompletionCallback(int result) {} | 71 void EmptyCompletionCallback(int result) {} |
| 71 | 72 |
| 73 constexpr net::NetworkTrafficAnnotationTag kTrafficAnnotation = | |
| 74 net::DefineNetworkTrafficAnnotation("appcache_update_job", R"( | |
| 75 semantics { | |
| 76 sender: "HTML5 AppCache System" | |
| 77 description: | |
| 78 "Web pages can include a link to a manifest file which lists " | |
| 79 "resources to be cached for offline access. The AppCache system" | |
| 80 "retrieves those resources in the background." | |
| 81 trigger: | |
| 82 "User visits a web page containing a <html manifest=manifestUrl> " | |
| 83 "tag, or navigates to a document retrieved from an existing appcache " | |
| 84 "and some resource should be updated." | |
| 85 data: "None" | |
| 86 destination: WEBSITE | |
| 87 } | |
| 88 policy { | |
| 89 cookies_allowed: true | |
| 90 cookies_store: "Profile cookie store" | |
|
msramek
2017/05/15 13:36:11
I think we say "user" in most other annotations.
Ramin Halavati
2017/05/15 14:01:03
Done.
| |
| 91 setting: | |
| 92 "Users can control this feature via the 'Cookies' setting under " | |
| 93 "'Privacy, Content settings'. If cookies are disabled for a single " | |
| 94 "site, appcaches are disabled for the site only. If they are totally " | |
| 95 "disabled, all appcache requests will be stopped." | |
| 96 policy_exception_justification: "Not implemented." | |
|
msramek
2017/05/15 13:36:11
Based on the "setting" field, this would be the De
Ramin Halavati
2017/05/15 14:01:03
Done.
| |
| 97 })"); | |
| 72 } // namespace | 98 } // namespace |
| 73 | 99 |
| 74 // Helper class for collecting hosts per frontend when sending notifications | 100 // Helper class for collecting hosts per frontend when sending notifications |
| 75 // so that only one notification is sent for all hosts using the same frontend. | 101 // so that only one notification is sent for all hosts using the same frontend. |
| 76 class HostNotifier { | 102 class HostNotifier { |
| 77 public: | 103 public: |
| 78 typedef std::vector<int> HostIds; | 104 typedef std::vector<int> HostIds; |
| 79 typedef std::map<AppCacheFrontend*, HostIds> NotifyHostMap; | 105 typedef std::map<AppCacheFrontend*, HostIds> NotifyHostMap; |
| 80 | 106 |
| 81 // Caller is responsible for ensuring there will be no duplicate hosts. | 107 // Caller is responsible for ensuring there will be no duplicate hosts. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 // can either fetch to an in-memory string or write the response | 177 // can either fetch to an in-memory string or write the response |
| 152 // data out to the disk cache. | 178 // data out to the disk cache. |
| 153 AppCacheUpdateJob::URLFetcher::URLFetcher(const GURL& url, | 179 AppCacheUpdateJob::URLFetcher::URLFetcher(const GURL& url, |
| 154 FetchType fetch_type, | 180 FetchType fetch_type, |
| 155 AppCacheUpdateJob* job) | 181 AppCacheUpdateJob* job) |
| 156 : url_(url), | 182 : url_(url), |
| 157 job_(job), | 183 job_(job), |
| 158 fetch_type_(fetch_type), | 184 fetch_type_(fetch_type), |
| 159 retry_503_attempts_(0), | 185 retry_503_attempts_(0), |
| 160 buffer_(new net::IOBuffer(kBufferSize)), | 186 buffer_(new net::IOBuffer(kBufferSize)), |
| 161 request_(job->service_->request_context() | 187 request_( |
| 162 ->CreateRequest(url, net::DEFAULT_PRIORITY, this)), | 188 job->service_->request_context()->CreateRequest(url, |
| 189 net::DEFAULT_PRIORITY, | |
| 190 this, | |
| 191 kTrafficAnnotation)), | |
| 163 result_(UPDATE_OK), | 192 result_(UPDATE_OK), |
| 164 redirect_response_code_(-1) {} | 193 redirect_response_code_(-1) {} |
| 165 | 194 |
| 166 AppCacheUpdateJob::URLFetcher::~URLFetcher() { | 195 AppCacheUpdateJob::URLFetcher::~URLFetcher() { |
| 167 // To defend against URLRequest calling delegate methods during | 196 // To defend against URLRequest calling delegate methods during |
| 168 // destruction, we test for a !request_ in those methods. | 197 // destruction, we test for a !request_ in those methods. |
| 169 std::unique_ptr<net::URLRequest> temp = std::move(request_); | 198 std::unique_ptr<net::URLRequest> temp = std::move(request_); |
| 170 } | 199 } |
| 171 | 200 |
| 172 void AppCacheUpdateJob::URLFetcher::Start() { | 201 void AppCacheUpdateJob::URLFetcher::Start() { |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 386 } | 415 } |
| 387 | 416 |
| 388 bool AppCacheUpdateJob::URLFetcher::MaybeRetryRequest() { | 417 bool AppCacheUpdateJob::URLFetcher::MaybeRetryRequest() { |
| 389 if (retry_503_attempts_ >= kMax503Retries || | 418 if (retry_503_attempts_ >= kMax503Retries || |
| 390 !request_->response_headers()->HasHeaderValue("retry-after", "0")) { | 419 !request_->response_headers()->HasHeaderValue("retry-after", "0")) { |
| 391 return false; | 420 return false; |
| 392 } | 421 } |
| 393 ++retry_503_attempts_; | 422 ++retry_503_attempts_; |
| 394 result_ = UPDATE_OK; | 423 result_ = UPDATE_OK; |
| 395 request_ = job_->service_->request_context()->CreateRequest( | 424 request_ = job_->service_->request_context()->CreateRequest( |
| 396 url_, net::DEFAULT_PRIORITY, this); | 425 url_, net::DEFAULT_PRIORITY, this, kTrafficAnnotation); |
| 397 Start(); | 426 Start(); |
| 398 return true; | 427 return true; |
| 399 } | 428 } |
| 400 | 429 |
| 401 AppCacheUpdateJob::AppCacheUpdateJob(AppCacheServiceImpl* service, | 430 AppCacheUpdateJob::AppCacheUpdateJob(AppCacheServiceImpl* service, |
| 402 AppCacheGroup* group) | 431 AppCacheGroup* group) |
| 403 : service_(service), | 432 : service_(service), |
| 404 manifest_url_(group->manifest_url()), | 433 manifest_url_(group->manifest_url()), |
| 405 group_(group), | 434 group_(group), |
| 406 update_type_(UNKNOWN_TYPE), | 435 update_type_(UNKNOWN_TYPE), |
| (...skipping 1307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1714 // on this object after we've posted a task to delete ourselves. | 1743 // on this object after we've posted a task to delete ourselves. |
| 1715 if (group_) { | 1744 if (group_) { |
| 1716 group_->SetUpdateAppCacheStatus(AppCacheGroup::IDLE); | 1745 group_->SetUpdateAppCacheStatus(AppCacheGroup::IDLE); |
| 1717 group_ = NULL; | 1746 group_ = NULL; |
| 1718 } | 1747 } |
| 1719 | 1748 |
| 1720 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); | 1749 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); |
| 1721 } | 1750 } |
| 1722 | 1751 |
| 1723 } // namespace content | 1752 } // namespace content |
| OLD | NEW |