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/memory/weak_ptr.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 "talk/xmpp/asyncsocket.h" | 23 #include "talk/xmpp/asyncsocket.h" |
24 | 24 |
25 namespace net { | 25 namespace net { |
26 class IOBufferWithSize; | 26 class IOBufferWithSize; |
27 class StreamSocket; | 27 class StreamSocket; |
28 } // namespace net | 28 } // namespace net |
29 | 29 |
30 namespace notifier { | 30 namespace notifier { |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 net::OldCompletionCallbackImpl<ChromeAsyncSocket> ssl_connect_callback_; | 182 net::OldCompletionCallbackImpl<ChromeAsyncSocket> ssl_connect_callback_; |
183 | 183 |
184 scoped_ptr<ResolvingClientSocketFactory> client_socket_factory_; | 184 scoped_ptr<ResolvingClientSocketFactory> client_socket_factory_; |
185 | 185 |
186 // buzz::AsyncSocket state. | 186 // buzz::AsyncSocket state. |
187 buzz::AsyncSocket::State state_; | 187 buzz::AsyncSocket::State state_; |
188 buzz::AsyncSocket::Error error_; | 188 buzz::AsyncSocket::Error error_; |
189 net::Error net_error_; | 189 net::Error net_error_; |
190 | 190 |
191 // Used by read/write loops. | 191 // Used by read/write loops. |
192 ScopedRunnableMethodFactory<ChromeAsyncSocket> | 192 base::WeakPtrFactory<ChromeAsyncSocket> weak_factory_; |
193 scoped_runnable_method_factory_; | |
194 | 193 |
195 // NULL iff state() == STATE_CLOSED. | 194 // NULL iff state() == STATE_CLOSED. |
196 // | 195 // |
197 // TODO(akalin): Use ClientSocketPool. | 196 // TODO(akalin): Use ClientSocketPool. |
198 scoped_ptr<net::StreamSocket> transport_socket_; | 197 scoped_ptr<net::StreamSocket> transport_socket_; |
199 | 198 |
200 // State for the read loop. |read_start_| <= |read_end_| <= | 199 // State for the read loop. |read_start_| <= |read_end_| <= |
201 // |read_buf_->size()|. There's a read in flight (i.e., | 200 // |read_buf_->size()|. There's a read in flight (i.e., |
202 // |read_state_| != IDLE) iff |read_end_| == 0. | 201 // |read_state_| != IDLE) iff |read_end_| == 0. |
203 AsyncIOState read_state_; | 202 AsyncIOState read_state_; |
204 scoped_refptr<net::IOBufferWithSize> read_buf_; | 203 scoped_refptr<net::IOBufferWithSize> read_buf_; |
205 size_t read_start_, read_end_; | 204 size_t read_start_, read_end_; |
206 | 205 |
207 // State for the write loop. |write_end_| <= |write_buf_->size()|. | 206 // State for the write loop. |write_end_| <= |write_buf_->size()|. |
208 // There's a write in flight (i.e., |write_state_| != IDLE) iff | 207 // There's a write in flight (i.e., |write_state_| != IDLE) iff |
209 // |write_end_| > 0. | 208 // |write_end_| > 0. |
210 AsyncIOState write_state_; | 209 AsyncIOState write_state_; |
211 scoped_refptr<net::IOBufferWithSize> write_buf_; | 210 scoped_refptr<net::IOBufferWithSize> write_buf_; |
212 size_t write_end_; | 211 size_t write_end_; |
213 | 212 |
214 DISALLOW_COPY_AND_ASSIGN(ChromeAsyncSocket); | 213 DISALLOW_COPY_AND_ASSIGN(ChromeAsyncSocket); |
215 }; | 214 }; |
216 | 215 |
217 } // namespace notifier | 216 } // namespace notifier |
218 | 217 |
219 #endif // JINGLE_NOTIFIER_BASE_CHROME_ASYNC_SOCKET_H_ | 218 #endif // JINGLE_NOTIFIER_BASE_CHROME_ASYNC_SOCKET_H_ |
OLD | NEW |