blob: 8453fc46475d637929e1f4838a3330127078c1d6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef REMOTING_PROTOCOL_PEPPER_TRANSPORT_SOCKET_ADAPTER_H_
#define REMOTING_PROTOCOL_PEPPER_TRANSPORT_SOCKET_ADAPTER_H_
#include <string>
#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
#include "base/threading/non_thread_safe.h"
#include "net/base/completion_callback.h"
#include "net/base/net_log.h"
#include "net/socket/stream_socket.h"
#include "ppapi/c/pp_stdint.h"
#include "ppapi/cpp/completion_callback.h"
namespace pp {
class Transport_Dev;
} // namespace pp
namespace remoting {
namespace protocol {
// This class implements net::StreamSocket interface on top of the the
// Pepper P2P Transport API.
class PepperTransportSocketAdapter : public base::NonThreadSafe,
public net::StreamSocket {
public:
// Observer is used to notify about new local candidates and
// deletion of the adapter.
class Observer {
public:
Observer() { }
virtual ~Observer() { }
virtual void OnChannelDeleted() = 0;
virtual void OnChannelNewLocalCandidate(const std::string& candidate) = 0;
};
PepperTransportSocketAdapter(pp::Transport_Dev* transport,
const std::string& name,
Observer* observer);
virtual ~PepperTransportSocketAdapter();
const std::string& name() { return name_; }
// Adds candidate received from the peer.
void AddRemoteCandidate(const std::string& candidate);
// net::Socket implementation.
virtual int Read(net::IOBuffer* buf, int buf_len,
net::OldCompletionCallback* callback) OVERRIDE;
virtual int Read(net::IOBuffer* buf, int buf_len,
const net::CompletionCallback& callback) OVERRIDE;
virtual int Write(net::IOBuffer* buf, int buf_len,
net::OldCompletionCallback* callback) OVERRIDE;
virtual int Write(net::IOBuffer* buf, int buf_len,
const net::CompletionCallback& callback) OVERRIDE;
virtual bool SetReceiveBufferSize(int32 size) OVERRIDE;
virtual bool SetSendBufferSize(int32 size) OVERRIDE;
// net::StreamSocket implementation.
virtual int Connect(net::OldCompletionCallback* callback) OVERRIDE;
virtual int Connect(const net::CompletionCallback& callback) OVERRIDE;
virtual void Disconnect() OVERRIDE;
virtual bool IsConnected() const OVERRIDE;
virtual bool IsConnectedAndIdle() const OVERRIDE;
virtual int GetPeerAddress(net::AddressList* address) const OVERRIDE;
virtual int GetLocalAddress(net::IPEndPoint* address) const OVERRIDE;
virtual const net::BoundNetLog& NetLog() const OVERRIDE;
virtual void SetSubresourceSpeculation() OVERRIDE;
virtual void SetOmniboxSpeculation() OVERRIDE;
virtual bool WasEverUsed() const OVERRIDE;
virtual bool UsingTCPFastOpen() const OVERRIDE;
virtual int64 NumBytesRead() const OVERRIDE;
virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE;
private:
// Callbacks for PPAPI calls.
void OnConnect(int result);
void OnNextAddress(int32_t result);
void OnRead(int32_t result);
void OnWrite(int32_t result);
int ProcessCandidates();
std::string name_;
Observer* observer_;
scoped_ptr<pp::Transport_Dev> transport_;
net::OldCompletionCallback* old_connect_callback_;
net::CompletionCallback connect_callback_;
bool connected_;
bool get_address_pending_;
net::OldCompletionCallback* old_read_callback_;
net::CompletionCallback read_callback_;
scoped_refptr<net::IOBuffer> read_buffer_;
net::OldCompletionCallback* old_write_callback_;
net::CompletionCallback write_callback_;
scoped_refptr<net::IOBuffer> write_buffer_;
net::BoundNetLog net_log_;
pp::CompletionCallbackFactory<PepperTransportSocketAdapter> callback_factory_;
DISALLOW_COPY_AND_ASSIGN(PepperTransportSocketAdapter);
};
} // namespace protocol
} // namespace remoting
#endif // REMOTING_PROTOCOL_PEPPER_TRANSPORT_SOCKET_ADAPTER_H_
|