Initialize Tizen 2.3
[external/chromium.git] / ipc / ipc_sync_message_filter.h
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.
4
5 #ifndef IPC_IPC_SYNC_MESSAGE_FILTER_H_
6 #define IPC_IPC_SYNC_MESSAGE_FILTER_H_
7 #pragma once
8
9 #include "base/basictypes.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/synchronization/lock.h"
12 #include "ipc/ipc_channel_proxy.h"
13 #include "ipc/ipc_sync_message.h"
14 #include <set>
15
16 namespace base {
17 class WaitableEvent;
18 }
19
20 class MessageLoop;
21
22 namespace IPC {
23
24 class MessageReplyDeserializer;
25
26 // This MessageFilter allows sending synchronous IPC messages from a thread
27 // other than the listener thread associated with the SyncChannel.  It does not
28 // support fancy features that SyncChannel does, such as handling recursion or
29 // receiving messages while waiting for a response.  Note that this object can
30 // be used to send simultaneous synchronous messages from different threads.
31 class IPC_EXPORT SyncMessageFilter : public ChannelProxy::MessageFilter,
32                                      public Message::Sender {
33  public:
34   explicit SyncMessageFilter(base::WaitableEvent* shutdown_event);
35   virtual ~SyncMessageFilter();
36
37   // Message::Sender implementation.
38   virtual bool Send(Message* message);
39
40   // ChannelProxy::MessageFilter implementation.
41   virtual void OnFilterAdded(Channel* channel);
42   virtual void OnChannelError();
43   virtual void OnChannelClosing();
44   virtual bool OnMessageReceived(const Message& message);
45
46  private:
47   void SendOnIOThread(Message* message);
48   // Signal all the pending sends as done, used in an error condition.
49   void SignalAllEvents();
50
51   // The channel to which this filter was added.
52   Channel* channel_;
53
54   MessageLoop* listener_loop_;  // The process's main thread.
55   MessageLoop* io_loop_;  // The message loop where the Channel lives.
56
57   typedef std::set<PendingSyncMsg*> PendingSyncMessages;
58   PendingSyncMessages pending_sync_messages_;
59
60   // Locks data members above.
61   base::Lock lock_;
62
63   base::WaitableEvent* shutdown_event_;
64
65   DISALLOW_COPY_AND_ASSIGN(SyncMessageFilter);
66 };
67
68 }  // namespace IPC
69
70 #endif  // IPC_IPC_SYNC_MESSAGE_FILTER_H_