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

Unified Diff: ppapi/proxy/udp_socket_shared.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
Index: ppapi/proxy/udp_socket_shared.cc
diff --git a/ppapi/proxy/udp_socket_private_resource.cc b/ppapi/proxy/udp_socket_shared.cc
similarity index 61%
copy from ppapi/proxy/udp_socket_private_resource.cc
copy to ppapi/proxy/udp_socket_shared.cc
index 608fc00a1613d5bd59e3bbd30ba97c45886f9997..f2c92834c388b1aa0e48f0a1ccaf7d6746f71ea4 100644
--- a/ppapi/proxy/udp_socket_private_resource.cc
+++ b/ppapi/proxy/udp_socket_shared.cc
@@ -1,27 +1,27 @@
-// 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_shared.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 UDPSocketShared::kMaxReadSize = 1024 * 1024;
+const int32_t UDPSocketShared::kMaxWriteSize = 1024 * 1024;
-UDPSocketPrivateResource::UDPSocketPrivateResource(Connection connection,
- PP_Instance instance)
+UDPSocketShared::UDPSocketShared(Connection connection, PP_Instance instance)
: PluginResource(connection, instance),
bound_(false),
closed_(false),
@@ -37,37 +37,33 @@ UDPSocketPrivateResource::UDPSocketPrivateResource(Connection connection,
SendCreate(BROWSER, PpapiHostMsg_UDPSocketPrivate_Create());
}
-UDPSocketPrivateResource::~UDPSocketPrivateResource() {
+UDPSocketShared::~UDPSocketShared() {
}
-thunk::PPB_UDPSocket_Private_API*
-UDPSocketPrivateResource::AsPPB_UDPSocket_Private_API() {
- return this;
-}
-
-int32_t UDPSocketPrivateResource::SetSocketFeature(
- PP_UDPSocketFeature_Private name,
- PP_Var value) {
+int32_t UDPSocketShared::SetSocketFeatureImpl(PP_UDPSocketFeature_Private name,
+ 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));
+ PpapiHostMsg_UDPSocketPrivate_SetBoolSocketFeature msg(
+ static_cast<int32_t>(name), PP_ToBool(value.value.as_bool));
+ Post(BROWSER, msg);
break;
- default:
+ }
+ default: {
return PP_ERROR_BADARGUMENT;
+ }
}
return PP_OK;
}
-int32_t UDPSocketPrivateResource::Bind(
- const PP_NetAddress_Private* addr,
- scoped_refptr<TrackedCallback> callback) {
+int32_t UDPSocketShared::BindImpl(const PP_NetAddress_Private* addr,
+ scoped_refptr<TrackedCallback> callback) {
if (!addr)
return PP_ERROR_BADARGUMENT;
if (bound_ || closed_)
@@ -78,11 +74,16 @@ int32_t UDPSocketPrivateResource::Bind(
bind_callback_ = callback;
// Send the request, the browser will call us back via BindReply.
- SendBind(*addr);
+ PpapiHostMsg_UDPSocketPrivate_Bind msg(*addr);
+ Call<PpapiPluginMsg_UDPSocketPrivate_BindReply>(
+ BROWSER,
+ msg,
+ base::Bind(&UDPSocketShared::OnPluginMsgBindReply,
+ base::Unretained(this)));
return PP_OK_COMPLETIONPENDING;
}
-PP_Bool UDPSocketPrivateResource::GetBoundAddress(PP_NetAddress_Private* addr) {
+PP_Bool UDPSocketShared::GetBoundAddressImpl(PP_NetAddress_Private* addr) {
if (!addr || !bound_ || closed_)
return PP_FALSE;
@@ -90,10 +91,10 @@ PP_Bool UDPSocketPrivateResource::GetBoundAddress(PP_NetAddress_Private* addr) {
return PP_TRUE;
}
-int32_t UDPSocketPrivateResource::RecvFrom(
- char* buffer,
- int32_t num_bytes,
- scoped_refptr<TrackedCallback> callback) {
+int32_t UDPSocketShared::RecvFromImpl(char* buffer,
+ int32_t num_bytes,
+ PP_Resource* addr,
+ scoped_refptr<TrackedCallback> callback) {
if (!buffer || num_bytes <= 0)
return PP_ERROR_BADARGUMENT;
if (!bound_)
@@ -106,29 +107,26 @@ int32_t UDPSocketPrivateResource::RecvFrom(
recvfrom_callback_ = callback;
// Send the request, the browser will call us back via RecvFromReply.
- SendRecvFrom(bytes_to_read_);
+ PpapiHostMsg_UDPSocketPrivate_RecvFrom msg(bytes_to_read_);
+ Call<PpapiPluginMsg_UDPSocketPrivate_RecvFromReply>(
+ BROWSER,
+ msg,
+ base::Bind(&UDPSocketShared::OnPluginMsgRecvFromReply,
+ base::Unretained(this), addr));
return PP_OK_COMPLETIONPENDING;
}
-PP_Bool UDPSocketPrivateResource::GetRecvFromAddress(
- PP_NetAddress_Private* addr) {
+PP_Bool UDPSocketShared::GetRecvFromAddressImpl(PP_NetAddress_Private* addr) {
if (!addr)
return PP_FALSE;
*addr = recvfrom_addr_;
return PP_TRUE;
}
-void UDPSocketPrivateResource::PostAbortIfNecessary(
- scoped_refptr<TrackedCallback>* callback) {
- if (TrackedCallback::IsPending(*callback))
- (*callback)->PostAbort();
-}
-
-int32_t UDPSocketPrivateResource::SendTo(
- const char* buffer,
- int32_t num_bytes,
- const PP_NetAddress_Private* addr,
- scoped_refptr<TrackedCallback> callback) {
+int32_t UDPSocketShared::SendToImpl(const char* buffer,
+ int32_t num_bytes,
+ const PP_NetAddress_Private* addr,
+ scoped_refptr<TrackedCallback> callback) {
if (!buffer || num_bytes <= 0 || !addr)
return PP_ERROR_BADARGUMENT;
if (!bound_)
@@ -142,63 +140,38 @@ 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);
+ PpapiHostMsg_UDPSocketPrivate_SendTo msg(std::string(buffer, num_bytes),
+ *addr);
+ Call<PpapiPluginMsg_UDPSocketPrivate_SendToReply>(
+ BROWSER,
+ msg,
+ base::Bind(&UDPSocketShared::OnPluginMsgSendToReply,
+ base::Unretained(this)));
return PP_OK_COMPLETIONPENDING;
}
-void UDPSocketPrivateResource::Close() {
+void UDPSocketShared::CloseImpl() {
if(closed_)
return;
bound_ = false;
closed_ = true;
- SendClose();
+ PpapiHostMsg_UDPSocketPrivate_Close msg;
+ Post(BROWSER, msg);
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 UDPSocketShared::PostAbortIfNecessary(
+ scoped_refptr<TrackedCallback>* callback) {
+ if (TrackedCallback::IsPending(*callback))
+ (*callback)->PostAbort();
}
-void UDPSocketPrivateResource::OnPluginMsgBindReply(
+void UDPSocketShared::OnPluginMsgBindReply(
const ResourceMessageReplyParams& params,
const PP_NetAddress_Private& bound_addr) {
if (!TrackedCallback::IsPending(bind_callback_)) {
@@ -211,7 +184,8 @@ void UDPSocketPrivateResource::OnPluginMsgBindReply(
bind_callback_->Run(params.result());
}
-void UDPSocketPrivateResource::OnPluginMsgRecvFromReply(
+void UDPSocketShared::OnPluginMsgRecvFromReply(
+ PP_Resource* output_addr,
const ResourceMessageReplyParams& params,
const std::string& data,
const PP_NetAddress_Private& addr) {
@@ -220,11 +194,22 @@ void UDPSocketPrivateResource::OnPluginMsgRecvFromReply(
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 +220,7 @@ void UDPSocketPrivateResource::OnPluginMsgRecvFromReply(
recvfrom_callback_->Run(params.result());
}
-void UDPSocketPrivateResource::OnPluginMsgSendToReply(
+void UDPSocketShared::OnPluginMsgSendToReply(
const ResourceMessageReplyParams& params,
int32_t bytes_written) {
if (!TrackedCallback::IsPending(sendto_callback_)) {

Powered by Google App Engine
This is Rietveld 408576698