Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2016 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 #ifndef PPAPI_PROXY_VPN_PROVIDER_RESOURCE_H_ | |
| 6 #define PPAPI_PROXY_VPN_PROVIDER_RESOURCE_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <queue> | |
| 10 | |
| 11 #include "ppapi/proxy/plugin_resource.h" | |
| 12 #include "ppapi/shared_impl/tracked_callback.h" | |
| 13 #include "ppapi/shared_impl/var.h" | |
| 14 #include "ppapi/shared_impl/vpn_provider_util.h" | |
| 15 #include "ppapi/thunk/ppb_vpn_provider_api.h" | |
| 16 | |
| 17 namespace ppapi { | |
| 18 namespace proxy { | |
| 19 | |
| 20 class PPAPI_PROXY_EXPORT VpnProviderResource | |
| 21 : public PluginResource, | |
| 22 public NON_EXPORTED_BASE(thunk::PPB_VpnProvider_API) { | |
| 23 public: | |
| 24 VpnProviderResource(Connection connection, PP_Instance instance); | |
| 25 virtual ~VpnProviderResource(); | |
| 26 | |
| 27 // PluginResource implementation. | |
| 28 virtual thunk::PPB_VpnProvider_API* AsPPB_VpnProvider_API() override; | |
| 29 | |
| 30 // PPB_VpnProvider_API implementation. | |
| 31 virtual int32_t Bind(const PP_Var& configuration_id, | |
| 32 const PP_Var& configuration_name, | |
| 33 const scoped_refptr<TrackedCallback>& callback) override; | |
| 34 virtual int32_t SendPacket( | |
| 35 const PP_Var& packet, | |
| 36 const scoped_refptr<TrackedCallback>& callback) override; | |
| 37 virtual int32_t ReceivePacket( | |
| 38 PP_Var* packet, | |
| 39 const scoped_refptr<TrackedCallback>& callback) override; | |
| 40 | |
| 41 private: | |
| 42 // PluginResource overrides. | |
| 43 virtual void OnReplyReceived(const ResourceMessageReplyParams& params, | |
| 44 const IPC::Message& msg) override; | |
| 45 | |
| 46 // PPB_VpnProvider IPC Replies | |
| 47 void OnPluginMsgBindReply(const ResourceMessageReplyParams& params, | |
| 48 uint32_t queue_depth, | |
| 49 uint32_t max_packet_size, | |
| 50 int32_t result); | |
| 51 void OnPluginMsgSendPacketReply(const ResourceMessageReplyParams& params, | |
| 52 int32_t result); | |
| 53 | |
| 54 // Browser callbacks | |
| 55 void OnPluginMsgOnUnbindReceived(const ResourceMessageReplyParams& params); | |
| 56 void OnPluginMsgOnPacketReceived(const ResourceMessageReplyParams& params, | |
| 57 uint32_t packet_size, | |
| 58 uint32_t id); | |
| 59 | |
| 60 // Picks up a received packet and moves it to user buffer. This method is used | |
| 61 // in both ReceivePacket() for fast returning path, and in | |
| 62 // OnPluginMsgOnPacketReceived() for delayed callback invocations. | |
| 63 void WritePacket(); | |
| 64 | |
| 65 // Send a packet to the browser. This method is used in both SendPacket() for | |
|
bbudge
2016/05/17 09:50:12
nit s/Send/Sends
adrian.belgun
2016/05/17 11:05:29
Done.
| |
| 66 // fast path, and in OnPluginMsgSendPacketReply for processing previously | |
| 67 // queued packets. | |
| 68 int32_t DoSendPacket(const PP_Var& packet, uint32_t id); | |
| 69 | |
| 70 // Holds user callbacks to invoke later. | |
|
bbudge
2016/05/17 09:50:12
nit: Comments don't add much and could be removed.
adrian.belgun
2016/05/17 11:05:29
Done.
| |
| 71 scoped_refptr<TrackedCallback> bind_callback_; | |
| 72 scoped_refptr<TrackedCallback> send_packet_callback_; | |
| 73 scoped_refptr<TrackedCallback> receive_packet_callback_; | |
| 74 | |
| 75 // Keeps a pointer to the provided callback variable. Received packet will be | |
| 76 // copied to this variable on ready. | |
| 77 PP_Var* receive_packet_callback_var_; | |
| 78 | |
| 79 // Shared memory buffers used in plugin <---> browser IPC | |
|
bbudge
2016/05/17 09:50:12
same
adrian.belgun
2016/05/17 11:05:29
Done.
| |
| 80 std::unique_ptr<ppapi::VpnProviderSharedBuffer> send_packet_buffer_; | |
| 81 std::unique_ptr<ppapi::VpnProviderSharedBuffer> receive_packet_buffer_; | |
| 82 | |
| 83 // Packet buffers | |
|
bbudge
2016/05/17 09:50:12
same
adrian.belgun
2016/05/17 11:05:29
Done.
| |
| 84 std::queue<PP_Var> send_packets_; | |
| 85 std::queue<scoped_refptr<Var>> received_packets_; | |
| 86 | |
| 87 // Connection bound state | |
| 88 bool bound_; | |
| 89 | |
| 90 DISALLOW_COPY_AND_ASSIGN(VpnProviderResource); | |
| 91 }; | |
| 92 | |
| 93 } // namespace proxy | |
| 94 } // namespace ppapi | |
| 95 | |
| 96 #endif // PPAPI_PROXY_VPN_PROVIDER_RESOURCE_H_ | |
| OLD | NEW |