| 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 22 matching lines...) Expand all Loading... |
| 33 #include "net/base/upload_progress.h" | 33 #include "net/base/upload_progress.h" |
| 34 #include "net/url_request/redirect_info.h" | 34 #include "net/url_request/redirect_info.h" |
| 35 | 35 |
| 36 using base::TimeDelta; | 36 using base::TimeDelta; |
| 37 using base::TimeTicks; | 37 using base::TimeTicks; |
| 38 | 38 |
| 39 namespace content { | 39 namespace content { |
| 40 namespace { | 40 namespace { |
| 41 | 41 |
| 42 static int kBufferSize = 1024 * 512; | 42 static int kBufferSize = 1024 * 512; |
| 43 static int kMinAllocationSize = 1024 * 4; | 43 static int kBufferMinAllocationSize = 1024 * 4; |
| 44 static int kMaxAllocationSize = 1024 * 32; | 44 static int kMaxAllocationSize = 1024 * 32; |
| 45 | 45 |
| 46 void GetNumericArg(const std::string& name, int* result) { | 46 void GetNumericCommandLineArg(const std::string& name, int* result) { |
| 47 const std::string& value = | 47 const std::string& value = |
| 48 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(name); | 48 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(name); |
| 49 if (!value.empty()) | 49 if (!value.empty()) |
| 50 base::StringToInt(value, result); | 50 base::StringToInt(value, result); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void InitializeResourceBufferConstants() { | 53 void InitializeResourceBufferConstantsFoo() { |
| 54 static bool did_init = false; | 54 static bool did_init = false; |
| 55 if (did_init) | 55 if (did_init) |
| 56 return; | 56 return; |
| 57 did_init = true; | 57 did_init = true; |
| 58 | 58 |
| 59 GetNumericArg("resource-buffer-size", &kBufferSize); | 59 GetNumericCommandLineArg("resource-buffer-size", &kBufferSize); |
| 60 GetNumericArg("resource-buffer-min-allocation-size", &kMinAllocationSize); | 60 GetNumericCommandLineArg("resource-buffer-min-allocation-size", &kBufferMinAll
ocationSize); |
| 61 GetNumericArg("resource-buffer-max-allocation-size", &kMaxAllocationSize); | 61 GetNumericCommandLineArg("resource-buffer-max-allocation-size", &kMaxAllocatio
nSize); |
| 62 } | 62 } |
| 63 | 63 |
| 64 // This enum is used for logging a histogram and should not be reordered. | 64 // This enum is used for logging a histogram and should not be reordered. |
| 65 enum ExpectedContentSizeResult { | 65 enum ExpectedContentSizeResult { |
| 66 EQ_RESPONSE_BODY = 0, | 66 EQ_RESPONSE_BODY = 0, |
| 67 EQ_RESPONSE_BODY_GT_EQ_BUFFER_SIZE = 1, | 67 EQ_RESPONSE_BODY_GT_EQ_BUFFER_SIZE = 1, |
| 68 GT_EQ_BUFFER_SIZE = 2, | 68 GT_EQ_BUFFER_SIZE = 2, |
| 69 LT_RESPONSE_BODY = 3, | 69 LT_RESPONSE_BODY = 3, |
| 70 GT_RESPONSE_BODY = 4, | 70 GT_RESPONSE_BODY = 4, |
| 71 UNKNOWN = 5, | 71 UNKNOWN = 5, |
| 72 EXPECTED_CONTENT_MAX, | 72 EXPECTED_CONTENT_MAX, |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 } // namespace | 75 } // namespace |
| 76 | 76 |
| 77 class DependentIOBuffer : public net::WrappedIOBuffer { | 77 class DependentIOBufferFoo : public net::WrappedIOBuffer { |
| 78 public: | 78 public: |
| 79 DependentIOBuffer(ResourceBuffer* backing, char* memory) | 79 DependentIOBufferFoo(ResourceBuffer* backing, char* memory) |
| 80 : net::WrappedIOBuffer(memory), | 80 : net::WrappedIOBuffer(memory), |
| 81 backing_(backing) { | 81 backing_(backing) { |
| 82 } | 82 } |
| 83 private: | 83 private: |
| 84 ~DependentIOBuffer() override {} | 84 ~DependentIOBufferFoo() override {} |
| 85 scoped_refptr<ResourceBuffer> backing_; | 85 scoped_refptr<ResourceBuffer> backing_; |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 AsyncResourceHandler::AsyncResourceHandler(net::URLRequest* request, | 88 AsyncResourceHandler::AsyncResourceHandler(net::URLRequest* request, |
| 89 ResourceDispatcherHostImpl* rdh) | 89 ResourceDispatcherHostImpl* rdh) |
| 90 : ResourceHandler(request), | 90 : ResourceHandler(request), |
| 91 ResourceMessageDelegate(request), | 91 ResourceMessageDelegate(request), |
| 92 rdh_(rdh), | 92 rdh_(rdh), |
| 93 pending_data_count_(0), | 93 pending_data_count_(0), |
| 94 allocation_size_(0), | 94 allocation_size_(0), |
| 95 total_read_body_bytes_(0), | 95 total_read_body_bytes_(0), |
| 96 has_checked_for_sufficient_resources_(false), | 96 has_checked_for_sufficient_resources_(false), |
| 97 sent_received_response_msg_(false), | 97 sent_received_response_msg_(false), |
| 98 sent_data_buffer_msg_(false), | 98 sent_data_buffer_msg_(false), |
| 99 reported_transfer_size_(0) { | 99 reported_transfer_size_(0) { |
| 100 DCHECK(GetRequestInfo()->requester_info()->IsRenderer()); | 100 DCHECK(GetRequestInfo()->requester_info()->IsRenderer()); |
| 101 InitializeResourceBufferConstants(); | 101 InitializeResourceBufferConstantsFoo(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 AsyncResourceHandler::~AsyncResourceHandler() { | 104 AsyncResourceHandler::~AsyncResourceHandler() { |
| 105 if (has_checked_for_sufficient_resources_) | 105 if (has_checked_for_sufficient_resources_) |
| 106 rdh_->FinishedWithResourcesForRequest(request()); | 106 rdh_->FinishedWithResourcesForRequest(request()); |
| 107 } | 107 } |
| 108 | 108 |
| 109 bool AsyncResourceHandler::OnMessageReceived(const IPC::Message& message) { | 109 bool AsyncResourceHandler::OnMessageReceived(const IPC::Message& message) { |
| 110 bool handled = true; | 110 bool handled = true; |
| 111 IPC_BEGIN_MESSAGE_MAP(AsyncResourceHandler, message) | 111 IPC_BEGIN_MESSAGE_MAP(AsyncResourceHandler, message) |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 | 253 |
| 254 if (!EnsureResourceBufferIsInitialized()) { | 254 if (!EnsureResourceBufferIsInitialized()) { |
| 255 controller->CancelWithError(net::ERR_INSUFFICIENT_RESOURCES); | 255 controller->CancelWithError(net::ERR_INSUFFICIENT_RESOURCES); |
| 256 return; | 256 return; |
| 257 } | 257 } |
| 258 | 258 |
| 259 DCHECK(buffer_->CanAllocate()); | 259 DCHECK(buffer_->CanAllocate()); |
| 260 char* memory = buffer_->Allocate(&allocation_size_); | 260 char* memory = buffer_->Allocate(&allocation_size_); |
| 261 CHECK(memory); | 261 CHECK(memory); |
| 262 | 262 |
| 263 *buf = new DependentIOBuffer(buffer_.get(), memory); | 263 *buf = new DependentIOBufferFoo(buffer_.get(), memory); |
| 264 *buf_size = allocation_size_; | 264 *buf_size = allocation_size_; |
| 265 | 265 |
| 266 controller->Resume(); | 266 controller->Resume(); |
| 267 } | 267 } |
| 268 | 268 |
| 269 void AsyncResourceHandler::OnReadCompleted( | 269 void AsyncResourceHandler::OnReadCompleted( |
| 270 int bytes_read, | 270 int bytes_read, |
| 271 std::unique_ptr<ResourceController> controller) { | 271 std::unique_ptr<ResourceController> controller) { |
| 272 DCHECK(!has_controller()); | 272 DCHECK(!has_controller()); |
| 273 DCHECK_GE(bytes_read, 0); | 273 DCHECK_GE(bytes_read, 0); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 } | 381 } |
| 382 | 382 |
| 383 bool AsyncResourceHandler::EnsureResourceBufferIsInitialized() { | 383 bool AsyncResourceHandler::EnsureResourceBufferIsInitialized() { |
| 384 DCHECK(has_checked_for_sufficient_resources_); | 384 DCHECK(has_checked_for_sufficient_resources_); |
| 385 | 385 |
| 386 if (buffer_.get() && buffer_->IsInitialized()) | 386 if (buffer_.get() && buffer_->IsInitialized()) |
| 387 return true; | 387 return true; |
| 388 | 388 |
| 389 buffer_ = new ResourceBuffer(); | 389 buffer_ = new ResourceBuffer(); |
| 390 return buffer_->Initialize(kBufferSize, | 390 return buffer_->Initialize(kBufferSize, |
| 391 kMinAllocationSize, | 391 kBufferMinAllocationSize, |
| 392 kMaxAllocationSize); | 392 kMaxAllocationSize); |
| 393 } | 393 } |
| 394 | 394 |
| 395 void AsyncResourceHandler::ResumeIfDeferred() { | 395 void AsyncResourceHandler::ResumeIfDeferred() { |
| 396 if (has_controller()) { | 396 if (has_controller()) { |
| 397 request()->LogUnblocked(); | 397 request()->LogUnblocked(); |
| 398 Resume(); | 398 Resume(); |
| 399 } | 399 } |
| 400 } | 400 } |
| 401 | 401 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 void AsyncResourceHandler::SendUploadProgress( | 478 void AsyncResourceHandler::SendUploadProgress( |
| 479 const net::UploadProgress& progress) { | 479 const net::UploadProgress& progress) { |
| 480 ResourceMessageFilter* filter = GetFilter(); | 480 ResourceMessageFilter* filter = GetFilter(); |
| 481 if (!filter) | 481 if (!filter) |
| 482 return; | 482 return; |
| 483 filter->Send(new ResourceMsg_UploadProgress( | 483 filter->Send(new ResourceMsg_UploadProgress( |
| 484 GetRequestID(), progress.position(), progress.size())); | 484 GetRequestID(), progress.position(), progress.size())); |
| 485 } | 485 } |
| 486 | 486 |
| 487 } // namespace content | 487 } // namespace content |
| OLD | NEW |