Chromium Code Reviews| Index: ppapi/shared_impl/vpn_provider_util.cc |
| diff --git a/ppapi/shared_impl/vpn_provider_util.cc b/ppapi/shared_impl/vpn_provider_util.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..51672528c33fd04c238ddce8acd1029c02f48878 |
| --- /dev/null |
| +++ b/ppapi/shared_impl/vpn_provider_util.cc |
| @@ -0,0 +1,54 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ppapi/shared_impl/vpn_provider_util.h" |
| + |
| +namespace ppapi { |
| + |
| +VpnProviderSharedBuffer::VpnProviderSharedBuffer( |
| + uint32_t capacity, |
| + uint32_t packet_size, |
| + std::unique_ptr<base::SharedMemory> shm) |
| + : capacity_(capacity), |
| + packet_size_(packet_size), |
| + shm_(std::move(shm)), |
| + available_(capacity, true) { |
| + DCHECK(this->shm_); |
| +} |
| + |
| +VpnProviderSharedBuffer::~VpnProviderSharedBuffer() {} |
| + |
| +bool VpnProviderSharedBuffer::GetAvailable(uint32_t* id) { |
| + for (uint32_t it = 0; it < capacity_; it++) { |
|
bbudge
2016/05/17 13:34:39
nit: s/it/i
since you're indexing, it seems cleare
adrian.belgun
2016/05/17 15:25:29
Done.
|
| + if (available_[it]) { |
| + if (id) { |
| + *id = it; |
| + } |
| + return true; |
| + } |
| + } |
| + return false; |
| +} |
| + |
| +void VpnProviderSharedBuffer::SetAvailable(uint32_t id, bool value) { |
| + if (id >= capacity_) { |
| + NOTREACHED(); |
| + return; |
| + } |
| + available_[id] = value; |
| +} |
| + |
| +void* VpnProviderSharedBuffer::GetBuffer(uint32_t id) { |
| + if (id >= capacity_) { |
| + NOTREACHED(); |
| + return nullptr; |
| + } |
| + return (void*)((char*)(shm_->memory()) + packet_size_ * id); |
|
bbudge
2016/05/17 13:34:39
c++-style casts for chromium code.
adrian.belgun
2016/05/17 15:25:29
Done.
|
| +} |
| + |
| +base::SharedMemoryHandle VpnProviderSharedBuffer::GetHandle() { |
| + return shm_->handle(); |
| +} |
| + |
| +} // namespace ppapi |