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 65% |
copy from ppapi/proxy/udp_socket_private_resource.cc |
copy to ppapi/proxy/udp_socket_resource_base.cc |
index 608fc00a1613d5bd59e3bbd30ba97c45886f9997..0c54dfb1e60330c93bdd7b77c1a76255415fe1dd 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)); |
+ 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( |
+int32_t UDPSocketResourceBase::BindImpl( |
const PP_NetAddress_Private* addr, |
scoped_refptr<TrackedCallback> callback) { |
if (!addr) |
@@ -78,11 +77,17 @@ 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, |
bbudge
2013/06/12 18:52:37
Why not construct the msg inline here?
yzshen1
2013/06/12 19:32:53
Done.
|
+ 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 +95,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 +112,16 @@ 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, |
bbudge
2013/06/12 18:52:37
Same as above.
yzshen1
2013/06/12 19:32:53
Done.
|
+ 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 +129,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 +147,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, |
bbudge
2013/06/12 18:52:37
inline?
yzshen1
2013/06/12 19:32:53
Done.
|
+ 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(); |
+ 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 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 +191,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 +227,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_)) { |