| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/child/shared_memory_received_data_factory.h" | 5 #include "content/child/shared_memory_received_data_factory.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "content/common/resource_messages.h" | 11 #include "content/common/resource_messages.h" |
| 12 #include "ipc/ipc_sender.h" | 12 #include "ipc/ipc_sender.h" |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 | 15 |
| 16 class SharedMemoryReceivedDataFactory::SharedMemoryReceivedData final | 16 class SharedMemoryReceivedDataFactory::SharedMemoryReceivedData final |
| 17 : public RequestPeer::ReceivedData { | 17 : public RequestPeer::ReceivedData { |
| 18 public: | 18 public: |
| 19 SharedMemoryReceivedData( | 19 SharedMemoryReceivedData( |
| 20 const char* payload, | 20 const char* payload, |
| 21 int length, | 21 int length, |
| 22 int encoded_length, | 22 int encoded_data_length, |
| 23 int encoded_body_length, |
| 23 scoped_refptr<SharedMemoryReceivedDataFactory> factory, | 24 scoped_refptr<SharedMemoryReceivedDataFactory> factory, |
| 24 SharedMemoryReceivedDataFactory::TicketId id) | 25 SharedMemoryReceivedDataFactory::TicketId id) |
| 25 : payload_(payload), | 26 : payload_(payload), |
| 26 length_(length), | 27 length_(length), |
| 27 encoded_length_(encoded_length), | 28 encoded_data_length_(encoded_data_length), |
| 29 encoded_body_length_(encoded_body_length), |
| 28 factory_(factory), | 30 factory_(factory), |
| 29 id_(id) {} | 31 id_(id) {} |
| 30 | 32 |
| 31 ~SharedMemoryReceivedData() override { factory_->Reclaim(id_); } | 33 ~SharedMemoryReceivedData() override { factory_->Reclaim(id_); } |
| 32 | 34 |
| 33 const char* payload() const override { return payload_; } | 35 const char* payload() const override { return payload_; } |
| 34 int length() const override { return length_; } | 36 int length() const override { return length_; } |
| 35 int encoded_length() const override { return encoded_length_; } | 37 int encoded_data_length() const override { return encoded_data_length_; } |
| 38 int encoded_body_length() const override { return encoded_body_length_; } |
| 36 | 39 |
| 37 private: | 40 private: |
| 38 const char* const payload_; | 41 const char* const payload_; |
| 39 const int length_; | 42 const int length_; |
| 40 const int encoded_length_; | 43 const int encoded_data_length_; |
| 44 const int encoded_body_length_; |
| 41 | 45 |
| 42 scoped_refptr<SharedMemoryReceivedDataFactory> factory_; | 46 scoped_refptr<SharedMemoryReceivedDataFactory> factory_; |
| 43 SharedMemoryReceivedDataFactory::TicketId id_; | 47 SharedMemoryReceivedDataFactory::TicketId id_; |
| 44 | 48 |
| 45 DISALLOW_COPY_AND_ASSIGN(SharedMemoryReceivedData); | 49 DISALLOW_COPY_AND_ASSIGN(SharedMemoryReceivedData); |
| 46 }; | 50 }; |
| 47 | 51 |
| 48 SharedMemoryReceivedDataFactory::SharedMemoryReceivedDataFactory( | 52 SharedMemoryReceivedDataFactory::SharedMemoryReceivedDataFactory( |
| 49 IPC::Sender* message_sender, | 53 IPC::Sender* message_sender, |
| 50 int request_id, | 54 int request_id, |
| 51 linked_ptr<base::SharedMemory> memory) | 55 linked_ptr<base::SharedMemory> memory) |
| 52 : id_(0), | 56 : id_(0), |
| 53 oldest_(0), | 57 oldest_(0), |
| 54 message_sender_(message_sender), | 58 message_sender_(message_sender), |
| 55 request_id_(request_id), | 59 request_id_(request_id), |
| 56 is_stopped_(false), | 60 is_stopped_(false), |
| 57 memory_(memory) { | 61 memory_(memory) { |
| 58 } | 62 } |
| 59 | 63 |
| 60 SharedMemoryReceivedDataFactory::~SharedMemoryReceivedDataFactory() { | 64 SharedMemoryReceivedDataFactory::~SharedMemoryReceivedDataFactory() { |
| 61 if (!is_stopped_) | 65 if (!is_stopped_) |
| 62 SendAck(released_tickets_.size()); | 66 SendAck(released_tickets_.size()); |
| 63 } | 67 } |
| 64 | 68 |
| 65 std::unique_ptr<RequestPeer::ReceivedData> | 69 std::unique_ptr<RequestPeer::ReceivedData> |
| 66 SharedMemoryReceivedDataFactory::Create(int offset, | 70 SharedMemoryReceivedDataFactory::Create(int offset, |
| 67 int length, | 71 int length, |
| 68 int encoded_length) { | 72 int encoded_data_length, |
| 73 int encoded_body_length) { |
| 69 const char* start = static_cast<char*>(memory_->memory()); | 74 const char* start = static_cast<char*>(memory_->memory()); |
| 70 const char* payload = start + offset; | 75 const char* payload = start + offset; |
| 71 TicketId id = id_++; | 76 TicketId id = id_++; |
| 72 | 77 |
| 73 return base::WrapUnique( | 78 return base::WrapUnique(new SharedMemoryReceivedData( |
| 74 new SharedMemoryReceivedData(payload, length, encoded_length, this, id)); | 79 payload, length, encoded_data_length, encoded_body_length, this, id)); |
| 75 } | 80 } |
| 76 | 81 |
| 77 void SharedMemoryReceivedDataFactory::Stop() { | 82 void SharedMemoryReceivedDataFactory::Stop() { |
| 78 is_stopped_ = true; | 83 is_stopped_ = true; |
| 79 released_tickets_.clear(); | 84 released_tickets_.clear(); |
| 80 message_sender_ = nullptr; | 85 message_sender_ = nullptr; |
| 81 } | 86 } |
| 82 | 87 |
| 83 class SharedMemoryReceivedDataFactory::TicketComparator final { | 88 class SharedMemoryReceivedDataFactory::TicketComparator final { |
| 84 public: | 89 public: |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 SendAck(count); | 129 SendAck(count); |
| 125 } | 130 } |
| 126 | 131 |
| 127 void SharedMemoryReceivedDataFactory::SendAck(size_t count) { | 132 void SharedMemoryReceivedDataFactory::SendAck(size_t count) { |
| 128 for (size_t i = 0; i < count; ++i) { | 133 for (size_t i = 0; i < count; ++i) { |
| 129 message_sender_->Send(new ResourceHostMsg_DataReceived_ACK(request_id_)); | 134 message_sender_->Send(new ResourceHostMsg_DataReceived_ACK(request_id_)); |
| 130 } | 135 } |
| 131 } | 136 } |
| 132 | 137 |
| 133 } // namespace content | 138 } // namespace content |
| OLD | NEW |