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

Side by Side Diff: webkit/plugins/ppapi/ppb_udp_socket_private_impl.cc

Issue 8688002: PPB_TCPSocket_Private/PPB_UDPSocket_Private are exposed to Browser (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed codereview issues. Created 9 years 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
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "webkit/plugins/ppapi/ppb_udp_socket_private_impl.h"
6
7 #include "base/message_loop.h"
8 #include "base/task.h"
9 #include "ppapi/c/pp_completion_callback.h"
10 #include "webkit/plugins/ppapi/host_globals.h"
11 #include "webkit/plugins/ppapi/plugin_delegate.h"
12 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
13 #include "webkit/plugins/ppapi/resource_helper.h"
14
15 namespace webkit {
16 namespace ppapi {
17
18 namespace {
19
20 class AbortCallbackTask : public Task {
21 public:
22 explicit AbortCallbackTask(PP_CompletionCallback callback)
23 : callback_(callback) {}
24 virtual ~AbortCallbackTask() {}
25 virtual void Run() {
26 if (callback_.func)
27 PP_RunCompletionCallback(&callback_, PP_ERROR_ABORTED);
28 }
29
30 private:
31 PP_CompletionCallback callback_;
32 };
33
34 } // namespace
35
36 PPB_UDPSocket_Private_Impl::PPB_UDPSocket_Private_Impl(
37 PP_Instance instance, uint32 socket_id)
38 : ::ppapi::UDPSocketImpl(instance, socket_id) {
39 }
40
41 PPB_UDPSocket_Private_Impl::~PPB_UDPSocket_Private_Impl() {
42 Close();
43 }
44
45 PP_Resource PPB_UDPSocket_Private_Impl::CreateResource(PP_Instance instance) {
46 PluginInstance* plugin_instance = HostGlobals::Get()->GetInstance(instance);
47 if (!plugin_instance)
48 return 0;
49
50 PluginDelegate* pluign_delegate = plugin_instance->delegate();
51 uint32 socket_id = pluign_delegate->UDPSocketCreate();
52 if (!socket_id)
53 return 0;
54
55 return (new PPB_UDPSocket_Private_Impl(instance, socket_id))->GetReference();
56 }
57
58 void PPB_UDPSocket_Private_Impl::SendBind(const PP_NetAddress_Private& addr) {
59 PluginDelegate* pluign_delegate = ResourceHelper::GetPluginDelegate(this);
60 if (!pluign_delegate)
61 return;
62
63 pluign_delegate->UDPSocketBind(this, socket_id_, addr);
64 }
65
66 void PPB_UDPSocket_Private_Impl::SendRecvFrom(int32_t num_bytes) {
67 PluginDelegate* pluign_delegate = ResourceHelper::GetPluginDelegate(this);
68 if (!pluign_delegate)
69 return;
70
71 pluign_delegate->UDPSocketRecvFrom(socket_id_, num_bytes);
72 }
73
74 void PPB_UDPSocket_Private_Impl::SendSendTo(const std::string& buffer,
75 const PP_NetAddress_Private& addr) {
76 PluginDelegate* pluign_delegate = ResourceHelper::GetPluginDelegate(this);
77 if (!pluign_delegate)
78 return;
79
80 pluign_delegate->UDPSocketSendTo(socket_id_, buffer, addr);
81 }
82
83 void PPB_UDPSocket_Private_Impl::SendClose() {
84 PluginDelegate* pluign_delegate = ResourceHelper::GetPluginDelegate(this);
85 if (!pluign_delegate)
86 return;
87
88 pluign_delegate->UDPSocketClose(socket_id_);
89 }
90
91 void PPB_UDPSocket_Private_Impl::PostAbort(PP_CompletionCallback callback) {
92 MessageLoop::current()->PostTask(FROM_HERE, new AbortCallbackTask(callback));
93 }
94
95 } // namespace ppapi
96 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698