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