| 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 #ifndef MOJO_EDK_SYSTEM_MESSAGE_IN_TRANSIT_H_ | 5 #ifndef MOJO_EDK_SYSTEM_MESSAGE_IN_TRANSIT_H_ |
| 6 #define MOJO_EDK_SYSTEM_MESSAGE_IN_TRANSIT_H_ | 6 #define MOJO_EDK_SYSTEM_MESSAGE_IN_TRANSIT_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <memory> |
| 11 #include <ostream> | 12 #include <ostream> |
| 12 #include <vector> | 13 #include <vector> |
| 13 | 14 |
| 14 #include "base/memory/aligned_memory.h" | 15 #include "base/memory/aligned_memory.h" |
| 15 #include "base/memory/scoped_ptr.h" | |
| 16 #include "mojo/edk/system/channel_endpoint_id.h" | 16 #include "mojo/edk/system/channel_endpoint_id.h" |
| 17 #include "mojo/edk/system/dispatcher.h" | 17 #include "mojo/edk/system/dispatcher.h" |
| 18 #include "mojo/edk/system/memory.h" | 18 #include "mojo/edk/system/memory.h" |
| 19 #include "mojo/edk/system/system_impl_export.h" | 19 #include "mojo/edk/system/system_impl_export.h" |
| 20 #include "mojo/public/cpp/system/macros.h" | 20 #include "mojo/public/cpp/system/macros.h" |
| 21 | 21 |
| 22 namespace mojo { | 22 namespace mojo { |
| 23 namespace system { | 23 namespace system { |
| 24 | 24 |
| 25 class Channel; | 25 class Channel; |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 // TODO(vtl): In |RawChannelPosix|, the alignment requirements are currently | 181 // TODO(vtl): In |RawChannelPosix|, the alignment requirements are currently |
| 182 // satisified on a faith-based basis. | 182 // satisified on a faith-based basis. |
| 183 static bool GetNextMessageSize(const void* buffer, | 183 static bool GetNextMessageSize(const void* buffer, |
| 184 size_t buffer_size, | 184 size_t buffer_size, |
| 185 size_t* next_message_size); | 185 size_t* next_message_size); |
| 186 | 186 |
| 187 // Makes this message "own" the given set of dispatchers. The dispatchers must | 187 // Makes this message "own" the given set of dispatchers. The dispatchers must |
| 188 // not be referenced from anywhere else (in particular, not from the handle | 188 // not be referenced from anywhere else (in particular, not from the handle |
| 189 // table), i.e., each dispatcher must have a reference count of 1. This | 189 // table), i.e., each dispatcher must have a reference count of 1. This |
| 190 // message must not already have dispatchers. | 190 // message must not already have dispatchers. |
| 191 void SetDispatchers(scoped_ptr<DispatcherVector> dispatchers); | 191 void SetDispatchers(std::unique_ptr<DispatcherVector> dispatchers); |
| 192 | 192 |
| 193 // Sets the |TransportData| for this message. This should only be done when | 193 // Sets the |TransportData| for this message. This should only be done when |
| 194 // there are no dispatchers and no existing |TransportData|. | 194 // there are no dispatchers and no existing |TransportData|. |
| 195 void SetTransportData(scoped_ptr<TransportData> transport_data); | 195 void SetTransportData(std::unique_ptr<TransportData> transport_data); |
| 196 | 196 |
| 197 // Serializes any dispatchers to the secondary buffer. This message must not | 197 // Serializes any dispatchers to the secondary buffer. This message must not |
| 198 // already have a secondary buffer (so this must only be called once). The | 198 // already have a secondary buffer (so this must only be called once). The |
| 199 // caller must ensure (e.g., by holding on to a reference) that |channel| | 199 // caller must ensure (e.g., by holding on to a reference) that |channel| |
| 200 // stays alive through the call. | 200 // stays alive through the call. |
| 201 void SerializeAndCloseDispatchers(Channel* channel); | 201 void SerializeAndCloseDispatchers(Channel* channel); |
| 202 | 202 |
| 203 // Gets the main buffer and its size (in number of bytes), respectively. | 203 // Gets the main buffer and its size (in number of bytes), respectively. |
| 204 const void* main_buffer() const { return main_buffer_.get(); } | 204 const void* main_buffer() const { return main_buffer_.get(); } |
| 205 size_t main_buffer_size() const { return main_buffer_size_; } | 205 size_t main_buffer_size() const { return main_buffer_size_; } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 | 269 |
| 270 const Header* header() const { | 270 const Header* header() const { |
| 271 return reinterpret_cast<const Header*>(main_buffer_.get()); | 271 return reinterpret_cast<const Header*>(main_buffer_.get()); |
| 272 } | 272 } |
| 273 Header* header() { return reinterpret_cast<Header*>(main_buffer_.get()); } | 273 Header* header() { return reinterpret_cast<Header*>(main_buffer_.get()); } |
| 274 | 274 |
| 275 void ConstructorHelper(Type type, Subtype subtype, uint32_t num_bytes); | 275 void ConstructorHelper(Type type, Subtype subtype, uint32_t num_bytes); |
| 276 void UpdateTotalSize(); | 276 void UpdateTotalSize(); |
| 277 | 277 |
| 278 const size_t main_buffer_size_; | 278 const size_t main_buffer_size_; |
| 279 const scoped_ptr<char, base::AlignedFreeDeleter> main_buffer_; // Never null. | 279 // Never null. |
| 280 const std::unique_ptr<char, base::AlignedFreeDeleter> main_buffer_; |
| 280 | 281 |
| 281 scoped_ptr<TransportData> transport_data_; // May be null. | 282 std::unique_ptr<TransportData> transport_data_; // May be null. |
| 282 | 283 |
| 283 // Any dispatchers that may be attached to this message. These dispatchers | 284 // Any dispatchers that may be attached to this message. These dispatchers |
| 284 // should be "owned" by this message, i.e., have a ref count of exactly 1. (We | 285 // should be "owned" by this message, i.e., have a ref count of exactly 1. (We |
| 285 // allow a dispatcher entry to be null, in case it couldn't be duplicated for | 286 // allow a dispatcher entry to be null, in case it couldn't be duplicated for |
| 286 // some reason.) | 287 // some reason.) |
| 287 scoped_ptr<DispatcherVector> dispatchers_; | 288 std::unique_ptr<DispatcherVector> dispatchers_; |
| 288 | 289 |
| 289 MOJO_DISALLOW_COPY_AND_ASSIGN(MessageInTransit); | 290 MOJO_DISALLOW_COPY_AND_ASSIGN(MessageInTransit); |
| 290 }; | 291 }; |
| 291 | 292 |
| 292 // So logging macros and |DCHECK_EQ()|, etc. work. | 293 // So logging macros and |DCHECK_EQ()|, etc. work. |
| 293 MOJO_SYSTEM_IMPL_EXPORT inline std::ostream& operator<<( | 294 MOJO_SYSTEM_IMPL_EXPORT inline std::ostream& operator<<( |
| 294 std::ostream& out, | 295 std::ostream& out, |
| 295 MessageInTransit::Type type) { | 296 MessageInTransit::Type type) { |
| 296 return out << static_cast<uint16_t>(type); | 297 return out << static_cast<uint16_t>(type); |
| 297 } | 298 } |
| 298 | 299 |
| 299 // So logging macros and |DCHECK_EQ()|, etc. work. | 300 // So logging macros and |DCHECK_EQ()|, etc. work. |
| 300 MOJO_SYSTEM_IMPL_EXPORT inline std::ostream& operator<<( | 301 MOJO_SYSTEM_IMPL_EXPORT inline std::ostream& operator<<( |
| 301 std::ostream& out, | 302 std::ostream& out, |
| 302 MessageInTransit::Subtype subtype) { | 303 MessageInTransit::Subtype subtype) { |
| 303 return out << static_cast<uint16_t>(subtype); | 304 return out << static_cast<uint16_t>(subtype); |
| 304 } | 305 } |
| 305 | 306 |
| 306 } // namespace system | 307 } // namespace system |
| 307 } // namespace mojo | 308 } // namespace mojo |
| 308 | 309 |
| 309 #endif // MOJO_EDK_SYSTEM_MESSAGE_IN_TRANSIT_H_ | 310 #endif // MOJO_EDK_SYSTEM_MESSAGE_IN_TRANSIT_H_ |
| OLD | NEW |