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

Side by Side Diff: chrome/common/ipc_sync_message.h

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

Powered by Google App Engine
This is Rietveld 408576698