OLD | NEW |
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 #include "ipc/ipc_message.h" | 5 #include "ipc/ipc_message.h" |
6 | 6 |
7 #include "base/atomic_sequence_num.h" | 7 #include "base/atomic_sequence_num.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 #include "ipc/ipc_message_attachment.h" | 10 #include "ipc/ipc_message_attachment.h" |
11 #include "ipc/ipc_message_attachment_set.h" | 11 #include "ipc/ipc_message_attachment_set.h" |
12 | 12 |
13 #if defined(OS_POSIX) | 13 #if defined(OS_POSIX) |
14 #include "base/file_descriptor_posix.h" | 14 #include "base/file_descriptor_posix.h" |
15 #include "ipc/ipc_platform_file_attachment_posix.h" | 15 #include "ipc/ipc_platform_file_attachment_posix.h" |
16 #endif | 16 #endif |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 base::StaticAtomicSequenceNumber g_ref_num; | 20 base::StaticAtomicSequenceNumber g_ref_num; |
21 | 21 |
22 // Create a reference number for identifying IPC messages in traces. The return | 22 // Create a reference number for identifying IPC messages in traces. The return |
23 // values has the reference number stored in the upper 24 bits, leaving the low | 23 // values has the reference number stored in the upper 24 bits, leaving the low |
24 // 8 bits set to 0 for use as flags. | 24 // 8 bits set to 0 for use as flags. |
25 inline uint32 GetRefNumUpper24() { | 25 inline uint32_t GetRefNumUpper24() { |
26 base::trace_event::TraceLog* trace_log = | 26 base::trace_event::TraceLog* trace_log = |
27 base::trace_event::TraceLog::GetInstance(); | 27 base::trace_event::TraceLog::GetInstance(); |
28 uint32 pid = trace_log ? trace_log->process_id() : 0; | 28 uint32_t pid = trace_log ? trace_log->process_id() : 0; |
29 uint32 count = g_ref_num.GetNext(); | 29 uint32_t count = g_ref_num.GetNext(); |
30 // The 24 bit hash is composed of 14 bits of the count and 10 bits of the | 30 // The 24 bit hash is composed of 14 bits of the count and 10 bits of the |
31 // Process ID. With the current trace event buffer cap, the 14-bit count did | 31 // Process ID. With the current trace event buffer cap, the 14-bit count did |
32 // not appear to wrap during a trace. Note that it is not a big deal if | 32 // not appear to wrap during a trace. Note that it is not a big deal if |
33 // collisions occur, as this is only used for debugging and trace analysis. | 33 // collisions occur, as this is only used for debugging and trace analysis. |
34 return ((pid << 14) | (count & 0x3fff)) << 8; | 34 return ((pid << 14) | (count & 0x3fff)) << 8; |
35 } | 35 } |
36 | 36 |
37 } // namespace | 37 } // namespace |
38 | 38 |
39 namespace IPC { | 39 namespace IPC { |
40 | 40 |
41 //------------------------------------------------------------------------------ | 41 //------------------------------------------------------------------------------ |
42 | 42 |
43 Message::~Message() { | 43 Message::~Message() { |
44 } | 44 } |
45 | 45 |
46 Message::Message() : base::Pickle(sizeof(Header)) { | 46 Message::Message() : base::Pickle(sizeof(Header)) { |
47 header()->routing = header()->type = 0; | 47 header()->routing = header()->type = 0; |
48 header()->flags = GetRefNumUpper24(); | 48 header()->flags = GetRefNumUpper24(); |
49 #if defined(OS_POSIX) | 49 #if defined(OS_POSIX) |
50 header()->num_fds = 0; | 50 header()->num_fds = 0; |
51 header()->pad = 0; | 51 header()->pad = 0; |
52 #endif | 52 #endif |
53 Init(); | 53 Init(); |
54 } | 54 } |
55 | 55 |
56 Message::Message(int32 routing_id, uint32 type, PriorityValue priority) | 56 Message::Message(int32_t routing_id, uint32_t type, PriorityValue priority) |
57 : base::Pickle(sizeof(Header)) { | 57 : base::Pickle(sizeof(Header)) { |
58 header()->routing = routing_id; | 58 header()->routing = routing_id; |
59 header()->type = type; | 59 header()->type = type; |
60 DCHECK((priority & 0xffffff00) == 0); | 60 DCHECK((priority & 0xffffff00) == 0); |
61 header()->flags = priority | GetRefNumUpper24(); | 61 header()->flags = priority | GetRefNumUpper24(); |
62 #if defined(OS_POSIX) | 62 #if defined(OS_POSIX) |
63 header()->num_fds = 0; | 63 header()->num_fds = 0; |
64 header()->pad = 0; | 64 header()->pad = 0; |
65 #endif | 65 #endif |
66 Init(); | 66 Init(); |
(...skipping 18 matching lines...) Expand all Loading... |
85 log_data_ = NULL; | 85 log_data_ = NULL; |
86 #endif | 86 #endif |
87 } | 87 } |
88 | 88 |
89 Message& Message::operator=(const Message& other) { | 89 Message& Message::operator=(const Message& other) { |
90 *static_cast<base::Pickle*>(this) = other; | 90 *static_cast<base::Pickle*>(this) = other; |
91 attachment_set_ = other.attachment_set_; | 91 attachment_set_ = other.attachment_set_; |
92 return *this; | 92 return *this; |
93 } | 93 } |
94 | 94 |
95 void Message::SetHeaderValues(int32 routing, uint32 type, uint32 flags) { | 95 void Message::SetHeaderValues(int32_t routing, uint32_t type, uint32_t flags) { |
96 // This should only be called when the message is already empty. | 96 // This should only be called when the message is already empty. |
97 DCHECK(payload_size() == 0); | 97 DCHECK(payload_size() == 0); |
98 | 98 |
99 header()->routing = routing; | 99 header()->routing = routing; |
100 header()->type = type; | 100 header()->type = type; |
101 header()->flags = flags; | 101 header()->flags = flags; |
102 } | 102 } |
103 | 103 |
104 void Message::EnsureMessageAttachmentSet() { | 104 void Message::EnsureMessageAttachmentSet() { |
105 if (attachment_set_.get() == NULL) | 105 if (attachment_set_.get() == NULL) |
106 attachment_set_ = new MessageAttachmentSet; | 106 attachment_set_ = new MessageAttachmentSet; |
107 } | 107 } |
108 | 108 |
109 #ifdef IPC_MESSAGE_LOG_ENABLED | 109 #ifdef IPC_MESSAGE_LOG_ENABLED |
110 void Message::set_sent_time(int64 time) { | 110 void Message::set_sent_time(int64_t time) { |
111 DCHECK((header()->flags & HAS_SENT_TIME_BIT) == 0); | 111 DCHECK((header()->flags & HAS_SENT_TIME_BIT) == 0); |
112 header()->flags |= HAS_SENT_TIME_BIT; | 112 header()->flags |= HAS_SENT_TIME_BIT; |
113 WriteInt64(time); | 113 WriteInt64(time); |
114 } | 114 } |
115 | 115 |
116 int64 Message::sent_time() const { | 116 int64_t Message::sent_time() const { |
117 if ((header()->flags & HAS_SENT_TIME_BIT) == 0) | 117 if ((header()->flags & HAS_SENT_TIME_BIT) == 0) |
118 return 0; | 118 return 0; |
119 | 119 |
120 const char* data = end_of_payload(); | 120 const char* data = end_of_payload(); |
121 data -= sizeof(int64); | 121 data -= sizeof(int64_t); |
122 return *(reinterpret_cast<const int64*>(data)); | 122 return *(reinterpret_cast<const int64_t*>(data)); |
123 } | 123 } |
124 | 124 |
125 void Message::set_received_time(int64 time) const { | 125 void Message::set_received_time(int64_t time) const { |
126 received_time_ = time; | 126 received_time_ = time; |
127 } | 127 } |
128 #endif | 128 #endif |
129 | 129 |
130 bool Message::WriteAttachment(scoped_refptr<MessageAttachment> attachment) { | 130 bool Message::WriteAttachment(scoped_refptr<MessageAttachment> attachment) { |
131 // We write the index of the descriptor so that we don't have to | 131 // We write the index of the descriptor so that we don't have to |
132 // keep the current descriptor as extra decoding state when deserialising. | 132 // keep the current descriptor as extra decoding state when deserialising. |
133 WriteInt(attachment_set()->size()); | 133 WriteInt(attachment_set()->size()); |
134 return attachment_set()->AddAttachment(attachment); | 134 return attachment_set()->AddAttachment(attachment); |
135 } | 135 } |
(...skipping 20 matching lines...) Expand all Loading... |
156 bool Message::HasMojoHandles() const { | 156 bool Message::HasMojoHandles() const { |
157 return attachment_set_.get() && attachment_set_->num_mojo_handles() > 0; | 157 return attachment_set_.get() && attachment_set_->num_mojo_handles() > 0; |
158 } | 158 } |
159 | 159 |
160 bool Message::HasBrokerableAttachments() const { | 160 bool Message::HasBrokerableAttachments() const { |
161 return attachment_set_.get() && | 161 return attachment_set_.get() && |
162 attachment_set_->num_brokerable_attachments() > 0; | 162 attachment_set_->num_brokerable_attachments() > 0; |
163 } | 163 } |
164 | 164 |
165 } // namespace IPC | 165 } // namespace IPC |
OLD | NEW |