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

Side by Side Diff: content/browser/loader/mojo_async_resource_handler.cc

Issue 2467833002: Implement redirect handling on MojoAsyncResourceHandler (Closed)
Patch Set: fix Created 4 years, 1 month 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/loader/mojo_async_resource_handler.h" 5 #include "content/browser/loader/mojo_async_resource_handler.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/containers/hash_tables.h" 10 #include "base/containers/hash_tables.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 120
121 MojoAsyncResourceHandler::~MojoAsyncResourceHandler() { 121 MojoAsyncResourceHandler::~MojoAsyncResourceHandler() {
122 if (has_checked_for_sufficient_resources_) 122 if (has_checked_for_sufficient_resources_)
123 rdh_->FinishedWithResourcesForRequest(request()); 123 rdh_->FinishedWithResourcesForRequest(request());
124 } 124 }
125 125
126 bool MojoAsyncResourceHandler::OnRequestRedirected( 126 bool MojoAsyncResourceHandler::OnRequestRedirected(
127 const net::RedirectInfo& redirect_info, 127 const net::RedirectInfo& redirect_info,
128 ResourceResponse* response, 128 ResourceResponse* response,
129 bool* defer) { 129 bool* defer) {
130 // Not implemented. 130 // Unlike OnResponseReceived, OnRequestRedirected will NOT be preceded by
131 return false; 131 // OnWillRead.
132 DCHECK(!shared_writer_);
133
134 *defer = true;
135 OnDefer();
136
137 NetLogObserver::PopulateResponseInfo(request(), response);
138 response->head.encoded_data_length = request()->GetTotalReceivedBytes();
139 response->head.request_start = request()->creation_time();
140 response->head.response_start = base::TimeTicks::Now();
141 // TODO(davidben): Is it necessary to pass the new first party URL for
142 // cookies? The only case where it can change is top-level navigation requests
143 // and hopefully those will eventually all be owned by the browser. It's
144 // possible this is still needed while renderer-owned ones exist.
145 url_loader_client_->OnReceiveRedirect(redirect_info, response->head);
146 return true;
132 } 147 }
133 148
134 bool MojoAsyncResourceHandler::OnResponseStarted(ResourceResponse* response, 149 bool MojoAsyncResourceHandler::OnResponseStarted(ResourceResponse* response,
135 bool* defer) { 150 bool* defer) {
136 const ResourceRequestInfoImpl* info = GetRequestInfo(); 151 const ResourceRequestInfoImpl* info = GetRequestInfo();
137 152
138 if (rdh_->delegate()) { 153 if (rdh_->delegate()) {
139 rdh_->delegate()->OnResponseStarted(request(), info->GetContext(), 154 rdh_->delegate()->OnResponseStarted(request(), info->GetContext(),
140 response); 155 response);
141 } 156 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 int64_t total_received_bytes = request()->GetTotalReceivedBytes(); 253 int64_t total_received_bytes = request()->GetTotalReceivedBytes();
239 int64_t bytes_to_report = 254 int64_t bytes_to_report =
240 total_received_bytes - reported_total_received_bytes_; 255 total_received_bytes - reported_total_received_bytes_;
241 reported_total_received_bytes_ = total_received_bytes; 256 reported_total_received_bytes_ = total_received_bytes;
242 DCHECK_LE(0, bytes_to_report); 257 DCHECK_LE(0, bytes_to_report);
243 258
244 url_loader_client_->OnDataDownloaded(bytes_downloaded, bytes_to_report); 259 url_loader_client_->OnDataDownloaded(bytes_downloaded, bytes_to_report);
245 } 260 }
246 261
247 void MojoAsyncResourceHandler::FollowRedirect() { 262 void MojoAsyncResourceHandler::FollowRedirect() {
248 NOTIMPLEMENTED(); 263 if (!request()->status().is_success()) {
264 DVLOG(1) << "OnFollowRedirect for invalid request";
265 return;
266 }
267
268 DCHECK(did_defer_);
dcheng 2016/11/10 07:09:27 Is it safe to allow this to be called multiple tim
mmenke 2016/11/10 21:42:40 Good question...It looks like it's actually safe (
yhirano 2016/11/11 09:47:03 Done. It's now cancelling the request, I don't kno
269 did_defer_ = false;
270 request()->LogUnblocked();
271 controller()->Resume();
249 } 272 }
250 273
251 void MojoAsyncResourceHandler::ResumeForTesting() { 274 void MojoAsyncResourceHandler::OnWritableForTesting() {
252 Resume(); 275 OnWritable(MOJO_RESULT_OK);
253 } 276 }
254 277
255 void MojoAsyncResourceHandler::SetAllocationSizeForTesting(size_t size) { 278 void MojoAsyncResourceHandler::SetAllocationSizeForTesting(size_t size) {
256 g_allocation_size = size; 279 g_allocation_size = size;
257 } 280 }
258 281
259 MojoResult MojoAsyncResourceHandler::BeginWrite(void** data, 282 MojoResult MojoAsyncResourceHandler::BeginWrite(void** data,
260 uint32_t* available) { 283 uint32_t* available) {
261 MojoResult result = mojo::BeginWriteDataRaw( 284 MojoResult result = mojo::BeginWriteDataRaw(
262 shared_writer_->writer(), data, available, MOJO_WRITE_DATA_FLAG_NONE); 285 shared_writer_->writer(), data, available, MOJO_WRITE_DATA_FLAG_NONE);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 if (result == MOJO_RESULT_SHOULD_WAIT) { 367 if (result == MOJO_RESULT_SHOULD_WAIT) {
345 *defer = true; 368 *defer = true;
346 return true; 369 return true;
347 } 370 }
348 if (result != MOJO_RESULT_OK) 371 if (result != MOJO_RESULT_OK)
349 return false; 372 return false;
350 *buf = new WriterIOBuffer(shared_writer_, data, available); 373 *buf = new WriterIOBuffer(shared_writer_, data, available);
351 return true; 374 return true;
352 } 375 }
353 376
354 void MojoAsyncResourceHandler::Resume() { 377 void MojoAsyncResourceHandler::OnDefer() {
378 request()->LogBlockedBy("MojoAsyncResourceHandler");
379 did_defer_ = true;
380 }
381
382 bool MojoAsyncResourceHandler::CheckForSufficientResource() {
383 if (has_checked_for_sufficient_resources_)
384 return true;
385 has_checked_for_sufficient_resources_ = true;
386
387 if (rdh_->HasSufficientResourcesForRequest(request()))
388 return true;
389
390 controller()->CancelWithError(net::ERR_INSUFFICIENT_RESOURCES);
391 return false;
392 }
393
394 void MojoAsyncResourceHandler::OnWritable(MojoResult unused) {
mmenke 2016/11/10 21:42:40 nit: I think the style is to not name unused vari
yhirano 2016/11/11 09:47:03 Done.
355 if (!did_defer_) 395 if (!did_defer_)
356 return; 396 return;
357 did_defer_ = false; 397 did_defer_ = false;
358 398
359 if (is_using_io_buffer_not_from_writer_) { 399 if (is_using_io_buffer_not_from_writer_) {
360 // |buffer_| is set to a net::IOBufferWithSize. Write the buffer contents 400 // |buffer_| is set to a net::IOBufferWithSize. Write the buffer contents
361 // to the data pipe. 401 // to the data pipe.
362 DCHECK_GT(buffer_bytes_read_, 0u); 402 DCHECK_GT(buffer_bytes_read_, 0u);
363 if (!CopyReadDataToDataPipe(&did_defer_)) { 403 if (!CopyReadDataToDataPipe(&did_defer_)) {
364 controller()->CancelWithError(net::ERR_FAILED); 404 controller()->CancelWithError(net::ERR_FAILED);
365 return; 405 return;
366 } 406 }
367 } else { 407 } else {
368 // Allocate a buffer for the next OnWillRead call here. 408 // Allocate a buffer for the next OnWillRead call here.
369 if (!AllocateWriterIOBuffer(&buffer_, &did_defer_)) { 409 if (!AllocateWriterIOBuffer(&buffer_, &did_defer_)) {
370 controller()->CancelWithError(net::ERR_FAILED); 410 controller()->CancelWithError(net::ERR_FAILED);
371 return; 411 return;
372 } 412 }
373 } 413 }
374 414
375 if (did_defer_) { 415 if (did_defer_) {
376 // Continue waiting. 416 // Continue waiting.
377 return; 417 return;
378 } 418 }
379 request()->LogUnblocked(); 419 request()->LogUnblocked();
380 controller()->Resume(); 420 controller()->Resume();
381 } 421 }
382 422
383 void MojoAsyncResourceHandler::OnDefer() {
384 request()->LogBlockedBy("MojoAsyncResourceHandler");
385 did_defer_ = true;
386 }
387
388 bool MojoAsyncResourceHandler::CheckForSufficientResource() {
389 if (has_checked_for_sufficient_resources_)
390 return true;
391 has_checked_for_sufficient_resources_ = true;
392
393 if (rdh_->HasSufficientResourcesForRequest(request()))
394 return true;
395
396 controller()->CancelWithError(net::ERR_INSUFFICIENT_RESOURCES);
397 return false;
398 }
399
400 void MojoAsyncResourceHandler::OnWritable(MojoResult unused) {
401 Resume();
402 }
403
404 void MojoAsyncResourceHandler::Cancel() { 423 void MojoAsyncResourceHandler::Cancel() {
405 const ResourceRequestInfoImpl* info = GetRequestInfo(); 424 const ResourceRequestInfoImpl* info = GetRequestInfo();
406 ResourceDispatcherHostImpl::Get()->CancelRequestFromRenderer( 425 ResourceDispatcherHostImpl::Get()->CancelRequestFromRenderer(
407 GlobalRequestID(info->GetChildID(), info->GetRequestID())); 426 GlobalRequestID(info->GetChildID(), info->GetRequestID()));
408 } 427 }
409 428
410 } // namespace content 429 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698