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

Unified Diff: ppapi/proxy/udp_socket_resource_base.cc

Issue 16282005: Introduce PPB_UDPSocket_Dev. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 6 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
« no previous file with comments | « ppapi/proxy/udp_socket_resource_base.h ('k') | ppapi/shared_impl/resource.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/proxy/udp_socket_resource_base.cc
diff --git a/ppapi/proxy/udp_socket_private_resource.cc b/ppapi/proxy/udp_socket_resource_base.cc
similarity index 64%
copy from ppapi/proxy/udp_socket_private_resource.cc
copy to ppapi/proxy/udp_socket_resource_base.cc
index 608fc00a1613d5bd59e3bbd30ba97c45886f9997..1b90ffdf4bcc3aa1a8ed0aa2dd414b2a3295960c 100644
--- a/ppapi/proxy/udp_socket_private_resource.cc
+++ b/ppapi/proxy/udp_socket_resource_base.cc
@@ -1,27 +1,28 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright (c) 2013 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/proxy/udp_socket_private_resource.h"
+#include "ppapi/proxy/udp_socket_resource_base.h"
#include <algorithm>
#include <cstring>
-#include "base/basictypes.h"
#include "base/logging.h"
#include "ppapi/c/pp_bool.h"
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/proxy/ppapi_messages.h"
+#include "ppapi/thunk/enter.h"
+#include "ppapi/thunk/resource_creation_api.h"
namespace ppapi {
namespace proxy {
-const int32_t UDPSocketPrivateResource::kMaxReadSize = 1024 * 1024;
-const int32_t UDPSocketPrivateResource::kMaxWriteSize = 1024 * 1024;
+const int32_t UDPSocketResourceBase::kMaxReadSize = 1024 * 1024;
+const int32_t UDPSocketResourceBase::kMaxWriteSize = 1024 * 1024;
-UDPSocketPrivateResource::UDPSocketPrivateResource(Connection connection,
- PP_Instance instance)
+UDPSocketResourceBase::UDPSocketResourceBase(Connection connection,
+ PP_Instance instance)
: PluginResource(connection, instance),
bound_(false),
closed_(false),
@@ -37,35 +38,33 @@ UDPSocketPrivateResource::UDPSocketPrivateResource(Connection connection,
SendCreate(BROWSER, PpapiHostMsg_UDPSocketPrivate_Create());
}
-UDPSocketPrivateResource::~UDPSocketPrivateResource() {
+UDPSocketResourceBase::~UDPSocketResourceBase() {
}
-thunk::PPB_UDPSocket_Private_API*
-UDPSocketPrivateResource::AsPPB_UDPSocket_Private_API() {
- return this;
-}
-
-int32_t UDPSocketPrivateResource::SetSocketFeature(
+int32_t UDPSocketResourceBase::SetSocketFeatureImpl(
PP_UDPSocketFeature_Private name,
- PP_Var value) {
+ const PP_Var& value) {
if (bound_ || closed_)
return PP_ERROR_FAILED;
switch (name) {
case PP_UDPSOCKETFEATURE_ADDRESS_REUSE:
- case PP_UDPSOCKETFEATURE_BROADCAST:
+ case PP_UDPSOCKETFEATURE_BROADCAST: {
if (value.type != PP_VARTYPE_BOOL)
return PP_ERROR_BADARGUMENT;
- SendBoolSocketFeature(static_cast<int32_t>(name),
- PP_ToBool(value.value.as_bool));
+ Post(BROWSER,
+ PpapiHostMsg_UDPSocketPrivate_SetBoolSocketFeature(
+ static_cast<int32_t>(name), PP_ToBool(value.value.as_bool)));
break;
- default:
+ }
+ default: {
return PP_ERROR_BADARGUMENT;
+ }
}
return PP_OK;
}
-int32_t UDPSocketPrivateResource::Bind(
+int32_t UDPSocketResourceBase::BindImpl(
const PP_NetAddress_Private* addr,
scoped_refptr<TrackedCallback> callback) {
if (!addr)
@@ -78,11 +77,16 @@ int32_t UDPSocketPrivateResource::Bind(
bind_callback_ = callback;
// Send the request, the browser will call us back via BindReply.
- SendBind(*addr);
+ Call<PpapiPluginMsg_UDPSocketPrivate_BindReply>(
+ BROWSER,
+ PpapiHostMsg_UDPSocketPrivate_Bind(*addr),
+ base::Bind(&UDPSocketResourceBase::OnPluginMsgBindReply,
+ base::Unretained(this)));
return PP_OK_COMPLETIONPENDING;
}
-PP_Bool UDPSocketPrivateResource::GetBoundAddress(PP_NetAddress_Private* addr) {
+PP_Bool UDPSocketResourceBase::GetBoundAddressImpl(
+ PP_NetAddress_Private* addr) {
if (!addr || !bound_ || closed_)
return PP_FALSE;
@@ -90,9 +94,10 @@ PP_Bool UDPSocketPrivateResource::GetBoundAddress(PP_NetAddress_Private* addr) {
return PP_TRUE;
}
-int32_t UDPSocketPrivateResource::RecvFrom(
+int32_t UDPSocketResourceBase::RecvFromImpl(
char* buffer,
int32_t num_bytes,
+ PP_Resource* addr,
scoped_refptr<TrackedCallback> callback) {
if (!buffer || num_bytes <= 0)
return PP_ERROR_BADARGUMENT;
@@ -106,11 +111,15 @@ int32_t UDPSocketPrivateResource::RecvFrom(
recvfrom_callback_ = callback;
// Send the request, the browser will call us back via RecvFromReply.
- SendRecvFrom(bytes_to_read_);
+ Call<PpapiPluginMsg_UDPSocketPrivate_RecvFromReply>(
+ BROWSER,
+ PpapiHostMsg_UDPSocketPrivate_RecvFrom(bytes_to_read_),
+ base::Bind(&UDPSocketResourceBase::OnPluginMsgRecvFromReply,
+ base::Unretained(this), addr));
return PP_OK_COMPLETIONPENDING;
}
-PP_Bool UDPSocketPrivateResource::GetRecvFromAddress(
+PP_Bool UDPSocketResourceBase::GetRecvFromAddressImpl(
PP_NetAddress_Private* addr) {
if (!addr)
return PP_FALSE;
@@ -118,13 +127,7 @@ PP_Bool UDPSocketPrivateResource::GetRecvFromAddress(
return PP_TRUE;
}
-void UDPSocketPrivateResource::PostAbortIfNecessary(
- scoped_refptr<TrackedCallback>* callback) {
- if (TrackedCallback::IsPending(*callback))
- (*callback)->PostAbort();
-}
-
-int32_t UDPSocketPrivateResource::SendTo(
+int32_t UDPSocketResourceBase::SendToImpl(
const char* buffer,
int32_t num_bytes,
const PP_NetAddress_Private* addr,
@@ -142,63 +145,36 @@ int32_t UDPSocketPrivateResource::SendTo(
sendto_callback_ = callback;
// Send the request, the browser will call us back via SendToReply.
- SendSendTo(std::string(buffer, num_bytes), *addr);
+ Call<PpapiPluginMsg_UDPSocketPrivate_SendToReply>(
+ BROWSER,
+ PpapiHostMsg_UDPSocketPrivate_SendTo(
+ std::string(buffer, num_bytes), *addr),
+ base::Bind(&UDPSocketResourceBase::OnPluginMsgSendToReply,
+ base::Unretained(this)));
return PP_OK_COMPLETIONPENDING;
}
-void UDPSocketPrivateResource::Close() {
+void UDPSocketResourceBase::CloseImpl() {
if(closed_)
return;
bound_ = false;
closed_ = true;
- SendClose();
+ Post(BROWSER, PpapiHostMsg_UDPSocketPrivate_Close());
PostAbortIfNecessary(&bind_callback_);
PostAbortIfNecessary(&recvfrom_callback_);
PostAbortIfNecessary(&sendto_callback_);
}
-void UDPSocketPrivateResource::SendBoolSocketFeature(int32_t name, bool value) {
- PpapiHostMsg_UDPSocketPrivate_SetBoolSocketFeature msg(name, value);
- Post(BROWSER, msg);
-}
-
-void UDPSocketPrivateResource::SendBind(const PP_NetAddress_Private& addr) {
- PpapiHostMsg_UDPSocketPrivate_Bind msg(addr);
- Call<PpapiPluginMsg_UDPSocketPrivate_BindReply>(
- BROWSER,
- msg,
- base::Bind(&UDPSocketPrivateResource::OnPluginMsgBindReply,
- base::Unretained(this)));
-}
-
-void UDPSocketPrivateResource::SendRecvFrom(int32_t num_bytes) {
- PpapiHostMsg_UDPSocketPrivate_RecvFrom msg(num_bytes);
- Call<PpapiPluginMsg_UDPSocketPrivate_RecvFromReply>(
- BROWSER,
- msg,
- base::Bind(&UDPSocketPrivateResource::OnPluginMsgRecvFromReply,
- base::Unretained(this)));
-}
-
-void UDPSocketPrivateResource::SendSendTo(const std::string& buffer,
- const PP_NetAddress_Private& addr) {
- PpapiHostMsg_UDPSocketPrivate_SendTo msg(buffer, addr);
- Call<PpapiPluginMsg_UDPSocketPrivate_SendToReply>(
- BROWSER,
- msg,
- base::Bind(&UDPSocketPrivateResource::OnPluginMsgSendToReply,
- base::Unretained(this)));
-}
-
-void UDPSocketPrivateResource::SendClose() {
- PpapiHostMsg_UDPSocketPrivate_Close msg;
- Post(BROWSER, msg);
+void UDPSocketResourceBase::PostAbortIfNecessary(
+ scoped_refptr<TrackedCallback>* callback) {
+ if (TrackedCallback::IsPending(*callback))
+ (*callback)->PostAbort();
}
-void UDPSocketPrivateResource::OnPluginMsgBindReply(
+void UDPSocketResourceBase::OnPluginMsgBindReply(
const ResourceMessageReplyParams& params,
const PP_NetAddress_Private& bound_addr) {
if (!TrackedCallback::IsPending(bind_callback_)) {
@@ -211,20 +187,32 @@ void UDPSocketPrivateResource::OnPluginMsgBindReply(
bind_callback_->Run(params.result());
}
-void UDPSocketPrivateResource::OnPluginMsgRecvFromReply(
+void UDPSocketResourceBase::OnPluginMsgRecvFromReply(
+ PP_Resource* output_addr,
const ResourceMessageReplyParams& params,
const std::string& data,
const PP_NetAddress_Private& addr) {
- if (!TrackedCallback::IsPending(recvfrom_callback_) || !read_buffer_) {
+ if (!TrackedCallback::IsPending(recvfrom_callback_)) {
NOTREACHED();
return;
}
bool succeeded = (params.result() == PP_OK);
+ if (succeeded && output_addr) {
+ thunk::EnterResourceCreationNoLock enter(pp_instance());
+ if (enter.succeeded()) {
+ *output_addr = enter.functions()->CreateNetAddressFromNetAddressPrivate(
+ pp_instance(), addr);
+ } else {
+ succeeded = false;
+ }
+ }
+
if (succeeded) {
CHECK_LE(static_cast<int32_t>(data.size()), bytes_to_read_);
if (!data.empty())
memcpy(read_buffer_, data.c_str(), data.size());
}
+
read_buffer_ = NULL;
bytes_to_read_ = -1;
recvfrom_addr_ = addr;
@@ -235,7 +223,7 @@ void UDPSocketPrivateResource::OnPluginMsgRecvFromReply(
recvfrom_callback_->Run(params.result());
}
-void UDPSocketPrivateResource::OnPluginMsgSendToReply(
+void UDPSocketResourceBase::OnPluginMsgSendToReply(
const ResourceMessageReplyParams& params,
int32_t bytes_written) {
if (!TrackedCallback::IsPending(sendto_callback_)) {
« no previous file with comments | « ppapi/proxy/udp_socket_resource_base.h ('k') | ppapi/shared_impl/resource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698