OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "mojo/public/cpp/bindings/message.h" | 5 #include "mojo/public/cpp/bindings/message.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 | 10 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 payload_end = reinterpret_cast<uintptr_t>(data() + data_num_bytes()); | 99 payload_end = reinterpret_cast<uintptr_t>(data() + data_num_bytes()); |
100 DCHECK_GE(payload_end, payload); | 100 DCHECK_GE(payload_end, payload); |
101 num_bytes = payload_end - payload; | 101 num_bytes = payload_end - payload; |
102 } | 102 } |
103 } | 103 } |
104 DCHECK_LE(num_bytes, std::numeric_limits<uint32_t>::max()); | 104 DCHECK_LE(num_bytes, std::numeric_limits<uint32_t>::max()); |
105 return static_cast<uint32_t>(num_bytes); | 105 return static_cast<uint32_t>(num_bytes); |
106 } | 106 } |
107 | 107 |
108 uint32_t Message::payload_num_interface_ids() const { | 108 uint32_t Message::payload_num_interface_ids() const { |
109 auto array_pointer = | 109 auto* array_pointer = |
110 version() < 2 ? nullptr : header_v2()->payload_interface_ids.Get(); | 110 version() < 2 ? nullptr : header_v2()->payload_interface_ids.Get(); |
111 return array_pointer ? static_cast<uint32_t>(array_pointer->size()) : 0; | 111 return array_pointer ? static_cast<uint32_t>(array_pointer->size()) : 0; |
112 } | 112 } |
113 | 113 |
114 const uint32_t* Message::payload_interface_ids() const { | 114 const uint32_t* Message::payload_interface_ids() const { |
115 auto array_pointer = | 115 auto* array_pointer = |
116 version() < 2 ? nullptr : header_v2()->payload_interface_ids.Get(); | 116 version() < 2 ? nullptr : header_v2()->payload_interface_ids.Get(); |
117 return array_pointer ? array_pointer->storage() : nullptr; | 117 return array_pointer ? array_pointer->storage() : nullptr; |
118 } | 118 } |
119 | 119 |
120 ScopedMessageHandle Message::TakeMojoMessage() { | 120 ScopedMessageHandle Message::TakeMojoMessage() { |
121 // If there are associated endpoints transferred, | 121 // If there are associated endpoints transferred, |
122 // SerializeAssociatedEndpointHandles() must be called before this method. | 122 // SerializeAssociatedEndpointHandles() must be called before this method. |
123 DCHECK(associated_endpoint_handles_.empty()); | 123 DCHECK(associated_endpoint_handles_.empty()); |
124 | 124 |
125 if (handles_.empty()) // Fast path for the common case: No handles. | 125 if (handles_.empty()) // Fast path for the common case: No handles. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 | 167 |
168 void Message::SerializeAssociatedEndpointHandles( | 168 void Message::SerializeAssociatedEndpointHandles( |
169 AssociatedGroupController* group_controller) { | 169 AssociatedGroupController* group_controller) { |
170 if (associated_endpoint_handles_.empty()) | 170 if (associated_endpoint_handles_.empty()) |
171 return; | 171 return; |
172 | 172 |
173 DCHECK_GE(version(), 2u); | 173 DCHECK_GE(version(), 2u); |
174 DCHECK(header_v2()->payload_interface_ids.is_null()); | 174 DCHECK(header_v2()->payload_interface_ids.is_null()); |
175 | 175 |
176 size_t size = associated_endpoint_handles_.size(); | 176 size_t size = associated_endpoint_handles_.size(); |
177 auto data = internal::Array_Data<uint32_t>::New(size, buffer()); | 177 auto* data = internal::Array_Data<uint32_t>::New(size, buffer()); |
178 header_v2()->payload_interface_ids.Set(data); | 178 header_v2()->payload_interface_ids.Set(data); |
179 | 179 |
180 for (size_t i = 0; i < size; ++i) { | 180 for (size_t i = 0; i < size; ++i) { |
181 ScopedInterfaceEndpointHandle& handle = associated_endpoint_handles_[i]; | 181 ScopedInterfaceEndpointHandle& handle = associated_endpoint_handles_[i]; |
182 | 182 |
183 DCHECK(handle.is_valid()); | 183 DCHECK(handle.is_valid()); |
184 DCHECK(!handle.is_local()); | 184 DCHECK(!handle.is_local()); |
185 DCHECK_EQ(group_controller, handle.group_controller()); | 185 DCHECK_EQ(group_controller, handle.group_controller()); |
186 data->storage()[i] = handle.release(); | 186 data->storage()[i] = handle.release(); |
187 } | 187 } |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 // static | 324 // static |
325 void SyncMessageResponseSetup::SetCurrentSyncResponseMessage(Message* message) { | 325 void SyncMessageResponseSetup::SetCurrentSyncResponseMessage(Message* message) { |
326 SyncMessageResponseContext* context = SyncMessageResponseContext::current(); | 326 SyncMessageResponseContext* context = SyncMessageResponseContext::current(); |
327 if (context) | 327 if (context) |
328 context->response_ = std::move(*message); | 328 context->response_ = std::move(*message); |
329 } | 329 } |
330 | 330 |
331 } // namespace internal | 331 } // namespace internal |
332 | 332 |
333 } // namespace mojo | 333 } // namespace mojo |
OLD | NEW |