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

Side by Side Diff: content/common/throttling_url_loader.cc

Issue 2893233002: Network traffic annotation added to URLLoaderImpl. (Closed)
Patch Set: Comment addressed, Merged. Created 3 years, 6 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/common/throttling_url_loader.h" 5 #include "content/common/throttling_url_loader.h"
6 6
7 #include "base/single_thread_task_runner.h" 7 #include "base/single_thread_task_runner.h"
8 8
9 namespace content { 9 namespace content {
10 10
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 50
51 // static 51 // static
52 std::unique_ptr<ThrottlingURLLoader> ThrottlingURLLoader::CreateLoaderAndStart( 52 std::unique_ptr<ThrottlingURLLoader> ThrottlingURLLoader::CreateLoaderAndStart(
53 mojom::URLLoaderFactory* factory, 53 mojom::URLLoaderFactory* factory,
54 std::vector<std::unique_ptr<URLLoaderThrottle>> throttles, 54 std::vector<std::unique_ptr<URLLoaderThrottle>> throttles,
55 int32_t routing_id, 55 int32_t routing_id,
56 int32_t request_id, 56 int32_t request_id,
57 uint32_t options, 57 uint32_t options,
58 std::unique_ptr<ResourceRequest> url_request, 58 std::unique_ptr<ResourceRequest> url_request,
59 mojom::URLLoaderClient* client, 59 mojom::URLLoaderClient* client,
60 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation,
60 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { 61 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
61 std::unique_ptr<ThrottlingURLLoader> loader( 62 std::unique_ptr<ThrottlingURLLoader> loader(new ThrottlingURLLoader(
62 new ThrottlingURLLoader(std::move(throttles), client)); 63 std::move(throttles), client, traffic_annotation));
63 loader->Start(factory, routing_id, request_id, options, 64 loader->Start(factory, routing_id, request_id, options,
64 std::move(url_request), std::move(task_runner)); 65 std::move(url_request), std::move(task_runner));
65 return loader; 66 return loader;
66 } 67 }
67 68
68 ThrottlingURLLoader::~ThrottlingURLLoader() {} 69 ThrottlingURLLoader::~ThrottlingURLLoader() {}
69 70
70 void ThrottlingURLLoader::FollowRedirect() { 71 void ThrottlingURLLoader::FollowRedirect() {
71 if (url_loader_) 72 if (url_loader_)
72 url_loader_->FollowRedirect(); 73 url_loader_->FollowRedirect();
73 } 74 }
74 75
75 void ThrottlingURLLoader::SetPriority(net::RequestPriority priority, 76 void ThrottlingURLLoader::SetPriority(net::RequestPriority priority,
76 int32_t intra_priority_value) { 77 int32_t intra_priority_value) {
77 if (!url_loader_ && !cancelled_by_throttle_) { 78 if (!url_loader_ && !cancelled_by_throttle_) {
78 DCHECK_EQ(DEFERRED_START, deferred_stage_); 79 DCHECK_EQ(DEFERRED_START, deferred_stage_);
79 priority_info_ = 80 priority_info_ =
80 base::MakeUnique<PriorityInfo>(priority, intra_priority_value); 81 base::MakeUnique<PriorityInfo>(priority, intra_priority_value);
81 return; 82 return;
82 } 83 }
83 84
84 url_loader_->SetPriority(priority, intra_priority_value); 85 url_loader_->SetPriority(priority, intra_priority_value);
85 } 86 }
86 87
87 ThrottlingURLLoader::ThrottlingURLLoader( 88 ThrottlingURLLoader::ThrottlingURLLoader(
88 std::vector<std::unique_ptr<URLLoaderThrottle>> throttles, 89 std::vector<std::unique_ptr<URLLoaderThrottle>> throttles,
89 mojom::URLLoaderClient* client) 90 mojom::URLLoaderClient* client,
90 : forwarding_client_(client), client_binding_(this) { 91 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation)
92 : forwarding_client_(client),
93 client_binding_(this),
94 traffic_annotation_(traffic_annotation) {
91 if (throttles.size() > 0) { 95 if (throttles.size() > 0) {
92 // TODO(yzshen): Implement a URLLoaderThrottle subclass which handles a list 96 // TODO(yzshen): Implement a URLLoaderThrottle subclass which handles a list
93 // of URLLoaderThrottles. 97 // of URLLoaderThrottles.
94 CHECK_EQ(1u, throttles.size()); 98 CHECK_EQ(1u, throttles.size());
95 throttle_ = std::move(throttles[0]); 99 throttle_ = std::move(throttles[0]);
96 throttle_->set_delegate(this); 100 throttle_->set_delegate(this);
97 } 101 }
98 } 102 }
99 103
100 void ThrottlingURLLoader::Start( 104 void ThrottlingURLLoader::Start(
(...skipping 19 matching lines...) Expand all
120 options, std::move(url_request), 124 options, std::move(url_request),
121 std::move(task_runner)); 125 std::move(task_runner));
122 return; 126 return;
123 } 127 }
124 } 128 }
125 129
126 mojom::URLLoaderClientPtr client; 130 mojom::URLLoaderClientPtr client;
127 client_binding_.Bind(mojo::MakeRequest(&client), std::move(task_runner)); 131 client_binding_.Bind(mojo::MakeRequest(&client), std::move(task_runner));
128 factory->CreateLoaderAndStart(mojo::MakeRequest(&url_loader_), routing_id, 132 factory->CreateLoaderAndStart(mojo::MakeRequest(&url_loader_), routing_id,
129 request_id, options, *url_request, 133 request_id, options, *url_request,
130 std::move(client)); 134 std::move(client), traffic_annotation_);
131 } 135 }
132 136
133 void ThrottlingURLLoader::OnReceiveResponse( 137 void ThrottlingURLLoader::OnReceiveResponse(
134 const ResourceResponseHead& response_head, 138 const ResourceResponseHead& response_head,
135 const base::Optional<net::SSLInfo>& ssl_info, 139 const base::Optional<net::SSLInfo>& ssl_info,
136 mojom::DownloadedTempFilePtr downloaded_file) { 140 mojom::DownloadedTempFilePtr downloaded_file) {
137 DCHECK_EQ(DEFERRED_NONE, deferred_stage_); 141 DCHECK_EQ(DEFERRED_NONE, deferred_stage_);
138 DCHECK(!cancelled_by_throttle_); 142 DCHECK(!cancelled_by_throttle_);
139 143
140 if (throttle_) { 144 if (throttle_) {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 return; 258 return;
255 259
256 switch (deferred_stage_) { 260 switch (deferred_stage_) {
257 case DEFERRED_START: { 261 case DEFERRED_START: {
258 mojom::URLLoaderClientPtr client; 262 mojom::URLLoaderClientPtr client;
259 client_binding_.Bind( 263 client_binding_.Bind(
260 mojo::MakeRequest(&client), std::move(start_info_->task_runner)); 264 mojo::MakeRequest(&client), std::move(start_info_->task_runner));
261 start_info_->url_loader_factory->CreateLoaderAndStart( 265 start_info_->url_loader_factory->CreateLoaderAndStart(
262 mojo::MakeRequest(&url_loader_), start_info_->routing_id, 266 mojo::MakeRequest(&url_loader_), start_info_->routing_id,
263 start_info_->request_id, start_info_->options, 267 start_info_->request_id, start_info_->options,
264 *start_info_->url_request, std::move(client)); 268 *start_info_->url_request, std::move(client), traffic_annotation_);
265 269
266 if (priority_info_) { 270 if (priority_info_) {
267 auto priority_info = std::move(priority_info_); 271 auto priority_info = std::move(priority_info_);
268 url_loader_->SetPriority(priority_info->priority, 272 url_loader_->SetPriority(priority_info->priority,
269 priority_info->intra_priority_value); 273 priority_info->intra_priority_value);
270 } 274 }
271 break; 275 break;
272 } 276 }
273 case DEFERRED_REDIRECT: { 277 case DEFERRED_REDIRECT: {
274 client_binding_.ResumeIncomingMethodCallProcessing(); 278 client_binding_.ResumeIncomingMethodCallProcessing();
275 forwarding_client_->OnReceiveRedirect(redirect_info_->redirect_info, 279 forwarding_client_->OnReceiveRedirect(redirect_info_->redirect_info,
276 redirect_info_->response_head); 280 redirect_info_->response_head);
277 break; 281 break;
278 } 282 }
279 case DEFERRED_RESPONSE: { 283 case DEFERRED_RESPONSE: {
280 client_binding_.ResumeIncomingMethodCallProcessing(); 284 client_binding_.ResumeIncomingMethodCallProcessing();
281 forwarding_client_->OnReceiveResponse( 285 forwarding_client_->OnReceiveResponse(
282 response_info_->response_head, response_info_->ssl_info, 286 response_info_->response_head, response_info_->ssl_info,
283 std::move(response_info_->downloaded_file)); 287 std::move(response_info_->downloaded_file));
284 break; 288 break;
285 } 289 }
286 default: 290 default:
287 NOTREACHED(); 291 NOTREACHED();
288 break; 292 break;
289 } 293 }
290 deferred_stage_ = DEFERRED_NONE; 294 deferred_stage_ = DEFERRED_NONE;
291 } 295 }
292 296
293 } // namespace content 297 } // namespace content
OLDNEW
« no previous file with comments | « content/common/throttling_url_loader.h ('k') | content/common/throttling_url_loader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698