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