1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef IPC_IPC_CHANNEL_WIN_H_
6 #define IPC_IPC_CHANNEL_WIN_H_
9 #include "ipc/ipc_channel.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/message_loop.h"
23 class Channel::ChannelImpl
: public MessageLoopForIO::IOHandler
{
25 // Mirror methods of Channel, see ipc_channel.h for description.
26 ChannelImpl(const IPC::ChannelHandle
&channel_handle
, Mode mode
,
31 void set_listener(Listener
* listener
) { listener_
= listener
; }
32 bool Send(Message
* message
);
34 const std::wstring
PipeName(const std::string
& channel_id
) const;
35 bool CreatePipe(const IPC::ChannelHandle
&channel_handle
, Mode mode
);
37 bool ProcessConnection();
38 bool ProcessIncomingMessages(MessageLoopForIO::IOContext
* context
,
40 bool ProcessOutgoingMessages(MessageLoopForIO::IOContext
* context
,
43 // MessageLoop::IOHandler implementation.
44 virtual void OnIOCompleted(MessageLoopForIO::IOContext
* context
,
45 DWORD bytes_transfered
, DWORD error
);
48 explicit State(ChannelImpl
* channel
);
50 MessageLoopForIO::IOContext context
;
61 // Messages to be sent are queued here.
62 std::queue
<Message
*> output_queue_
;
64 // We read from the pipe into this buffer
65 char input_buf_
[Channel::kReadBufferSize
];
67 // Large messages that span multiple pipe buffers, get built-up using
69 std::string input_overflow_buf_
;
71 // In server-mode, we have to wait for the client to connect before we
72 // can begin reading. We make use of the input_state_ when performing
73 // the connect operation in overlapped mode.
74 bool waiting_connect_
;
76 // This flag is set when processing incoming messages. It is used to
77 // avoid recursing through ProcessIncomingMessages, which could cause
78 // problems. TODO(darin): make this unnecessary
79 bool processing_incoming_
;
81 ScopedRunnableMethodFactory
<ChannelImpl
> factory_
;
83 scoped_ptr
<base::NonThreadSafe
> thread_check_
;
85 DISALLOW_COPY_AND_ASSIGN(ChannelImpl
);
90 #endif // IPC_IPC_CHANNEL_WIN_H_