dbus: Property<>.value() should be const
[chromium-blink-merge.git] / ipc / ipc_channel_win.h
blob77bc119bc197c28e13f86aef10c1c77f91f6db79
1 // Copyright (c) 2011 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_
7 #pragma once
9 #include "ipc/ipc_channel.h"
11 #include <queue>
12 #include <string>
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "base/message_loop.h"
18 namespace base {
19 class NonThreadSafe;
22 namespace IPC {
24 class Channel::ChannelImpl : public MessageLoopForIO::IOHandler {
25 public:
26 // Mirror methods of Channel, see ipc_channel.h for description.
27 ChannelImpl(const IPC::ChannelHandle &channel_handle, Mode mode,
28 Listener* listener);
29 ~ChannelImpl();
30 bool Connect();
31 void Close();
32 void set_listener(Listener* listener) { listener_ = listener; }
33 bool Send(Message* message);
34 static bool IsNamedServerInitialized(const std::string& channel_id);
35 private:
36 static const std::wstring PipeName(const std::string& channel_id);
37 bool CreatePipe(const IPC::ChannelHandle &channel_handle, Mode mode);
39 bool ProcessConnection();
40 bool ProcessIncomingMessages(MessageLoopForIO::IOContext* context,
41 DWORD bytes_read);
42 bool ProcessOutgoingMessages(MessageLoopForIO::IOContext* context,
43 DWORD bytes_written);
45 // MessageLoop::IOHandler implementation.
46 virtual void OnIOCompleted(MessageLoopForIO::IOContext* context,
47 DWORD bytes_transfered, DWORD error);
48 private:
49 struct State {
50 explicit State(ChannelImpl* channel);
51 ~State();
52 MessageLoopForIO::IOContext context;
53 bool is_pending;
56 State input_state_;
57 State output_state_;
59 HANDLE pipe_;
61 Listener* listener_;
63 // Messages to be sent are queued here.
64 std::queue<Message*> output_queue_;
66 // We read from the pipe into this buffer
67 char input_buf_[Channel::kReadBufferSize];
69 // Large messages that span multiple pipe buffers, get built-up using
70 // this buffer.
71 std::string input_overflow_buf_;
73 // 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_;
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_;
83 base::WeakPtrFactory<ChannelImpl> weak_factory_;
85 scoped_ptr<base::NonThreadSafe> thread_check_;
87 DISALLOW_COPY_AND_ASSIGN(ChannelImpl);
90 } // namespace IPC
92 #endif // IPC_IPC_CHANNEL_WIN_H_