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_TRANSPORT_SOCKET_ADAPTER_H_ |
| 6 #define REMOTING_PROTOCOL_PEPPER_TRANSPORT_SOCKET_ADAPTER_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/base/net_log.h" |
| 14 #include "net/socket/stream_socket.h" |
| 15 #include "ppapi/c/pp_stdint.h" |
| 16 #include "ppapi/cpp/completion_callback.h" |
| 17 |
| 18 namespace pp { |
| 19 class Instance; |
| 20 class Transport_Dev; |
| 21 } // namespace pp |
| 22 |
| 23 namespace remoting { |
| 24 namespace protocol { |
| 25 |
| 26 // This class implements net::StreamSocket interface on top of the the |
| 27 // Pepper P2P Transport API. |
| 28 class PepperTransportSocketAdapter : public base::NonThreadSafe, |
| 29 public net::StreamSocket { |
| 30 public: |
| 31 // Observer is used to notify about new local candidates and |
| 32 // deletion of the adapter. |
| 33 class Observer { |
| 34 public: |
| 35 Observer() { } |
| 36 virtual ~Observer() { } |
| 37 virtual void OnChannelDeleted() = 0; |
| 38 virtual void OnChannelNewLocalCandidate(const std::string& candidate) = 0; |
| 39 }; |
| 40 |
| 41 PepperTransportSocketAdapter(pp::Instance* pp_instance, |
| 42 const std::string& name, |
| 43 Observer* observer); |
| 44 virtual ~PepperTransportSocketAdapter(); |
| 45 |
| 46 const std::string& name() { return name_; } |
| 47 |
| 48 // Adds candidate received from the peer. |
| 49 void AddRemoteCandidate(const std::string& candidate); |
| 50 |
| 51 // net::Socket interface. |
| 52 virtual int Read(net::IOBuffer* buf, int buf_len, |
| 53 net::CompletionCallback* callback) OVERRIDE; |
| 54 virtual int Write(net::IOBuffer* buf, int buf_len, |
| 55 net::CompletionCallback* callback) OVERRIDE; |
| 56 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE; |
| 57 virtual bool SetSendBufferSize(int32 size) OVERRIDE; |
| 58 |
| 59 // net::StreamSocket interface. |
| 60 virtual int Connect(net::CompletionCallback* callback) OVERRIDE; |
| 61 virtual void Disconnect() OVERRIDE; |
| 62 virtual bool IsConnected() const OVERRIDE; |
| 63 virtual bool IsConnectedAndIdle() const OVERRIDE; |
| 64 virtual int GetPeerAddress(net::AddressList* address) const OVERRIDE; |
| 65 virtual int GetLocalAddress(net::IPEndPoint* address) const OVERRIDE; |
| 66 virtual const net::BoundNetLog& NetLog() const OVERRIDE; |
| 67 virtual void SetSubresourceSpeculation() OVERRIDE; |
| 68 virtual void SetOmniboxSpeculation() OVERRIDE; |
| 69 virtual bool WasEverUsed() const OVERRIDE; |
| 70 virtual bool UsingTCPFastOpen() const OVERRIDE; |
| 71 virtual int64 NumBytesRead() const OVERRIDE; |
| 72 virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE; |
| 73 |
| 74 private: |
| 75 // Callbacks for PPAPI calls. |
| 76 void OnConnect(int result); |
| 77 void OnNextAddress(int32_t result); |
| 78 void OnRead(int32_t result); |
| 79 void OnWrite(int32_t result); |
| 80 |
| 81 int ProcessCandidates(); |
| 82 |
| 83 std::string name_; |
| 84 Observer* observer_; |
| 85 |
| 86 scoped_ptr<pp::Transport_Dev> transport_; |
| 87 |
| 88 net::CompletionCallback* connect_callback_; |
| 89 bool connected_; |
| 90 |
| 91 bool get_address_pending_; |
| 92 |
| 93 net::CompletionCallback* read_callback_; |
| 94 scoped_refptr<net::IOBuffer> read_buffer_; |
| 95 |
| 96 net::CompletionCallback* write_callback_; |
| 97 scoped_refptr<net::IOBuffer> write_buffer_; |
| 98 |
| 99 net::BoundNetLog net_log_; |
| 100 |
| 101 pp::CompletionCallbackFactory<PepperTransportSocketAdapter> callback_factory_; |
| 102 |
| 103 DISALLOW_COPY_AND_ASSIGN(PepperTransportSocketAdapter); |
| 104 }; |
| 105 |
| 106 } // namespace protocol |
| 107 } // namespace remoting |
| 108 |
| 109 #endif // REMOTING_PROTOCOL_PEPPER_TRANSPORT_SOCKET_ADAPTER_H_ |
OLD | NEW |