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..0833b9b726709d24d9d22eb711f19fa643dc2d5f |
--- /dev/null |
+++ b/ppapi/shared_impl/vpn_provider_util.cc |
@@ -0,0 +1,50 @@ |
+// 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_(new bool[capacity]) { |
+ DCHECK(this->shm_); |
+ for (uint32_t it = 0; it < capacity_; it++) |
+ available_[it] = true; |
+} |
+ |
+VpnProviderSharedBuffer::~VpnProviderSharedBuffer() {} |
+ |
+bool VpnProviderSharedBuffer::GetAvailable(uint32_t* id) { |
+ for (uint32_t it = 0; it < capacity_; it++) { |
+ if (available_[it]) { |
+ if (id) { |
+ *id = it; |
+ } |
+ return true; |
+ } |
+ } |
+ return false; |
+} |
+ |
+void VpnProviderSharedBuffer::SetAvailable(uint32_t id, bool value) { |
+ available_[id] = value; |
+} |
+ |
+void* VpnProviderSharedBuffer::GetBuffer(uint32_t id) { |
+ if (id >= capacity_) |
+ return nullptr; |
+ return (void*)((char*)(shm_->memory()) + packet_size_ * id); |
+} |
+ |
+base::SharedMemoryHandle VpnProviderSharedBuffer::GetHandle() { |
+ return shm_->handle(); |
+} |
+ |
+} // namespace ppapi |