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/edk/system/message_in_transit.h" | 5 #include "mojo/edk/system/message_in_transit.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <ostream> | 9 #include <utility> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "mojo/edk/system/configuration.h" | 12 #include "mojo/edk/system/configuration.h" |
13 #include "mojo/edk/system/transport_data.h" | 13 #include "mojo/edk/system/transport_data.h" |
14 | 14 |
15 namespace mojo { | 15 namespace mojo { |
16 namespace system { | 16 namespace system { |
17 | 17 |
18 MOJO_STATIC_CONST_MEMBER_DEFINITION const size_t | 18 MOJO_STATIC_CONST_MEMBER_DEFINITION const size_t |
19 MessageInTransit::kMessageAlignment; | 19 MessageInTransit::kMessageAlignment; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 if (buffer_size < sizeof(Header)) | 137 if (buffer_size < sizeof(Header)) |
138 return false; | 138 return false; |
139 | 139 |
140 const Header* header = static_cast<const Header*>(buffer); | 140 const Header* header = static_cast<const Header*>(buffer); |
141 *next_message_size = header->total_size; | 141 *next_message_size = header->total_size; |
142 DCHECK_EQ(*next_message_size % kMessageAlignment, 0u); | 142 DCHECK_EQ(*next_message_size % kMessageAlignment, 0u); |
143 return true; | 143 return true; |
144 } | 144 } |
145 | 145 |
146 void MessageInTransit::SetDispatchers( | 146 void MessageInTransit::SetDispatchers( |
147 scoped_ptr<DispatcherVector> dispatchers) { | 147 std::unique_ptr<DispatcherVector> dispatchers) { |
148 DCHECK(dispatchers); | 148 DCHECK(dispatchers); |
149 DCHECK(!dispatchers_); | 149 DCHECK(!dispatchers_); |
150 DCHECK(!transport_data_); | 150 DCHECK(!transport_data_); |
151 | 151 |
152 dispatchers_ = dispatchers.Pass(); | 152 dispatchers_ = std::move(dispatchers); |
153 #ifndef NDEBUG | 153 #ifndef NDEBUG |
154 for (size_t i = 0; i < dispatchers_->size(); i++) | 154 for (size_t i = 0; i < dispatchers_->size(); i++) |
155 DCHECK(!(*dispatchers_)[i] || (*dispatchers_)[i]->HasOneRef()); | 155 DCHECK(!(*dispatchers_)[i] || (*dispatchers_)[i]->HasOneRef()); |
156 #endif | 156 #endif |
157 } | 157 } |
158 | 158 |
159 void MessageInTransit::SetTransportData( | 159 void MessageInTransit::SetTransportData( |
160 scoped_ptr<TransportData> transport_data) { | 160 std::unique_ptr<TransportData> transport_data) { |
161 DCHECK(transport_data); | 161 DCHECK(transport_data); |
162 DCHECK(!transport_data_); | 162 DCHECK(!transport_data_); |
163 DCHECK(!dispatchers_); | 163 DCHECK(!dispatchers_); |
164 | 164 |
165 transport_data_ = transport_data.Pass(); | 165 transport_data_ = std::move(transport_data); |
166 UpdateTotalSize(); | 166 UpdateTotalSize(); |
167 } | 167 } |
168 | 168 |
169 void MessageInTransit::SerializeAndCloseDispatchers(Channel* channel) { | 169 void MessageInTransit::SerializeAndCloseDispatchers(Channel* channel) { |
170 DCHECK(channel); | 170 DCHECK(channel); |
171 DCHECK(!transport_data_); | 171 DCHECK(!transport_data_); |
172 | 172 |
173 if (!dispatchers_ || !dispatchers_->size()) | 173 if (!dispatchers_ || !dispatchers_->size()) |
174 return; | 174 return; |
175 | 175 |
176 transport_data_.reset(new TransportData(dispatchers_.Pass(), channel)); | 176 transport_data_.reset(new TransportData(std::move(dispatchers_), channel)); |
177 | 177 |
178 // Update the sizes in the message header. | 178 // Update the sizes in the message header. |
179 UpdateTotalSize(); | 179 UpdateTotalSize(); |
180 } | 180 } |
181 | 181 |
182 void MessageInTransit::ConstructorHelper(Type type, | 182 void MessageInTransit::ConstructorHelper(Type type, |
183 Subtype subtype, | 183 Subtype subtype, |
184 uint32_t num_bytes) { | 184 uint32_t num_bytes) { |
185 DCHECK_LE(num_bytes, GetConfiguration().max_message_num_bytes); | 185 DCHECK_LE(num_bytes, GetConfiguration().max_message_num_bytes); |
186 | 186 |
(...skipping 13 matching lines...) Expand all Loading... |
200 DCHECK_EQ(main_buffer_size_ % kMessageAlignment, 0u); | 200 DCHECK_EQ(main_buffer_size_ % kMessageAlignment, 0u); |
201 header()->total_size = static_cast<uint32_t>(main_buffer_size_); | 201 header()->total_size = static_cast<uint32_t>(main_buffer_size_); |
202 if (transport_data_) { | 202 if (transport_data_) { |
203 header()->total_size += | 203 header()->total_size += |
204 static_cast<uint32_t>(transport_data_->buffer_size()); | 204 static_cast<uint32_t>(transport_data_->buffer_size()); |
205 } | 205 } |
206 } | 206 } |
207 | 207 |
208 } // namespace system | 208 } // namespace system |
209 } // namespace mojo | 209 } // namespace mojo |
OLD | NEW |