| 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/edk/system/shared_buffer_dispatcher.h" | 5 #include "mojo/edk/system/shared_buffer_dispatcher.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 | 147 |
| 148 scoped_refptr<PlatformSharedBuffer> retval = shared_buffer_; | 148 scoped_refptr<PlatformSharedBuffer> retval = shared_buffer_; |
| 149 shared_buffer_ = nullptr; | 149 shared_buffer_ = nullptr; |
| 150 return retval; | 150 return retval; |
| 151 } | 151 } |
| 152 | 152 |
| 153 Dispatcher::Type SharedBufferDispatcher::GetType() const { | 153 Dispatcher::Type SharedBufferDispatcher::GetType() const { |
| 154 return Type::SHARED_BUFFER; | 154 return Type::SHARED_BUFFER; |
| 155 } | 155 } |
| 156 | 156 |
| 157 MojoResult SharedBufferDispatcher::Close() { | 157 MojoResult SharedBufferDispatcher::Close(RequestContext* request_context) { |
| 158 base::AutoLock lock(lock_); | 158 base::AutoLock lock(lock_); |
| 159 if (in_transit_) | 159 if (in_transit_) |
| 160 return MOJO_RESULT_INVALID_ARGUMENT; | 160 return MOJO_RESULT_INVALID_ARGUMENT; |
| 161 | 161 |
| 162 shared_buffer_ = nullptr; | 162 shared_buffer_ = nullptr; |
| 163 return MOJO_RESULT_OK; | 163 return MOJO_RESULT_OK; |
| 164 } | 164 } |
| 165 | 165 |
| 166 MojoResult SharedBufferDispatcher::DuplicateBufferHandle( | 166 MojoResult SharedBufferDispatcher::DuplicateBufferHandle( |
| 167 const MojoDuplicateBufferHandleOptions* options, | 167 const MojoDuplicateBufferHandleOptions* options, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 | 224 |
| 225 handle_for_transit_ = shared_buffer_->DuplicatePlatformHandle(); | 225 handle_for_transit_ = shared_buffer_->DuplicatePlatformHandle(); |
| 226 if (!handle_for_transit_.is_valid()) { | 226 if (!handle_for_transit_.is_valid()) { |
| 227 shared_buffer_ = nullptr; | 227 shared_buffer_ = nullptr; |
| 228 return false; | 228 return false; |
| 229 } | 229 } |
| 230 handles[0] = handle_for_transit_.get(); | 230 handles[0] = handle_for_transit_.get(); |
| 231 return true; | 231 return true; |
| 232 } | 232 } |
| 233 | 233 |
| 234 bool SharedBufferDispatcher::BeginTransit() { | 234 bool SharedBufferDispatcher::BeginTransit(RequestContext* request_context) { |
| 235 base::AutoLock lock(lock_); | 235 base::AutoLock lock(lock_); |
| 236 if (in_transit_) | 236 if (in_transit_) |
| 237 return false; | 237 return false; |
| 238 in_transit_ = shared_buffer_ != nullptr; | 238 in_transit_ = shared_buffer_ != nullptr; |
| 239 return in_transit_; | 239 return in_transit_; |
| 240 } | 240 } |
| 241 | 241 |
| 242 void SharedBufferDispatcher::CompleteTransitAndClose() { | 242 void SharedBufferDispatcher::CompleteTransitAndClose( |
| 243 RequestContext* request_context) { |
| 243 base::AutoLock lock(lock_); | 244 base::AutoLock lock(lock_); |
| 244 in_transit_ = false; | 245 in_transit_ = false; |
| 245 shared_buffer_ = nullptr; | 246 shared_buffer_ = nullptr; |
| 246 ignore_result(handle_for_transit_.release()); | 247 ignore_result(handle_for_transit_.release()); |
| 247 } | 248 } |
| 248 | 249 |
| 249 void SharedBufferDispatcher::CancelTransit() { | 250 void SharedBufferDispatcher::CancelTransit( |
| 251 RequestContext* request_context) { |
| 250 base::AutoLock lock(lock_); | 252 base::AutoLock lock(lock_); |
| 251 in_transit_ = false; | 253 in_transit_ = false; |
| 252 handle_for_transit_.reset(); | 254 handle_for_transit_.reset(); |
| 253 } | 255 } |
| 254 | 256 |
| 255 SharedBufferDispatcher::SharedBufferDispatcher( | 257 SharedBufferDispatcher::SharedBufferDispatcher( |
| 256 scoped_refptr<PlatformSharedBuffer> shared_buffer) | 258 scoped_refptr<PlatformSharedBuffer> shared_buffer) |
| 257 : shared_buffer_(shared_buffer) { | 259 : shared_buffer_(shared_buffer) { |
| 258 DCHECK(shared_buffer_); | 260 DCHECK(shared_buffer_); |
| 259 } | 261 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 289 | 291 |
| 290 // Checks for fields beyond |flags|: | 292 // Checks for fields beyond |flags|: |
| 291 | 293 |
| 292 // (Nothing here yet.) | 294 // (Nothing here yet.) |
| 293 | 295 |
| 294 return MOJO_RESULT_OK; | 296 return MOJO_RESULT_OK; |
| 295 } | 297 } |
| 296 | 298 |
| 297 } // namespace edk | 299 } // namespace edk |
| 298 } // namespace mojo | 300 } // namespace mojo |
| OLD | NEW |