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

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

Issue 2799133005: Network traffic annotation added to appcache_update_job. (Closed)
Patch Set: Header added. Created 3 years, 8 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 =
michaeln 2017/04/07 20:36:59 "In case you believe that annotation should be pas
Ramin Halavati 2017/04/10 05:50:31 Sometimes, based on the inputs to the function tha
74 net::DefineNetworkTrafficAnnotation("...", R"(
75 semantics {
76 sender: "..."
77 description: "..."
78 trigger: "..."
79 data: "..."
80 destination: WEBSITE/GOOGLE_OWNED_SERVICE/OTHER/LOCAL
81 }
82 policy {
83 cookies_allowed: false/true
84 cookies_store: "..."
85 setting: "..."
86 chrome_policy {
87 [POLICY_NAME] {
88 policy_options {mode: MANDATORY/RECOMMENDED/UNSET}
89 [POLICY_NAME]: ... //(value to disable it)
90 }
91 }
92 policy_exception_justification: "..."
93 })");
michaeln 2017/04/20 20:22:00 constexpr net::NetworkTrafficAnnotationTag kTraffi
Ramin Halavati 2017/04/21 05:41:14 Done.
72 } // namespace 94 } // namespace
73 95
74 // Helper class for collecting hosts per frontend when sending notifications 96 // 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. 97 // so that only one notification is sent for all hosts using the same frontend.
76 class HostNotifier { 98 class HostNotifier {
77 public: 99 public:
78 typedef std::vector<int> HostIds; 100 typedef std::vector<int> HostIds;
79 typedef std::map<AppCacheFrontend*, HostIds> NotifyHostMap; 101 typedef std::map<AppCacheFrontend*, HostIds> NotifyHostMap;
80 102
81 // Caller is responsible for ensuring there will be no duplicate hosts. 103 // 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 173 // can either fetch to an in-memory string or write the response
152 // data out to the disk cache. 174 // data out to the disk cache.
153 AppCacheUpdateJob::URLFetcher::URLFetcher(const GURL& url, 175 AppCacheUpdateJob::URLFetcher::URLFetcher(const GURL& url,
154 FetchType fetch_type, 176 FetchType fetch_type,
155 AppCacheUpdateJob* job) 177 AppCacheUpdateJob* job)
156 : url_(url), 178 : url_(url),
157 job_(job), 179 job_(job),
158 fetch_type_(fetch_type), 180 fetch_type_(fetch_type),
159 retry_503_attempts_(0), 181 retry_503_attempts_(0),
160 buffer_(new net::IOBuffer(kBufferSize)), 182 buffer_(new net::IOBuffer(kBufferSize)),
161 request_(job->service_->request_context() 183 request_(
162 ->CreateRequest(url, net::DEFAULT_PRIORITY, this)), 184 job->service_->request_context()->CreateRequest(url,
185 net::DEFAULT_PRIORITY,
186 this,
187 kTrafficAnnotation)),
163 result_(UPDATE_OK), 188 result_(UPDATE_OK),
164 redirect_response_code_(-1) {} 189 redirect_response_code_(-1) {}
165 190
166 AppCacheUpdateJob::URLFetcher::~URLFetcher() { 191 AppCacheUpdateJob::URLFetcher::~URLFetcher() {
167 // To defend against URLRequest calling delegate methods during 192 // To defend against URLRequest calling delegate methods during
168 // destruction, we test for a !request_ in those methods. 193 // destruction, we test for a !request_ in those methods.
169 std::unique_ptr<net::URLRequest> temp = std::move(request_); 194 std::unique_ptr<net::URLRequest> temp = std::move(request_);
170 } 195 }
171 196
172 void AppCacheUpdateJob::URLFetcher::Start() { 197 void AppCacheUpdateJob::URLFetcher::Start() {
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 delete this; 410 delete this;
386 } 411 }
387 412
388 bool AppCacheUpdateJob::URLFetcher::MaybeRetryRequest() { 413 bool AppCacheUpdateJob::URLFetcher::MaybeRetryRequest() {
389 if (retry_503_attempts_ >= kMax503Retries || 414 if (retry_503_attempts_ >= kMax503Retries ||
390 !request_->response_headers()->HasHeaderValue("retry-after", "0")) { 415 !request_->response_headers()->HasHeaderValue("retry-after", "0")) {
391 return false; 416 return false;
392 } 417 }
393 ++retry_503_attempts_; 418 ++retry_503_attempts_;
394 result_ = UPDATE_OK; 419 result_ = UPDATE_OK;
420 net::NetworkTrafficAnnotationTag traffic_annotation =
421 net::DefineNetworkTrafficAnnotation("...", R"(
422 semantics {
423 sender: "..."
424 description: "..."
425 trigger: "..."
426 data: "..."
427 destination: WEBSITE/GOOGLE_OWNED_SERVICE/OTHER/LOCAL
428 }
429 policy {
430 cookies_allowed: false/true
431 cookies_store: "..."
432 setting: "..."
433 chrome_policy {
434 [POLICY_NAME] {
435 policy_options {mode: MANDATORY/RECOMMENDED/UNSET}
436 [POLICY_NAME]: ... //(value to disable it)
437 }
438 }
439 policy_exception_justification: "..."
440 })");
395 request_ = job_->service_->request_context()->CreateRequest( 441 request_ = job_->service_->request_context()->CreateRequest(
396 url_, net::DEFAULT_PRIORITY, this); 442 url_, net::DEFAULT_PRIORITY, this, traffic_annotation);
michaeln 2017/04/07 20:36:59 Why not use kTrafficAnnotation here too? Do you wa
Ramin Halavati 2017/04/10 05:50:31 If both network requests can be described with one
michaeln 2017/04/20 20:22:00 Both can be described with the same annotation.
Ramin Halavati 2017/04/21 05:41:14 Done.
397 Start(); 443 Start();
398 return true; 444 return true;
399 } 445 }
400 446
401 AppCacheUpdateJob::AppCacheUpdateJob(AppCacheServiceImpl* service, 447 AppCacheUpdateJob::AppCacheUpdateJob(AppCacheServiceImpl* service,
402 AppCacheGroup* group) 448 AppCacheGroup* group)
403 : service_(service), 449 : service_(service),
404 manifest_url_(group->manifest_url()), 450 manifest_url_(group->manifest_url()),
405 group_(group), 451 group_(group),
406 update_type_(UNKNOWN_TYPE), 452 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. 1760 // on this object after we've posted a task to delete ourselves.
1715 if (group_) { 1761 if (group_) {
1716 group_->SetUpdateAppCacheStatus(AppCacheGroup::IDLE); 1762 group_->SetUpdateAppCacheStatus(AppCacheGroup::IDLE);
1717 group_ = NULL; 1763 group_ = NULL;
1718 } 1764 }
1719 1765
1720 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); 1766 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
1721 } 1767 }
1722 1768
1723 } // namespace content 1769 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698