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