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 #ifndef WEBKIT_PLUGINS_PPAPI_PPB_TRANSPORT_IMPL_H_ | 5 #ifndef WEBKIT_PLUGINS_PPAPI_PPB_TRANSPORT_IMPL_H_ |
6 #define WEBKIT_PLUGINS_PPAPI_PPB_TRANSPORT_IMPL_H_ | 6 #define WEBKIT_PLUGINS_PPAPI_PPB_TRANSPORT_IMPL_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "net/base/completion_callback.h" | 13 #include "net/base/completion_callback.h" |
14 #include "ppapi/c/dev/ppb_transport_dev.h" | 14 #include "ppapi/thunk/ppb_transport_api.h" |
15 #include "webkit/glue/p2p_transport.h" | 15 #include "webkit/glue/p2p_transport.h" |
16 #include "webkit/plugins/ppapi/callbacks.h" | 16 #include "webkit/plugins/ppapi/callbacks.h" |
17 #include "webkit/plugins/ppapi/resource.h" | 17 #include "webkit/plugins/ppapi/resource.h" |
18 | 18 |
19 namespace webkit { | 19 namespace webkit { |
20 namespace ppapi { | 20 namespace ppapi { |
21 | 21 |
22 class PPB_Transport_Impl : public Resource, | 22 class PPB_Transport_Impl : public Resource, |
| 23 public ::ppapi::thunk::PPB_Transport_API, |
23 public webkit_glue::P2PTransport::EventHandler { | 24 public webkit_glue::P2PTransport::EventHandler { |
24 public: | 25 public: |
25 static const PPB_Transport_Dev* GetInterface(); | |
26 | |
27 explicit PPB_Transport_Impl(PluginInstance* instance); | |
28 virtual ~PPB_Transport_Impl(); | 26 virtual ~PPB_Transport_Impl(); |
29 | 27 |
30 bool Init(const char* name, const char* proto); | 28 static PP_Resource Create(PP_Instance instance, |
| 29 const char* name, |
| 30 const char* proto); |
31 | 31 |
32 // Resource override. | 32 // ResourceObjectBase override. |
33 virtual PPB_Transport_Impl* AsPPB_Transport_Impl() OVERRIDE; | 33 virtual ::ppapi::thunk::PPB_Transport_API* AsPPB_Transport_API() OVERRIDE; |
34 | 34 |
35 bool IsWritable() const; | 35 // PPB_Transport_API implementation. |
36 int32_t Connect(PP_CompletionCallback cb); | 36 virtual PP_Bool IsWritable() OVERRIDE; |
37 int32_t GetNextAddress(PP_Var* address, PP_CompletionCallback cb); | 37 virtual int32_t Connect(PP_CompletionCallback callback) OVERRIDE; |
38 int32_t ReceiveRemoteAddress(PP_Var address); | 38 virtual int32_t GetNextAddress(PP_Var* address, |
39 int32_t Recv(void* data, uint32_t len, PP_CompletionCallback cb); | 39 PP_CompletionCallback callback) OVERRIDE; |
40 int32_t Send(const void* data, uint32_t len, PP_CompletionCallback cb); | 40 virtual int32_t ReceiveRemoteAddress(PP_Var address) OVERRIDE; |
41 int32_t Close(); | 41 virtual int32_t Recv(void* data, uint32_t len, |
| 42 PP_CompletionCallback callback) OVERRIDE; |
| 43 virtual int32_t Send(const void* data, uint32_t len, |
| 44 PP_CompletionCallback callback) OVERRIDE; |
| 45 virtual int32_t Close() OVERRIDE; |
42 | 46 |
43 // webkit_glue::P2PTransport::EventHandler implementation. | 47 // webkit_glue::P2PTransport::EventHandler implementation. |
44 virtual void OnCandidateReady(const std::string& address) OVERRIDE; | 48 virtual void OnCandidateReady(const std::string& address) OVERRIDE; |
45 virtual void OnStateChange(webkit_glue::P2PTransport::State state) OVERRIDE; | 49 virtual void OnStateChange(webkit_glue::P2PTransport::State state) OVERRIDE; |
46 virtual void OnError(int error) OVERRIDE; | 50 virtual void OnError(int error) OVERRIDE; |
47 | 51 |
48 private: | 52 private: |
| 53 explicit PPB_Transport_Impl(PluginInstance* instance); |
| 54 |
| 55 bool Init(const char* name, const char* proto); |
| 56 |
49 void OnRead(int result); | 57 void OnRead(int result); |
50 void OnWritten(int result); | 58 void OnWritten(int result); |
51 | 59 |
52 std::string name_; | 60 std::string name_; |
53 bool use_tcp_; | 61 bool use_tcp_; |
54 bool started_; | 62 bool started_; |
55 scoped_ptr<webkit_glue::P2PTransport> p2p_transport_; | 63 scoped_ptr<webkit_glue::P2PTransport> p2p_transport_; |
56 bool writable_; | 64 bool writable_; |
57 std::list<std::string> local_candidates_; | 65 std::list<std::string> local_candidates_; |
58 | 66 |
59 scoped_refptr<TrackedCompletionCallback> connect_callback_; | 67 scoped_refptr<TrackedCompletionCallback> connect_callback_; |
60 scoped_refptr<TrackedCompletionCallback> next_address_callback_; | 68 scoped_refptr<TrackedCompletionCallback> next_address_callback_; |
61 | 69 |
62 scoped_refptr<TrackedCompletionCallback> recv_callback_; | 70 scoped_refptr<TrackedCompletionCallback> recv_callback_; |
63 scoped_refptr<TrackedCompletionCallback> send_callback_; | 71 scoped_refptr<TrackedCompletionCallback> send_callback_; |
64 | 72 |
65 net::CompletionCallbackImpl<PPB_Transport_Impl> channel_write_callback_; | 73 net::CompletionCallbackImpl<PPB_Transport_Impl> channel_write_callback_; |
66 net::CompletionCallbackImpl<PPB_Transport_Impl> channel_read_callback_; | 74 net::CompletionCallbackImpl<PPB_Transport_Impl> channel_read_callback_; |
67 | 75 |
68 DISALLOW_COPY_AND_ASSIGN(PPB_Transport_Impl); | 76 DISALLOW_COPY_AND_ASSIGN(PPB_Transport_Impl); |
69 }; | 77 }; |
70 | 78 |
71 } // namespace ppapi | 79 } // namespace ppapi |
72 } // namespace webkit | 80 } // namespace webkit |
73 | 81 |
74 #endif // WEBKIT_PLUGINS_PPAPI_PPB_TRANSPORT_IMPL_H_ | 82 #endif // WEBKIT_PLUGINS_PPAPI_PPB_TRANSPORT_IMPL_H_ |
OLD | NEW |