| 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_SYSTEM_MESSAGE_IN_TRANSIT_H_ | 5 #ifndef MOJO_SYSTEM_MESSAGE_IN_TRANSIT_H_ |
| 6 #define MOJO_SYSTEM_MESSAGE_IN_TRANSIT_H_ | 6 #define MOJO_SYSTEM_MESSAGE_IN_TRANSIT_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/aligned_memory.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "mojo/embedder/platform_handle.h" | 15 #include "mojo/embedder/platform_handle.h" |
| 15 #include "mojo/system/dispatcher.h" | 16 #include "mojo/system/dispatcher.h" |
| 16 #include "mojo/system/system_impl_export.h" | 17 #include "mojo/system/system_impl_export.h" |
| 17 | 18 |
| 18 namespace mojo { | 19 namespace mojo { |
| 19 namespace system { | 20 namespace system { |
| 20 | 21 |
| 21 class Channel; | 22 class Channel; |
| 22 | 23 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 // stays alive through the call. | 172 // stays alive through the call. |
| 172 void SerializeAndCloseDispatchers(Channel* channel); | 173 void SerializeAndCloseDispatchers(Channel* channel); |
| 173 | 174 |
| 174 // Deserializes any dispatchers from the secondary buffer. This message must | 175 // Deserializes any dispatchers from the secondary buffer. This message must |
| 175 // not have any dispatchers attached. | 176 // not have any dispatchers attached. |
| 176 // TODO(vtl): Having to copy the secondary buffer (in the constructor from a | 177 // TODO(vtl): Having to copy the secondary buffer (in the constructor from a |
| 177 // |View|) is suboptimal. Maybe this should just be done in the constructor? | 178 // |View|) is suboptimal. Maybe this should just be done in the constructor? |
| 178 void DeserializeDispatchers(Channel* channel); | 179 void DeserializeDispatchers(Channel* channel); |
| 179 | 180 |
| 180 // Gets the main buffer and its size (in number of bytes), respectively. | 181 // Gets the main buffer and its size (in number of bytes), respectively. |
| 181 const void* main_buffer() const { return main_buffer_; } | 182 const void* main_buffer() const { return main_buffer_.get(); } |
| 182 size_t main_buffer_size() const { return main_buffer_size_; } | 183 size_t main_buffer_size() const { return main_buffer_size_; } |
| 183 | 184 |
| 184 // Gets the secondary buffer and its size (in number of bytes), respectively. | 185 // Gets the secondary buffer and its size (in number of bytes), respectively. |
| 185 const void* secondary_buffer() const { return secondary_buffer_; } | 186 const void* secondary_buffer() const { return secondary_buffer_.get(); } |
| 186 size_t secondary_buffer_size() const { return secondary_buffer_size_; } | 187 size_t secondary_buffer_size() const { return secondary_buffer_size_; } |
| 187 | 188 |
| 188 // Gets the total size of the message (see comment in |Header|, below). | 189 // Gets the total size of the message (see comment in |Header|, below). |
| 189 size_t total_size() const { return header()->total_size; } | 190 size_t total_size() const { return header()->total_size; } |
| 190 | 191 |
| 191 // Gets the size of the message data. | 192 // Gets the size of the message data. |
| 192 uint32_t num_bytes() const { return header()->num_bytes; } | 193 uint32_t num_bytes() const { return header()->num_bytes; } |
| 193 | 194 |
| 194 // Gets the message data (of size |num_bytes()| bytes). | 195 // Gets the message data (of size |num_bytes()| bytes). |
| 195 const void* bytes() const { | 196 const void* bytes() const { return main_buffer_.get() + sizeof(Header); } |
| 196 return static_cast<const char*>(main_buffer_) + sizeof(Header); | 197 void* bytes() { return main_buffer_.get() + sizeof(Header); } |
| 197 } | |
| 198 void* bytes() { return static_cast<char*>(main_buffer_) + sizeof(Header); } | |
| 199 | 198 |
| 200 uint32_t num_handles() const { return header()->num_handles; } | 199 uint32_t num_handles() const { return header()->num_handles; } |
| 201 | 200 |
| 202 Type type() const { return header()->type; } | 201 Type type() const { return header()->type; } |
| 203 Subtype subtype() const { return header()->subtype; } | 202 Subtype subtype() const { return header()->subtype; } |
| 204 EndpointId source_id() const { return header()->source_id; } | 203 EndpointId source_id() const { return header()->source_id; } |
| 205 EndpointId destination_id() const { return header()->destination_id; } | 204 EndpointId destination_id() const { return header()->destination_id; } |
| 206 | 205 |
| 207 void set_source_id(EndpointId source_id) { header()->source_id = source_id; } | 206 void set_source_id(EndpointId source_id) { header()->source_id = source_id; } |
| 208 void set_destination_id(EndpointId destination_id) { | 207 void set_destination_id(EndpointId destination_id) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 // The maximum total number of platform handles that may be attached. | 273 // The maximum total number of platform handles that may be attached. |
| 275 static const size_t kMaxPlatformHandles; | 274 static const size_t kMaxPlatformHandles; |
| 276 | 275 |
| 277 // Validates the secondary buffer. Returns null on success, or a | 276 // Validates the secondary buffer. Returns null on success, or a |
| 278 // human-readable error message (meant for logging/debugging) on error. | 277 // human-readable error message (meant for logging/debugging) on error. |
| 279 static const char* ValidateSecondaryBuffer(size_t num_handles, | 278 static const char* ValidateSecondaryBuffer(size_t num_handles, |
| 280 const void* secondary_buffer, | 279 const void* secondary_buffer, |
| 281 size_t secondary_buffer_size); | 280 size_t secondary_buffer_size); |
| 282 | 281 |
| 283 const Header* header() const { | 282 const Header* header() const { |
| 284 return static_cast<const Header*>(main_buffer_); | 283 return reinterpret_cast<const Header*>(main_buffer_.get()); |
| 285 } | 284 } |
| 286 Header* header() { return static_cast<Header*>(main_buffer_); } | 285 Header* header() { return reinterpret_cast<Header*>(main_buffer_.get()); } |
| 287 | 286 |
| 288 void UpdateTotalSize(); | 287 void UpdateTotalSize(); |
| 289 | 288 |
| 290 size_t main_buffer_size_; | 289 const size_t main_buffer_size_; |
| 291 void* main_buffer_; | 290 const scoped_ptr<char, base::AlignedFreeDeleter> main_buffer_; // Never null. |
| 292 | 291 |
| 293 size_t secondary_buffer_size_; | 292 size_t secondary_buffer_size_; |
| 294 void* secondary_buffer_; // May be null. | 293 scoped_ptr<char, base::AlignedFreeDeleter> secondary_buffer_; // May be null. |
| 295 | 294 |
| 296 // Any dispatchers that may be attached to this message. These dispatchers | 295 // Any dispatchers that may be attached to this message. These dispatchers |
| 297 // should be "owned" by this message, i.e., have a ref count of exactly 1. (We | 296 // should be "owned" by this message, i.e., have a ref count of exactly 1. (We |
| 298 // allow a dispatcher entry to be null, in case it couldn't be duplicated for | 297 // allow a dispatcher entry to be null, in case it couldn't be duplicated for |
| 299 // some reason.) | 298 // some reason.) |
| 300 scoped_ptr<std::vector<scoped_refptr<Dispatcher> > > dispatchers_; | 299 scoped_ptr<std::vector<scoped_refptr<Dispatcher> > > dispatchers_; |
| 301 | 300 |
| 302 // Any platform-specific handles attached to this message (for inter-process | 301 // Any platform-specific handles attached to this message (for inter-process |
| 303 // transport). The vector (if any) owns the handles that it contains (and is | 302 // transport). The vector (if any) owns the handles that it contains (and is |
| 304 // responsible for closing them). | 303 // responsible for closing them). |
| 305 // TODO(vtl): With C++11, change it to a vector of |ScopedPlatformHandles|. | 304 // TODO(vtl): With C++11, change it to a vector of |ScopedPlatformHandles|. |
| 306 scoped_ptr<std::vector<embedder::PlatformHandle> > platform_handles_; | 305 scoped_ptr<std::vector<embedder::PlatformHandle> > platform_handles_; |
| 307 | 306 |
| 308 DISALLOW_COPY_AND_ASSIGN(MessageInTransit); | 307 DISALLOW_COPY_AND_ASSIGN(MessageInTransit); |
| 309 }; | 308 }; |
| 310 | 309 |
| 311 } // namespace system | 310 } // namespace system |
| 312 } // namespace mojo | 311 } // namespace mojo |
| 313 | 312 |
| 314 #endif // MOJO_SYSTEM_MESSAGE_IN_TRANSIT_H_ | 313 #endif // MOJO_SYSTEM_MESSAGE_IN_TRANSIT_H_ |
| OLD | NEW |