1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/ipc/chromium/src/chrome/common/ipc_channel_win.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,117 @@ 1.4 +// Copyright (c) 2008 The Chromium Authors. All rights reserved. 1.5 +// Use of this source code is governed by a BSD-style license that can be 1.6 +// found in the LICENSE file. 1.7 + 1.8 +#ifndef CHROME_COMMON_IPC_CHANNEL_WIN_H_ 1.9 +#define CHROME_COMMON_IPC_CHANNEL_WIN_H_ 1.10 + 1.11 +#include "chrome/common/ipc_channel.h" 1.12 + 1.13 +#include <queue> 1.14 +#include <string> 1.15 + 1.16 +#include "base/message_loop.h" 1.17 + 1.18 +class NonThreadSafe; 1.19 + 1.20 +namespace IPC { 1.21 + 1.22 +class Channel::ChannelImpl : public MessageLoopForIO::IOHandler { 1.23 + public: 1.24 + // Mirror methods of Channel, see ipc_channel.h for description. 1.25 + ChannelImpl(const std::wstring& channel_id, Mode mode, Listener* listener); 1.26 + ChannelImpl(const std::wstring& channel_id, HANDLE server_pipe, 1.27 + Mode mode, Listener* listener); 1.28 + ~ChannelImpl() { 1.29 + if (pipe_ != INVALID_HANDLE_VALUE) { 1.30 + Close(); 1.31 + } 1.32 + } 1.33 + bool Connect(); 1.34 + void Close(); 1.35 + HANDLE GetServerPipeHandle() const; 1.36 + Listener* set_listener(Listener* listener) { 1.37 + Listener* old = listener_; 1.38 + listener_ = listener; 1.39 + return old; 1.40 + } 1.41 + bool Send(Message* message); 1.42 + 1.43 + // See the comment in ipc_channel.h for info on Unsound_IsClosed() and 1.44 + // Unsound_NumQueuedMessages(). 1.45 + bool Unsound_IsClosed() const; 1.46 + uint32_t Unsound_NumQueuedMessages() const; 1.47 + 1.48 + private: 1.49 + void Init(Mode mode, Listener* listener); 1.50 + 1.51 + void OutputQueuePush(Message* msg); 1.52 + void OutputQueuePop(); 1.53 + 1.54 + const std::wstring PipeName(const std::wstring& channel_id) const; 1.55 + bool CreatePipe(const std::wstring& channel_id, Mode mode); 1.56 + bool EnqueueHelloMessage(); 1.57 + 1.58 + bool ProcessConnection(); 1.59 + bool ProcessIncomingMessages(MessageLoopForIO::IOContext* context, 1.60 + DWORD bytes_read); 1.61 + bool ProcessOutgoingMessages(MessageLoopForIO::IOContext* context, 1.62 + DWORD bytes_written); 1.63 + 1.64 + // MessageLoop::IOHandler implementation. 1.65 + virtual void OnIOCompleted(MessageLoopForIO::IOContext* context, 1.66 + DWORD bytes_transfered, DWORD error); 1.67 + private: 1.68 + struct State { 1.69 + explicit State(ChannelImpl* channel); 1.70 + ~State(); 1.71 + MessageLoopForIO::IOContext context; 1.72 + bool is_pending; 1.73 + }; 1.74 + 1.75 + State input_state_; 1.76 + State output_state_; 1.77 + 1.78 + HANDLE pipe_; 1.79 + 1.80 + Listener* listener_; 1.81 + 1.82 + // Messages to be sent are queued here. 1.83 + std::queue<Message*> output_queue_; 1.84 + 1.85 + // We read from the pipe into this buffer 1.86 + char input_buf_[Channel::kReadBufferSize]; 1.87 + 1.88 + // Large messages that span multiple pipe buffers, get built-up using 1.89 + // this buffer. 1.90 + std::string input_overflow_buf_; 1.91 + 1.92 + // In server-mode, we have to wait for the client to connect before we 1.93 + // can begin reading. We make use of the input_state_ when performing 1.94 + // the connect operation in overlapped mode. 1.95 + bool waiting_connect_; 1.96 + 1.97 + // This flag is set when processing incoming messages. It is used to 1.98 + // avoid recursing through ProcessIncomingMessages, which could cause 1.99 + // problems. TODO(darin): make this unnecessary 1.100 + bool processing_incoming_; 1.101 + 1.102 + // This flag is set after Close() is run on the channel. 1.103 + bool closed_; 1.104 + 1.105 + // This variable is updated so it matches output_queue_.size(), except we can 1.106 + // read output_queue_length_ from any thread (if we're OK getting an 1.107 + // occasional out-of-date or bogus value). We use output_queue_length_ to 1.108 + // implement Unsound_NumQueuedMessages. 1.109 + size_t output_queue_length_; 1.110 + 1.111 + ScopedRunnableMethodFactory<ChannelImpl> factory_; 1.112 + 1.113 + scoped_ptr<NonThreadSafe> thread_check_; 1.114 + 1.115 + DISALLOW_COPY_AND_ASSIGN(ChannelImpl); 1.116 +}; 1.117 + 1.118 +} // namespace IPC 1.119 + 1.120 +#endif // CHROME_COMMON_IPC_CHANNEL_WIN_H_