OLD | NEW |
1 // Copyright (c) 2012 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 #ifndef NET_SERVER_WEB_SOCKET_H_ | 5 #ifndef NET_SERVER_WEB_SOCKET_H_ |
6 #define NET_SERVER_WEB_SOCKET_H_ | 6 #define NET_SERVER_WEB_SOCKET_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/memory/scoped_ptr.h" |
11 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
12 | 13 |
13 namespace net { | 14 namespace net { |
14 | 15 |
15 class HttpConnection; | 16 class HttpConnection; |
16 class HttpServer; | 17 class HttpServer; |
17 class HttpServerRequestInfo; | 18 class HttpServerRequestInfo; |
| 19 class WebSocketEncoder; |
18 | 20 |
19 class WebSocket { | 21 class WebSocket final { |
20 public: | 22 public: |
21 enum ParseResult { | 23 enum ParseResult { |
22 FRAME_OK, | 24 FRAME_OK, |
23 FRAME_INCOMPLETE, | 25 FRAME_INCOMPLETE, |
24 FRAME_CLOSE, | 26 FRAME_CLOSE, |
25 FRAME_ERROR | 27 FRAME_ERROR |
26 }; | 28 }; |
27 | 29 |
28 static WebSocket* CreateWebSocket(HttpServer* server, | 30 static WebSocket* CreateWebSocket(HttpServer* server, |
29 HttpConnection* connection, | 31 HttpConnection* connection, |
30 const HttpServerRequestInfo& request, | 32 const HttpServerRequestInfo& request, |
31 size_t* pos); | 33 size_t* pos); |
32 | 34 |
33 virtual void Accept(const HttpServerRequestInfo& request) = 0; | 35 void Accept(const HttpServerRequestInfo& request); |
34 virtual ParseResult Read(std::string* message) = 0; | 36 ParseResult Read(std::string* message); |
35 virtual void Send(const std::string& message) = 0; | 37 void Send(const std::string& message); |
36 virtual ~WebSocket(); | 38 ~WebSocket(); |
37 | 39 |
38 protected: | 40 private: |
39 WebSocket(HttpServer* server, HttpConnection* connection); | 41 WebSocket(HttpServer* server, |
| 42 HttpConnection* connection, |
| 43 const HttpServerRequestInfo& request, |
| 44 size_t* pos); |
40 | 45 |
41 HttpServer* const server_; | 46 HttpServer* const server_; |
42 HttpConnection* const connection_; | 47 HttpConnection* const connection_; |
| 48 scoped_ptr<WebSocketEncoder> encoder_; |
| 49 std::string response_extensions_; |
| 50 bool closed_; |
43 | 51 |
44 private: | |
45 DISALLOW_COPY_AND_ASSIGN(WebSocket); | 52 DISALLOW_COPY_AND_ASSIGN(WebSocket); |
46 }; | 53 }; |
47 | 54 |
48 } // namespace net | 55 } // namespace net |
49 | 56 |
50 #endif // NET_SERVER_WEB_SOCKET_H_ | 57 #endif // NET_SERVER_WEB_SOCKET_H_ |
OLD | NEW |