Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(288)

Side by Side Diff: jingle/notifier/base/chrome_async_socket.h

Issue 10389098: [Sync] Make ChromeAsyncSocket use only the hostname on connect (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More tweaks Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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
(...skipping 15 matching lines...) Expand all
27 class IOBufferWithSize; 27 class IOBufferWithSize;
28 class StreamSocket; 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|. 37 // Takes ownership of |resolving_client_socket_factory|.
38 ChromeAsyncSocket(ResolvingClientSocketFactory* client_socket_factory, 38 ChromeAsyncSocket(
39 size_t read_buf_size, 39 ResolvingClientSocketFactory* resolving_client_socket_factory,
40 size_t write_buf_size); 40 size_t read_buf_size,
41 size_t write_buf_size);
41 42
42 // Does not raise any signals. 43 // Does not raise any signals.
43 virtual ~ChromeAsyncSocket(); 44 virtual ~ChromeAsyncSocket();
44 45
45 // buzz::AsyncSocket implementation. 46 // buzz::AsyncSocket implementation.
46 47
47 // The current state (see buzz::AsyncSocket::State; all but 48 // The current state (see buzz::AsyncSocket::State; all but
48 // STATE_CLOSING is used). 49 // STATE_CLOSING is used).
49 virtual State state() OVERRIDE; 50 virtual State state() OVERRIDE;
50 51
51 // The last generated error. Errors are generated when the main 52 // The last generated error. Errors are generated when the main
52 // functions below return false or when SignalClosed is raised due 53 // functions below return false or when SignalClosed is raised due
53 // to an asynchronous error. 54 // to an asynchronous error.
54 virtual Error error() OVERRIDE; 55 virtual Error error() OVERRIDE;
55 56
56 // GetError() (which is of type net::Error) != net::OK only when 57 // GetError() (which is of type net::Error) != net::OK only when
57 // error() == ERROR_WINSOCK. 58 // error() == ERROR_WINSOCK.
58 virtual int GetError() OVERRIDE; 59 virtual int GetError() OVERRIDE;
59 60
60 // Tries to connect to the given address. 61 // Tries to connect to the given address.
61 // 62 //
62 // If state() is not STATE_CLOSED, sets error to ERROR_WRONGSTATE 63 // If state() is not STATE_CLOSED, sets error to ERROR_WRONGSTATE
63 // and returns false. 64 // and returns false.
64 // 65 //
65 // If |address| is not resolved, sets error to ERROR_DNS and returns 66 // If |address| has an empty hostname or a zero port, sets error to
66 // false. 67 // ERROR_DNS and returns false. (We don't use the IP address even
68 // if it's present, as DNS resolution is done by
69 // |resolving_client_socket_factory_|.)
67 // 70 //
68 // Otherwise, starts the connection process and returns true. 71 // Otherwise, starts the connection process and returns true.
69 // SignalConnected will be raised when the connection is successful; 72 // SignalConnected will be raised when the connection is successful;
70 // otherwise, SignalClosed will be raised with a net error set. 73 // otherwise, SignalClosed will be raised with a net error set.
71 virtual bool Connect(const talk_base::SocketAddress& address) OVERRIDE; 74 virtual bool Connect(const talk_base::SocketAddress& address) OVERRIDE;
72 75
73 // Tries to read at most |len| bytes into |data|. 76 // Tries to read at most |len| bytes into |data|.
74 // 77 //
75 // If state() is not STATE_TLS_CONNECTING, STATE_OPEN, or 78 // If state() is not STATE_TLS_CONNECTING, STATE_OPEN, or
76 // STATE_TLS_OPEN, sets error to ERROR_WRONGSTATE and returns false. 79 // STATE_TLS_OPEN, sets error to ERROR_WRONGSTATE and returns false.
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 void PostDoWrite(); 172 void PostDoWrite();
170 void DoWrite(); 173 void DoWrite();
171 void ProcessWriteDone(int status); 174 void ProcessWriteDone(int status);
172 175
173 // SSL/TLS connection functions. 176 // SSL/TLS connection functions.
174 void ProcessSSLConnectDone(int status); 177 void ProcessSSLConnectDone(int status);
175 178
176 // Close functions. 179 // Close functions.
177 void DoClose(); 180 void DoClose();
178 181
179 scoped_ptr<ResolvingClientSocketFactory> client_socket_factory_; 182 base::WeakPtrFactory<ChromeAsyncSocket> weak_ptr_factory_;
183 scoped_ptr<ResolvingClientSocketFactory> resolving_client_socket_factory_;
180 184
181 // buzz::AsyncSocket state. 185 // buzz::AsyncSocket state.
182 buzz::AsyncSocket::State state_; 186 buzz::AsyncSocket::State state_;
183 buzz::AsyncSocket::Error error_; 187 buzz::AsyncSocket::Error error_;
184 net::Error net_error_; 188 net::Error net_error_;
185 189
186 // Used by read/write loops.
187 base::WeakPtrFactory<ChromeAsyncSocket> weak_factory_;
188
189 // NULL iff state() == STATE_CLOSED. 190 // NULL iff state() == STATE_CLOSED.
190 //
191 // TODO(akalin): Use ClientSocketPool.
192 scoped_ptr<net::StreamSocket> transport_socket_; 191 scoped_ptr<net::StreamSocket> transport_socket_;
193 192
194 // State for the read loop. |read_start_| <= |read_end_| <= 193 // State for the read loop. |read_start_| <= |read_end_| <=
195 // |read_buf_->size()|. There's a read in flight (i.e., 194 // |read_buf_->size()|. There's a read in flight (i.e.,
196 // |read_state_| != IDLE) iff |read_end_| == 0. 195 // |read_state_| != IDLE) iff |read_end_| == 0.
197 AsyncIOState read_state_; 196 AsyncIOState read_state_;
198 scoped_refptr<net::IOBufferWithSize> read_buf_; 197 scoped_refptr<net::IOBufferWithSize> read_buf_;
199 size_t read_start_, read_end_; 198 size_t read_start_, read_end_;
200 199
201 // State for the write loop. |write_end_| <= |write_buf_->size()|. 200 // State for the write loop. |write_end_| <= |write_buf_->size()|.
202 // There's a write in flight (i.e., |write_state_| != IDLE) iff 201 // There's a write in flight (i.e., |write_state_| != IDLE) iff
203 // |write_end_| > 0. 202 // |write_end_| > 0.
204 AsyncIOState write_state_; 203 AsyncIOState write_state_;
205 scoped_refptr<net::IOBufferWithSize> write_buf_; 204 scoped_refptr<net::IOBufferWithSize> write_buf_;
206 size_t write_end_; 205 size_t write_end_;
207 206
208 DISALLOW_COPY_AND_ASSIGN(ChromeAsyncSocket); 207 DISALLOW_COPY_AND_ASSIGN(ChromeAsyncSocket);
209 }; 208 };
210 209
211 } // namespace notifier 210 } // namespace notifier
212 211
213 #endif // JINGLE_NOTIFIER_BASE_CHROME_ASYNC_SOCKET_H_ 212 #endif // JINGLE_NOTIFIER_BASE_CHROME_ASYNC_SOCKET_H_
OLDNEW
« no previous file with comments | « no previous file | jingle/notifier/base/chrome_async_socket.cc » ('j') | jingle/notifier/base/chrome_async_socket_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698