| OLD | NEW |
| 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 #include "mojo/system/shared_buffer_dispatcher.h" | 5 #include "mojo/system/shared_buffer_dispatcher.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 // static | 29 // static |
| 30 const MojoCreateSharedBufferOptions | 30 const MojoCreateSharedBufferOptions |
| 31 SharedBufferDispatcher::kDefaultCreateOptions = { | 31 SharedBufferDispatcher::kDefaultCreateOptions = { |
| 32 static_cast<uint32_t>(sizeof(MojoCreateSharedBufferOptions)), | 32 static_cast<uint32_t>(sizeof(MojoCreateSharedBufferOptions)), |
| 33 MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE | 33 MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 // static | 36 // static |
| 37 MojoResult SharedBufferDispatcher::ValidateCreateOptions( | 37 MojoResult SharedBufferDispatcher::ValidateCreateOptions( |
| 38 const MojoCreateSharedBufferOptions* in_options, | 38 UserPointer<const MojoCreateSharedBufferOptions> in_options, |
| 39 MojoCreateSharedBufferOptions* out_options) { | 39 MojoCreateSharedBufferOptions* out_options) { |
| 40 const MojoCreateSharedBufferOptionsFlags kKnownFlags = | 40 const MojoCreateSharedBufferOptionsFlags kKnownFlags = |
| 41 MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE; | 41 MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE; |
| 42 | 42 |
| 43 *out_options = kDefaultCreateOptions; | 43 *out_options = kDefaultCreateOptions; |
| 44 if (!in_options) | 44 if (in_options.IsNull()) |
| 45 return MOJO_RESULT_OK; | 45 return MOJO_RESULT_OK; |
| 46 | 46 |
| 47 MojoResult result = | 47 UserOptionsReader<MojoCreateSharedBufferOptions> reader(in_options); |
| 48 ValidateOptionsStructPointerSizeAndFlags<MojoCreateSharedBufferOptions>( | 48 if (!reader.is_valid()) |
| 49 in_options, kKnownFlags, out_options); | 49 return MOJO_RESULT_INVALID_ARGUMENT; |
| 50 if (result != MOJO_RESULT_OK) | 50 |
| 51 return result; | 51 if (!OPTIONS_STRUCT_HAS_MEMBER(MojoCreateSharedBufferOptions, flags, reader)) |
| 52 return MOJO_RESULT_OK; |
| 53 if ((reader.options().flags & ~kKnownFlags)) |
| 54 return MOJO_RESULT_UNIMPLEMENTED; |
| 55 out_options->flags = reader.options().flags; |
| 52 | 56 |
| 53 // Checks for fields beyond |flags|: | 57 // Checks for fields beyond |flags|: |
| 54 | 58 |
| 55 // (Nothing here yet.) | 59 // (Nothing here yet.) |
| 56 | 60 |
| 57 return MOJO_RESULT_OK; | 61 return MOJO_RESULT_OK; |
| 58 } | 62 } |
| 59 | 63 |
| 60 // static | 64 // static |
| 61 MojoResult SharedBufferDispatcher::Create( | 65 MojoResult SharedBufferDispatcher::Create( |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 scoped_refptr<RawSharedBuffer> shared_buffer) | 137 scoped_refptr<RawSharedBuffer> shared_buffer) |
| 134 : shared_buffer_(shared_buffer) { | 138 : shared_buffer_(shared_buffer) { |
| 135 DCHECK(shared_buffer_); | 139 DCHECK(shared_buffer_); |
| 136 } | 140 } |
| 137 | 141 |
| 138 SharedBufferDispatcher::~SharedBufferDispatcher() { | 142 SharedBufferDispatcher::~SharedBufferDispatcher() { |
| 139 } | 143 } |
| 140 | 144 |
| 141 // static | 145 // static |
| 142 MojoResult SharedBufferDispatcher::ValidateDuplicateOptions( | 146 MojoResult SharedBufferDispatcher::ValidateDuplicateOptions( |
| 143 const MojoDuplicateBufferHandleOptions* in_options, | 147 UserPointer<const MojoDuplicateBufferHandleOptions> in_options, |
| 144 MojoDuplicateBufferHandleOptions* out_options) { | 148 MojoDuplicateBufferHandleOptions* out_options) { |
| 145 const MojoDuplicateBufferHandleOptionsFlags kKnownFlags = | 149 const MojoDuplicateBufferHandleOptionsFlags kKnownFlags = |
| 146 MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE; | 150 MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE; |
| 147 static const MojoDuplicateBufferHandleOptions kDefaultOptions = { | 151 static const MojoDuplicateBufferHandleOptions kDefaultOptions = { |
| 148 static_cast<uint32_t>(sizeof(MojoDuplicateBufferHandleOptions)), | 152 static_cast<uint32_t>(sizeof(MojoDuplicateBufferHandleOptions)), |
| 149 MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE | 153 MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE |
| 150 }; | 154 }; |
| 151 | 155 |
| 152 *out_options = kDefaultOptions; | 156 *out_options = kDefaultOptions; |
| 153 if (!in_options) | 157 if (in_options.IsNull()) |
| 154 return MOJO_RESULT_OK; | 158 return MOJO_RESULT_OK; |
| 155 | 159 |
| 156 MojoResult result = | 160 UserOptionsReader<MojoDuplicateBufferHandleOptions> reader(in_options); |
| 157 ValidateOptionsStructPointerSizeAndFlags< | 161 if (!reader.is_valid()) |
| 158 MojoDuplicateBufferHandleOptions>( | 162 return MOJO_RESULT_INVALID_ARGUMENT; |
| 159 in_options, kKnownFlags, out_options); | 163 |
| 160 if (result != MOJO_RESULT_OK) | 164 if (!OPTIONS_STRUCT_HAS_MEMBER(MojoDuplicateBufferHandleOptions, flags, |
| 161 return result; | 165 reader)) |
| 166 return MOJO_RESULT_OK; |
| 167 if ((reader.options().flags & ~kKnownFlags)) |
| 168 return MOJO_RESULT_UNIMPLEMENTED; |
| 169 out_options->flags = reader.options().flags; |
| 162 | 170 |
| 163 // Checks for fields beyond |flags|: | 171 // Checks for fields beyond |flags|: |
| 164 | 172 |
| 165 // (Nothing here yet.) | 173 // (Nothing here yet.) |
| 166 | 174 |
| 167 return MOJO_RESULT_OK; | 175 return MOJO_RESULT_OK; |
| 168 } | 176 } |
| 169 | 177 |
| 170 void SharedBufferDispatcher::CloseImplNoLock() { | 178 void SharedBufferDispatcher::CloseImplNoLock() { |
| 171 lock().AssertAcquired(); | 179 lock().AssertAcquired(); |
| 172 DCHECK(shared_buffer_); | 180 DCHECK(shared_buffer_); |
| 173 shared_buffer_ = NULL; | 181 shared_buffer_ = NULL; |
| 174 } | 182 } |
| 175 | 183 |
| 176 scoped_refptr<Dispatcher> | 184 scoped_refptr<Dispatcher> |
| 177 SharedBufferDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() { | 185 SharedBufferDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() { |
| 178 lock().AssertAcquired(); | 186 lock().AssertAcquired(); |
| 179 DCHECK(shared_buffer_); | 187 DCHECK(shared_buffer_); |
| 180 scoped_refptr<RawSharedBuffer> shared_buffer; | 188 scoped_refptr<RawSharedBuffer> shared_buffer; |
| 181 shared_buffer.swap(shared_buffer_); | 189 shared_buffer.swap(shared_buffer_); |
| 182 return scoped_refptr<Dispatcher>(new SharedBufferDispatcher(shared_buffer)); | 190 return scoped_refptr<Dispatcher>(new SharedBufferDispatcher(shared_buffer)); |
| 183 } | 191 } |
| 184 | 192 |
| 185 MojoResult SharedBufferDispatcher::DuplicateBufferHandleImplNoLock( | 193 MojoResult SharedBufferDispatcher::DuplicateBufferHandleImplNoLock( |
| 186 const MojoDuplicateBufferHandleOptions* options, | 194 UserPointer<const MojoDuplicateBufferHandleOptions> options, |
| 187 scoped_refptr<Dispatcher>* new_dispatcher) { | 195 scoped_refptr<Dispatcher>* new_dispatcher) { |
| 188 lock().AssertAcquired(); | 196 lock().AssertAcquired(); |
| 189 | 197 |
| 190 MojoDuplicateBufferHandleOptions validated_options; | 198 MojoDuplicateBufferHandleOptions validated_options; |
| 191 MojoResult result = ValidateDuplicateOptions(options, &validated_options); | 199 MojoResult result = ValidateDuplicateOptions(options, &validated_options); |
| 192 if (result != MOJO_RESULT_OK) | 200 if (result != MOJO_RESULT_OK) |
| 193 return result; | 201 return result; |
| 194 | 202 |
| 195 *new_dispatcher = new SharedBufferDispatcher(shared_buffer_); | 203 *new_dispatcher = new SharedBufferDispatcher(shared_buffer_); |
| 196 return MOJO_RESULT_OK; | 204 return MOJO_RESULT_OK; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 return true; | 271 return true; |
| 264 } | 272 } |
| 265 | 273 |
| 266 HandleSignalsState SharedBufferDispatcher::GetHandleSignalsStateNoLock() const { | 274 HandleSignalsState SharedBufferDispatcher::GetHandleSignalsStateNoLock() const { |
| 267 // TODO(vtl): Add transferrable flag. | 275 // TODO(vtl): Add transferrable flag. |
| 268 return HandleSignalsState(); | 276 return HandleSignalsState(); |
| 269 } | 277 } |
| 270 | 278 |
| 271 } // namespace system | 279 } // namespace system |
| 272 } // namespace mojo | 280 } // namespace mojo |
| OLD | NEW |