Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: chrome/browser/chromeos/gdata/test_servers/http_server.h

Issue 11088073: HTTP server for testing Google Drive. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Addressed comments. Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_GDATA_TEST_SERVERS_HTTP_SERVER_H_
6 #define CHROME_BROWSER_CHROMEOS_GDATA_TEST_SERVERS_HTTP_SERVER_H_
7
8 #include <string>
9 #include "base/basictypes.h"
10 #include "chrome/browser/chromeos/gdata/test_servers/http_connection.h"
11 #include "net/base/tcp_listen_socket.h"
12
13 namespace base {
14 class WaitableEvent;
15 }
16
17 namespace gdata {
18 namespace test_servers {
19
20 class HttpConnectionDelegate;
21
22 // General purpose, simple http server which runs on Browser::IO thread.
23 class HttpServer : public net::TCPListenSocket,
24 private net::StreamListenSocket::Delegate {
25 public:
26 // Factory method. Returns empty scoped_refptr, if creating of a server
27 // failed. Can be called from any thread. Returned object runs in the
28 // Browser::IO thread, though.
29 // Passed |connection_delegate|'s methods are called from the IO thread.
30 static scoped_refptr<HttpServer> CreateServer(
31 const std::string& address,
32 int port,
33 HttpConnectionDelegate* connection_delegate);
34
35 // Drops the http connection. It will remove reference to it from internal
36 // collections and cause closing of an underlying socket. Should be called
37 // from the IO thread.
38 void DropHttpConnection(HttpConnection* connection);
39
40 private:
41 virtual ~HttpServer();
42
43 // Creates a server on IO thread. The test server pointer is returned
44 // before signaling the waiter (if provided).
45 static void CreateServerOnIOThread(
46 const std::string& address,
47 int port,
48 HttpConnectionDelegate* connection_delegate,
49 base::WaitableEvent* waiter,
50 HttpServer** server_ptr);
51
52 HttpServer(SocketDescriptor& socket,
53 HttpConnectionDelegate* connection_delegate);
54
55 // |server| is the original listening Socket, connection is the new
56 // Socket that was created. Ownership of |connection| is transferred
57 // to the delegate with this call.
58 virtual void DidAccept(StreamListenSocket* server,
59 StreamListenSocket* connection) OVERRIDE;
60 virtual void DidRead(StreamListenSocket* connection,
61 const char* data,
62 int length) OVERRIDE;
63 virtual void DidClose(StreamListenSocket* connection) OVERRIDE;
64
65 virtual HttpConnection* FindConnection(StreamListenSocket* socket);
66
67 // Owns the HttpConnection objects.
68 std::map<StreamListenSocket*, HttpConnection*> connections_;
69 HttpConnectionDelegate* connection_delegate_; // Does not own.
70
71 DISALLOW_COPY_AND_ASSIGN(HttpServer);
72 };
73
74 } // namespace test_servers
75 } // namespace gdata
76
77 #endif // CHROME_BROWSER_CHROMEOS_GDATA_TEST_SERVERS_HTTP_SERVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698