OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ppapi/proxy/ppb_flash_tcp_socket_proxy.h" | 5 #include "ppapi/proxy/ppb_flash_tcp_socket_proxy.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstring> | 8 #include <cstring> |
9 #include <map> | 9 #include <map> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
14 #include "base/task.h" | 14 #include "base/task.h" |
15 #include "ppapi/c/pp_errors.h" | 15 #include "ppapi/c/pp_errors.h" |
16 #include "ppapi/proxy/plugin_dispatcher.h" | 16 #include "ppapi/proxy/plugin_dispatcher.h" |
17 #include "ppapi/proxy/plugin_resource.h" | |
18 #include "ppapi/proxy/plugin_resource_tracker.h" | 17 #include "ppapi/proxy/plugin_resource_tracker.h" |
19 #include "ppapi/proxy/ppapi_messages.h" | 18 #include "ppapi/proxy/ppapi_messages.h" |
19 #include "ppapi/shared_impl/resource.h" | |
20 #include "ppapi/thunk/ppb_flash_tcp_socket_api.h" | 20 #include "ppapi/thunk/ppb_flash_tcp_socket_api.h" |
21 #include "ppapi/thunk/thunk.h" | 21 #include "ppapi/thunk/thunk.h" |
22 | 22 |
23 using ppapi::HostResource; | 23 using ppapi::HostResource; |
24 using ppapi::Resource; | |
24 using ppapi::thunk::PPB_Flash_TCPSocket_API; | 25 using ppapi::thunk::PPB_Flash_TCPSocket_API; |
25 | 26 |
26 namespace pp { | 27 namespace pp { |
27 namespace proxy { | 28 namespace proxy { |
28 | 29 |
29 const int32_t kFlashTCPSocketMaxReadSize = 1024 * 1024; | 30 const int32_t kFlashTCPSocketMaxReadSize = 1024 * 1024; |
30 const int32_t kFlashTCPSocketMaxWriteSize = 1024 * 1024; | 31 const int32_t kFlashTCPSocketMaxWriteSize = 1024 * 1024; |
31 | 32 |
32 class FlashTCPSocket; | 33 class FlashTCPSocket; |
33 | 34 |
(...skipping 17 matching lines...) Expand all Loading... | |
51 }; | 52 }; |
52 | 53 |
53 InterfaceProxy* CreateFlashTCPSocketProxy(Dispatcher* dispatcher, | 54 InterfaceProxy* CreateFlashTCPSocketProxy(Dispatcher* dispatcher, |
54 const void* target_interface) { | 55 const void* target_interface) { |
55 return new PPB_Flash_TCPSocket_Proxy(dispatcher, target_interface); | 56 return new PPB_Flash_TCPSocket_Proxy(dispatcher, target_interface); |
56 } | 57 } |
57 | 58 |
58 } // namespace | 59 } // namespace |
59 | 60 |
60 class FlashTCPSocket : public PPB_Flash_TCPSocket_API, | 61 class FlashTCPSocket : public PPB_Flash_TCPSocket_API, |
61 public PluginResource { | 62 public Resource { |
62 public: | 63 public: |
63 FlashTCPSocket(const HostResource& resource, uint32 socket_id); | 64 FlashTCPSocket(const HostResource& resource, uint32 socket_id); |
64 virtual ~FlashTCPSocket(); | 65 virtual ~FlashTCPSocket(); |
65 | 66 |
66 // ResourceObjectBase overrides. | 67 // Resource overrides. |
67 virtual PPB_Flash_TCPSocket_API* AsPPB_Flash_TCPSocket_API() OVERRIDE; | 68 virtual PPB_Flash_TCPSocket_API* AsPPB_Flash_TCPSocket_API() OVERRIDE; |
68 | 69 |
69 // PPB_Flash_TCPSocket_API implementation. | 70 // PPB_Flash_TCPSocket_API implementation. |
70 virtual int32_t Connect(const char* host, | 71 virtual int32_t Connect(const char* host, |
71 uint16_t port, | 72 uint16_t port, |
72 PP_CompletionCallback callback) OVERRIDE; | 73 PP_CompletionCallback callback) OVERRIDE; |
73 virtual int32_t ConnectWithNetAddress( | 74 virtual int32_t ConnectWithNetAddress( |
74 const PP_Flash_NetAddress* addr, | 75 const PP_Flash_NetAddress* addr, |
75 PP_CompletionCallback callback) OVERRIDE; | 76 PP_CompletionCallback callback) OVERRIDE; |
76 virtual PP_Bool GetLocalAddress(PP_Flash_NetAddress* local_addr) OVERRIDE; | 77 virtual PP_Bool GetLocalAddress(PP_Flash_NetAddress* local_addr) OVERRIDE; |
(...skipping 17 matching lines...) Expand all Loading... | |
94 | 95 |
95 private: | 96 private: |
96 enum ConnectionState { | 97 enum ConnectionState { |
97 // Before a connection is successfully established (including a connect | 98 // Before a connection is successfully established (including a connect |
98 // request is pending or a previous connect request failed). | 99 // request is pending or a previous connect request failed). |
99 BEFORE_CONNECT, | 100 BEFORE_CONNECT, |
100 CONNECTED, | 101 CONNECTED, |
101 DISCONNECTED | 102 DISCONNECTED |
102 }; | 103 }; |
103 | 104 |
105 PluginDispatcher* GetDispatcher() const { | |
106 return PluginDispatcher::GetForResource(this); | |
107 } | |
dmichael (off chromium)
2011/08/17 16:28:07
optional nit: You didn't do this anywhere else...
brettw
2011/08/17 17:16:25
I did this in a few places where we used GetDispat
| |
108 | |
104 // Backend for both Connect() and ConnectWithNetAddress(). To keep things | 109 // Backend for both Connect() and ConnectWithNetAddress(). To keep things |
105 // generic, the message is passed in (on error, it's deleted). | 110 // generic, the message is passed in (on error, it's deleted). |
106 int32_t ConnectWithMessage(IPC::Message* msg, | 111 int32_t ConnectWithMessage(IPC::Message* msg, |
107 PP_CompletionCallback callback); | 112 PP_CompletionCallback callback); |
108 | 113 |
109 void PostAbortAndClearIfNecessary(PP_CompletionCallback* callback); | 114 void PostAbortAndClearIfNecessary(PP_CompletionCallback* callback); |
110 | 115 |
111 uint32 socket_id_; | 116 uint32 socket_id_; |
112 ConnectionState connection_state_; | 117 ConnectionState connection_state_; |
113 | 118 |
114 PP_CompletionCallback connect_callback_; | 119 PP_CompletionCallback connect_callback_; |
115 PP_CompletionCallback read_callback_; | 120 PP_CompletionCallback read_callback_; |
116 PP_CompletionCallback write_callback_; | 121 PP_CompletionCallback write_callback_; |
117 | 122 |
118 char* read_buffer_; | 123 char* read_buffer_; |
119 int32_t bytes_to_read_; | 124 int32_t bytes_to_read_; |
120 | 125 |
121 PP_Flash_NetAddress local_addr_; | 126 PP_Flash_NetAddress local_addr_; |
122 PP_Flash_NetAddress remote_addr_; | 127 PP_Flash_NetAddress remote_addr_; |
123 | 128 |
124 DISALLOW_COPY_AND_ASSIGN(FlashTCPSocket); | 129 DISALLOW_COPY_AND_ASSIGN(FlashTCPSocket); |
125 }; | 130 }; |
126 | 131 |
127 FlashTCPSocket::FlashTCPSocket(const HostResource& resource, uint32 socket_id) | 132 FlashTCPSocket::FlashTCPSocket(const HostResource& resource, uint32 socket_id) |
128 : PluginResource(resource), | 133 : Resource(resource), |
129 socket_id_(socket_id), | 134 socket_id_(socket_id), |
130 connection_state_(BEFORE_CONNECT), | 135 connection_state_(BEFORE_CONNECT), |
131 connect_callback_(PP_BlockUntilComplete()), | 136 connect_callback_(PP_BlockUntilComplete()), |
132 read_callback_(PP_BlockUntilComplete()), | 137 read_callback_(PP_BlockUntilComplete()), |
133 write_callback_(PP_BlockUntilComplete()), | 138 write_callback_(PP_BlockUntilComplete()), |
134 read_buffer_(NULL), | 139 read_buffer_(NULL), |
135 bytes_to_read_(-1) { | 140 bytes_to_read_(-1) { |
136 DCHECK(socket_id != 0); | 141 DCHECK(socket_id != 0); |
137 | 142 |
138 local_addr_.size = 0; | 143 local_addr_.size = 0; |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
367 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | 372 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
368 if (!dispatcher) | 373 if (!dispatcher) |
369 return 0; | 374 return 0; |
370 | 375 |
371 uint32 socket_id = 0; | 376 uint32 socket_id = 0; |
372 dispatcher->SendToBrowser(new PpapiHostMsg_PPBFlashTCPSocket_Create( | 377 dispatcher->SendToBrowser(new PpapiHostMsg_PPBFlashTCPSocket_Create( |
373 INTERFACE_ID_PPB_FLASH_TCPSOCKET, dispatcher->plugin_dispatcher_id(), | 378 INTERFACE_ID_PPB_FLASH_TCPSOCKET, dispatcher->plugin_dispatcher_id(), |
374 &socket_id)); | 379 &socket_id)); |
375 if (socket_id == 0) | 380 if (socket_id == 0) |
376 return 0; | 381 return 0; |
377 | 382 return (new FlashTCPSocket(HostResource::MakeInstanceOnly(instance), |
378 return PluginResourceTracker::GetInstance()->AddResource( | 383 socket_id))->GetReference(); |
379 new FlashTCPSocket(HostResource::MakeInstanceOnly(instance), socket_id)); | |
380 } | 384 } |
381 | 385 |
382 bool PPB_Flash_TCPSocket_Proxy::OnMessageReceived(const IPC::Message& msg) { | 386 bool PPB_Flash_TCPSocket_Proxy::OnMessageReceived(const IPC::Message& msg) { |
383 bool handled = true; | 387 bool handled = true; |
384 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_TCPSocket_Proxy, msg) | 388 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_TCPSocket_Proxy, msg) |
385 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFlashTCPSocket_ConnectACK, OnMsgConnectACK) | 389 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFlashTCPSocket_ConnectACK, OnMsgConnectACK) |
386 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFlashTCPSocket_ReadACK, OnMsgReadACK) | 390 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFlashTCPSocket_ReadACK, OnMsgReadACK) |
387 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFlashTCPSocket_WriteACK, OnMsgWriteACK) | 391 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFlashTCPSocket_WriteACK, OnMsgWriteACK) |
388 IPC_MESSAGE_UNHANDLED(handled = false) | 392 IPC_MESSAGE_UNHANDLED(handled = false) |
389 IPC_END_MESSAGE_MAP() | 393 IPC_END_MESSAGE_MAP() |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
429 return; | 433 return; |
430 } | 434 } |
431 IDToSocketMap::iterator iter = g_id_to_socket->find(socket_id); | 435 IDToSocketMap::iterator iter = g_id_to_socket->find(socket_id); |
432 if (iter == g_id_to_socket->end()) | 436 if (iter == g_id_to_socket->end()) |
433 return; | 437 return; |
434 iter->second->OnWriteCompleted(succeeded, bytes_written); | 438 iter->second->OnWriteCompleted(succeeded, bytes_written); |
435 } | 439 } |
436 | 440 |
437 } // namespace proxy | 441 } // namespace proxy |
438 } // namespace pp | 442 } // namespace pp |
OLD | NEW |