Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: mojo/edk/system/transport_data.h

Issue 1478503003: EDK: Convert most uses of PlatformHandleVector to std::vector<ScopedPlatformHandle>. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/edk/system/slave_connection_manager.cc ('k') | mojo/edk/system/transport_data.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_TRANSPORT_DATA_H_ 5 #ifndef MOJO_EDK_SYSTEM_TRANSPORT_DATA_H_
6 #define MOJO_EDK_SYSTEM_TRANSPORT_DATA_H_ 6 #define MOJO_EDK_SYSTEM_TRANSPORT_DATA_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/memory/aligned_memory.h" 13 #include "base/memory/aligned_memory.h"
14 #include "mojo/edk/embedder/platform_handle.h" 14 #include "mojo/edk/embedder/scoped_platform_handle.h"
15 #include "mojo/edk/embedder/platform_handle_vector.h"
16 #include "mojo/edk/system/dispatcher.h" 15 #include "mojo/edk/system/dispatcher.h"
17 #include "mojo/public/cpp/system/macros.h" 16 #include "mojo/public/cpp/system/macros.h"
18 17
19 namespace mojo { 18 namespace mojo {
20 namespace system { 19 namespace system {
21 20
22 class Channel; 21 class Channel;
23 22
24 // This class is used by |MessageInTransit| to represent handles (|Dispatcher|s) 23 // This class is used by |MessageInTransit| to represent handles (|Dispatcher|s)
25 // in various stages of serialization. 24 // in various stages of serialization.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 static size_t GetMaxPlatformHandles(); 87 static size_t GetMaxPlatformHandles();
89 88
90 TransportData(std::unique_ptr<DispatcherVector> dispatchers, 89 TransportData(std::unique_ptr<DispatcherVector> dispatchers,
91 Channel* channel); 90 Channel* channel);
92 91
93 // This is used for users of |MessageInTransit|/|TransportData|/|RawChannel| 92 // This is used for users of |MessageInTransit|/|TransportData|/|RawChannel|
94 // that want to simply transport data and platform handles, and not 93 // that want to simply transport data and platform handles, and not
95 // |Dispatcher|s. (|Header| will be present, and zero except for 94 // |Dispatcher|s. (|Header| will be present, and zero except for
96 // |num_platform_handles|, and |platform_handle_table_offset| if necessary.) 95 // |num_platform_handles|, and |platform_handle_table_offset| if necessary.)
97 explicit TransportData( 96 explicit TransportData(
98 embedder::ScopedPlatformHandleVectorPtr platform_handles, 97 std::unique_ptr<std::vector<embedder::ScopedPlatformHandle>>
98 platform_handles,
99 size_t serialized_platform_handle_size); 99 size_t serialized_platform_handle_size);
100 100
101 ~TransportData(); 101 ~TransportData();
102 102
103 const void* buffer() const { return buffer_.get(); } 103 const void* buffer() const { return buffer_.get(); }
104 void* buffer() { return buffer_.get(); } 104 void* buffer() { return buffer_.get(); }
105 size_t buffer_size() const { return buffer_size_; } 105 size_t buffer_size() const { return buffer_size_; }
106 106
107 uint32_t platform_handle_table_offset() const { 107 uint32_t platform_handle_table_offset() const {
108 return header()->platform_handle_table_offset; 108 return header()->platform_handle_table_offset;
109 } 109 }
110 110
111 // Gets attached platform-specific handles; this may return null if there are 111 // Gets attached platform-specific handles; this may return null if there are
112 // none. Note that the caller may mutate the set of platform-specific handles. 112 // none. Note that the caller may mutate the set of platform-specific handles.
113 const embedder::PlatformHandleVector* platform_handles() const { 113 const std::vector<embedder::ScopedPlatformHandle>* platform_handles() const {
114 return platform_handles_.get(); 114 return platform_handles_.get();
115 } 115 }
116 embedder::PlatformHandleVector* platform_handles() { 116 std::vector<embedder::ScopedPlatformHandle>* platform_handles() {
117 return platform_handles_.get(); 117 return platform_handles_.get();
118 } 118 }
119 119
120 // Receive-side functions: 120 // Receive-side functions:
121 121
122 // Checks if the given buffer (from the "wire") looks like a valid 122 // Checks if the given buffer (from the "wire") looks like a valid
123 // |TransportData| buffer. (Should only be called if |buffer_size| is 123 // |TransportData| buffer. (Should only be called if |buffer_size| is
124 // nonzero.) Returns null if valid, and a pointer to a human-readable error 124 // nonzero.) Returns null if valid, and a pointer to a human-readable error
125 // message (for debug/logging purposes) on error. Note: This checks the 125 // message (for debug/logging purposes) on error. Note: This checks the
126 // validity of the handle table entries (i.e., does range checking), but does 126 // validity of the handle table entries (i.e., does range checking), but does
127 // not check that the validity of the actual serialized dispatcher 127 // not check that the validity of the actual serialized dispatcher
128 // information. 128 // information.
129 static const char* ValidateBuffer(size_t serialized_platform_handle_size, 129 static const char* ValidateBuffer(size_t serialized_platform_handle_size,
130 const void* buffer, 130 const void* buffer,
131 size_t buffer_size); 131 size_t buffer_size);
132 132
133 // Gets the platform handle table from a (valid) |TransportData| buffer (which 133 // Gets the platform handle table from a (valid) |TransportData| buffer (which
134 // should have been validated using |ValidateBuffer()| first). 134 // should have been validated using |ValidateBuffer()| first).
135 static void GetPlatformHandleTable(const void* transport_data_buffer, 135 static void GetPlatformHandleTable(const void* transport_data_buffer,
136 size_t* num_platform_handles, 136 size_t* num_platform_handles,
137 const void** platform_handle_table); 137 const void** platform_handle_table);
138 138
139 // Deserializes dispatchers from the given (serialized) transport data buffer 139 // Deserializes dispatchers from the given (serialized) transport data buffer
140 // (typically from a |MessageInTransit::View|) and vector of platform handles. 140 // (typically from a |MessageInTransit::View|) and vector of platform handles.
141 // |buffer| should be non-null and |buffer_size| should be nonzero. 141 // |buffer| should be non-null and |buffer_size| should be nonzero.
142 static std::unique_ptr<DispatcherVector> DeserializeDispatchers( 142 static std::unique_ptr<DispatcherVector> DeserializeDispatchers(
143 const void* buffer, 143 const void* buffer,
144 size_t buffer_size, 144 size_t buffer_size,
145 embedder::ScopedPlatformHandleVectorPtr platform_handles, 145 std::unique_ptr<std::vector<embedder::ScopedPlatformHandle>>
146 platform_handles,
146 Channel* channel); 147 Channel* channel);
147 148
148 private: 149 private:
149 // To allow us to make compile-assertions about |Header|, etc. in the .cc 150 // To allow us to make compile-assertions about |Header|, etc. in the .cc
150 // file. 151 // file.
151 struct PrivateStructForCompileAsserts; 152 struct PrivateStructForCompileAsserts;
152 153
153 // Header for the "secondary buffer"/"transport data". Must be a multiple of 154 // Header for the "secondary buffer"/"transport data". Must be a multiple of
154 // |MessageInTransit::kMessageAlignment| in size. Must be POD. 155 // |MessageInTransit::kMessageAlignment| in size. Must be POD.
155 struct Header { 156 struct Header {
(...skipping 16 matching lines...) Expand all
172 return reinterpret_cast<const Header*>(buffer_.get()); 173 return reinterpret_cast<const Header*>(buffer_.get());
173 } 174 }
174 175
175 size_t buffer_size_; 176 size_t buffer_size_;
176 std::unique_ptr<char, base::AlignedFreeDeleter> buffer_; // Never null. 177 std::unique_ptr<char, base::AlignedFreeDeleter> buffer_; // Never null.
177 178
178 // Any platform-specific handles attached to this message (for inter-process 179 // Any platform-specific handles attached to this message (for inter-process
179 // transport). The vector (if any) owns the handles that it contains (and is 180 // transport). The vector (if any) owns the handles that it contains (and is
180 // responsible for closing them). 181 // responsible for closing them).
181 // TODO(vtl): With C++11, change it to a vector of |ScopedPlatformHandle|s. 182 // TODO(vtl): With C++11, change it to a vector of |ScopedPlatformHandle|s.
182 embedder::ScopedPlatformHandleVectorPtr platform_handles_; 183 std::unique_ptr<std::vector<embedder::ScopedPlatformHandle>>
184 platform_handles_;
183 185
184 MOJO_DISALLOW_COPY_AND_ASSIGN(TransportData); 186 MOJO_DISALLOW_COPY_AND_ASSIGN(TransportData);
185 }; 187 };
186 188
187 } // namespace system 189 } // namespace system
188 } // namespace mojo 190 } // namespace mojo
189 191
190 #endif // MOJO_EDK_SYSTEM_TRANSPORT_DATA_H_ 192 #endif // MOJO_EDK_SYSTEM_TRANSPORT_DATA_H_
OLDNEW
« no previous file with comments | « mojo/edk/system/slave_connection_manager.cc ('k') | mojo/edk/system/transport_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698