OLD | NEW |
| (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 #ifndef REMOTING_PROTOCOL_PEPPER_P2P_CHANNEL_H_ | |
6 #define REMOTING_PROTOCOL_PEPPER_P2P_CHANNEL_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/callback.h" | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/threading/non_thread_safe.h" | |
13 #include "net/socket/socket.h" | |
14 #include "ppapi/c/pp_stdint.h" | |
15 | |
16 namespace pp { | |
17 class Instance; | |
18 class Transport_Dev; | |
19 } // namespace pp | |
20 | |
21 namespace remoting { | |
22 namespace protocol { | |
23 | |
24 // This class create P2PChannel based on the Pepper P2P Transport API | |
25 // and provides net::Socket interface on top of it. | |
26 class PepperP2PChannel : public base::NonThreadSafe, | |
27 public net::Socket { | |
28 public: | |
29 // TODO(sergeyu): Use cricket::Candidate instead of strings to | |
30 // represent candidates. | |
31 typedef base::Callback<void(const std::string&)> IncomingCandidateCallback; | |
32 | |
33 PepperP2PChannel(pp::Instance* pp_instance, const char* name, | |
34 const IncomingCandidateCallback& candidate_callback); | |
35 virtual ~PepperP2PChannel(); | |
36 | |
37 bool Init(); | |
38 | |
39 // Adds candidate received from the peer. | |
40 void AddRemoteCandidate(const std::string& candidate); | |
41 | |
42 // net::Socket interface. | |
43 virtual int Read(net::IOBuffer* buf, int buf_len, | |
44 net::CompletionCallback* callback); | |
45 virtual int Write(net::IOBuffer* buf, int buf_len, | |
46 net::CompletionCallback* callback); | |
47 virtual bool SetReceiveBufferSize(int32 size); | |
48 virtual bool SetSendBufferSize(int32 size); | |
49 | |
50 private: | |
51 // Callbacks for PPAPI calls. | |
52 static void NextAddressCallback(void* data, int32_t result); | |
53 static void ReadCallback(void* data, int32_t result); | |
54 static void WriteCallback(void* data, int32_t result); | |
55 | |
56 bool ProcessCandidates(); | |
57 | |
58 IncomingCandidateCallback candidate_callback_; | |
59 | |
60 scoped_ptr<pp::Transport_Dev> transport_; | |
61 | |
62 bool get_address_pending_; | |
63 | |
64 net::CompletionCallback* read_callback_; | |
65 scoped_refptr<net::IOBuffer> read_buffer_; | |
66 | |
67 net::CompletionCallback* write_callback_; | |
68 scoped_refptr<net::IOBuffer> write_buffer_; | |
69 | |
70 DISALLOW_COPY_AND_ASSIGN(PepperP2PChannel); | |
71 }; | |
72 | |
73 } // namespace protocol | |
74 } // namespace remoting | |
75 | |
76 #endif // REMOTING_PROTOCOL_PEPPER_P2P_CHANNEL_H_ | |
OLD | NEW |