Index: chrome/browser/chromeos/drive/test_servers/http_connection.h |
diff --git a/chrome/browser/chromeos/drive/test_servers/http_connection.h b/chrome/browser/chromeos/drive/test_servers/http_connection.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..65c49378ae529fb78db0d60c0aa6bdbadb3b88dd |
--- /dev/null |
+++ b/chrome/browser/chromeos/drive/test_servers/http_connection.h |
@@ -0,0 +1,54 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_CHROMEOS_DRIVE_TEST_SERVERS_HTTP_CONNECTION_H_ |
+#define CHROME_BROWSER_CHROMEOS_DRIVE_TEST_SERVERS_HTTP_CONNECTION_H_ |
+ |
+#include <string> |
+#include "base/basictypes.h" |
+#include "net/base/stream_listen_socket.h" |
+#include "chrome/browser/chromeos/drive/test_servers/http_request.h" |
+ |
+namespace drive { |
+namespace test_servers { |
+ |
+class HttpConnection; |
+class HttpResponse; |
+ |
+// Calblack called when a request is parsed. Response should be sent |
+// using HttpConnection::SendResponse() on the |connection| argument. |
+typedef base::Callback<void(HttpConnection* connection, |
+ scoped_ptr<HttpRequest> request)> |
+ HandleRequestCallback; |
+ |
+// Wraps the connection socket. Accepts incoming data and sends responses. |
+// If a valid request is parsed, then |callback_| is invoked. |
+class HttpConnection { |
+ public: |
+ HttpConnection(net::StreamListenSocket* socket, |
+ const HandleRequestCallback& callback); |
+ virtual ~HttpConnection(); |
+ |
+ // Sends the HTTP response to the client. |
+ virtual void SendResponse(scoped_ptr<HttpResponse> response) const; |
satorux1
2012/11/12 06:07:00
Should this be a virtual function? There are no cl
mtomasz
2012/11/12 12:17:44
Why don't we make public methods virtual by defaul
satorux1
2012/11/13 05:13:18
See YAGNI on wikipedia. :) Besides:
1) It's helpf
mtomasz
2012/11/13 12:23:07
Got it.
|
+ |
+ private: |
+ friend class HttpTestServer; |
+ |
+ // Accepts raw chunk of data from the client. Internally, passes it to the |
+ // HttpRequestParser class. If a request is parsed, then |callback_| is |
+ // called. |
satorux1
2012/11/12 06:07:00
ditto.
mtomasz
2012/11/12 12:17:44
Done.
|
+ virtual void ReceiveData(const char* data, size_t length); |
satorux1
2012/11/12 06:07:00
Can we use StringPiece instead? One less parameter
mtomasz
2012/11/12 12:17:44
How about just std::string since we don't need any
satorux1
2012/11/13 05:13:18
const std::string& will make a copy if the input i
mtomasz
2012/11/13 12:23:07
Done.
|
+ |
+ scoped_refptr<net::StreamListenSocket> socket_; |
+ const HandleRequestCallback callback_; |
+ HttpRequestParser request_parser_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(HttpConnection); |
+}; |
+ |
+} // namespace test_servers |
+} // namespace drive |
+ |
+#endif // CHROME_BROWSER_CHROMEOS_DRIVE_TEST_SERVERS_HTTP_CONNECTION_H_ |