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

Side by Side Diff: ppapi/proxy/udp_socket_filter.cc

Issue 1864293002: Convert //ppapi to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more nullptr Created 4 years, 8 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 unified diff | Download patch
« no previous file with comments | « ppapi/proxy/udp_socket_filter.h ('k') | ppapi/proxy/video_capture_resource.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/proxy/udp_socket_filter.h" 5 #include "ppapi/proxy/udp_socket_filter.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cstring> 8 #include <cstring>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "ppapi/c/pp_errors.h" 12 #include "ppapi/c/pp_errors.h"
13 #include "ppapi/proxy/error_conversion.h" 13 #include "ppapi/proxy/error_conversion.h"
14 #include "ppapi/proxy/plugin_globals.h" 14 #include "ppapi/proxy/plugin_globals.h"
15 #include "ppapi/proxy/ppapi_messages.h" 15 #include "ppapi/proxy/ppapi_messages.h"
16 #include "ppapi/thunk/enter.h" 16 #include "ppapi/thunk/enter.h"
17 #include "ppapi/thunk/resource_creation_api.h" 17 #include "ppapi/thunk/resource_creation_api.h"
18 18
19 namespace ppapi { 19 namespace ppapi {
20 namespace proxy { 20 namespace proxy {
21 21
22 const int32_t UDPSocketFilter::kMaxReadSize = 128 * 1024; 22 const int32_t UDPSocketFilter::kMaxReadSize = 128 * 1024;
23 const int32_t UDPSocketFilter::kMaxReceiveBufferSize = 23 const int32_t UDPSocketFilter::kMaxReceiveBufferSize =
24 1024 * UDPSocketFilter::kMaxReadSize; 24 1024 * UDPSocketFilter::kMaxReadSize;
25 const size_t UDPSocketFilter::kPluginReceiveBufferSlots = 32u; 25 const size_t UDPSocketFilter::kPluginReceiveBufferSlots = 32u;
26 26
27 namespace { 27 namespace {
28 28
29 int32_t SetRecvFromOutput(PP_Instance pp_instance, 29 int32_t SetRecvFromOutput(PP_Instance pp_instance,
30 const scoped_ptr<std::string>& data, 30 const std::unique_ptr<std::string>& data,
31 const PP_NetAddress_Private& addr, 31 const PP_NetAddress_Private& addr,
32 char* output_buffer, 32 char* output_buffer,
33 int32_t num_bytes, 33 int32_t num_bytes,
34 PP_Resource* output_addr, 34 PP_Resource* output_addr,
35 int32_t browser_result) { 35 int32_t browser_result) {
36 ProxyLock::AssertAcquired(); 36 ProxyLock::AssertAcquired();
37 DCHECK_GE(num_bytes, static_cast<int32_t>(data->size())); 37 DCHECK_GE(num_bytes, static_cast<int32_t>(data->size()));
38 38
39 int32_t result = browser_result; 39 int32_t result = browser_result;
40 if (result == PP_OK && output_addr) { 40 if (result == PP_OK && output_addr) {
(...skipping 21 matching lines...) Expand all
62 } 62 }
63 63
64 void UDPSocketFilter::AddUDPResource( 64 void UDPSocketFilter::AddUDPResource(
65 PP_Instance instance, 65 PP_Instance instance,
66 PP_Resource resource, 66 PP_Resource resource,
67 bool private_api, 67 bool private_api,
68 const base::Closure& slot_available_callback) { 68 const base::Closure& slot_available_callback) {
69 ProxyLock::AssertAcquired(); 69 ProxyLock::AssertAcquired();
70 base::AutoLock acquire(lock_); 70 base::AutoLock acquire(lock_);
71 DCHECK(!queues_.contains(resource)); 71 DCHECK(!queues_.contains(resource));
72 queues_.add(resource, scoped_ptr<RecvQueue>(new RecvQueue( 72 queues_.add(resource, std::unique_ptr<RecvQueue>(new RecvQueue(
73 instance, private_api, slot_available_callback))); 73 instance, private_api, slot_available_callback)));
74 } 74 }
75 75
76 void UDPSocketFilter::RemoveUDPResource(PP_Resource resource) { 76 void UDPSocketFilter::RemoveUDPResource(PP_Resource resource) {
77 ProxyLock::AssertAcquired(); 77 ProxyLock::AssertAcquired();
78 base::AutoLock acquire(lock_); 78 base::AutoLock acquire(lock_);
79 DCHECK(queues_.contains(resource)); 79 DCHECK(queues_.contains(resource));
80 queues_.erase(resource); 80 queues_.erase(resource);
81 } 81 }
82 82
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 175
176 result = PP_ERROR_MESSAGE_TOO_BIG; 176 result = PP_ERROR_MESSAGE_TOO_BIG;
177 } else { 177 } else {
178 // Instead of calling SetRecvFromOutput directly, post it as a completion 178 // Instead of calling SetRecvFromOutput directly, post it as a completion
179 // task, so that: 179 // task, so that:
180 // 1) It can run with the ProxyLock (we can't lock it on the IO thread.) 180 // 1) It can run with the ProxyLock (we can't lock it on the IO thread.)
181 // 2) So that we only write to the output params in the case of success. 181 // 2) So that we only write to the output params in the case of success.
182 // (Since the callback will complete on another thread, it's possible 182 // (Since the callback will complete on another thread, it's possible
183 // that the resource will be deleted and abort the callback before it 183 // that the resource will be deleted and abort the callback before it
184 // is actually run.) 184 // is actually run.)
185 scoped_ptr<std::string> data_to_pass(new std::string(data)); 185 std::unique_ptr<std::string> data_to_pass(new std::string(data));
186 recvfrom_callback_->set_completion_task(base::Bind( 186 recvfrom_callback_->set_completion_task(base::Bind(
187 &SetRecvFromOutput, pp_instance_, base::Passed(std::move(data_to_pass)), 187 &SetRecvFromOutput, pp_instance_, base::Passed(std::move(data_to_pass)),
188 addr, base::Unretained(read_buffer_), bytes_to_read_, 188 addr, base::Unretained(read_buffer_), bytes_to_read_,
189 base::Unretained(recvfrom_addr_resource_))); 189 base::Unretained(recvfrom_addr_resource_)));
190 last_recvfrom_addr_ = addr; 190 last_recvfrom_addr_ = addr;
191 PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( 191 PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask(
192 FROM_HERE, 192 FROM_HERE,
193 RunWhileLocked(slot_available_callback_)); 193 RunWhileLocked(slot_available_callback_));
194 } 194 }
195 195
(...skipping 22 matching lines...) Expand all
218 recvfrom_addr_resource_ = addr_out; 218 recvfrom_addr_resource_ = addr_out;
219 recvfrom_callback_ = callback; 219 recvfrom_callback_ = callback;
220 return PP_OK_COMPLETIONPENDING; 220 return PP_OK_COMPLETIONPENDING;
221 } else { 221 } else {
222 RecvBuffer& front = recv_buffers_.front(); 222 RecvBuffer& front = recv_buffers_.front();
223 223
224 if (static_cast<size_t>(num_bytes) < front.data.size()) 224 if (static_cast<size_t>(num_bytes) < front.data.size())
225 return PP_ERROR_MESSAGE_TOO_BIG; 225 return PP_ERROR_MESSAGE_TOO_BIG;
226 226
227 int32_t result = static_cast<int32_t>(front.data.size()); 227 int32_t result = static_cast<int32_t>(front.data.size());
228 scoped_ptr<std::string> data_to_pass(new std::string); 228 std::unique_ptr<std::string> data_to_pass(new std::string);
229 data_to_pass->swap(front.data); 229 data_to_pass->swap(front.data);
230 SetRecvFromOutput(pp_instance_, std::move(data_to_pass), front.addr, 230 SetRecvFromOutput(pp_instance_, std::move(data_to_pass), front.addr,
231 buffer_out, num_bytes, addr_out, PP_OK); 231 buffer_out, num_bytes, addr_out, PP_OK);
232 last_recvfrom_addr_ = front.addr; 232 last_recvfrom_addr_ = front.addr;
233 recv_buffers_.pop(); 233 recv_buffers_.pop();
234 slot_available_callback_.Run(); 234 slot_available_callback_.Run();
235 235
236 return result; 236 return result;
237 } 237 }
238 } 238 }
239 239
240 PP_NetAddress_Private UDPSocketFilter::RecvQueue::GetLastAddrPrivate() const { 240 PP_NetAddress_Private UDPSocketFilter::RecvQueue::GetLastAddrPrivate() const {
241 CHECK(private_api_); 241 CHECK(private_api_);
242 return last_recvfrom_addr_; 242 return last_recvfrom_addr_;
243 } 243 }
244 244
245 } // namespace proxy 245 } // namespace proxy
246 } // namespace ppapi 246 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/udp_socket_filter.h ('k') | ppapi/proxy/video_capture_resource.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698