OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CHROME_BROWSER_GOOGLE_APIS_TEST_SERVER_HTTP_CONNECTION_H_ | |
6 #define CHROME_BROWSER_GOOGLE_APIS_TEST_SERVER_HTTP_CONNECTION_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/string_piece.h" | |
12 #include "chrome/browser/google_apis/test_server/http_request.h" | |
13 #include "net/base/stream_listen_socket.h" | |
14 | |
15 namespace drive { | |
16 namespace test_server { | |
17 | |
18 class HttpConnection; | |
19 class HttpResponse; | |
20 | |
21 // Calblack called when a request is parsed. Response should be sent | |
22 // using HttpConnection::SendResponse() on the |connection| argument. | |
23 typedef base::Callback<void(HttpConnection* connection, | |
24 scoped_ptr<HttpRequest> request)> | |
25 HandleRequestCallback; | |
26 | |
27 // Wraps the connection socket. Accepts incoming data and sends responses. | |
28 // If a valid request is parsed, then |callback_| is invoked. | |
29 class HttpConnection { | |
30 public: | |
31 HttpConnection(net::StreamListenSocket* socket, | |
32 const HandleRequestCallback& callback); | |
33 ~HttpConnection(); | |
34 | |
35 // Sends the HTTP response to the client. | |
36 void SendResponse(scoped_ptr<HttpResponse> response) const; | |
37 | |
38 private: | |
39 friend class HttpServer; | |
40 | |
41 // Accepts raw chunk of data from the client. Internally, passes it to the | |
42 // HttpRequestParser class. If a request is parsed, then |callback_| is | |
43 // called. | |
44 void ReceiveData(const base::StringPiece& data); | |
45 | |
46 scoped_refptr<net::StreamListenSocket> socket_; | |
47 const HandleRequestCallback callback_; | |
48 HttpRequestParser request_parser_; | |
49 | |
50 DISALLOW_COPY_AND_ASSIGN(HttpConnection); | |
51 }; | |
52 | |
53 } // namespace test_server | |
54 } // namespace drive | |
55 | |
56 #endif // CHROME_BROWSER_GOOGLE_APIS_TEST_SERVER_HTTP_CONNECTION_H_ | |
OLD | NEW |