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

Side by Side Diff: content/browser/appcache/appcache_update_job.cc

Issue 2799133005: Network traffic annotation added to appcache_update_job. (Closed)
Patch Set: Comments addressed. Created 3 years, 7 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
OLDNEW
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
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: "user"
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 chrome_policy {
97 DefaultCookiesSetting {
98 policy_options {mode: MANDATORY}
99 DefaultCookiesSetting: 2
100 }
101 }
102 })");
72 } // namespace 103 } // namespace
73 104
74 // Helper class for collecting hosts per frontend when sending notifications 105 // 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. 106 // so that only one notification is sent for all hosts using the same frontend.
76 class HostNotifier { 107 class HostNotifier {
77 public: 108 public:
78 typedef std::vector<int> HostIds; 109 typedef std::vector<int> HostIds;
79 typedef std::map<AppCacheFrontend*, HostIds> NotifyHostMap; 110 typedef std::map<AppCacheFrontend*, HostIds> NotifyHostMap;
80 111
81 // Caller is responsible for ensuring there will be no duplicate hosts. 112 // Caller is responsible for ensuring there will be no duplicate hosts.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 // can either fetch to an in-memory string or write the response 182 // can either fetch to an in-memory string or write the response
152 // data out to the disk cache. 183 // data out to the disk cache.
153 AppCacheUpdateJob::URLFetcher::URLFetcher(const GURL& url, 184 AppCacheUpdateJob::URLFetcher::URLFetcher(const GURL& url,
154 FetchType fetch_type, 185 FetchType fetch_type,
155 AppCacheUpdateJob* job) 186 AppCacheUpdateJob* job)
156 : url_(url), 187 : url_(url),
157 job_(job), 188 job_(job),
158 fetch_type_(fetch_type), 189 fetch_type_(fetch_type),
159 retry_503_attempts_(0), 190 retry_503_attempts_(0),
160 buffer_(new net::IOBuffer(kBufferSize)), 191 buffer_(new net::IOBuffer(kBufferSize)),
161 request_(job->service_->request_context() 192 request_(
162 ->CreateRequest(url, net::DEFAULT_PRIORITY, this)), 193 job->service_->request_context()->CreateRequest(url,
194 net::DEFAULT_PRIORITY,
195 this,
196 kTrafficAnnotation)),
163 result_(UPDATE_OK), 197 result_(UPDATE_OK),
164 redirect_response_code_(-1) {} 198 redirect_response_code_(-1) {}
165 199
166 AppCacheUpdateJob::URLFetcher::~URLFetcher() { 200 AppCacheUpdateJob::URLFetcher::~URLFetcher() {
167 // To defend against URLRequest calling delegate methods during 201 // To defend against URLRequest calling delegate methods during
168 // destruction, we test for a !request_ in those methods. 202 // destruction, we test for a !request_ in those methods.
169 std::unique_ptr<net::URLRequest> temp = std::move(request_); 203 std::unique_ptr<net::URLRequest> temp = std::move(request_);
170 } 204 }
171 205
172 void AppCacheUpdateJob::URLFetcher::Start() { 206 void AppCacheUpdateJob::URLFetcher::Start() {
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 } 420 }
387 421
388 bool AppCacheUpdateJob::URLFetcher::MaybeRetryRequest() { 422 bool AppCacheUpdateJob::URLFetcher::MaybeRetryRequest() {
389 if (retry_503_attempts_ >= kMax503Retries || 423 if (retry_503_attempts_ >= kMax503Retries ||
390 !request_->response_headers()->HasHeaderValue("retry-after", "0")) { 424 !request_->response_headers()->HasHeaderValue("retry-after", "0")) {
391 return false; 425 return false;
392 } 426 }
393 ++retry_503_attempts_; 427 ++retry_503_attempts_;
394 result_ = UPDATE_OK; 428 result_ = UPDATE_OK;
395 request_ = job_->service_->request_context()->CreateRequest( 429 request_ = job_->service_->request_context()->CreateRequest(
396 url_, net::DEFAULT_PRIORITY, this); 430 url_, net::DEFAULT_PRIORITY, this, kTrafficAnnotation);
397 Start(); 431 Start();
398 return true; 432 return true;
399 } 433 }
400 434
401 AppCacheUpdateJob::AppCacheUpdateJob(AppCacheServiceImpl* service, 435 AppCacheUpdateJob::AppCacheUpdateJob(AppCacheServiceImpl* service,
402 AppCacheGroup* group) 436 AppCacheGroup* group)
403 : service_(service), 437 : service_(service),
404 manifest_url_(group->manifest_url()), 438 manifest_url_(group->manifest_url()),
405 group_(group), 439 group_(group),
406 update_type_(UNKNOWN_TYPE), 440 update_type_(UNKNOWN_TYPE),
(...skipping 1307 matching lines...) Expand 10 before | Expand all | Expand 10 after
1714 // on this object after we've posted a task to delete ourselves. 1748 // on this object after we've posted a task to delete ourselves.
1715 if (group_) { 1749 if (group_) {
1716 group_->SetUpdateAppCacheStatus(AppCacheGroup::IDLE); 1750 group_->SetUpdateAppCacheStatus(AppCacheGroup::IDLE);
1717 group_ = NULL; 1751 group_ = NULL;
1718 } 1752 }
1719 1753
1720 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); 1754 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
1721 } 1755 }
1722 1756
1723 } // namespace content 1757 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698