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

Side by Side Diff: ipc/ipc_channel_reader.h

Issue 1345353004: Resize IPC input buffer to fit the next message. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix overflow test to actually overflow on 32-bit Created 5 years, 2 months 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 (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 #ifndef IPC_IPC_CHANNEL_READER_H_ 5 #ifndef IPC_IPC_CHANNEL_READER_H_
6 #define IPC_IPC_CHANNEL_READER_H_ 6 #define IPC_IPC_CHANNEL_READER_H_
7 7
8 #include <set> 8 #include <set>
9 9
10 #include "base/gtest_prod_util.h" 10 #include "base/gtest_prod_util.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 120
121 // Get the process ID for the sender of the message. 121 // Get the process ID for the sender of the message.
122 virtual base::ProcessId GetSenderPID() = 0; 122 virtual base::ProcessId GetSenderPID() = 0;
123 123
124 // Whether the channel is an endpoint of attachment brokering. 124 // Whether the channel is an endpoint of attachment brokering.
125 virtual bool IsAttachmentBrokerEndpoint() = 0; 125 virtual bool IsAttachmentBrokerEndpoint() = 0;
126 126
127 private: 127 private:
128 FRIEND_TEST_ALL_PREFIXES(ChannelReaderTest, AttachmentAlreadyBrokered); 128 FRIEND_TEST_ALL_PREFIXES(ChannelReaderTest, AttachmentAlreadyBrokered);
129 FRIEND_TEST_ALL_PREFIXES(ChannelReaderTest, AttachmentNotYetBrokered); 129 FRIEND_TEST_ALL_PREFIXES(ChannelReaderTest, AttachmentNotYetBrokered);
130 FRIEND_TEST_ALL_PREFIXES(ChannelReaderTest, ResizeOverflowBuffer);
131 FRIEND_TEST_ALL_PREFIXES(ChannelReaderTest, InvalidMessageSize);
130 132
131 typedef std::set<BrokerableAttachment::AttachmentId> AttachmentIdSet; 133 typedef std::set<BrokerableAttachment::AttachmentId> AttachmentIdSet;
132 134
133 // Takes the given data received from the IPC channel, translates it into 135 // Takes the given data received from the IPC channel, translates it into
134 // Messages, and puts them in queued_messages_. 136 // Messages, and puts them in queued_messages_.
135 // As an optimization, after a message is translated, the message is 137 // As an optimization, after a message is translated, the message is
136 // immediately dispatched if able. This prevents an otherwise unnecessary deep 138 // immediately dispatched if able. This prevents an otherwise unnecessary deep
137 // copy of the message which is needed to store the message in the message 139 // copy of the message which is needed to store the message in the message
138 // queue. 140 // queue.
139 bool TranslateInputData(const char* input_data, int input_data_len); 141 bool TranslateInputData(const char* input_data, int input_data_len);
140 142
141 // Dispatches messages from queued_messages_ to listeners. Successfully 143 // Dispatches messages from queued_messages_ to listeners. Successfully
142 // dispatched messages are removed from queued_messages_. 144 // dispatched messages are removed from queued_messages_.
143 DispatchState DispatchMessages(); 145 DispatchState DispatchMessages();
144 146
145 // Attempts to fill in the brokerable attachments of |msg| with information 147 // Attempts to fill in the brokerable attachments of |msg| with information
146 // from the Attachment Broker. 148 // from the Attachment Broker.
147 // Returns the set of ids that are still waiting to be brokered. 149 // Returns the set of ids that are still waiting to be brokered.
148 AttachmentIdSet GetBrokeredAttachments(Message* msg); 150 AttachmentIdSet GetBrokeredAttachments(Message* msg);
149 151
150 // AttachmentBroker::Observer overrides. 152 // AttachmentBroker::Observer overrides.
151 void ReceivedBrokerableAttachmentWithId( 153 void ReceivedBrokerableAttachmentWithId(
152 const BrokerableAttachment::AttachmentId& id) override; 154 const BrokerableAttachment::AttachmentId& id) override;
153 155
154 // This class should observe the attachment broker if and only if blocked_ids_ 156 // This class should observe the attachment broker if and only if blocked_ids_
155 // is not empty. 157 // is not empty.
156 void StartObservingAttachmentBroker(); 158 void StartObservingAttachmentBroker();
157 void StopObservingAttachmentBroker(); 159 void StopObservingAttachmentBroker();
158 160
161 bool CheckMessageSize(size_t size);
Maria 2015/09/25 22:23:00 Comment?
Dmitry Skiba 2015/09/28 17:37:17 Done.
162
159 Listener* listener_; 163 Listener* listener_;
160 164
161 // We read from the pipe into this buffer. Managed by DispatchInputData, do 165 // We read from the pipe into this buffer. Managed by DispatchInputData, do
162 // not access directly outside that function. 166 // not access directly outside that function.
163 char input_buf_[Channel::kReadBufferSize]; 167 char input_buf_[Channel::kReadBufferSize];
164 168
165 // Large messages that span multiple pipe buffers, get built-up using 169 // Large messages that span multiple pipe buffers, get built-up using
166 // this buffer. 170 // this buffer.
167 std::string input_overflow_buf_; 171 std::string input_overflow_buf_;
168 172
169 // These messages are waiting to be dispatched. If this vector is non-empty, 173 // These messages are waiting to be dispatched. If this vector is non-empty,
170 // then the front Message must be blocked on receiving an attachment from the 174 // then the front Message must be blocked on receiving an attachment from the
171 // AttachmentBroker. 175 // AttachmentBroker.
172 ScopedVector<Message> queued_messages_; 176 ScopedVector<Message> queued_messages_;
173 177
174 // If the next message to be processed is blocked by the broker, then this 178 // If the next message to be processed is blocked by the broker, then this
175 // set contains the AttachmentIds that are needed to unblock the message. 179 // set contains the AttachmentIds that are needed to unblock the message.
176 AttachmentIdSet blocked_ids_; 180 AttachmentIdSet blocked_ids_;
177 181
178 DISALLOW_COPY_AND_ASSIGN(ChannelReader); 182 DISALLOW_COPY_AND_ASSIGN(ChannelReader);
179 }; 183 };
180 184
181 } // namespace internal 185 } // namespace internal
182 } // namespace IPC 186 } // namespace IPC
183 187
184 #endif // IPC_IPC_CHANNEL_READER_H_ 188 #endif // IPC_IPC_CHANNEL_READER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698