OLD | NEW |
---|---|
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 Loading... | |
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 // Checks that |size| is a valid message size. Has side effects if it's not. | |
jam
2015/09/30 14:18:16
nit: why does it need to mention an internal impl'
Dmitry Skiba
2015/09/30 15:32:35
Well, the function is named 'Check', so personally
| |
162 bool CheckMessageSize(size_t size); | |
163 | |
159 Listener* listener_; | 164 Listener* listener_; |
160 | 165 |
161 // We read from the pipe into this buffer. Managed by DispatchInputData, do | 166 // We read from the pipe into this buffer. Managed by DispatchInputData, do |
162 // not access directly outside that function. | 167 // not access directly outside that function. |
163 char input_buf_[Channel::kReadBufferSize]; | 168 char input_buf_[Channel::kReadBufferSize]; |
164 | 169 |
165 // Large messages that span multiple pipe buffers, get built-up using | 170 // Large messages that span multiple pipe buffers, get built-up using |
166 // this buffer. | 171 // this buffer. |
167 std::string input_overflow_buf_; | 172 std::string input_overflow_buf_; |
168 | 173 |
169 // These messages are waiting to be dispatched. If this vector is non-empty, | 174 // 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 | 175 // then the front Message must be blocked on receiving an attachment from the |
171 // AttachmentBroker. | 176 // AttachmentBroker. |
172 ScopedVector<Message> queued_messages_; | 177 ScopedVector<Message> queued_messages_; |
173 | 178 |
174 // If the next message to be processed is blocked by the broker, then this | 179 // 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. | 180 // set contains the AttachmentIds that are needed to unblock the message. |
176 AttachmentIdSet blocked_ids_; | 181 AttachmentIdSet blocked_ids_; |
177 | 182 |
178 DISALLOW_COPY_AND_ASSIGN(ChannelReader); | 183 DISALLOW_COPY_AND_ASSIGN(ChannelReader); |
179 }; | 184 }; |
180 | 185 |
181 } // namespace internal | 186 } // namespace internal |
182 } // namespace IPC | 187 } // namespace IPC |
183 | 188 |
184 #endif // IPC_IPC_CHANNEL_READER_H_ | 189 #endif // IPC_IPC_CHANNEL_READER_H_ |
OLD | NEW |