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

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

Issue 2893233002: Network traffic annotation added to URLLoaderImpl. (Closed)
Patch Set: Changed ParamTraits to StructTraits. 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 namespace content { 7 namespace content {
8 8
9 // static 9 // static
10 std::unique_ptr<ThrottlingURLLoader> ThrottlingURLLoader::CreateLoaderAndStart( 10 std::unique_ptr<ThrottlingURLLoader> ThrottlingURLLoader::CreateLoaderAndStart(
11 mojom::URLLoaderFactory* factory, 11 mojom::URLLoaderFactory* factory,
12 std::vector<std::unique_ptr<URLLoaderThrottle>> throttles, 12 std::vector<std::unique_ptr<URLLoaderThrottle>> throttles,
13 int32_t routing_id, 13 int32_t routing_id,
14 int32_t request_id, 14 int32_t request_id,
15 uint32_t options, 15 uint32_t options,
16 std::unique_ptr<ResourceRequest> url_request, 16 std::unique_ptr<ResourceRequest> url_request,
17 mojom::URLLoaderClient* client) { 17 mojom::URLLoaderClient* client,
18 std::unique_ptr<ThrottlingURLLoader> loader( 18 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) {
19 new ThrottlingURLLoader(std::move(throttles), client)); 19 std::unique_ptr<ThrottlingURLLoader> loader(new ThrottlingURLLoader(
20 std::move(throttles), client, traffic_annotation));
20 loader->Start(factory, routing_id, request_id, options, 21 loader->Start(factory, routing_id, request_id, options,
21 std::move(url_request)); 22 std::move(url_request));
22 return loader; 23 return loader;
23 } 24 }
24 25
25 ThrottlingURLLoader::~ThrottlingURLLoader() {} 26 ThrottlingURLLoader::~ThrottlingURLLoader() {}
26 27
27 void ThrottlingURLLoader::FollowRedirect() { 28 void ThrottlingURLLoader::FollowRedirect() {
28 if (url_loader_) 29 if (url_loader_)
29 url_loader_->FollowRedirect(); 30 url_loader_->FollowRedirect();
30 } 31 }
31 32
32 void ThrottlingURLLoader::SetPriority(net::RequestPriority priority, 33 void ThrottlingURLLoader::SetPriority(net::RequestPriority priority,
33 int32_t intra_priority_value) { 34 int32_t intra_priority_value) {
34 if (!url_loader_ && !cancelled_by_throttle_) { 35 if (!url_loader_ && !cancelled_by_throttle_) {
35 DCHECK_EQ(DEFERRED_START, deferred_stage_); 36 DCHECK_EQ(DEFERRED_START, deferred_stage_);
36 set_priority_cached_ = true; 37 set_priority_cached_ = true;
37 priority_ = priority; 38 priority_ = priority;
38 intra_priority_value_ = intra_priority_value; 39 intra_priority_value_ = intra_priority_value;
39 return; 40 return;
40 } 41 }
41 42
42 url_loader_->SetPriority(priority, intra_priority_value); 43 url_loader_->SetPriority(priority, intra_priority_value);
43 } 44 }
44 45
45 ThrottlingURLLoader::ThrottlingURLLoader( 46 ThrottlingURLLoader::ThrottlingURLLoader(
46 std::vector<std::unique_ptr<URLLoaderThrottle>> throttles, 47 std::vector<std::unique_ptr<URLLoaderThrottle>> throttles,
47 mojom::URLLoaderClient* client) 48 mojom::URLLoaderClient* client,
48 : forwarding_client_(client), client_binding_(this) { 49 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation)
50 : forwarding_client_(client),
51 client_binding_(this),
52 traffic_annotation_(traffic_annotation) {
49 if (throttles.size() > 0) { 53 if (throttles.size() > 0) {
50 // TODO(yzshen): Implement a URLLoaderThrottle subclass which handles a list 54 // TODO(yzshen): Implement a URLLoaderThrottle subclass which handles a list
51 // of URLLoaderThrottles. 55 // of URLLoaderThrottles.
52 CHECK_EQ(1u, throttles.size()); 56 CHECK_EQ(1u, throttles.size());
53 throttle_ = std::move(throttles[0]); 57 throttle_ = std::move(throttles[0]);
54 throttle_->set_delegate(this); 58 throttle_->set_delegate(this);
55 } 59 }
56 } 60 }
57 61
58 void ThrottlingURLLoader::Start(mojom::URLLoaderFactory* factory, 62 void ThrottlingURLLoader::Start(mojom::URLLoaderFactory* factory,
(...skipping 17 matching lines...) Expand all
76 routing_id_ = routing_id; 80 routing_id_ = routing_id;
77 request_id_ = request_id; 81 request_id_ = request_id;
78 options_ = options; 82 options_ = options;
79 url_request_ = std::move(url_request); 83 url_request_ = std::move(url_request);
80 return; 84 return;
81 } 85 }
82 } 86 }
83 87
84 factory->CreateLoaderAndStart(mojo::MakeRequest(&url_loader_), routing_id, 88 factory->CreateLoaderAndStart(mojo::MakeRequest(&url_loader_), routing_id,
85 request_id, options, *url_request, 89 request_id, options, *url_request,
86 client_binding_.CreateInterfacePtrAndBind()); 90 client_binding_.CreateInterfacePtrAndBind(),
91 traffic_annotation_);
87 } 92 }
88 93
89 void ThrottlingURLLoader::OnReceiveResponse( 94 void ThrottlingURLLoader::OnReceiveResponse(
90 const ResourceResponseHead& response_head, 95 const ResourceResponseHead& response_head,
91 const base::Optional<net::SSLInfo>& ssl_info, 96 const base::Optional<net::SSLInfo>& ssl_info,
92 mojom::DownloadedTempFilePtr downloaded_file) { 97 mojom::DownloadedTempFilePtr downloaded_file) {
93 DCHECK_EQ(DEFERRED_NONE, deferred_stage_); 98 DCHECK_EQ(DEFERRED_NONE, deferred_stage_);
94 DCHECK(!cancelled_by_throttle_); 99 DCHECK(!cancelled_by_throttle_);
95 100
96 if (throttle_) { 101 if (throttle_) {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 } 212 }
208 213
209 void ThrottlingURLLoader::Resume() { 214 void ThrottlingURLLoader::Resume() {
210 if (cancelled_by_throttle_ || deferred_stage_ == DEFERRED_NONE) 215 if (cancelled_by_throttle_ || deferred_stage_ == DEFERRED_NONE)
211 return; 216 return;
212 217
213 switch (deferred_stage_) { 218 switch (deferred_stage_) {
214 case DEFERRED_START: { 219 case DEFERRED_START: {
215 url_loader_factory_->CreateLoaderAndStart( 220 url_loader_factory_->CreateLoaderAndStart(
216 mojo::MakeRequest(&url_loader_), routing_id_, request_id_, options_, 221 mojo::MakeRequest(&url_loader_), routing_id_, request_id_, options_,
217 *url_request_, client_binding_.CreateInterfacePtrAndBind()); 222 *url_request_, client_binding_.CreateInterfacePtrAndBind(),
223 traffic_annotation_);
218 224
219 if (set_priority_cached_) { 225 if (set_priority_cached_) {
220 set_priority_cached_ = false; 226 set_priority_cached_ = false;
221 url_loader_->SetPriority(priority_, intra_priority_value_); 227 url_loader_->SetPriority(priority_, intra_priority_value_);
222 } 228 }
223 break; 229 break;
224 } 230 }
225 case DEFERRED_REDIRECT: { 231 case DEFERRED_REDIRECT: {
226 client_binding_.ResumeIncomingMethodCallProcessing(); 232 client_binding_.ResumeIncomingMethodCallProcessing();
227 forwarding_client_->OnReceiveRedirect(redirect_info_, response_head_); 233 forwarding_client_->OnReceiveRedirect(redirect_info_, response_head_);
228 break; 234 break;
229 } 235 }
230 case DEFERRED_RESPONSE: { 236 case DEFERRED_RESPONSE: {
231 client_binding_.ResumeIncomingMethodCallProcessing(); 237 client_binding_.ResumeIncomingMethodCallProcessing();
232 forwarding_client_->OnReceiveResponse(response_head_, ssl_info_, 238 forwarding_client_->OnReceiveResponse(response_head_, ssl_info_,
233 std::move(downloaded_file_)); 239 std::move(downloaded_file_));
234 break; 240 break;
235 } 241 }
236 default: 242 default:
237 NOTREACHED(); 243 NOTREACHED();
238 break; 244 break;
239 } 245 }
240 deferred_stage_ = DEFERRED_NONE; 246 deferred_stage_ = DEFERRED_NONE;
241 } 247 }
242 248
243 } // namespace content 249 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698