[rAc Android] Disallow insecure dialog invocations.
[chromium-blink-merge.git] / ipc / ipc_channel_win.h
blob711f57fde72075cc9daf03876d189fc75813086a
1 // Copyright (c) 2012 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_
8 #include "ipc/ipc_channel.h"
10 #include <queue>
11 #include <string>
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/message_loop/message_loop.h"
16 #include "ipc/ipc_channel_reader.h"
18 namespace base {
19 class ThreadChecker;
22 namespace IPC {
24 class Channel::ChannelImpl : public internal::ChannelReader,
25 public base::MessageLoopForIO::IOHandler {
26 public:
27 // Mirror methods of Channel, see ipc_channel.h for description.
28 ChannelImpl(const IPC::ChannelHandle &channel_handle, Mode mode,
29 Listener* listener);
30 ~ChannelImpl();
31 bool Connect();
32 void Close();
33 bool Send(Message* message);
34 static bool IsNamedServerInitialized(const std::string& channel_id);
35 base::ProcessId peer_pid() const { return peer_pid_; }
37 private:
38 // 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;
46 static const string16 PipeName(const std::string& channel_id,
47 int32* secret);
48 bool CreatePipe(const IPC::ChannelHandle &channel_handle, Mode mode);
50 bool ProcessConnection();
51 bool ProcessOutgoingMessages(base::MessageLoopForIO::IOContext* context,
52 DWORD bytes_written);
54 // MessageLoop::IOHandler implementation.
55 virtual void OnIOCompleted(base::MessageLoopForIO::IOContext* context,
56 DWORD bytes_transfered,
57 DWORD error);
59 private:
60 struct State {
61 explicit State(ChannelImpl* channel);
62 ~State();
63 base::MessageLoopForIO::IOContext context;
64 bool is_pending;
67 State input_state_;
68 State output_state_;
70 HANDLE pipe_;
72 base::ProcessId peer_pid_;
74 // Messages to be sent are queued here.
75 std::queue<Message*> output_queue_;
77 // In server-mode, we have to wait for the client to connect before we
78 // can begin reading. We make use of the input_state_ when performing
79 // the connect operation in overlapped mode.
80 bool waiting_connect_;
82 // This flag is set when processing incoming messages. It is used to
83 // avoid recursing through ProcessIncomingMessages, which could cause
84 // problems. TODO(darin): make this unnecessary
85 bool processing_incoming_;
87 // Determines if we should validate a client's secret on connection.
88 bool validate_client_;
90 // This is a unique per-channel value used to authenticate the client end of
91 // a connection. If the value is non-zero, the client passes it in the hello
92 // and the host validates. (We don't send the zero value fto preserve IPC
93 // compatability with existing clients that don't validate the channel.)
94 int32 client_secret_;
97 base::WeakPtrFactory<ChannelImpl> weak_factory_;
99 scoped_ptr<base::ThreadChecker> thread_check_;
101 DISALLOW_COPY_AND_ASSIGN(ChannelImpl);
104 } // namespace IPC
106 #endif // IPC_IPC_CHANNEL_WIN_H_