OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/async_resource_handler.h" | 5 #include "content/browser/loader/async_resource_handler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 request()->has_upload()) { | 360 request()->has_upload()) { |
361 upload_progress_tracker_ = base::MakeUnique<UploadProgressTracker>( | 361 upload_progress_tracker_ = base::MakeUnique<UploadProgressTracker>( |
362 FROM_HERE, | 362 FROM_HERE, |
363 base::BindRepeating(&AsyncResourceHandler::SendUploadProgress, | 363 base::BindRepeating(&AsyncResourceHandler::SendUploadProgress, |
364 base::Unretained(this)), | 364 base::Unretained(this)), |
365 request()); | 365 request()); |
366 } | 366 } |
367 controller->Resume(); | 367 controller->Resume(); |
368 } | 368 } |
369 | 369 |
370 bool AsyncResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf, | 370 void AsyncResourceHandler::OnWillRead( |
371 int* buf_size) { | 371 scoped_refptr<net::IOBuffer>* buf, |
| 372 int* buf_size, |
| 373 std::unique_ptr<ResourceController> controller) { |
372 DCHECK(!has_controller()); | 374 DCHECK(!has_controller()); |
373 | 375 |
374 // TODO(mmenke): Should fail with ERR_INSUFFICIENT_RESOURCES here. | 376 if (!CheckForSufficientResource()) { |
375 if (!CheckForSufficientResource()) | 377 controller->CancelWithError(net::ERR_INSUFFICIENT_RESOURCES); |
376 return false; | 378 return; |
| 379 } |
377 | 380 |
378 // Return early if InliningHelper allocates the buffer, so that we should | 381 // Return early if InliningHelper allocates the buffer, so that we should |
379 // inline the data into the IPC message without allocating SharedMemory. | 382 // inline the data into the IPC message without allocating SharedMemory. |
380 if (inlining_helper_->PrepareInlineBufferIfApplicable(buf, buf_size)) | 383 if (inlining_helper_->PrepareInlineBufferIfApplicable(buf, buf_size)) { |
381 return true; | 384 controller->Resume(); |
| 385 return; |
| 386 } |
382 | 387 |
383 if (!EnsureResourceBufferIsInitialized()) | 388 if (!EnsureResourceBufferIsInitialized()) { |
384 return false; | 389 controller->CancelWithError(net::ERR_INSUFFICIENT_RESOURCES); |
| 390 return; |
| 391 } |
385 | 392 |
386 DCHECK(buffer_->CanAllocate()); | 393 DCHECK(buffer_->CanAllocate()); |
387 char* memory = buffer_->Allocate(&allocation_size_); | 394 char* memory = buffer_->Allocate(&allocation_size_); |
388 CHECK(memory); | 395 CHECK(memory); |
389 | 396 |
390 *buf = new DependentIOBuffer(buffer_.get(), memory); | 397 *buf = new DependentIOBuffer(buffer_.get(), memory); |
391 *buf_size = allocation_size_; | 398 *buf_size = allocation_size_; |
392 | 399 |
393 return true; | 400 controller->Resume(); |
394 } | 401 } |
395 | 402 |
396 void AsyncResourceHandler::OnReadCompleted( | 403 void AsyncResourceHandler::OnReadCompleted( |
397 int bytes_read, | 404 int bytes_read, |
398 std::unique_ptr<ResourceController> controller) { | 405 std::unique_ptr<ResourceController> controller) { |
399 DCHECK(!has_controller()); | 406 DCHECK(!has_controller()); |
400 DCHECK_GE(bytes_read, 0); | 407 DCHECK_GE(bytes_read, 0); |
401 | 408 |
402 if (!bytes_read) { | 409 if (!bytes_read) { |
403 controller->Resume(); | 410 controller->Resume(); |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 void AsyncResourceHandler::SendUploadProgress( | 627 void AsyncResourceHandler::SendUploadProgress( |
621 const net::UploadProgress& progress) { | 628 const net::UploadProgress& progress) { |
622 ResourceMessageFilter* filter = GetFilter(); | 629 ResourceMessageFilter* filter = GetFilter(); |
623 if (!filter) | 630 if (!filter) |
624 return; | 631 return; |
625 filter->Send(new ResourceMsg_UploadProgress( | 632 filter->Send(new ResourceMsg_UploadProgress( |
626 GetRequestID(), progress.position(), progress.size())); | 633 GetRequestID(), progress.position(), progress.size())); |
627 } | 634 } |
628 | 635 |
629 } // namespace content | 636 } // namespace content |
OLD | NEW |