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

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

Issue 2467833002: Implement redirect handling on MojoAsyncResourceHandler (Closed)
Patch Set: rebase 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 OnResponseStarted, OnRequestRedirected will NOT be preceded by
131 return false; 131 // OnWillRead.
132 DCHECK(!shared_writer_);
133
134 *defer = true;
135 request()->LogBlockedBy("MojoAsyncResourceHandler");
136 did_defer_on_redirect_ = true;
137
138 NetLogObserver::PopulateResponseInfo(request(), response);
139 response->head.encoded_data_length = request()->GetTotalReceivedBytes();
140 response->head.request_start = request()->creation_time();
141 response->head.response_start = base::TimeTicks::Now();
142 // TODO(davidben): Is it necessary to pass the new first party URL for
143 // cookies? The only case where it can change is top-level navigation requests
144 // and hopefully those will eventually all be owned by the browser. It's
145 // possible this is still needed while renderer-owned ones exist.
146 url_loader_client_->OnReceiveRedirect(redirect_info, response->head);
147 return true;
132 } 148 }
133 149
134 bool MojoAsyncResourceHandler::OnResponseStarted(ResourceResponse* response, 150 bool MojoAsyncResourceHandler::OnResponseStarted(ResourceResponse* response,
135 bool* defer) { 151 bool* defer) {
136 const ResourceRequestInfoImpl* info = GetRequestInfo(); 152 const ResourceRequestInfoImpl* info = GetRequestInfo();
137 153
138 if (rdh_->delegate()) { 154 if (rdh_->delegate()) {
139 rdh_->delegate()->OnResponseStarted(request(), info->GetContext(), 155 rdh_->delegate()->OnResponseStarted(request(), info->GetContext(),
140 response); 156 response);
141 } 157 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 227
212 if (!bytes_read) 228 if (!bytes_read)
213 return true; 229 return true;
214 230
215 if (is_using_io_buffer_not_from_writer_) { 231 if (is_using_io_buffer_not_from_writer_) {
216 // Couldn't allocate a buffer on the data pipe in OnWillRead. 232 // Couldn't allocate a buffer on the data pipe in OnWillRead.
217 DCHECK_EQ(0u, buffer_bytes_read_); 233 DCHECK_EQ(0u, buffer_bytes_read_);
218 buffer_bytes_read_ = bytes_read; 234 buffer_bytes_read_ = bytes_read;
219 if (!CopyReadDataToDataPipe(defer)) 235 if (!CopyReadDataToDataPipe(defer))
220 return false; 236 return false;
221 if (*defer) 237 if (*defer) {
222 OnDefer(); 238 request()->LogBlockedBy("MojoAsyncResourceHandler");
239 did_defer_on_writing_ = true;
240 }
223 return true; 241 return true;
224 } 242 }
225 243
226 if (EndWrite(bytes_read) != MOJO_RESULT_OK) 244 if (EndWrite(bytes_read) != MOJO_RESULT_OK)
227 return false; 245 return false;
228 // Allocate a buffer for the next OnWillRead call here, because OnWillRead 246 // Allocate a buffer for the next OnWillRead call here, because OnWillRead
229 // doesn't have |defer| parameter. 247 // doesn't have |defer| parameter.
230 if (!AllocateWriterIOBuffer(&buffer_, defer)) 248 if (!AllocateWriterIOBuffer(&buffer_, defer))
231 return false; 249 return false;
232 if (*defer) 250 if (*defer) {
233 OnDefer(); 251 request()->LogBlockedBy("MojoAsyncResourceHandler");
252 did_defer_on_writing_ = true;
253 }
234 return true; 254 return true;
235 } 255 }
236 256
237 void MojoAsyncResourceHandler::OnDataDownloaded(int bytes_downloaded) { 257 void MojoAsyncResourceHandler::OnDataDownloaded(int bytes_downloaded) {
238 int64_t total_received_bytes = request()->GetTotalReceivedBytes(); 258 int64_t total_received_bytes = request()->GetTotalReceivedBytes();
239 int64_t bytes_to_report = 259 int64_t bytes_to_report =
240 total_received_bytes - reported_total_received_bytes_; 260 total_received_bytes - reported_total_received_bytes_;
241 reported_total_received_bytes_ = total_received_bytes; 261 reported_total_received_bytes_ = total_received_bytes;
242 DCHECK_LE(0, bytes_to_report); 262 DCHECK_LE(0, bytes_to_report);
243 263
244 url_loader_client_->OnDataDownloaded(bytes_downloaded, bytes_to_report); 264 url_loader_client_->OnDataDownloaded(bytes_downloaded, bytes_to_report);
245 } 265 }
246 266
247 void MojoAsyncResourceHandler::FollowRedirect() { 267 void MojoAsyncResourceHandler::FollowRedirect() {
248 NOTIMPLEMENTED(); 268 if (!request()->status().is_success()) {
269 DVLOG(1) << "FollowRedirect for invalid request";
270 return;
271 }
272 if (!did_defer_on_redirect_) {
273 DVLOG(1) << "Malformed FollowRedirect request";
274 controller()->Cancel();
mmenke 2016/11/11 15:47:17 Seems like we should have a test for this. Should
yhirano 2016/11/14 08:56:05 Done.
275 return;
276 }
277
278 DCHECK(!did_defer_on_writing_);
279 did_defer_on_redirect_ = false;
280 request()->LogUnblocked();
281 controller()->Resume();
249 } 282 }
250 283
251 void MojoAsyncResourceHandler::ResumeForTesting() { 284 void MojoAsyncResourceHandler::OnWritableForTesting() {
252 Resume(); 285 OnWritable(MOJO_RESULT_OK);
253 } 286 }
254 287
255 void MojoAsyncResourceHandler::SetAllocationSizeForTesting(size_t size) { 288 void MojoAsyncResourceHandler::SetAllocationSizeForTesting(size_t size) {
256 g_allocation_size = size; 289 g_allocation_size = size;
257 } 290 }
258 291
259 MojoResult MojoAsyncResourceHandler::BeginWrite(void** data, 292 MojoResult MojoAsyncResourceHandler::BeginWrite(void** data,
260 uint32_t* available) { 293 uint32_t* available) {
261 MojoResult result = mojo::BeginWriteDataRaw( 294 MojoResult result = mojo::BeginWriteDataRaw(
262 shared_writer_->writer(), data, available, MOJO_WRITE_DATA_FLAG_NONE); 295 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) { 377 if (result == MOJO_RESULT_SHOULD_WAIT) {
345 *defer = true; 378 *defer = true;
346 return true; 379 return true;
347 } 380 }
348 if (result != MOJO_RESULT_OK) 381 if (result != MOJO_RESULT_OK)
349 return false; 382 return false;
350 *buf = new WriterIOBuffer(shared_writer_, data, available); 383 *buf = new WriterIOBuffer(shared_writer_, data, available);
351 return true; 384 return true;
352 } 385 }
353 386
354 void MojoAsyncResourceHandler::Resume() { 387 bool MojoAsyncResourceHandler::CheckForSufficientResource() {
355 if (!did_defer_) 388 if (has_checked_for_sufficient_resources_)
389 return true;
390 has_checked_for_sufficient_resources_ = true;
391
392 if (rdh_->HasSufficientResourcesForRequest(request()))
393 return true;
394
395 controller()->CancelWithError(net::ERR_INSUFFICIENT_RESOURCES);
396 return false;
397 }
398
399 void MojoAsyncResourceHandler::OnWritable(MojoResult result) {
400 if (!did_defer_on_writing_)
356 return; 401 return;
357 did_defer_ = false; 402 DCHECK(!did_defer_on_redirect_);
403 did_defer_on_writing_ = false;
358 404
359 if (is_using_io_buffer_not_from_writer_) { 405 if (is_using_io_buffer_not_from_writer_) {
360 // |buffer_| is set to a net::IOBufferWithSize. Write the buffer contents 406 // |buffer_| is set to a net::IOBufferWithSize. Write the buffer contents
361 // to the data pipe. 407 // to the data pipe.
362 DCHECK_GT(buffer_bytes_read_, 0u); 408 DCHECK_GT(buffer_bytes_read_, 0u);
363 if (!CopyReadDataToDataPipe(&did_defer_)) { 409 if (!CopyReadDataToDataPipe(&did_defer_on_writing_)) {
364 controller()->CancelWithError(net::ERR_FAILED); 410 controller()->CancelWithError(net::ERR_FAILED);
365 return; 411 return;
366 } 412 }
367 } else { 413 } else {
368 // Allocate a buffer for the next OnWillRead call here. 414 // Allocate a buffer for the next OnWillRead call here.
369 if (!AllocateWriterIOBuffer(&buffer_, &did_defer_)) { 415 if (!AllocateWriterIOBuffer(&buffer_, &did_defer_on_writing_)) {
370 controller()->CancelWithError(net::ERR_FAILED); 416 controller()->CancelWithError(net::ERR_FAILED);
371 return; 417 return;
372 } 418 }
373 } 419 }
374 420
375 if (did_defer_) { 421 if (did_defer_on_writing_) {
376 // Continue waiting. 422 // Continue waiting.
377 return; 423 return;
378 } 424 }
379 request()->LogUnblocked(); 425 request()->LogUnblocked();
380 controller()->Resume(); 426 controller()->Resume();
381 } 427 }
382 428
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() { 429 void MojoAsyncResourceHandler::Cancel() {
405 const ResourceRequestInfoImpl* info = GetRequestInfo(); 430 const ResourceRequestInfoImpl* info = GetRequestInfo();
406 ResourceDispatcherHostImpl::Get()->CancelRequestFromRenderer( 431 ResourceDispatcherHostImpl::Get()->CancelRequestFromRenderer(
407 GlobalRequestID(info->GetChildID(), info->GetRequestID())); 432 GlobalRequestID(info->GetChildID(), info->GetRequestID()));
408 } 433 }
409 434
410 } // namespace content 435 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/mojo_async_resource_handler.h ('k') | content/browser/loader/mojo_async_resource_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698