| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/mojo/ipc_message_pipe_reader.h" | 5 #include "ipc/mojo/ipc_message_pipe_reader.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 | 154 |
| 155 void MessagePipeReader::ReadMessagesThenWait() { | 155 void MessagePipeReader::ReadMessagesThenWait() { |
| 156 while (true) { | 156 while (true) { |
| 157 ReadAvailableMessages(); | 157 ReadAvailableMessages(); |
| 158 if (!pipe_.is_valid()) | 158 if (!pipe_.is_valid()) |
| 159 break; | 159 break; |
| 160 // |Wait()| is safe to call only after all messages are read. | 160 // |Wait()| is safe to call only after all messages are read. |
| 161 // If can fail with |MOJO_RESULT_ALREADY_EXISTS| otherwise. | 161 // If can fail with |MOJO_RESULT_ALREADY_EXISTS| otherwise. |
| 162 // Also, we don't use MOJO_HANDLE_SIGNAL_WRITABLE here, expecting buffer in | 162 // Also, we don't use MOJO_HANDLE_SIGNAL_WRITABLE here, expecting buffer in |
| 163 // MessagePipe. | 163 // MessagePipe. |
| 164 MojoResult result = async_waiter_->Wait( | 164 MojoResult result = |
| 165 pipe_.get().value(), | 165 async_waiter_->Wait(pipe_.get().value(), MOJO_HANDLE_SIGNAL_READABLE); |
| 166 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED); | |
| 167 // If the result is |MOJO_RESULT_ALREADY_EXISTS|, there could be messages | 166 // If the result is |MOJO_RESULT_ALREADY_EXISTS|, there could be messages |
| 168 // that have been arrived after the last |ReadAvailableMessages()|. | 167 // that have been arrived after the last |ReadAvailableMessages()|. |
| 169 // We have to consume then and retry in that case. | 168 // We have to consume then and retry in that case. |
| 170 if (result != MOJO_RESULT_ALREADY_EXISTS) { | 169 if (result != MOJO_RESULT_ALREADY_EXISTS) { |
| 171 if (result != MOJO_RESULT_OK) { | 170 if (result != MOJO_RESULT_OK) { |
| 172 LOG(ERROR) << "Failed to wait on the pipe. Result is " << result; | 171 LOG(ERROR) << "Failed to wait on the pipe. Result is " << result; |
| 173 OnPipeError(result); | 172 OnPipeError(result); |
| 174 Close(); | 173 Close(); |
| 175 } | 174 } |
| 176 | 175 |
| 177 break; | 176 break; |
| 178 } | 177 } |
| 179 } | 178 } |
| 180 } | 179 } |
| 181 | 180 |
| 182 void MessagePipeReader::PipeIsReady(MojoResult wait_result) { | 181 void MessagePipeReader::PipeIsReady(MojoResult wait_result) { |
| 183 if (wait_result != MOJO_RESULT_OK) { | 182 if (wait_result != MOJO_RESULT_OK) { |
| 184 CHECK_NE(wait_result, MOJO_RESULT_ABORTED); | 183 if (wait_result != MOJO_RESULT_ABORTED) { |
| 185 LOG(ERROR) << "Pipe got error from the waiter. Closing: " << wait_result; | 184 // FAILED_PRECONDITION happens every time the peer is dead so |
| 186 OnPipeError(wait_result); | 185 // it isn't worth polluting the log message. |
| 186 LOG_IF(WARNING, wait_result != MOJO_RESULT_FAILED_PRECONDITION) |
| 187 << "Pipe got error from the waiter. Closing: " << wait_result; |
| 188 OnPipeError(wait_result); |
| 189 } |
| 187 | 190 |
| 188 Close(); | 191 Close(); |
| 189 return; | 192 return; |
| 190 } | 193 } |
| 191 | 194 |
| 192 ReadMessagesThenWait(); | 195 ReadMessagesThenWait(); |
| 193 } | 196 } |
| 194 | 197 |
| 195 void MessagePipeReader::DelayedDeleter::operator()( | 198 void MessagePipeReader::DelayedDeleter::operator()( |
| 196 MessagePipeReader* ptr) const { | 199 MessagePipeReader* ptr) const { |
| 197 ptr->Close(); | 200 ptr->Close(); |
| 198 base::MessageLoopProxy::current()->PostTask( | 201 base::MessageLoopProxy::current()->PostTask( |
| 199 FROM_HERE, base::Bind(&DeleteNow, ptr)); | 202 FROM_HERE, base::Bind(&DeleteNow, ptr)); |
| 200 } | 203 } |
| 201 | 204 |
| 202 } // namespace internal | 205 } // namespace internal |
| 203 } // namespace IPC | 206 } // namespace IPC |
| OLD | NEW |