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

Unified Diff: ipc/ipc_channel_posix.h

Issue 9547009: Factor out the shared parts of IPC channel reading. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ipc/ipc_channel.h ('k') | ipc/ipc_channel_posix.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ipc/ipc_channel_posix.h
diff --git a/ipc/ipc_channel_posix.h b/ipc/ipc_channel_posix.h
index 7d26e9b168cc6b4d245dbfc1fa76bca92d5a37ba..028e5d934ccc06814b5139e06dea9f774a919c17 100644
--- a/ipc/ipc_channel_posix.h
+++ b/ipc/ipc_channel_posix.h
@@ -16,6 +16,7 @@
#include "base/message_loop.h"
#include "ipc/file_descriptor_set_posix.h"
+#include "ipc/ipc_channel_reader.h"
#if !defined(OS_MACOSX)
// On Linux, the seccomp sandbox makes it very expensive to call
@@ -47,7 +48,8 @@
namespace IPC {
-class Channel::ChannelImpl : public MessageLoopForIO::Watcher {
+class Channel::ChannelImpl : public internal::ChannelReader,
+ public MessageLoopForIO::Watcher {
public:
// Mirror methods of Channel, see ipc_channel.h for description.
ChannelImpl(const IPC::ChannelHandle& channel_handle, Mode mode,
@@ -55,7 +57,6 @@ class Channel::ChannelImpl : public MessageLoopForIO::Watcher {
virtual ~ChannelImpl();
bool Connect();
void Close();
- void set_listener(Listener* listener) { listener_ = listener; }
bool Send(Message* message);
int GetClientFileDescriptor();
int TakeClientFileDescriptor();
@@ -70,38 +71,22 @@ class Channel::ChannelImpl : public MessageLoopForIO::Watcher {
#endif // OS_LINUX
private:
- enum ReadState { READ_SUCCEEDED, READ_FAILED, READ_PENDING };
-
bool CreatePipe(const IPC::ChannelHandle& channel_handle);
- bool ProcessIncomingMessages();
bool ProcessOutgoingMessages();
bool AcceptConnection();
void ClosePipeOnError();
int GetHelloMessageProcId();
void QueueHelloMessage();
- bool IsHelloMessage(const Message* m) const;
- // Populates the given buffer with data from the pipe.
- //
- // Returns the state of the read. On READ_SUCCESS, the number of bytes
- // read will be placed into |*bytes_read| (which can be less than the
- // buffer size). On READ_FAILED, the channel will be closed.
- //
- // If the return value is READ_PENDING, it means that there was no data
- // ready for reading. The implementation is then responsible for either
- // calling AsyncReadComplete with the number of bytes read into the
- // buffer, or ProcessIncomingMessages to try the read again (depending
- // on whether the platform's async I/O is "try again" or "write
- // asynchronously into your buffer").
- ReadState ReadData(char* buffer, int buffer_len, int* bytes_read);
-
- // Takes the given data received from the IPC channel and dispatches any
- // fully completed messages.
- //
- // Returns true on success. False means channel error.
- bool DispatchInputData(const char* input_data, int input_data_len);
+ // ChannelReader implementation.
+ virtual ReadState ReadData(char* buffer,
+ int buffer_len,
+ int* bytes_read) OVERRIDE;
+ virtual bool WillDispatchInputMessage(Message* msg) OVERRIDE;
+ virtual bool DidEmptyInputBuffers() OVERRIDE;
+ virtual void HandleHelloMessage(const Message& msg) OVERRIDE;
#if defined(IPC_USES_READWRITE)
// Reads the next message from the fd_pipe_ and appends them to the
@@ -111,17 +96,6 @@ class Channel::ChannelImpl : public MessageLoopForIO::Watcher {
bool ReadFileDescriptorsFromFDPipe();
#endif
- // Loads the required file desciptors into the given message. Returns true
- // on success. False means a fatal channel error.
- //
- // This will read from the input_fds_ and read more handles from the FD
- // pipe if necessary.
- bool WillDispatchInputMessage(Message* msg);
-
- // Performs post-dispatch checks. Called when all input buffers are empty,
- // though there could be more data ready to be read from the OS.
- bool DidEmptyInputBuffers();
-
// Finds the set of file descriptors in the given message. On success,
// appends the descriptors to the input_fds_ member and returns true
//
@@ -133,9 +107,6 @@ class Channel::ChannelImpl : public MessageLoopForIO::Watcher {
// used to clean up handles in error conditions to avoid leaking the handles.
void ClearInputFDs();
- // Handles the first message sent over the pipe which contains setup info.
- void HandleHelloMessage(const Message& msg);
-
// MessageLoopForIO::Watcher implementation.
virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE;
virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE;
@@ -178,19 +149,9 @@ class Channel::ChannelImpl : public MessageLoopForIO::Watcher {
// the pipe. On POSIX it's used as a key in a local map of file descriptors.
std::string pipe_name_;
- Listener* listener_;
-
// Messages to be sent are queued here.
std::queue<Message*> output_queue_;
- // We read from the pipe into this buffer. Managed by DispatchInputData, do
- // not access directly outside that function.
- char input_buf_[Channel::kReadBufferSize];
-
- // Large messages that span multiple pipe buffers, get built-up using
- // this buffer.
- std::string input_overflow_buf_;
-
// We assume a worst case: kReadBufferSize bytes of messages, where each
// message has no payload and a full complement of descriptors.
static const size_t kMaxReadFDs =
« no previous file with comments | « ipc/ipc_channel.h ('k') | ipc/ipc_channel_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698