OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 // WebSocket protocol implementation in chromium. | 5 // WebSocket protocol implementation in chromium. |
6 // It is intended to be used for live experiment of WebSocket connectivity | 6 // It is intended to be used for live experiment of WebSocket connectivity |
7 // metrics. | 7 // metrics. |
8 // Note that it is not used for WebKit's WebSocket communication. | 8 // Note that it is not used for WebKit's WebSocket communication. |
9 // See third_party/WebKit/WebCore/websockets/ instead. | 9 // See third_party/WebKit/WebCore/websockets/ instead. |
10 | 10 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 53 |
54 class WebSocket : public base::RefCountedThreadSafe<WebSocket>, | 54 class WebSocket : public base::RefCountedThreadSafe<WebSocket>, |
55 public SocketStream::Delegate { | 55 public SocketStream::Delegate { |
56 public: | 56 public: |
57 enum State { | 57 enum State { |
58 INITIALIZED = -1, | 58 INITIALIZED = -1, |
59 CONNECTING = 0, | 59 CONNECTING = 0, |
60 OPEN = 1, | 60 OPEN = 1, |
61 CLOSED = 2, | 61 CLOSED = 2, |
62 }; | 62 }; |
| 63 enum ProtocolVersion { |
| 64 DEFAULT_VERSION = 0, |
| 65 DRAFT75 = 1, |
| 66 }; |
63 class Request { | 67 class Request { |
64 public: | 68 public: |
65 Request(const GURL& url, const std::string protocol, | 69 Request(const GURL& url, const std::string protocol, |
66 const std::string origin, const std::string location, | 70 const std::string origin, const std::string location, |
| 71 ProtocolVersion version, |
67 URLRequestContext* context) | 72 URLRequestContext* context) |
68 : url_(url), | 73 : url_(url), |
69 protocol_(protocol), | 74 protocol_(protocol), |
70 origin_(origin), | 75 origin_(origin), |
71 location_(location), | 76 location_(location), |
| 77 version_(version), |
72 context_(context), | 78 context_(context), |
73 host_resolver_(NULL), | 79 host_resolver_(NULL), |
74 client_socket_factory_(NULL) {} | 80 client_socket_factory_(NULL) {} |
75 ~Request() {} | 81 ~Request() {} |
76 | 82 |
77 const GURL& url() const { return url_; } | 83 const GURL& url() const { return url_; } |
78 const std::string& protocol() const { return protocol_; } | 84 const std::string& protocol() const { return protocol_; } |
79 const std::string& origin() const { return origin_; } | 85 const std::string& origin() const { return origin_; } |
80 const std::string& location() const { return location_; } | 86 const std::string& location() const { return location_; } |
| 87 ProtocolVersion version() const { return version_; } |
81 URLRequestContext* context() const { return context_; } | 88 URLRequestContext* context() const { return context_; } |
82 | 89 |
83 // Sets an alternative HostResolver. For testing purposes only. | 90 // Sets an alternative HostResolver. For testing purposes only. |
84 void SetHostResolver(HostResolver* host_resolver) { | 91 void SetHostResolver(HostResolver* host_resolver) { |
85 host_resolver_ = host_resolver; | 92 host_resolver_ = host_resolver; |
86 } | 93 } |
87 HostResolver* host_resolver() const { return host_resolver_; } | 94 HostResolver* host_resolver() const { return host_resolver_; } |
88 | 95 |
89 // Sets an alternative ClientSocketFactory. Doesn't take ownership of | 96 // Sets an alternative ClientSocketFactory. Doesn't take ownership of |
90 // |factory|. For testing purposes only. | 97 // |factory|. For testing purposes only. |
91 void SetClientSocketFactory(ClientSocketFactory* factory) { | 98 void SetClientSocketFactory(ClientSocketFactory* factory) { |
92 client_socket_factory_ = factory; | 99 client_socket_factory_ = factory; |
93 } | 100 } |
94 ClientSocketFactory* client_socket_factory() const { | 101 ClientSocketFactory* client_socket_factory() const { |
95 return client_socket_factory_; | 102 return client_socket_factory_; |
96 } | 103 } |
97 | 104 |
98 private: | 105 private: |
99 GURL url_; | 106 GURL url_; |
100 std::string protocol_; | 107 std::string protocol_; |
101 std::string origin_; | 108 std::string origin_; |
102 std::string location_; | 109 std::string location_; |
| 110 ProtocolVersion version_; |
103 scoped_refptr<URLRequestContext> context_; | 111 scoped_refptr<URLRequestContext> context_; |
104 | 112 |
105 scoped_refptr<HostResolver> host_resolver_; | 113 scoped_refptr<HostResolver> host_resolver_; |
106 ClientSocketFactory* client_socket_factory_; | 114 ClientSocketFactory* client_socket_factory_; |
107 | 115 |
108 DISALLOW_COPY_AND_ASSIGN(Request); | 116 DISALLOW_COPY_AND_ASSIGN(Request); |
109 }; | 117 }; |
110 | 118 |
111 // Constructs new WebSocket. | 119 // Constructs new WebSocket. |
112 // It takes ownership of |req|. | 120 // It takes ownership of |req|. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 // Deque of IOBuffers in pending. | 204 // Deque of IOBuffers in pending. |
197 // Front IOBuffer is being sent via |current_write_buf_|. | 205 // Front IOBuffer is being sent via |current_write_buf_|. |
198 PendingDataQueue pending_write_bufs_; | 206 PendingDataQueue pending_write_bufs_; |
199 | 207 |
200 DISALLOW_COPY_AND_ASSIGN(WebSocket); | 208 DISALLOW_COPY_AND_ASSIGN(WebSocket); |
201 }; | 209 }; |
202 | 210 |
203 } // namespace net | 211 } // namespace net |
204 | 212 |
205 #endif // NET_WEBSOCKETS_WEBSOCKET_H_ | 213 #endif // NET_WEBSOCKETS_WEBSOCKET_H_ |
OLD | NEW |