Added histograms for default search provider protection. Removed protection
[chromium-blink-merge.git] / ipc / ipc_sync_message.h
blob087df0d9b5bb0254793d0685f74bda6ca2ae1872
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_SYNC_MESSAGE_H_
6 #define IPC_IPC_SYNC_MESSAGE_H_
7 #pragma once
9 #if defined(OS_WIN)
10 #include <windows.h>
11 #endif
12 #include <string>
13 #include "base/basictypes.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "ipc/ipc_message.h"
17 namespace base {
18 class WaitableEvent;
21 namespace IPC {
23 class MessageReplyDeserializer;
25 class IPC_EXPORT SyncMessage : public Message {
26 public:
27 SyncMessage(int32 routing_id, uint32 type, PriorityValue priority,
28 MessageReplyDeserializer* deserializer);
29 virtual ~SyncMessage();
31 // Call this to get a deserializer for the output parameters.
32 // Note that this can only be called once, and the caller is responsible
33 // for deleting the deserializer when they're done.
34 MessageReplyDeserializer* GetReplyDeserializer();
36 // If this message can cause the receiver to block while waiting for user
37 // input (i.e. by calling MessageBox), then the caller needs to pump window
38 // messages and dispatch asynchronous messages while waiting for the reply.
39 // If this event is passed in, then window messages will start being pumped
40 // when it's set. Note that this behavior will continue even if the event is
41 // later reset. The event must be valid until after the Send call returns.
42 void set_pump_messages_event(base::WaitableEvent* event) {
43 pump_messages_event_ = event;
44 if (event) {
45 header()->flags |= PUMPING_MSGS_BIT;
46 } else {
47 header()->flags &= ~PUMPING_MSGS_BIT;
51 // Call this if you always want to pump messages. You can call this method
52 // or set_pump_messages_event but not both.
53 void EnableMessagePumping();
55 base::WaitableEvent* pump_messages_event() const {
56 return pump_messages_event_;
59 // Returns true if the message is a reply to the given request id.
60 static bool IsMessageReplyTo(const Message& msg, int request_id);
62 // Given a reply message, returns an iterator to the beginning of the data
63 // (i.e. skips over the synchronous specific data).
64 static void* GetDataIterator(const Message* msg);
66 // Given a synchronous message (or its reply), returns its id.
67 static int GetMessageId(const Message& msg);
69 // Generates a reply message to the given message.
70 static Message* GenerateReply(const Message* msg);
72 private:
73 struct SyncHeader {
74 // unique ID (unique per sender)
75 int message_id;
78 static bool ReadSyncHeader(const Message& msg, SyncHeader* header);
79 static bool WriteSyncHeader(Message* msg, const SyncHeader& header);
81 scoped_ptr<MessageReplyDeserializer> deserializer_;
82 base::WaitableEvent* pump_messages_event_;
85 // Used to deserialize parameters from a reply to a synchronous message
86 class IPC_EXPORT MessageReplyDeserializer {
87 public:
88 virtual ~MessageReplyDeserializer() {}
89 bool SerializeOutputParameters(const Message& msg);
90 private:
91 // Derived classes need to implement this, using the given iterator (which
92 // is skipped past the header for synchronous messages).
93 virtual bool SerializeOutputParameters(const Message& msg, void* iter) = 0;
96 // When sending a synchronous message, this structure contains an object
97 // that knows how to deserialize the response.
98 struct PendingSyncMsg {
99 PendingSyncMsg(int id,
100 MessageReplyDeserializer* d,
101 base::WaitableEvent* e)
102 : id(id), deserializer(d), done_event(e), send_result(false) { }
103 int id;
104 MessageReplyDeserializer* deserializer;
105 base::WaitableEvent* done_event;
106 bool send_result;
109 } // namespace IPC
111 #endif // IPC_IPC_SYNC_MESSAGE_H_