OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ppapi/shared_impl/vpn_provider_util.h" |
| 6 |
| 7 namespace ppapi { |
| 8 |
| 9 VpnProviderSharedBuffer::VpnProviderSharedBuffer( |
| 10 uint32_t capacity, |
| 11 uint32_t packet_size, |
| 12 std::unique_ptr<base::SharedMemory> shm) |
| 13 : capacity_(capacity), |
| 14 packet_size_(packet_size), |
| 15 shm_(std::move(shm)), |
| 16 available_(new bool[capacity]) { |
| 17 DCHECK(this->shm_); |
| 18 for (uint32_t it = 0; it < capacity_; it++) |
| 19 available_[it] = true; |
| 20 } |
| 21 |
| 22 VpnProviderSharedBuffer::~VpnProviderSharedBuffer() {} |
| 23 |
| 24 bool VpnProviderSharedBuffer::GetAvailable(uint32_t* id) { |
| 25 for (uint32_t it = 0; it < capacity_; it++) { |
| 26 if (available_[it]) { |
| 27 if (id) { |
| 28 *id = it; |
| 29 } |
| 30 return true; |
| 31 } |
| 32 } |
| 33 return false; |
| 34 } |
| 35 |
| 36 void VpnProviderSharedBuffer::SetAvailable(uint32_t id, bool value) { |
| 37 available_[id] = value; |
| 38 } |
| 39 |
| 40 void* VpnProviderSharedBuffer::GetBuffer(uint32_t id) { |
| 41 if (id >= capacity_) |
| 42 return nullptr; |
| 43 return (void*)((char*)(shm_->memory()) + packet_size_ * id); |
| 44 } |
| 45 |
| 46 base::SharedMemoryHandle VpnProviderSharedBuffer::GetHandle() { |
| 47 return shm_->handle(); |
| 48 } |
| 49 |
| 50 } // namespace ppapi |
OLD | NEW |