diff options
author | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-10 22:28:11 +0000 |
---|---|---|
committer | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-10 22:28:11 +0000 |
commit | 514411fcb4657f575eeb3e39a9056478a28306a0 (patch) | |
tree | be2bcacf0d4cffd91ceded1f4e03bc3d6ae3d6e6 /chrome/common/ipc_channel_win.h | |
parent | f20b9e922a26e045af6bc7a5c3c46d78abb04aac (diff) | |
download | chromium_src-514411fcb4657f575eeb3e39a9056478a28306a0.zip chromium_src-514411fcb4657f575eeb3e39a9056478a28306a0.tar.gz chromium_src-514411fcb4657f575eeb3e39a9056478a28306a0.tar.bz2 |
Refactor IPC::Channel to have a common header.
Review URL: http://codereview.chromium.org/11024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6743 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/ipc_channel_win.h')
-rw-r--r-- | chrome/common/ipc_channel_win.h | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/chrome/common/ipc_channel_win.h b/chrome/common/ipc_channel_win.h new file mode 100644 index 0000000..fcd8abe --- /dev/null +++ b/chrome/common/ipc_channel_win.h @@ -0,0 +1,81 @@ +// Copyright (c) 2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_COMMON_IPC_CHANNEL_WIN_H_ +#define CHROME_COMMON_IPC_CHANNEL_WIN_H_ + +#include "chrome/common/ipc_channel.h" + +#include <queue> +#include <string> + +#include "base/message_loop.h" + +namespace IPC { + +class Channel::ChannelImpl : public MessageLoopForIO::IOHandler { + public: + // Mirror methods of Channel, see ipc_channel.h for description. + ChannelImpl(const std::wstring& channel_id, Mode mode, Listener* listener); + ~ChannelImpl() { Close(); } + bool Connect(); + void Close(); + void set_listener(Listener* listener) { listener_ = listener; } + bool Send(Message* message); + private: + const std::wstring PipeName(const std::wstring& channel_id) const; + bool CreatePipe(const std::wstring& channel_id, Mode mode); + + bool ProcessConnection(); + bool ProcessIncomingMessages(MessageLoopForIO::IOContext* context, + DWORD bytes_read); + bool ProcessOutgoingMessages(MessageLoopForIO::IOContext* context, + DWORD bytes_written); + + // MessageLoop::IOHandler implementation. + virtual void OnIOCompleted(MessageLoopForIO::IOContext* context, + DWORD bytes_transfered, DWORD error); + private: + struct State { + explicit State(ChannelImpl* channel); + ~State(); + MessageLoopForIO::IOContext context; + bool is_pending; + }; + + State input_state_; + State output_state_; + + HANDLE pipe_; + + Listener* listener_; + + // Messages to be sent are queued here. + std::queue<Message*> output_queue_; + + // We read from the pipe into this buffer + char input_buf_[Channel::kReadBufferSize]; + + // Large messages that span multiple pipe buffers, get built-up using + // this buffer. + std::string input_overflow_buf_; + + // In server-mode, we have to wait for the client to connect before we + // can begin reading. We make use of the input_state_ when performing + // the connect operation in overlapped mode. + bool waiting_connect_; + + // This flag is set when processing incoming messages. It is used to + // avoid recursing through ProcessIncomingMessages, which could cause + // problems. TODO(darin): make this unnecessary + bool processing_incoming_; + + ScopedRunnableMethodFactory<ChannelImpl> factory_; + + DISALLOW_COPY_AND_ASSIGN(ChannelImpl); +}; + +} // namespace IPC + +#endif // CHROME_COMMON_IPC_CHANNEL_WIN_H_ |