| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/browser/renderer_host/async_resource_handler.h" | 5 #include "chrome/browser/renderer_host/async_resource_handler.h" |
| 6 | 6 |
| 7 #include "base/process.h" | 7 #include "base/process.h" |
| 8 #include "base/shared_memory.h" | 8 #include "base/shared_memory.h" |
| 9 #include "chrome/common/render_messages.h" | 9 #include "chrome/common/render_messages.h" |
| 10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 base::SharedMemory* shared_memory() { return &shared_memory_; } | 28 base::SharedMemory* shared_memory() { return &shared_memory_; } |
| 29 bool ok() { return ok_; } | 29 bool ok() { return ok_; } |
| 30 | 30 |
| 31 private: | 31 private: |
| 32 base::SharedMemory shared_memory_; | 32 base::SharedMemory shared_memory_; |
| 33 bool ok_; | 33 bool ok_; |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 AsyncResourceHandler::AsyncResourceHandler( | 36 AsyncResourceHandler::AsyncResourceHandler( |
| 37 ResourceDispatcherHost::Receiver* receiver, | 37 ResourceDispatcherHost::Receiver* receiver, |
| 38 int render_process_host_id, | 38 int process_id, |
| 39 int routing_id, | 39 int routing_id, |
| 40 base::ProcessHandle render_process, | 40 base::ProcessHandle process_handle, |
| 41 const GURL& url, | 41 const GURL& url, |
| 42 ResourceDispatcherHost* resource_dispatcher_host) | 42 ResourceDispatcherHost* resource_dispatcher_host) |
| 43 : receiver_(receiver), | 43 : receiver_(receiver), |
| 44 render_process_host_id_(render_process_host_id), | 44 process_id_(process_id), |
| 45 routing_id_(routing_id), | 45 routing_id_(routing_id), |
| 46 render_process_(render_process), | 46 process_handle_(process_handle), |
| 47 rdh_(resource_dispatcher_host) { | 47 rdh_(resource_dispatcher_host) { |
| 48 } | 48 } |
| 49 | 49 |
| 50 bool AsyncResourceHandler::OnUploadProgress(int request_id, | 50 bool AsyncResourceHandler::OnUploadProgress(int request_id, |
| 51 uint64 position, | 51 uint64 position, |
| 52 uint64 size) { | 52 uint64 size) { |
| 53 return receiver_->Send(new ViewMsg_Resource_UploadProgress(routing_id_, | 53 return receiver_->Send(new ViewMsg_Resource_UploadProgress(routing_id_, |
| 54 request_id, | 54 request_id, |
| 55 position, size)); | 55 position, size)); |
| 56 } | 56 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 84 *buf = read_buffer_.get(); | 84 *buf = read_buffer_.get(); |
| 85 *buf_size = kReadBufSize; | 85 *buf_size = kReadBufSize; |
| 86 return true; | 86 return true; |
| 87 } | 87 } |
| 88 | 88 |
| 89 bool AsyncResourceHandler::OnReadCompleted(int request_id, int* bytes_read) { | 89 bool AsyncResourceHandler::OnReadCompleted(int request_id, int* bytes_read) { |
| 90 if (!*bytes_read) | 90 if (!*bytes_read) |
| 91 return true; | 91 return true; |
| 92 DCHECK(read_buffer_.get()); | 92 DCHECK(read_buffer_.get()); |
| 93 | 93 |
| 94 if (!rdh_->WillSendData(render_process_host_id_, request_id)) { | 94 if (!rdh_->WillSendData(process_id_, request_id)) { |
| 95 // We should not send this data now, we have too many pending requests. | 95 // We should not send this data now, we have too many pending requests. |
| 96 return true; | 96 return true; |
| 97 } | 97 } |
| 98 | 98 |
| 99 base::SharedMemoryHandle handle; | 99 base::SharedMemoryHandle handle; |
| 100 if (!read_buffer_->shared_memory()->GiveToProcess(render_process_, &handle)) { | 100 if (!read_buffer_->shared_memory()->GiveToProcess(process_handle_, &handle)) { |
| 101 // We wrongfully incremented the pending data count. Fake an ACK message | 101 // We wrongfully incremented the pending data count. Fake an ACK message |
| 102 // to fix this. We can't move this call above the WillSendData because | 102 // to fix this. We can't move this call above the WillSendData because |
| 103 // it's killing our read_buffer_, and we don't want that when we pause | 103 // it's killing our read_buffer_, and we don't want that when we pause |
| 104 // the request. | 104 // the request. |
| 105 rdh_->OnDataReceivedACK(render_process_host_id_, request_id); | 105 rdh_->OnDataReceivedACK(process_id_, request_id); |
| 106 // We just unmapped the memory. | 106 // We just unmapped the memory. |
| 107 read_buffer_ = NULL; | 107 read_buffer_ = NULL; |
| 108 return false; | 108 return false; |
| 109 } | 109 } |
| 110 // We just unmapped the memory. | 110 // We just unmapped the memory. |
| 111 read_buffer_ = NULL; | 111 read_buffer_ = NULL; |
| 112 | 112 |
| 113 receiver_->Send(new ViewMsg_Resource_DataReceived( | 113 receiver_->Send(new ViewMsg_Resource_DataReceived( |
| 114 routing_id_, request_id, handle, *bytes_read)); | 114 routing_id_, request_id, handle, *bytes_read)); |
| 115 | 115 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 134 return true; | 134 return true; |
| 135 } | 135 } |
| 136 | 136 |
| 137 // static | 137 // static |
| 138 void AsyncResourceHandler::GlobalCleanup() { | 138 void AsyncResourceHandler::GlobalCleanup() { |
| 139 if (spare_read_buffer_) { | 139 if (spare_read_buffer_) { |
| 140 spare_read_buffer_->Release(); | 140 spare_read_buffer_->Release(); |
| 141 spare_read_buffer_ = NULL; | 141 spare_read_buffer_ = NULL; |
| 142 } | 142 } |
| 143 } | 143 } |
| OLD | NEW |