Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Unified Diff: ppapi/shared_impl/vpn_provider_util.cc

Issue 1931513002: ppapi: PPB_VpnProvider: Implement Resource Stub (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@vpn-api-messages
Patch Set: Respond to review. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« ppapi/proxy/ppapi_messages.h ('K') | « ppapi/shared_impl/vpn_provider_util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« ppapi/proxy/ppapi_messages.h ('K') | « ppapi/shared_impl/vpn_provider_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698