Chromium Code Reviews| 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/strings/string_piece.h" | |
| 11 | 12 |
| 12 namespace net { | 13 namespace net { |
| 13 | 14 |
| 14 class HttpConnection; | 15 class HttpConnection; |
| 16 class HttpServer; | |
| 15 class HttpServerRequestInfo; | 17 class HttpServerRequestInfo; |
| 16 | 18 |
| 17 class WebSocket { | 19 class WebSocket { |
| 18 public: | 20 public: |
| 19 enum ParseResult { | 21 enum ParseResult { |
| 20 FRAME_OK, | 22 FRAME_OK, |
| 21 FRAME_INCOMPLETE, | 23 FRAME_INCOMPLETE, |
| 22 FRAME_CLOSE, | 24 FRAME_CLOSE, |
| 23 FRAME_ERROR | 25 FRAME_ERROR |
| 24 }; | 26 }; |
| 25 | 27 |
| 26 static WebSocket* CreateWebSocket(HttpConnection* connection, | 28 static WebSocket* CreateWebSocket(HttpServer* server, |
| 29 HttpConnection* connection, | |
| 27 const HttpServerRequestInfo& request, | 30 const HttpServerRequestInfo& request, |
| 28 size_t* pos); | 31 size_t* pos); |
| 29 | 32 |
| 30 static ParseResult DecodeFrameHybi17(const std::string& frame, | 33 static ParseResult DecodeFrameHybi17(const base::StringPiece& frame, |
| 31 bool client_frame, | 34 bool client_frame, |
| 32 int* bytes_consumed, | 35 int* bytes_consumed, |
| 33 std::string* output); | 36 std::string* output); |
| 34 | 37 |
| 35 static std::string EncodeFrameHybi17(const std::string& data, | 38 static std::string EncodeFrameHybi17(const std::string& data, |
| 36 int masking_key); | 39 int masking_key); |
| 37 | 40 |
| 38 virtual void Accept(const HttpServerRequestInfo& request) = 0; | 41 virtual void Accept(const HttpServerRequestInfo& request) = 0; |
| 39 virtual ParseResult Read(std::string* message) = 0; | 42 virtual ParseResult Read(std::string* message) = 0; |
| 40 virtual void Send(const std::string& message) = 0; | 43 virtual void Send(const std::string& message) = 0; |
| 41 virtual ~WebSocket() {} | 44 virtual ~WebSocket() {} |
| 42 | 45 |
| 43 protected: | 46 protected: |
| 44 explicit WebSocket(HttpConnection* connection); | 47 explicit WebSocket(HttpServer* server, HttpConnection* connection); |
|
mmenke
2014/08/14 16:36:03
nit: Explicit no longer needed.
byungchul
2014/08/14 18:44:03
Done.
| |
| 45 HttpConnection* connection_; | 48 |
| 49 HttpServer* const server_; | |
| 50 HttpConnection* const connection_; | |
| 46 | 51 |
| 47 private: | 52 private: |
| 48 DISALLOW_COPY_AND_ASSIGN(WebSocket); | 53 DISALLOW_COPY_AND_ASSIGN(WebSocket); |
| 49 }; | 54 }; |
| 50 | 55 |
| 51 } // namespace net | 56 } // namespace net |
| 52 | 57 |
| 53 #endif // NET_SERVER_WEB_SOCKET_H_ | 58 #endif // NET_SERVER_WEB_SOCKET_H_ |
| OLD | NEW |