Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(839)

Side by Side Diff: content/child/shared_memory_received_data_factory.cc

Issue 2540023003: Dispatch encoded_data_length separately in content/child (Closed)
Patch Set: fix Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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,
23 scoped_refptr<SharedMemoryReceivedDataFactory> factory, 22 scoped_refptr<SharedMemoryReceivedDataFactory> factory,
24 SharedMemoryReceivedDataFactory::TicketId id) 23 SharedMemoryReceivedDataFactory::TicketId id)
25 : payload_(payload), 24 : payload_(payload),
26 length_(length), 25 length_(length),
27 encoded_data_length_(encoded_data_length),
28 factory_(factory), 26 factory_(factory),
29 id_(id) {} 27 id_(id) {}
30 28
31 ~SharedMemoryReceivedData() override { factory_->Reclaim(id_); } 29 ~SharedMemoryReceivedData() override { factory_->Reclaim(id_); }
32 30
33 const char* payload() const override { return payload_; } 31 const char* payload() const override { return payload_; }
34 int length() const override { return length_; } 32 int length() const override { return length_; }
35 int encoded_data_length() const override { return encoded_data_length_; }
36 33
37 private: 34 private:
38 const char* const payload_; 35 const char* const payload_;
39 const int length_; 36 const int length_;
40 const int encoded_data_length_;
41 37
42 scoped_refptr<SharedMemoryReceivedDataFactory> factory_; 38 scoped_refptr<SharedMemoryReceivedDataFactory> factory_;
43 SharedMemoryReceivedDataFactory::TicketId id_; 39 SharedMemoryReceivedDataFactory::TicketId id_;
44 40
45 DISALLOW_COPY_AND_ASSIGN(SharedMemoryReceivedData); 41 DISALLOW_COPY_AND_ASSIGN(SharedMemoryReceivedData);
46 }; 42 };
47 43
48 SharedMemoryReceivedDataFactory::SharedMemoryReceivedDataFactory( 44 SharedMemoryReceivedDataFactory::SharedMemoryReceivedDataFactory(
49 IPC::Sender* message_sender, 45 IPC::Sender* message_sender,
50 int request_id, 46 int request_id,
51 linked_ptr<base::SharedMemory> memory) 47 linked_ptr<base::SharedMemory> memory)
52 : id_(0), 48 : id_(0),
53 oldest_(0), 49 oldest_(0),
54 message_sender_(message_sender), 50 message_sender_(message_sender),
55 request_id_(request_id), 51 request_id_(request_id),
56 is_stopped_(false), 52 is_stopped_(false),
57 memory_(memory) { 53 memory_(memory) {
58 } 54 }
59 55
60 SharedMemoryReceivedDataFactory::~SharedMemoryReceivedDataFactory() { 56 SharedMemoryReceivedDataFactory::~SharedMemoryReceivedDataFactory() {
61 if (!is_stopped_) 57 if (!is_stopped_)
62 SendAck(released_tickets_.size()); 58 SendAck(released_tickets_.size());
63 } 59 }
64 60
65 std::unique_ptr<RequestPeer::ReceivedData> 61 std::unique_ptr<RequestPeer::ReceivedData>
66 SharedMemoryReceivedDataFactory::Create(int offset, 62 SharedMemoryReceivedDataFactory::Create(int offset, int length) {
67 int length,
68 int encoded_data_length) {
69 const char* start = static_cast<char*>(memory_->memory()); 63 const char* start = static_cast<char*>(memory_->memory());
70 const char* payload = start + offset; 64 const char* payload = start + offset;
71 TicketId id = id_++; 65 TicketId id = id_++;
72 66
73 return base::MakeUnique<SharedMemoryReceivedData>( 67 return base::MakeUnique<SharedMemoryReceivedData>(payload, length, this, id);
74 payload, length, encoded_data_length, this, id);
75 } 68 }
76 69
77 void SharedMemoryReceivedDataFactory::Stop() { 70 void SharedMemoryReceivedDataFactory::Stop() {
78 is_stopped_ = true; 71 is_stopped_ = true;
79 released_tickets_.clear(); 72 released_tickets_.clear();
80 message_sender_ = nullptr; 73 message_sender_ = nullptr;
81 } 74 }
82 75
83 class SharedMemoryReceivedDataFactory::TicketComparator final { 76 class SharedMemoryReceivedDataFactory::TicketComparator final {
84 public: 77 public:
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 SendAck(count); 117 SendAck(count);
125 } 118 }
126 119
127 void SharedMemoryReceivedDataFactory::SendAck(size_t count) { 120 void SharedMemoryReceivedDataFactory::SendAck(size_t count) {
128 for (size_t i = 0; i < count; ++i) { 121 for (size_t i = 0; i < count; ++i) {
129 message_sender_->Send(new ResourceHostMsg_DataReceived_ACK(request_id_)); 122 message_sender_->Send(new ResourceHostMsg_DataReceived_ACK(request_id_));
130 } 123 }
131 } 124 }
132 125
133 } // namespace content 126 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698