OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 "ppapi/shared_impl/vpn_provider_util.h" | 5 #include "ppapi/shared_impl/vpn_provider_util.h" |
6 | 6 |
7 namespace ppapi { | 7 namespace ppapi { |
8 | 8 |
9 VpnProviderSharedBuffer::VpnProviderSharedBuffer( | 9 VpnProviderSharedBuffer::VpnProviderSharedBuffer( |
10 uint32_t capacity, | 10 uint32_t capacity, |
11 uint32_t packet_size, | 11 uint32_t packet_size, |
12 std::unique_ptr<base::SharedMemory> shm) | 12 std::unique_ptr<base::SharedMemory> shm) |
13 : capacity_(capacity), | 13 : capacity_(capacity), |
14 max_packet_size_(packet_size), | 14 packet_size_(packet_size), |
15 shm_(std::move(shm)), | 15 shm_(std::move(shm)), |
16 available_(capacity, true) { | 16 available_(capacity, true) { |
17 DCHECK(this->shm_); | 17 DCHECK(this->shm_); |
18 } | 18 } |
19 | 19 |
20 VpnProviderSharedBuffer::~VpnProviderSharedBuffer() {} | 20 VpnProviderSharedBuffer::~VpnProviderSharedBuffer() {} |
21 | 21 |
22 bool VpnProviderSharedBuffer::GetAvailable(uint32_t* id) { | 22 bool VpnProviderSharedBuffer::GetAvailable(uint32_t* id) { |
23 for (uint32_t i = 0; i < capacity_; i++) { | 23 for (uint32_t i = 0; i < capacity_; i++) { |
24 if (available_[i]) { | 24 if (available_[i]) { |
(...skipping 12 matching lines...) Expand all Loading... |
37 return; | 37 return; |
38 } | 38 } |
39 available_[id] = value; | 39 available_[id] = value; |
40 } | 40 } |
41 | 41 |
42 void* VpnProviderSharedBuffer::GetBuffer(uint32_t id) { | 42 void* VpnProviderSharedBuffer::GetBuffer(uint32_t id) { |
43 if (id >= capacity_) { | 43 if (id >= capacity_) { |
44 NOTREACHED(); | 44 NOTREACHED(); |
45 return nullptr; | 45 return nullptr; |
46 } | 46 } |
47 return reinterpret_cast<char*>(shm_->memory()) + max_packet_size_ * id; | 47 return reinterpret_cast<char*>(shm_->memory()) + packet_size_ * id; |
48 } | 48 } |
49 | 49 |
50 base::SharedMemoryHandle VpnProviderSharedBuffer::GetHandle() { | 50 base::SharedMemoryHandle VpnProviderSharedBuffer::GetHandle() { |
51 return shm_->handle(); | 51 return shm_->handle(); |
52 } | 52 } |
53 | 53 |
54 } // namespace ppapi | 54 } // namespace ppapi |
OLD | NEW |