Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / net / server / web_socket.h
blobd9509d88dbbf94a8bc44c0429b58cb144496966b
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
3 // found in the LICENSE file.
5 #ifndef NET_SERVER_WEB_SOCKET_H_
6 #define NET_SERVER_WEB_SOCKET_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/strings/string_piece.h"
14 namespace net {
16 class HttpConnection;
17 class HttpServer;
18 class HttpServerRequestInfo;
19 class WebSocketEncoder;
21 class WebSocket final {
22 public:
23 enum ParseResult {
24 FRAME_OK,
25 FRAME_INCOMPLETE,
26 FRAME_CLOSE,
27 FRAME_ERROR
30 static scoped_ptr<WebSocket> CreateWebSocket(
31 HttpServer* server,
32 HttpConnection* connection,
33 const HttpServerRequestInfo& request);
35 void Accept(const HttpServerRequestInfo& request);
36 ParseResult Read(std::string* message);
37 void Send(const std::string& message);
38 ~WebSocket();
40 private:
41 WebSocket(HttpServer* server,
42 HttpConnection* connection,
43 const HttpServerRequestInfo& request);
45 HttpServer* const server_;
46 HttpConnection* const connection_;
47 scoped_ptr<WebSocketEncoder> encoder_;
48 std::string response_extensions_;
49 bool closed_;
51 DISALLOW_COPY_AND_ASSIGN(WebSocket);
54 } // namespace net
56 #endif // NET_SERVER_WEB_SOCKET_H_