OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2008 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. |
| 4 |
| 5 #ifndef IPC_IPC_CHANNEL_WIN_H_ |
| 6 #define IPC_IPC_CHANNEL_WIN_H_ |
| 7 |
| 8 #include "ipc/ipc_channel.h" |
| 9 |
| 10 #include <queue> |
| 11 #include <string> |
| 12 |
| 13 #include "base/message_loop.h" |
| 14 |
| 15 class NonThreadSafe; |
| 16 |
| 17 namespace IPC { |
| 18 |
| 19 class Channel::ChannelImpl : public MessageLoopForIO::IOHandler { |
| 20 public: |
| 21 // Mirror methods of Channel, see ipc_channel.h for description. |
| 22 ChannelImpl(const std::string& channel_id, Mode mode, Listener* listener); |
| 23 ~ChannelImpl() { Close(); } |
| 24 bool Connect(); |
| 25 void Close(); |
| 26 void set_listener(Listener* listener) { listener_ = listener; } |
| 27 bool Send(Message* message); |
| 28 private: |
| 29 const std::wstring PipeName(const std::string& channel_id) const; |
| 30 bool CreatePipe(const std::string& channel_id, Mode mode); |
| 31 |
| 32 bool ProcessConnection(); |
| 33 bool ProcessIncomingMessages(MessageLoopForIO::IOContext* context, |
| 34 DWORD bytes_read); |
| 35 bool ProcessOutgoingMessages(MessageLoopForIO::IOContext* context, |
| 36 DWORD bytes_written); |
| 37 |
| 38 // MessageLoop::IOHandler implementation. |
| 39 virtual void OnIOCompleted(MessageLoopForIO::IOContext* context, |
| 40 DWORD bytes_transfered, DWORD error); |
| 41 private: |
| 42 struct State { |
| 43 explicit State(ChannelImpl* channel); |
| 44 ~State(); |
| 45 MessageLoopForIO::IOContext context; |
| 46 bool is_pending; |
| 47 }; |
| 48 |
| 49 State input_state_; |
| 50 State output_state_; |
| 51 |
| 52 HANDLE pipe_; |
| 53 |
| 54 Listener* listener_; |
| 55 |
| 56 // Messages to be sent are queued here. |
| 57 std::queue<Message*> output_queue_; |
| 58 |
| 59 // We read from the pipe into this buffer |
| 60 char input_buf_[Channel::kReadBufferSize]; |
| 61 |
| 62 // Large messages that span multiple pipe buffers, get built-up using |
| 63 // this buffer. |
| 64 std::string input_overflow_buf_; |
| 65 |
| 66 // In server-mode, we have to wait for the client to connect before we |
| 67 // can begin reading. We make use of the input_state_ when performing |
| 68 // the connect operation in overlapped mode. |
| 69 bool waiting_connect_; |
| 70 |
| 71 // This flag is set when processing incoming messages. It is used to |
| 72 // avoid recursing through ProcessIncomingMessages, which could cause |
| 73 // problems. TODO(darin): make this unnecessary |
| 74 bool processing_incoming_; |
| 75 |
| 76 ScopedRunnableMethodFactory<ChannelImpl> factory_; |
| 77 |
| 78 scoped_ptr<NonThreadSafe> thread_check_; |
| 79 |
| 80 DISALLOW_COPY_AND_ASSIGN(ChannelImpl); |
| 81 }; |
| 82 |
| 83 } // namespace IPC |
| 84 |
| 85 #endif // IPC_IPC_CHANNEL_WIN_H_ |
OLD | NEW |