OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 JINGLE_GLUE_CHANNEL_SOCKET_ADAPTER_H_ | 5 #ifndef REMOTING_PROTOCOL_CHANNEL_SOCKET_ADAPTER_H_ |
6 #define JINGLE_GLUE_CHANNEL_SOCKET_ADAPTER_H_ | 6 #define REMOTING_PROTOCOL_CHANNEL_SOCKET_ADAPTER_H_ |
7 | 7 |
8 #include "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/threading/thread_checker.h" |
10 #include "net/socket/socket.h" | 11 #include "net/socket/socket.h" |
11 #include "third_party/webrtc/base/asyncpacketsocket.h" | 12 #include "third_party/webrtc/base/asyncpacketsocket.h" |
12 #include "third_party/webrtc/base/sigslot.h" | 13 #include "third_party/webrtc/base/sigslot.h" |
13 #include "third_party/webrtc/base/socketaddress.h" | 14 #include "third_party/webrtc/base/socketaddress.h" |
14 | 15 |
15 namespace base { | |
16 class MessageLoop; | |
17 } | |
18 | |
19 namespace cricket { | 16 namespace cricket { |
20 class TransportChannel; | 17 class TransportChannel; |
21 } // namespace cricket | 18 } // namespace cricket |
22 | 19 |
23 namespace jingle_glue { | 20 namespace remoting { |
| 21 namespace protocol { |
24 | 22 |
25 // TransportChannelSocketAdapter implements net::Socket interface on | 23 // TransportChannelSocketAdapter implements net::Socket interface on |
26 // top of libjingle's TransportChannel. It is used by | 24 // top of libjingle's TransportChannel. It is used by LibjingleTransportFactory |
27 // JingleChromotocolConnection to provide net::Socket interface for channels. | 25 // to provide net::Socket interface for channels. |
28 class TransportChannelSocketAdapter : public net::Socket, | 26 class TransportChannelSocketAdapter : public net::Socket, |
29 public sigslot::has_slots<> { | 27 public sigslot::has_slots<> { |
30 public: | 28 public: |
31 // TransportChannel object is always owned by the corresponding session. | 29 // Doesn't take ownership of the |channel|. The |channel| must outlive |
| 30 // this adapter. |
32 explicit TransportChannelSocketAdapter(cricket::TransportChannel* channel); | 31 explicit TransportChannelSocketAdapter(cricket::TransportChannel* channel); |
33 ~TransportChannelSocketAdapter() override; | 32 ~TransportChannelSocketAdapter() override; |
34 | 33 |
35 // Sets callback that should be called when the adapter is being | 34 // Sets callback that should be called when the adapter is being |
36 // destroyed. The callback is not allowed to touch the adapter, but | 35 // destroyed. The callback is not allowed to touch the adapter, but |
37 // can do anything else, e.g. destroy the TransportChannel. | 36 // can do anything else, e.g. destroy the TransportChannel. |
38 void SetOnDestroyedCallback(const base::Closure& callback); | 37 void SetOnDestroyedCallback(const base::Closure& callback); |
39 | 38 |
40 // Closes the stream. |error_code| specifies error code that will | 39 // Closes the stream. |error_code| specifies error code that will |
41 // be returned by Read() and Write() after the stream is closed. | 40 // be returned by Read() and Write() after the stream is closed. |
42 // Must be called before the session and the channel are destroyed. | 41 // Must be called before the session and the channel are destroyed. |
43 void Close(int error_code); | 42 void Close(int error_code); |
44 | 43 |
45 // Socket implementation. | 44 // net::Socket interface. |
46 int Read(net::IOBuffer* buf, | 45 int Read(net::IOBuffer* buf, |
47 int buf_len, | 46 int buf_len, |
48 const net::CompletionCallback& callback) override; | 47 const net::CompletionCallback& callback) override; |
49 int Write(net::IOBuffer* buf, | 48 int Write(net::IOBuffer* buf, |
50 int buf_len, | 49 int buf_len, |
51 const net::CompletionCallback& callback) override; | 50 const net::CompletionCallback& callback) override; |
52 | 51 |
53 int SetReceiveBufferSize(int32 size) override; | 52 int SetReceiveBufferSize(int32 size) override; |
54 int SetSendBufferSize(int32 size) override; | 53 int SetSendBufferSize(int32 size) override; |
55 | 54 |
56 private: | 55 private: |
57 void OnNewPacket(cricket::TransportChannel* channel, | 56 void OnNewPacket(cricket::TransportChannel* channel, |
58 const char* data, | 57 const char* data, |
59 size_t data_size, | 58 size_t data_size, |
60 const rtc::PacketTime& packet_time, | 59 const rtc::PacketTime& packet_time, |
61 int flags); | 60 int flags); |
62 void OnWritableState(cricket::TransportChannel* channel); | 61 void OnWritableState(cricket::TransportChannel* channel); |
63 void OnChannelDestroyed(cricket::TransportChannel* channel); | 62 void OnChannelDestroyed(cricket::TransportChannel* channel); |
64 | 63 |
65 base::MessageLoop* message_loop_; | 64 base::ThreadChecker thread_checker_; |
66 | 65 |
67 cricket::TransportChannel* channel_; | 66 cricket::TransportChannel* channel_; |
68 | 67 |
69 base::Closure destruction_callback_; | 68 base::Closure destruction_callback_; |
70 | 69 |
71 net::CompletionCallback read_callback_; | 70 net::CompletionCallback read_callback_; |
72 scoped_refptr<net::IOBuffer> read_buffer_; | 71 scoped_refptr<net::IOBuffer> read_buffer_; |
73 int read_buffer_size_; | 72 int read_buffer_size_; |
74 | 73 |
75 net::CompletionCallback write_callback_; | 74 net::CompletionCallback write_callback_; |
76 scoped_refptr<net::IOBuffer> write_buffer_; | 75 scoped_refptr<net::IOBuffer> write_buffer_; |
77 int write_buffer_size_; | 76 int write_buffer_size_; |
78 | 77 |
79 int closed_error_code_; | 78 int closed_error_code_; |
80 | 79 |
81 DISALLOW_COPY_AND_ASSIGN(TransportChannelSocketAdapter); | 80 DISALLOW_COPY_AND_ASSIGN(TransportChannelSocketAdapter); |
82 }; | 81 }; |
83 | 82 |
84 } // namespace jingle_glue | 83 } // namespace protocol |
| 84 } // namespace remoting |
85 | 85 |
86 #endif // JINGLE_GLUE_CHANNEL_SOCKET_ADAPTER_H_ | 86 #endif // REMOTING_PROTOCOL_CHANNEL_SOCKET_ADAPTER_H_ |
OLD | NEW |