| 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 "ipc/ipc_listener.h" | 7 #include "ipc/ipc_listener.h" |
| 8 #include "ipc/ipc_logging.h" | 8 #include "ipc/ipc_logging.h" |
| 9 #include "ipc/ipc_message_macros.h" | 9 #include "ipc/ipc_message_macros.h" |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 DCHECK(bytes_read > 0); | 31 DCHECK(bytes_read > 0); |
| 32 if (!DispatchInputData(input_buf_, bytes_read)) | 32 if (!DispatchInputData(input_buf_, bytes_read)) |
| 33 return false; | 33 return false; |
| 34 } | 34 } |
| 35 } | 35 } |
| 36 | 36 |
| 37 bool ChannelReader::AsyncReadComplete(int bytes_read) { | 37 bool ChannelReader::AsyncReadComplete(int bytes_read) { |
| 38 return DispatchInputData(input_buf_, bytes_read); | 38 return DispatchInputData(input_buf_, bytes_read); |
| 39 } | 39 } |
| 40 | 40 |
| 41 bool ChannelReader::IsInternalMessage(const Message& m) const { |
| 42 return m.routing_id() == MSG_ROUTING_NONE && |
| 43 m.type() >= Channel::CLOSE_FD_MESSAGE_TYPE && |
| 44 m.type() <= Channel::HELLO_MESSAGE_TYPE; |
| 45 } |
| 46 |
| 41 bool ChannelReader::IsHelloMessage(const Message& m) const { | 47 bool ChannelReader::IsHelloMessage(const Message& m) const { |
| 42 return m.routing_id() == MSG_ROUTING_NONE && | 48 return m.routing_id() == MSG_ROUTING_NONE && |
| 43 m.type() == Channel::HELLO_MESSAGE_TYPE; | 49 m.type() == Channel::HELLO_MESSAGE_TYPE; |
| 44 } | 50 } |
| 45 | 51 |
| 46 bool ChannelReader::DispatchInputData(const char* input_data, | 52 bool ChannelReader::DispatchInputData(const char* input_data, |
| 47 int input_data_len) { | 53 int input_data_len) { |
| 48 const char* p; | 54 const char* p; |
| 49 const char* end; | 55 const char* end; |
| 50 | 56 |
| 51 // Possibly combine with the overflow buffer to make a larger buffer. | 57 // Possibly combine with the overflow buffer to make a larger buffer. |
| 52 if (input_overflow_buf_.empty()) { | 58 if (input_overflow_buf_.empty()) { |
| 53 p = input_data; | 59 p = input_data; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 77 Logging* logger = Logging::GetInstance(); | 83 Logging* logger = Logging::GetInstance(); |
| 78 std::string name; | 84 std::string name; |
| 79 logger->GetMessageText(m.type(), &name, &m, NULL); | 85 logger->GetMessageText(m.type(), &name, &m, NULL); |
| 80 TRACE_EVENT1("ipc", "ChannelReader::DispatchInputData", "name", name); | 86 TRACE_EVENT1("ipc", "ChannelReader::DispatchInputData", "name", name); |
| 81 #else | 87 #else |
| 82 TRACE_EVENT2("ipc", "ChannelReader::DispatchInputData", | 88 TRACE_EVENT2("ipc", "ChannelReader::DispatchInputData", |
| 83 "class", IPC_MESSAGE_ID_CLASS(m.type()), | 89 "class", IPC_MESSAGE_ID_CLASS(m.type()), |
| 84 "line", IPC_MESSAGE_ID_LINE(m.type())); | 90 "line", IPC_MESSAGE_ID_LINE(m.type())); |
| 85 #endif | 91 #endif |
| 86 m.TraceMessageEnd(); | 92 m.TraceMessageEnd(); |
| 87 if (IsHelloMessage(m)) | 93 if (IsInternalMessage(m)) |
| 88 HandleHelloMessage(m); | 94 HandleInternalMessage(m); |
| 89 else | 95 else |
| 90 listener_->OnMessageReceived(m); | 96 listener_->OnMessageReceived(m); |
| 91 p = message_tail; | 97 p = message_tail; |
| 92 } else { | 98 } else { |
| 93 // Last message is partial. | 99 // Last message is partial. |
| 94 break; | 100 break; |
| 95 } | 101 } |
| 96 } | 102 } |
| 97 | 103 |
| 98 // Save any partial data in the overflow buffer. | 104 // Save any partial data in the overflow buffer. |
| 99 input_overflow_buf_.assign(p, end - p); | 105 input_overflow_buf_.assign(p, end - p); |
| 100 | 106 |
| 101 if (input_overflow_buf_.empty() && !DidEmptyInputBuffers()) | 107 if (input_overflow_buf_.empty() && !DidEmptyInputBuffers()) |
| 102 return false; | 108 return false; |
| 103 return true; | 109 return true; |
| 104 } | 110 } |
| 105 | 111 |
| 106 | 112 |
| 107 } // namespace internal | 113 } // namespace internal |
| 108 } // namespace IPC | 114 } // namespace IPC |
| OLD | NEW |