blob: d680fb72a54bfdc4c6cc5a5cfb7dab89bd07db98 [file] [log] [blame]
[email protected]215f6fd2012-03-03 08:55:451// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]514411fc2008-12-10 22:28:112// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]946d1b22009-07-22 23:57:215#ifndef IPC_IPC_CHANNEL_WIN_H_
6#define IPC_IPC_CHANNEL_WIN_H_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
[email protected]514411fc2008-12-10 22:28:118
[email protected]946d1b22009-07-22 23:57:219#include "ipc/ipc_channel.h"
[email protected]514411fc2008-12-10 22:28:1110
11#include <queue>
12#include <string>
13
[email protected]3b63f8f42011-03-28 01:54:1514#include "base/memory/scoped_ptr.h"
[email protected]72b6f8e22011-11-12 21:16:4115#include "base/memory/weak_ptr.h"
[email protected]514411fc2008-12-10 22:28:1116#include "base/message_loop.h"
[email protected]d805c6a2012-03-08 12:30:2817#include "ipc/ipc_channel_reader.h"
[email protected]514411fc2008-12-10 22:28:1118
[email protected]c9177502011-01-01 04:48:4919namespace base {
[email protected]c1e4bff32009-01-29 00:07:0620class NonThreadSafe;
[email protected]c9177502011-01-01 04:48:4921}
[email protected]c1e4bff32009-01-29 00:07:0622
[email protected]514411fc2008-12-10 22:28:1123namespace IPC {
24
[email protected]d805c6a2012-03-08 12:30:2825class Channel::ChannelImpl : public internal::ChannelReader,
26 public MessageLoopForIO::IOHandler {
[email protected]514411fc2008-12-10 22:28:1127 public:
28 // Mirror methods of Channel, see ipc_channel.h for description.
[email protected]42ce94e2010-12-08 19:28:0929 ChannelImpl(const IPC::ChannelHandle &channel_handle, Mode mode,
30 Listener* listener);
[email protected]601858c02010-09-01 17:08:2031 ~ChannelImpl();
[email protected]514411fc2008-12-10 22:28:1132 bool Connect();
33 void Close();
[email protected]514411fc2008-12-10 22:28:1134 bool Send(Message* message);
[email protected]313c00e52011-08-09 06:46:0635 static bool IsNamedServerInitialized(const std::string& channel_id);
[email protected]215f6fd2012-03-03 08:55:4536
[email protected]514411fc2008-12-10 22:28:1137 private:
[email protected]d805c6a2012-03-08 12:30:2838 // ChannelReader implementation.
39 virtual ReadState ReadData(char* buffer,
40 int buffer_len,
41 int* bytes_read) OVERRIDE;
42 virtual bool WillDispatchInputMessage(Message* msg) OVERRIDE;
43 bool DidEmptyInputBuffers() OVERRIDE;
44 virtual void HandleHelloMessage(const Message& msg) OVERRIDE;
[email protected]215f6fd2012-03-03 08:55:4545
[email protected]5c41e6e12012-03-17 02:20:4646 static const string16 PipeName(const std::string& channel_id,
47 int32* secret);
[email protected]42ce94e2010-12-08 19:28:0948 bool CreatePipe(const IPC::ChannelHandle &channel_handle, Mode mode);
[email protected]514411fc2008-12-10 22:28:1149
50 bool ProcessConnection();
[email protected]514411fc2008-12-10 22:28:1151 bool ProcessOutgoingMessages(MessageLoopForIO::IOContext* context,
52 DWORD bytes_written);
53
54 // MessageLoop::IOHandler implementation.
55 virtual void OnIOCompleted(MessageLoopForIO::IOContext* context,
56 DWORD bytes_transfered, DWORD error);
57 private:
58 struct State {
59 explicit State(ChannelImpl* channel);
60 ~State();
61 MessageLoopForIO::IOContext context;
62 bool is_pending;
63 };
64
65 State input_state_;
66 State output_state_;
67
68 HANDLE pipe_;
69
[email protected]514411fc2008-12-10 22:28:1170 // Messages to be sent are queued here.
71 std::queue<Message*> output_queue_;
72
[email protected]514411fc2008-12-10 22:28:1173 // In server-mode, we have to wait for the client to connect before we
74 // can begin reading. We make use of the input_state_ when performing
75 // the connect operation in overlapped mode.
76 bool waiting_connect_;
77
78 // This flag is set when processing incoming messages. It is used to
79 // avoid recursing through ProcessIncomingMessages, which could cause
80 // problems. TODO(darin): make this unnecessary
81 bool processing_incoming_;
82
[email protected]5c41e6e12012-03-17 02:20:4683 // Determines if we should validate a client's secret on connection.
84 bool validate_client_;
85
86 // This is a unique per-channel value used to authenticate the client end of
87 // a connection. If the value is non-zero, the client passes it in the hello
88 // and the host validates. (We don't send the zero value fto preserve IPC
89 // compatability with existing clients that don't validate the channel.)
90 int32 client_secret_;
91
92
[email protected]72b6f8e22011-11-12 21:16:4193 base::WeakPtrFactory<ChannelImpl> weak_factory_;
[email protected]514411fc2008-12-10 22:28:1194
[email protected]c9177502011-01-01 04:48:4995 scoped_ptr<base::NonThreadSafe> thread_check_;
[email protected]c1e4bff32009-01-29 00:07:0696
[email protected]514411fc2008-12-10 22:28:1197 DISALLOW_COPY_AND_ASSIGN(ChannelImpl);
98};
99
100} // namespace IPC
101
[email protected]946d1b22009-07-22 23:57:21102#endif // IPC_IPC_CHANNEL_WIN_H_