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 #include "ipc/ipc_channel_reader.h" | 5 #include "ipc/ipc_channel_reader.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ipc/ipc_listener.h" | 9 #include "ipc/ipc_listener.h" |
10 #include "ipc/ipc_logging.h" | 10 #include "ipc/ipc_logging.h" |
11 #include "ipc/ipc_message.h" | 11 #include "ipc/ipc_message.h" |
12 #include "ipc/ipc_message_attachment_set.h" | 12 #include "ipc/ipc_message_attachment_set.h" |
13 #include "ipc/ipc_message_macros.h" | 13 #include "ipc/ipc_message_macros.h" |
14 | 14 |
15 namespace IPC { | 15 namespace IPC { |
16 namespace internal { | 16 namespace internal { |
17 | 17 |
18 ChannelReader::ChannelReader(Listener* listener) : listener_(listener) { | 18 ChannelReader::ChannelReader(Listener* listener) : listener_(listener) { |
19 memset(input_buf_, 0, sizeof(input_buf_)); | 19 memset(input_buf_, 0, sizeof(input_buf_)); |
20 } | 20 } |
21 | 21 |
22 ChannelReader::~ChannelReader() { | 22 ChannelReader::~ChannelReader() { |
23 if (!blocked_ids_.empty()) | 23 DCHECK(blocked_ids_.empty()); |
24 StopObservingAttachmentBroker(); | |
25 } | 24 } |
26 | 25 |
27 ChannelReader::DispatchState ChannelReader::ProcessIncomingMessages() { | 26 ChannelReader::DispatchState ChannelReader::ProcessIncomingMessages() { |
28 while (true) { | 27 while (true) { |
29 int bytes_read = 0; | 28 int bytes_read = 0; |
30 ReadState read_state = ReadData(input_buf_, Channel::kReadBufferSize, | 29 ReadState read_state = ReadData(input_buf_, Channel::kReadBufferSize, |
31 &bytes_read); | 30 &bytes_read); |
32 if (read_state == READ_FAILED) | 31 if (read_state == READ_FAILED) |
33 return DISPATCH_ERROR; | 32 return DISPATCH_ERROR; |
34 if (read_state == READ_PENDING) | 33 if (read_state == READ_PENDING) |
(...skipping 20 matching lines...) Expand all Loading... |
55 return m.routing_id() == MSG_ROUTING_NONE && | 54 return m.routing_id() == MSG_ROUTING_NONE && |
56 m.type() >= Channel::CLOSE_FD_MESSAGE_TYPE && | 55 m.type() >= Channel::CLOSE_FD_MESSAGE_TYPE && |
57 m.type() <= Channel::HELLO_MESSAGE_TYPE; | 56 m.type() <= Channel::HELLO_MESSAGE_TYPE; |
58 } | 57 } |
59 | 58 |
60 bool ChannelReader::IsHelloMessage(const Message& m) { | 59 bool ChannelReader::IsHelloMessage(const Message& m) { |
61 return m.routing_id() == MSG_ROUTING_NONE && | 60 return m.routing_id() == MSG_ROUTING_NONE && |
62 m.type() == Channel::HELLO_MESSAGE_TYPE; | 61 m.type() == Channel::HELLO_MESSAGE_TYPE; |
63 } | 62 } |
64 | 63 |
| 64 void ChannelReader::CleanUp() { |
| 65 if (!blocked_ids_.empty()) { |
| 66 StopObservingAttachmentBroker(); |
| 67 blocked_ids_.clear(); |
| 68 } |
| 69 } |
| 70 |
65 bool ChannelReader::TranslateInputData(const char* input_data, | 71 bool ChannelReader::TranslateInputData(const char* input_data, |
66 int input_data_len) { | 72 int input_data_len) { |
67 const char* p; | 73 const char* p; |
68 const char* end; | 74 const char* end; |
69 | 75 |
70 // Possibly combine with the overflow buffer to make a larger buffer. | 76 // Possibly combine with the overflow buffer to make a larger buffer. |
71 if (input_overflow_buf_.empty()) { | 77 if (input_overflow_buf_.empty()) { |
72 p = input_data; | 78 p = input_data; |
73 end = input_data + input_data_len; | 79 end = input_data + input_data_len; |
74 } else { | 80 } else { |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 } | 239 } |
234 | 240 |
235 void ChannelReader::StopObservingAttachmentBroker() { | 241 void ChannelReader::StopObservingAttachmentBroker() { |
236 #if USE_ATTACHMENT_BROKER | 242 #if USE_ATTACHMENT_BROKER |
237 GetAttachmentBroker()->RemoveObserver(this); | 243 GetAttachmentBroker()->RemoveObserver(this); |
238 #endif // USE_ATTACHMENT_BROKER | 244 #endif // USE_ATTACHMENT_BROKER |
239 } | 245 } |
240 | 246 |
241 } // namespace internal | 247 } // namespace internal |
242 } // namespace IPC | 248 } // namespace IPC |
OLD | NEW |