Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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.
5 #ifndef CHROME_COMMON_IPC_CHANNEL_WIN_H_
6 #define CHROME_COMMON_IPC_CHANNEL_WIN_H_
8 #include "chrome/common/ipc_channel.h"
10 #include <queue>
11 #include <string>
13 #include "base/message_loop.h"
15 class NonThreadSafe;
17 namespace IPC {
19 class Channel::ChannelImpl : public MessageLoopForIO::IOHandler {
20 public:
21 // Mirror methods of Channel, see ipc_channel.h for description.
22 ChannelImpl(const std::wstring& channel_id, Mode mode, Listener* listener);
23 ChannelImpl(const std::wstring& channel_id, HANDLE server_pipe,
24 Mode mode, Listener* listener);
25 ~ChannelImpl() {
26 if (pipe_ != INVALID_HANDLE_VALUE) {
27 Close();
28 }
29 }
30 bool Connect();
31 void Close();
32 HANDLE GetServerPipeHandle() const;
33 Listener* set_listener(Listener* listener) {
34 Listener* old = listener_;
35 listener_ = listener;
36 return old;
37 }
38 bool Send(Message* message);
40 // See the comment in ipc_channel.h for info on Unsound_IsClosed() and
41 // Unsound_NumQueuedMessages().
42 bool Unsound_IsClosed() const;
43 uint32_t Unsound_NumQueuedMessages() const;
45 private:
46 void Init(Mode mode, Listener* listener);
48 void OutputQueuePush(Message* msg);
49 void OutputQueuePop();
51 const std::wstring PipeName(const std::wstring& channel_id) const;
52 bool CreatePipe(const std::wstring& channel_id, Mode mode);
53 bool EnqueueHelloMessage();
55 bool ProcessConnection();
56 bool ProcessIncomingMessages(MessageLoopForIO::IOContext* context,
57 DWORD bytes_read);
58 bool ProcessOutgoingMessages(MessageLoopForIO::IOContext* context,
59 DWORD bytes_written);
61 // MessageLoop::IOHandler implementation.
62 virtual void OnIOCompleted(MessageLoopForIO::IOContext* context,
63 DWORD bytes_transfered, DWORD error);
64 private:
65 struct State {
66 explicit State(ChannelImpl* channel);
67 ~State();
68 MessageLoopForIO::IOContext context;
69 bool is_pending;
70 };
72 State input_state_;
73 State output_state_;
75 HANDLE pipe_;
77 Listener* listener_;
79 // Messages to be sent are queued here.
80 std::queue<Message*> output_queue_;
82 // We read from the pipe into this buffer
83 char input_buf_[Channel::kReadBufferSize];
85 // Large messages that span multiple pipe buffers, get built-up using
86 // this buffer.
87 std::string input_overflow_buf_;
89 // In server-mode, we have to wait for the client to connect before we
90 // can begin reading. We make use of the input_state_ when performing
91 // the connect operation in overlapped mode.
92 bool waiting_connect_;
94 // This flag is set when processing incoming messages. It is used to
95 // avoid recursing through ProcessIncomingMessages, which could cause
96 // problems. TODO(darin): make this unnecessary
97 bool processing_incoming_;
99 // This flag is set after Close() is run on the channel.
100 bool closed_;
102 // This variable is updated so it matches output_queue_.size(), except we can
103 // read output_queue_length_ from any thread (if we're OK getting an
104 // occasional out-of-date or bogus value). We use output_queue_length_ to
105 // implement Unsound_NumQueuedMessages.
106 size_t output_queue_length_;
108 ScopedRunnableMethodFactory<ChannelImpl> factory_;
110 scoped_ptr<NonThreadSafe> thread_check_;
112 DISALLOW_COPY_AND_ASSIGN(ChannelImpl);
113 };
115 } // namespace IPC
117 #endif // CHROME_COMMON_IPC_CHANNEL_WIN_H_