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