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 // An implementation of buzz::AsyncSocket that uses Chrome sockets. | 5 // An implementation of buzz::AsyncSocket that uses Chrome sockets. |
6 | 6 |
7 #ifndef JINGLE_NOTIFIER_BASE_CHROME_ASYNC_SOCKET_H_ | 7 #ifndef JINGLE_NOTIFIER_BASE_CHROME_ASYNC_SOCKET_H_ |
8 #define JINGLE_NOTIFIER_BASE_CHROME_ASYNC_SOCKET_H_ | 8 #define JINGLE_NOTIFIER_BASE_CHROME_ASYNC_SOCKET_H_ |
9 | 9 |
10 #if !defined(FEATURE_ENABLE_SSL) | 10 #if !defined(FEATURE_ENABLE_SSL) |
11 #error ChromeAsyncSocket expects FEATURE_ENABLE_SSL to be defined | 11 #error ChromeAsyncSocket expects FEATURE_ENABLE_SSL to be defined |
12 #endif | 12 #endif |
13 | 13 |
14 #include <string> | 14 #include <string> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "base/basictypes.h" | 17 #include "base/basictypes.h" |
18 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
19 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
20 #include "base/task.h" | 20 #include "base/task.h" |
21 #include "net/base/completion_callback.h" | 21 #include "net/base/completion_callback.h" |
22 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
23 #include "net/base/net_log.h" | 23 #include "net/base/net_log.h" |
24 #include "talk/xmpp/asyncsocket.h" | 24 #include "talk/xmpp/asyncsocket.h" |
25 | 25 |
26 namespace net { | 26 namespace net { |
27 class ClientSocket; | |
28 class IOBufferWithSize; | 27 class IOBufferWithSize; |
| 28 class StreamSocket; |
29 } // namespace net | 29 } // namespace net |
30 | 30 |
31 namespace notifier { | 31 namespace notifier { |
32 | 32 |
33 class ResolvingClientSocketFactory; | 33 class ResolvingClientSocketFactory; |
34 | 34 |
35 class ChromeAsyncSocket : public buzz::AsyncSocket { | 35 class ChromeAsyncSocket : public buzz::AsyncSocket { |
36 public: | 36 public: |
37 // Takes ownership of |client_socket_factory| but not |net_log|. | 37 // Takes ownership of |client_socket_factory| but not |net_log|. |
38 // |net_log| may be NULL. | 38 // |net_log| may be NULL. |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 buzz::AsyncSocket::Error error_; | 192 buzz::AsyncSocket::Error error_; |
193 net::Error net_error_; | 193 net::Error net_error_; |
194 | 194 |
195 // Used by read/write loops. | 195 // Used by read/write loops. |
196 ScopedRunnableMethodFactory<ChromeAsyncSocket> | 196 ScopedRunnableMethodFactory<ChromeAsyncSocket> |
197 scoped_runnable_method_factory_; | 197 scoped_runnable_method_factory_; |
198 | 198 |
199 // NULL iff state() == STATE_CLOSED. | 199 // NULL iff state() == STATE_CLOSED. |
200 // | 200 // |
201 // TODO(akalin): Use ClientSocketPool. | 201 // TODO(akalin): Use ClientSocketPool. |
202 scoped_ptr<net::ClientSocket> transport_socket_; | 202 scoped_ptr<net::StreamSocket> transport_socket_; |
203 | 203 |
204 // State for the read loop. |read_start_| <= |read_end_| <= | 204 // State for the read loop. |read_start_| <= |read_end_| <= |
205 // |read_buf_->size()|. There's a read in flight (i.e., | 205 // |read_buf_->size()|. There's a read in flight (i.e., |
206 // |read_state_| != IDLE) iff |read_end_| == 0. | 206 // |read_state_| != IDLE) iff |read_end_| == 0. |
207 AsyncIOState read_state_; | 207 AsyncIOState read_state_; |
208 scoped_refptr<net::IOBufferWithSize> read_buf_; | 208 scoped_refptr<net::IOBufferWithSize> read_buf_; |
209 size_t read_start_, read_end_; | 209 size_t read_start_, read_end_; |
210 | 210 |
211 // State for the write loop. |write_end_| <= |write_buf_->size()|. | 211 // State for the write loop. |write_end_| <= |write_buf_->size()|. |
212 // There's a write in flight (i.e., |write_state_| != IDLE) iff | 212 // There's a write in flight (i.e., |write_state_| != IDLE) iff |
213 // |write_end_| > 0. | 213 // |write_end_| > 0. |
214 AsyncIOState write_state_; | 214 AsyncIOState write_state_; |
215 scoped_refptr<net::IOBufferWithSize> write_buf_; | 215 scoped_refptr<net::IOBufferWithSize> write_buf_; |
216 size_t write_end_; | 216 size_t write_end_; |
217 | 217 |
218 DISALLOW_COPY_AND_ASSIGN(ChromeAsyncSocket); | 218 DISALLOW_COPY_AND_ASSIGN(ChromeAsyncSocket); |
219 }; | 219 }; |
220 | 220 |
221 } // namespace notifier | 221 } // namespace notifier |
222 | 222 |
223 #endif // JINGLE_NOTIFIER_BASE_CHROME_ASYNC_SOCKET_H_ | 223 #endif // JINGLE_NOTIFIER_BASE_CHROME_ASYNC_SOCKET_H_ |
OLD | NEW |