Index: chrome/browser/chromeos/gdata/test_servers/http_server.h |
diff --git a/chrome/browser/chromeos/gdata/test_servers/http_server.h b/chrome/browser/chromeos/gdata/test_servers/http_server.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d33862df4c41f024f5b7ff815015eb198c4cacb0 |
--- /dev/null |
+++ b/chrome/browser/chromeos/gdata/test_servers/http_server.h |
@@ -0,0 +1,77 @@ |
+// 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_GDATA_TEST_SERVERS_HTTP_SERVER_H_ |
+#define CHROME_BROWSER_CHROMEOS_GDATA_TEST_SERVERS_HTTP_SERVER_H_ |
+ |
+#include <string> |
+#include "base/basictypes.h" |
+#include "chrome/browser/chromeos/gdata/test_servers/http_connection.h" |
+#include "net/base/tcp_listen_socket.h" |
+ |
+namespace base { |
+class WaitableEvent; |
+} |
+ |
+namespace gdata { |
+namespace test_servers { |
+ |
+class HttpConnectionDelegate; |
+ |
+// General purpose, simple http server which runs on Browser::IO thread. |
+class HttpServer : public net::TCPListenSocket, |
+ private net::StreamListenSocket::Delegate { |
+ public: |
+ // Factory method. Returns empty scoped_refptr, if creating of a server |
+ // failed. Can be called from any thread. Returned object runs in the |
+ // Browser::IO thread, though. |
+ // Passed |connection_delegate|'s methods are called from the IO thread. |
+ static scoped_refptr<HttpServer> CreateServer( |
+ const std::string& address, |
+ int port, |
+ HttpConnectionDelegate* connection_delegate); |
+ |
+ // Drops the http connection. It will remove reference to it from internal |
+ // collections and cause closing of an underlying socket. Should be called |
+ // from the IO thread. |
+ void DropHttpConnection(HttpConnection* connection); |
+ |
+ private: |
+ virtual ~HttpServer(); |
+ |
+ // Creates a server on IO thread. The test server pointer is returned |
+ // before signaling the waiter (if provided). |
+ static void CreateServerOnIOThread( |
+ const std::string& address, |
+ int port, |
+ HttpConnectionDelegate* connection_delegate, |
+ base::WaitableEvent* waiter, |
+ HttpServer** server_ptr); |
+ |
+ HttpServer(SocketDescriptor& socket, |
+ HttpConnectionDelegate* connection_delegate); |
+ |
+ // |server| is the original listening Socket, connection is the new |
+ // Socket that was created. Ownership of |connection| is transferred |
+ // to the delegate with this call. |
+ virtual void DidAccept(StreamListenSocket* server, |
+ StreamListenSocket* connection) OVERRIDE; |
+ virtual void DidRead(StreamListenSocket* connection, |
+ const char* data, |
+ int length) OVERRIDE; |
+ virtual void DidClose(StreamListenSocket* connection) OVERRIDE; |
+ |
+ virtual HttpConnection* FindConnection(StreamListenSocket* socket); |
+ |
+ // Owns the HttpConnection objects. |
+ std::map<StreamListenSocket*, HttpConnection*> connections_; |
+ HttpConnectionDelegate* connection_delegate_; // Does not own. |
+ |
+ DISALLOW_COPY_AND_ASSIGN(HttpServer); |
+}; |
+ |
+} // namespace test_servers |
+} // namespace gdata |
+ |
+#endif // CHROME_BROWSER_CHROMEOS_GDATA_TEST_SERVERS_HTTP_SERVER_H_ |