Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: ipc/ipc_sync_message.h

Issue 2097103002: Revert Mojo-based SyncChannel waiting again (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ipc/ipc_sync_channel.cc ('k') | ipc/ipc_sync_message.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef IPC_IPC_SYNC_MESSAGE_H_ 5 #ifndef IPC_IPC_SYNC_MESSAGE_H_
6 #define IPC_IPC_SYNC_MESSAGE_H_ 6 #define IPC_IPC_SYNC_MESSAGE_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #if defined(OS_WIN) 10 #if defined(OS_WIN)
11 #include <windows.h> 11 #include <windows.h>
12 #endif 12 #endif
13 13
14 #include <memory> 14 #include <memory>
15 #include <string> 15 #include <string>
16 16
17 #include "build/build_config.h" 17 #include "build/build_config.h"
18 #include "ipc/ipc_message.h" 18 #include "ipc/ipc_message.h"
19 19
20 namespace base {
21 class WaitableEvent;
22 }
23
20 namespace IPC { 24 namespace IPC {
21 25
22 class MessageReplyDeserializer; 26 class MessageReplyDeserializer;
23 class MojoEvent;
24 27
25 class IPC_EXPORT SyncMessage : public Message { 28 class IPC_EXPORT SyncMessage : public Message {
26 public: 29 public:
27 SyncMessage(int32_t routing_id, 30 SyncMessage(int32_t routing_id,
28 uint32_t type, 31 uint32_t type,
29 PriorityValue priority, 32 PriorityValue priority,
30 MessageReplyDeserializer* deserializer); 33 MessageReplyDeserializer* deserializer);
31 ~SyncMessage() override; 34 ~SyncMessage() override;
32 35
33 // Call this to get a deserializer for the output parameters. 36 // Call this to get a deserializer for the output parameters.
34 // Note that this can only be called once, and the caller is responsible 37 // Note that this can only be called once, and the caller is responsible
35 // for deleting the deserializer when they're done. 38 // for deleting the deserializer when they're done.
36 MessageReplyDeserializer* GetReplyDeserializer(); 39 MessageReplyDeserializer* GetReplyDeserializer();
37 40
38 // If this message can cause the receiver to block while waiting for user 41 // If this message can cause the receiver to block while waiting for user
39 // input (i.e. by calling MessageBox), then the caller needs to pump window 42 // input (i.e. by calling MessageBox), then the caller needs to pump window
40 // messages and dispatch asynchronous messages while waiting for the reply. 43 // messages and dispatch asynchronous messages while waiting for the reply.
41 // This call enables message pumping behavior while waiting for a reply to 44 // If this event is passed in, then window messages will start being pumped
42 // this message. 45 // when it's set. Note that this behavior will continue even if the event is
43 void EnableMessagePumping() { 46 // later reset. The event must be valid until after the Send call returns.
44 header()->flags |= PUMPING_MSGS_BIT; 47 void set_pump_messages_event(base::WaitableEvent* event) {
48 pump_messages_event_ = event;
49 if (event) {
50 header()->flags |= PUMPING_MSGS_BIT;
51 } else {
52 header()->flags &= ~PUMPING_MSGS_BIT;
53 }
45 } 54 }
46 55
47 // Indicates whether window messages should be pumped while waiting for a 56 // Call this if you always want to pump messages. You can call this method
48 // reply to this message. 57 // or set_pump_messages_event but not both.
49 bool ShouldPumpMessages() const { 58 void EnableMessagePumping();
50 return (header()->flags & PUMPING_MSGS_BIT) != 0; 59
60 base::WaitableEvent* pump_messages_event() const {
61 return pump_messages_event_;
51 } 62 }
52 63
53 // Returns true if the message is a reply to the given request id. 64 // Returns true if the message is a reply to the given request id.
54 static bool IsMessageReplyTo(const Message& msg, int request_id); 65 static bool IsMessageReplyTo(const Message& msg, int request_id);
55 66
56 // Given a reply message, returns an iterator to the beginning of the data 67 // Given a reply message, returns an iterator to the beginning of the data
57 // (i.e. skips over the synchronous specific data). 68 // (i.e. skips over the synchronous specific data).
58 static base::PickleIterator GetDataIterator(const Message* msg); 69 static base::PickleIterator GetDataIterator(const Message* msg);
59 70
60 // Given a synchronous message (or its reply), returns its id. 71 // Given a synchronous message (or its reply), returns its id.
61 static int GetMessageId(const Message& msg); 72 static int GetMessageId(const Message& msg);
62 73
63 // Generates a reply message to the given message. 74 // Generates a reply message to the given message.
64 static Message* GenerateReply(const Message* msg); 75 static Message* GenerateReply(const Message* msg);
65 76
66 private: 77 private:
67 struct SyncHeader { 78 struct SyncHeader {
68 // unique ID (unique per sender) 79 // unique ID (unique per sender)
69 int message_id; 80 int message_id;
70 }; 81 };
71 82
72 static bool ReadSyncHeader(const Message& msg, SyncHeader* header); 83 static bool ReadSyncHeader(const Message& msg, SyncHeader* header);
73 static bool WriteSyncHeader(Message* msg, const SyncHeader& header); 84 static bool WriteSyncHeader(Message* msg, const SyncHeader& header);
74 85
75 std::unique_ptr<MessageReplyDeserializer> deserializer_; 86 std::unique_ptr<MessageReplyDeserializer> deserializer_;
87 base::WaitableEvent* pump_messages_event_;
76 }; 88 };
77 89
78 // Used to deserialize parameters from a reply to a synchronous message 90 // Used to deserialize parameters from a reply to a synchronous message
79 class IPC_EXPORT MessageReplyDeserializer { 91 class IPC_EXPORT MessageReplyDeserializer {
80 public: 92 public:
81 virtual ~MessageReplyDeserializer() {} 93 virtual ~MessageReplyDeserializer() {}
82 bool SerializeOutputParameters(const Message& msg); 94 bool SerializeOutputParameters(const Message& msg);
83 private: 95 private:
84 // Derived classes need to implement this, using the given iterator (which 96 // Derived classes need to implement this, using the given iterator (which
85 // is skipped past the header for synchronous messages). 97 // is skipped past the header for synchronous messages).
86 virtual bool SerializeOutputParameters(const Message& msg, 98 virtual bool SerializeOutputParameters(const Message& msg,
87 base::PickleIterator iter) = 0; 99 base::PickleIterator iter) = 0;
88 }; 100 };
89 101
90 // When sending a synchronous message, this structure contains an object 102 // When sending a synchronous message, this structure contains an object
91 // that knows how to deserialize the response. 103 // that knows how to deserialize the response.
92 struct PendingSyncMsg { 104 struct PendingSyncMsg {
93 PendingSyncMsg(int id, MessageReplyDeserializer* d, MojoEvent* e) 105 PendingSyncMsg(int id,
106 MessageReplyDeserializer* d,
107 base::WaitableEvent* e)
94 : id(id), deserializer(d), done_event(e), send_result(false) { } 108 : id(id), deserializer(d), done_event(e), send_result(false) { }
95
96 int id; 109 int id;
97 MessageReplyDeserializer* deserializer; 110 MessageReplyDeserializer* deserializer;
98 MojoEvent* done_event; 111 base::WaitableEvent* done_event;
99 bool send_result; 112 bool send_result;
100 }; 113 };
101 114
102 } // namespace IPC 115 } // namespace IPC
103 116
104 #endif // IPC_IPC_SYNC_MESSAGE_H_ 117 #endif // IPC_IPC_SYNC_MESSAGE_H_
OLDNEW
« no previous file with comments | « ipc/ipc_sync_channel.cc ('k') | ipc/ipc_sync_message.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698