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

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

Issue 2982363002: Add support for fallback content for the frame. This includes main and subframes. (Closed)
Patch Set: Renamed the ThrottlingURLLoader's cancelled_by_throttle_ member to loader_cancelled_ and set it in … Created 3 years, 5 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 86
87 ThrottlingURLLoader::~ThrottlingURLLoader() {} 87 ThrottlingURLLoader::~ThrottlingURLLoader() {}
88 88
89 void ThrottlingURLLoader::FollowRedirect() { 89 void ThrottlingURLLoader::FollowRedirect() {
90 if (url_loader_) 90 if (url_loader_)
91 url_loader_->FollowRedirect(); 91 url_loader_->FollowRedirect();
92 } 92 }
93 93
94 void ThrottlingURLLoader::SetPriority(net::RequestPriority priority, 94 void ThrottlingURLLoader::SetPriority(net::RequestPriority priority,
95 int32_t intra_priority_value) { 95 int32_t intra_priority_value) {
96 if (!url_loader_ && !cancelled_by_throttle_) { 96 if (!url_loader_ && !loader_cancelled_) {
97 DCHECK_EQ(DEFERRED_START, deferred_stage_); 97 DCHECK_EQ(DEFERRED_START, deferred_stage_);
98 priority_info_ = 98 priority_info_ =
99 base::MakeUnique<PriorityInfo>(priority, intra_priority_value); 99 base::MakeUnique<PriorityInfo>(priority, intra_priority_value);
100 return; 100 return;
101 } 101 }
102 102
103 url_loader_->SetPriority(priority, intra_priority_value); 103 url_loader_->SetPriority(priority, intra_priority_value);
104 } 104 }
105 105
106 void ThrottlingURLLoader::DisconnectClient() {
107 client_binding_.Close();
108 url_loader_ = nullptr;
109 loader_cancelled_ = true;
110 }
111
106 ThrottlingURLLoader::ThrottlingURLLoader( 112 ThrottlingURLLoader::ThrottlingURLLoader(
107 std::vector<std::unique_ptr<URLLoaderThrottle>> throttles, 113 std::vector<std::unique_ptr<URLLoaderThrottle>> throttles,
108 mojom::URLLoaderClient* client, 114 mojom::URLLoaderClient* client,
109 const net::NetworkTrafficAnnotationTag& traffic_annotation) 115 const net::NetworkTrafficAnnotationTag& traffic_annotation)
110 : forwarding_client_(client), 116 : forwarding_client_(client),
111 client_binding_(this), 117 client_binding_(this),
112 traffic_annotation_(traffic_annotation) { 118 traffic_annotation_(traffic_annotation) {
113 if (throttles.size() > 0) { 119 if (throttles.size() > 0) {
114 // TODO(yzshen): Implement a URLLoaderThrottle subclass which handles a list 120 // TODO(yzshen): Implement a URLLoaderThrottle subclass which handles a list
115 // of URLLoaderThrottles. 121 // of URLLoaderThrottles.
116 CHECK_EQ(1u, throttles.size()); 122 CHECK_EQ(1u, throttles.size());
117 throttle_ = std::move(throttles[0]); 123 throttle_ = std::move(throttles[0]);
118 throttle_->set_delegate(this); 124 throttle_->set_delegate(this);
119 } 125 }
120 } 126 }
121 127
122 void ThrottlingURLLoader::Start( 128 void ThrottlingURLLoader::Start(
123 mojom::URLLoaderFactory* factory, 129 mojom::URLLoaderFactory* factory,
124 int32_t routing_id, 130 int32_t routing_id,
125 int32_t request_id, 131 int32_t request_id,
126 uint32_t options, 132 uint32_t options,
127 StartLoaderCallback start_loader_callback, 133 StartLoaderCallback start_loader_callback,
128 const ResourceRequest& url_request, 134 const ResourceRequest& url_request,
129 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { 135 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
130 DCHECK_EQ(DEFERRED_NONE, deferred_stage_); 136 DCHECK_EQ(DEFERRED_NONE, deferred_stage_);
131 DCHECK(!cancelled_by_throttle_); 137 DCHECK(!loader_cancelled_);
132 138
133 if (throttle_) { 139 if (throttle_) {
134 bool deferred = false; 140 bool deferred = false;
135 throttle_->WillStartRequest(url_request.url, url_request.load_flags, 141 throttle_->WillStartRequest(url_request.url, url_request.load_flags,
136 url_request.resource_type, &deferred); 142 url_request.resource_type, &deferred);
137 if (cancelled_by_throttle_) 143 if (loader_cancelled_)
138 return; 144 return;
139 145
140 if (deferred) { 146 if (deferred) {
141 deferred_stage_ = DEFERRED_START; 147 deferred_stage_ = DEFERRED_START;
142 start_info_ = 148 start_info_ =
143 base::MakeUnique<StartInfo>(factory, routing_id, request_id, options, 149 base::MakeUnique<StartInfo>(factory, routing_id, request_id, options,
144 std::move(start_loader_callback), 150 std::move(start_loader_callback),
145 url_request, std::move(task_runner)); 151 url_request, std::move(task_runner));
146 return; 152 return;
147 } 153 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 std::move(start_loader_callback) 186 std::move(start_loader_callback)
181 .Run(std::move(url_loader_request), std::move(client)); 187 .Run(std::move(url_loader_request), std::move(client));
182 } 188 }
183 } 189 }
184 190
185 void ThrottlingURLLoader::OnReceiveResponse( 191 void ThrottlingURLLoader::OnReceiveResponse(
186 const ResourceResponseHead& response_head, 192 const ResourceResponseHead& response_head,
187 const base::Optional<net::SSLInfo>& ssl_info, 193 const base::Optional<net::SSLInfo>& ssl_info,
188 mojom::DownloadedTempFilePtr downloaded_file) { 194 mojom::DownloadedTempFilePtr downloaded_file) {
189 DCHECK_EQ(DEFERRED_NONE, deferred_stage_); 195 DCHECK_EQ(DEFERRED_NONE, deferred_stage_);
190 DCHECK(!cancelled_by_throttle_); 196 DCHECK(!loader_cancelled_);
191 197
192 if (throttle_) { 198 if (throttle_) {
193 bool deferred = false; 199 bool deferred = false;
194 throttle_->WillProcessResponse(&deferred); 200 throttle_->WillProcessResponse(&deferred);
195 if (cancelled_by_throttle_) 201 if (loader_cancelled_)
196 return; 202 return;
197 203
198 if (deferred) { 204 if (deferred) {
199 deferred_stage_ = DEFERRED_RESPONSE; 205 deferred_stage_ = DEFERRED_RESPONSE;
200 response_info_ = base::MakeUnique<ResponseInfo>( 206 response_info_ = base::MakeUnique<ResponseInfo>(
201 response_head, ssl_info, std::move(downloaded_file)); 207 response_head, ssl_info, std::move(downloaded_file));
202 client_binding_.PauseIncomingMethodCallProcessing(); 208 client_binding_.PauseIncomingMethodCallProcessing();
203 return; 209 return;
204 } 210 }
205 } 211 }
206 212
207 forwarding_client_->OnReceiveResponse(response_head, ssl_info, 213 forwarding_client_->OnReceiveResponse(response_head, ssl_info,
208 std::move(downloaded_file)); 214 std::move(downloaded_file));
209 } 215 }
210 216
211 void ThrottlingURLLoader::OnReceiveRedirect( 217 void ThrottlingURLLoader::OnReceiveRedirect(
212 const net::RedirectInfo& redirect_info, 218 const net::RedirectInfo& redirect_info,
213 const ResourceResponseHead& response_head) { 219 const ResourceResponseHead& response_head) {
214 DCHECK_EQ(DEFERRED_NONE, deferred_stage_); 220 DCHECK_EQ(DEFERRED_NONE, deferred_stage_);
215 DCHECK(!cancelled_by_throttle_); 221 DCHECK(!loader_cancelled_);
216 222
217 if (throttle_) { 223 if (throttle_) {
218 bool deferred = false; 224 bool deferred = false;
219 throttle_->WillRedirectRequest(redirect_info, &deferred); 225 throttle_->WillRedirectRequest(redirect_info, &deferred);
220 if (cancelled_by_throttle_) 226 if (loader_cancelled_)
221 return; 227 return;
222 228
223 if (deferred) { 229 if (deferred) {
224 deferred_stage_ = DEFERRED_REDIRECT; 230 deferred_stage_ = DEFERRED_REDIRECT;
225 redirect_info_ = 231 redirect_info_ =
226 base::MakeUnique<RedirectInfo>(redirect_info, response_head); 232 base::MakeUnique<RedirectInfo>(redirect_info, response_head);
227 client_binding_.PauseIncomingMethodCallProcessing(); 233 client_binding_.PauseIncomingMethodCallProcessing();
228 return; 234 return;
229 } 235 }
230 } 236 }
231 237
232 forwarding_client_->OnReceiveRedirect(redirect_info, response_head); 238 forwarding_client_->OnReceiveRedirect(redirect_info, response_head);
233 } 239 }
234 240
235 void ThrottlingURLLoader::OnDataDownloaded(int64_t data_len, 241 void ThrottlingURLLoader::OnDataDownloaded(int64_t data_len,
236 int64_t encoded_data_len) { 242 int64_t encoded_data_len) {
237 DCHECK_EQ(DEFERRED_NONE, deferred_stage_); 243 DCHECK_EQ(DEFERRED_NONE, deferred_stage_);
238 DCHECK(!cancelled_by_throttle_); 244 DCHECK(!loader_cancelled_);
239 245
240 forwarding_client_->OnDataDownloaded(data_len, encoded_data_len); 246 forwarding_client_->OnDataDownloaded(data_len, encoded_data_len);
241 } 247 }
242 248
243 void ThrottlingURLLoader::OnUploadProgress( 249 void ThrottlingURLLoader::OnUploadProgress(
244 int64_t current_position, 250 int64_t current_position,
245 int64_t total_size, 251 int64_t total_size,
246 OnUploadProgressCallback ack_callback) { 252 OnUploadProgressCallback ack_callback) {
247 DCHECK_EQ(DEFERRED_NONE, deferred_stage_); 253 DCHECK_EQ(DEFERRED_NONE, deferred_stage_);
248 DCHECK(!cancelled_by_throttle_); 254 DCHECK(!loader_cancelled_);
249 255
250 forwarding_client_->OnUploadProgress(current_position, total_size, 256 forwarding_client_->OnUploadProgress(current_position, total_size,
251 std::move(ack_callback)); 257 std::move(ack_callback));
252 } 258 }
253 259
254 void ThrottlingURLLoader::OnReceiveCachedMetadata( 260 void ThrottlingURLLoader::OnReceiveCachedMetadata(
255 const std::vector<uint8_t>& data) { 261 const std::vector<uint8_t>& data) {
256 DCHECK_EQ(DEFERRED_NONE, deferred_stage_); 262 DCHECK_EQ(DEFERRED_NONE, deferred_stage_);
257 DCHECK(!cancelled_by_throttle_); 263 DCHECK(!loader_cancelled_);
258 264
259 forwarding_client_->OnReceiveCachedMetadata(data); 265 forwarding_client_->OnReceiveCachedMetadata(data);
260 } 266 }
261 267
262 void ThrottlingURLLoader::OnTransferSizeUpdated(int32_t transfer_size_diff) { 268 void ThrottlingURLLoader::OnTransferSizeUpdated(int32_t transfer_size_diff) {
263 DCHECK_EQ(DEFERRED_NONE, deferred_stage_); 269 DCHECK_EQ(DEFERRED_NONE, deferred_stage_);
264 DCHECK(!cancelled_by_throttle_); 270 DCHECK(!loader_cancelled_);
265 271
266 forwarding_client_->OnTransferSizeUpdated(transfer_size_diff); 272 forwarding_client_->OnTransferSizeUpdated(transfer_size_diff);
267 } 273 }
268 274
269 void ThrottlingURLLoader::OnStartLoadingResponseBody( 275 void ThrottlingURLLoader::OnStartLoadingResponseBody(
270 mojo::ScopedDataPipeConsumerHandle body) { 276 mojo::ScopedDataPipeConsumerHandle body) {
271 DCHECK_EQ(DEFERRED_NONE, deferred_stage_); 277 DCHECK_EQ(DEFERRED_NONE, deferred_stage_);
272 DCHECK(!cancelled_by_throttle_); 278 DCHECK(!loader_cancelled_);
273 279
274 forwarding_client_->OnStartLoadingResponseBody(std::move(body)); 280 forwarding_client_->OnStartLoadingResponseBody(std::move(body));
275 } 281 }
276 282
277 void ThrottlingURLLoader::OnComplete( 283 void ThrottlingURLLoader::OnComplete(
278 const ResourceRequestCompletionStatus& status) { 284 const ResourceRequestCompletionStatus& status) {
279 DCHECK_EQ(DEFERRED_NONE, deferred_stage_); 285 DCHECK_EQ(DEFERRED_NONE, deferred_stage_);
280 DCHECK(!cancelled_by_throttle_); 286 DCHECK(!loader_cancelled_);
281 287
282 forwarding_client_->OnComplete(status); 288 forwarding_client_->OnComplete(status);
283 } 289 }
284 290
285 void ThrottlingURLLoader::CancelWithError(int error_code) { 291 void ThrottlingURLLoader::CancelWithError(int error_code) {
286 // TODO(yzshen): Support a mode that cancellation also deletes the disk cache 292 // TODO(yzshen): Support a mode that cancellation also deletes the disk cache
287 // entry. 293 // entry.
288 if (cancelled_by_throttle_) 294 if (loader_cancelled_)
289 return; 295 return;
290 296
291 cancelled_by_throttle_ = true; 297 loader_cancelled_ = true;
yzshen1 2017/07/24 17:48:54 nit: You could remove this line because Disconnect
ananta 2017/07/24 18:53:18 Done.
292 298
293 ResourceRequestCompletionStatus request_complete_data; 299 ResourceRequestCompletionStatus request_complete_data;
294 request_complete_data.error_code = error_code; 300 request_complete_data.error_code = error_code;
295 request_complete_data.completion_time = base::TimeTicks::Now(); 301 request_complete_data.completion_time = base::TimeTicks::Now();
296 302
297 deferred_stage_ = DEFERRED_NONE; 303 deferred_stage_ = DEFERRED_NONE;
298 client_binding_.Close(); 304 DisconnectClient();
299 url_loader_ = nullptr;
300
301 forwarding_client_->OnComplete(request_complete_data); 305 forwarding_client_->OnComplete(request_complete_data);
302 } 306 }
303 307
304 void ThrottlingURLLoader::Resume() { 308 void ThrottlingURLLoader::Resume() {
305 if (cancelled_by_throttle_ || deferred_stage_ == DEFERRED_NONE) 309 if (loader_cancelled_ || deferred_stage_ == DEFERRED_NONE)
306 return; 310 return;
307 311
308 switch (deferred_stage_) { 312 switch (deferred_stage_) {
309 case DEFERRED_START: { 313 case DEFERRED_START: {
310 StartNow(start_info_->url_loader_factory, start_info_->routing_id, 314 StartNow(start_info_->url_loader_factory, start_info_->routing_id,
311 start_info_->request_id, start_info_->options, 315 start_info_->request_id, start_info_->options,
312 std::move(start_info_->start_loader_callback), 316 std::move(start_info_->start_loader_callback),
313 start_info_->url_request, std::move(start_info_->task_runner)); 317 start_info_->url_request, std::move(start_info_->task_runner));
314 318
315 if (priority_info_) { 319 if (priority_info_) {
(...skipping 17 matching lines...) Expand all
333 break; 337 break;
334 } 338 }
335 default: 339 default:
336 NOTREACHED(); 340 NOTREACHED();
337 break; 341 break;
338 } 342 }
339 deferred_stage_ = DEFERRED_NONE; 343 deferred_stage_ = DEFERRED_NONE;
340 } 344 }
341 345
342 } // namespace content 346 } // namespace content
OLDNEW
« content/browser/appcache/appcache_url_loader_job.h ('K') | « content/common/throttling_url_loader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698