OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015 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 "ppapi/c/ppb_vpn_provider.h" |
| 9 #include "ppapi/proxy/plugin_dispatcher.h" |
| 10 #include "ppapi/proxy/plugin_resource.h" |
| 11 #include "ppapi/proxy/serialized_structs.h" |
| 12 #include "ppapi/shared_impl/tracked_callback.h" |
| 13 #include "ppapi/shared_impl/vpn_provider_util.h" |
| 14 #include "ppapi/thunk/ppb_vpn_provider_api.h" |
| 15 |
| 16 namespace ppapi { |
| 17 namespace proxy { |
| 18 |
| 19 class PPAPI_PROXY_EXPORT VpnProviderResource |
| 20 : public PluginResource, |
| 21 public NON_EXPORTED_BASE(thunk::PPB_VpnProvider_API) { |
| 22 public: |
| 23 VpnProviderResource(Connection connection, PP_Instance instance); |
| 24 virtual ~VpnProviderResource(); |
| 25 |
| 26 // PluginResource implementation. |
| 27 virtual thunk::PPB_VpnProvider_API* AsPPB_VpnProvider_API() override; |
| 28 |
| 29 // PPB_VpnProvider_API implementation. |
| 30 virtual int32_t Bind(const PP_Var& configuration_id, |
| 31 const PP_Var& configuration_name, |
| 32 const scoped_refptr<TrackedCallback>& callback) override; |
| 33 virtual int32_t GetUnBindEvent( |
| 34 const scoped_refptr<TrackedCallback>& callback) override; |
| 35 virtual int32_t SendPacket( |
| 36 const PP_Var& data, |
| 37 const scoped_refptr<TrackedCallback>& callback) override; |
| 38 virtual int32_t ReceivePacket( |
| 39 PP_Var* packet, |
| 40 const scoped_refptr<TrackedCallback>& callback) override; |
| 41 |
| 42 private: |
| 43 // PluginResource overrides. |
| 44 virtual void OnReplyReceived(const ResourceMessageReplyParams& params, |
| 45 const IPC::Message& msg) override; |
| 46 |
| 47 // PPB_VpnProvider IPC Replies |
| 48 void OnPluginMsgBindReply(const ResourceMessageReplyParams& params, |
| 49 uint32_t queue_depth, |
| 50 uint32_t packet_size, |
| 51 int32_t result); |
| 52 void OnPluginMsgSendPacketReply(const ResourceMessageReplyParams& params, |
| 53 int32_t result); |
| 54 |
| 55 // Browser callbacks |
| 56 void OnPluginMsgOnUnBindReceived(const ResourceMessageReplyParams& params); |
| 57 void OnPluginMsgOnPacketReceived(const ResourceMessageReplyParams& params, |
| 58 uint32_t data_length, |
| 59 uint32_t id); |
| 60 |
| 61 // Picks up a received message and moves it to user receiving buffer. This |
| 62 // function is used in both Get*() for fast returning path, and |
| 63 // OnPluginMsgOn*() for delayed callback invocations. |
| 64 void WritePacket(); |
| 65 |
| 66 void ProcessQueuedPackets(uint32_t id); |
| 67 int32_t DoSendPacket(const PP_Var& data, uint32_t id); |
| 68 |
| 69 // Holds user callbacks to invoke later. |
| 70 scoped_refptr<TrackedCallback> bind_callback_; |
| 71 scoped_refptr<TrackedCallback> get_unbind_event_callback_; |
| 72 scoped_refptr<TrackedCallback> send_packet_callback_; |
| 73 scoped_refptr<TrackedCallback> receive_packet_callback_; |
| 74 |
| 75 // Keeps a pointer to the callback variable provided. |
| 76 // Received data will be copied to this variable on ready. |
| 77 PP_Var* receive_packet_callback_var_; |
| 78 |
| 79 std::unique_ptr<ppapi::VpnProviderSharedBuffer> send_packet_buffer_; |
| 80 std::unique_ptr<ppapi::VpnProviderSharedBuffer> receive_packet_buffer_; |
| 81 |
| 82 // Packet buffers |
| 83 std::queue<PP_Var> send_packets_; |
| 84 std::queue<scoped_refptr<Var>> received_packets_; |
| 85 |
| 86 DISALLOW_COPY_AND_ASSIGN(VpnProviderResource); |
| 87 }; |
| 88 |
| 89 } // namespace proxy |
| 90 } // namespace ppapi |
| 91 |
| 92 #endif // PPAPI_PROXY_VPN_PROVIDER_RESOURCE_H_ |
OLD | NEW |