Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
michael@0 | 2 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 3 | // found in the LICENSE file. |
michael@0 | 4 | |
michael@0 | 5 | #ifndef CHROME_COMMON_IPC_SYNC_MESSAGE_H__ |
michael@0 | 6 | #define CHROME_COMMON_IPC_SYNC_MESSAGE_H__ |
michael@0 | 7 | |
michael@0 | 8 | #if defined(OS_WIN) |
michael@0 | 9 | #include <windows.h> |
michael@0 | 10 | #endif |
michael@0 | 11 | #include <string> |
michael@0 | 12 | #include "base/basictypes.h" |
michael@0 | 13 | #include "chrome/common/ipc_message.h" |
michael@0 | 14 | |
michael@0 | 15 | namespace base { |
michael@0 | 16 | class WaitableEvent; |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | namespace IPC { |
michael@0 | 20 | |
michael@0 | 21 | class MessageReplyDeserializer; |
michael@0 | 22 | |
michael@0 | 23 | class SyncMessage : public Message { |
michael@0 | 24 | public: |
michael@0 | 25 | SyncMessage(int32_t routing_id, uint16_t type, PriorityValue priority, |
michael@0 | 26 | MessageReplyDeserializer* deserializer); |
michael@0 | 27 | |
michael@0 | 28 | // Call this to get a deserializer for the output parameters. |
michael@0 | 29 | // Note that this can only be called once, and the caller is responsible |
michael@0 | 30 | // for deleting the deserializer when they're done. |
michael@0 | 31 | MessageReplyDeserializer* GetReplyDeserializer(); |
michael@0 | 32 | |
michael@0 | 33 | // If this message can cause the receiver to block while waiting for user |
michael@0 | 34 | // input (i.e. by calling MessageBox), then the caller needs to pump window |
michael@0 | 35 | // messages and dispatch asynchronous messages while waiting for the reply. |
michael@0 | 36 | // If this event is passed in, then window messages will start being pumped |
michael@0 | 37 | // when it's set. Note that this behavior will continue even if the event is |
michael@0 | 38 | // later reset. The event must be valid until after the Send call returns. |
michael@0 | 39 | void set_pump_messages_event(base::WaitableEvent* event) { |
michael@0 | 40 | pump_messages_event_ = event; |
michael@0 | 41 | if (event) { |
michael@0 | 42 | header()->flags |= PUMPING_MSGS_BIT; |
michael@0 | 43 | } else { |
michael@0 | 44 | header()->flags &= ~PUMPING_MSGS_BIT; |
michael@0 | 45 | } |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | // Call this if you always want to pump messages. You can call this method |
michael@0 | 49 | // or set_pump_messages_event but not both. |
michael@0 | 50 | void EnableMessagePumping(); |
michael@0 | 51 | |
michael@0 | 52 | base::WaitableEvent* pump_messages_event() const { |
michael@0 | 53 | return pump_messages_event_; |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | // Returns true if the message is a reply to the given request id. |
michael@0 | 57 | static bool IsMessageReplyTo(const Message& msg, int request_id); |
michael@0 | 58 | |
michael@0 | 59 | // Given a reply message, returns an iterator to the beginning of the data |
michael@0 | 60 | // (i.e. skips over the synchronous specific data). |
michael@0 | 61 | static void* GetDataIterator(const Message* msg); |
michael@0 | 62 | |
michael@0 | 63 | // Given a synchronous message (or its reply), returns its id. |
michael@0 | 64 | static int GetMessageId(const Message& msg); |
michael@0 | 65 | |
michael@0 | 66 | // Generates a reply message to the given message. |
michael@0 | 67 | static Message* GenerateReply(const Message* msg); |
michael@0 | 68 | |
michael@0 | 69 | private: |
michael@0 | 70 | struct SyncHeader { |
michael@0 | 71 | // unique ID (unique per sender) |
michael@0 | 72 | int message_id; |
michael@0 | 73 | }; |
michael@0 | 74 | |
michael@0 | 75 | static bool ReadSyncHeader(const Message& msg, SyncHeader* header); |
michael@0 | 76 | static bool WriteSyncHeader(Message* msg, const SyncHeader& header); |
michael@0 | 77 | |
michael@0 | 78 | MessageReplyDeserializer* deserializer_; |
michael@0 | 79 | base::WaitableEvent* pump_messages_event_; |
michael@0 | 80 | |
michael@0 | 81 | static uint32_t next_id_; // for generation of unique ids |
michael@0 | 82 | }; |
michael@0 | 83 | |
michael@0 | 84 | // Used to deserialize parameters from a reply to a synchronous message |
michael@0 | 85 | class MessageReplyDeserializer { |
michael@0 | 86 | public: |
michael@0 | 87 | bool SerializeOutputParameters(const Message& msg); |
michael@0 | 88 | virtual ~MessageReplyDeserializer() {} |
michael@0 | 89 | private: |
michael@0 | 90 | // Derived classes need to implement this, using the given iterator (which |
michael@0 | 91 | // is skipped past the header for synchronous messages). |
michael@0 | 92 | virtual bool SerializeOutputParameters(const Message& msg, void* iter) = 0; |
michael@0 | 93 | }; |
michael@0 | 94 | |
michael@0 | 95 | } // namespace IPC |
michael@0 | 96 | |
michael@0 | 97 | #endif // CHROME_COMMON_IPC_SYNC_MESSAGE_H__ |