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

Side by Side Diff: net/test/embedded_test_server/embedded_test_server.h

Issue 20142003: Remove ref-counting from StreamListenSocket (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed comments Created 7 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_TEST_EMBEDDED_TEST_SERVER_EMBEDDED_TEST_SERVER_H_ 5 #ifndef NET_TEST_EMBEDDED_TEST_SERVER_EMBEDDED_TEST_SERVER_H_
6 #define NET_TEST_EMBEDDED_TEST_SERVER_EMBEDDED_TEST_SERVER_H_ 6 #define NET_TEST_EMBEDDED_TEST_SERVER_EMBEDDED_TEST_SERVER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 15 matching lines...) Expand all
26 26
27 class HttpConnection; 27 class HttpConnection;
28 class HttpResponse; 28 class HttpResponse;
29 struct HttpRequest; 29 struct HttpRequest;
30 30
31 // This class is required to be able to have composition instead of inheritance, 31 // This class is required to be able to have composition instead of inheritance,
32 class HttpListenSocket : public TCPListenSocket { 32 class HttpListenSocket : public TCPListenSocket {
33 public: 33 public:
34 HttpListenSocket(const SocketDescriptor socket_descriptor, 34 HttpListenSocket(const SocketDescriptor socket_descriptor,
35 StreamListenSocket::Delegate* delegate); 35 StreamListenSocket::Delegate* delegate);
36 virtual ~HttpListenSocket();
36 virtual void Listen(); 37 virtual void Listen();
37 38
38 private: 39 private:
39 virtual ~HttpListenSocket();
40 40
41 base::ThreadChecker thread_checker_; 41 base::ThreadChecker thread_checker_;
42 }; 42 };
43 43
44 // Class providing an HTTP server for testing purpose. This is a basic server 44 // Class providing an HTTP server for testing purpose. This is a basic server
45 // providing only an essential subset of HTTP/1.1 protocol. Especially, 45 // providing only an essential subset of HTTP/1.1 protocol. Especially,
46 // it assumes that the request syntax is correct. It *does not* support 46 // it assumes that the request syntax is correct. It *does not* support
47 // a Chunked Transfer Encoding. 47 // a Chunked Transfer Encoding.
48 // 48 //
49 // The common use case is below: 49 // The common use case is below:
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 // Shuts down the server. 130 // Shuts down the server.
131 void ShutdownOnIOThread(); 131 void ShutdownOnIOThread();
132 132
133 // Handles a request when it is parsed. It passes the request to registed 133 // Handles a request when it is parsed. It passes the request to registed
134 // request handlers and sends a http response. 134 // request handlers and sends a http response.
135 void HandleRequest(HttpConnection* connection, 135 void HandleRequest(HttpConnection* connection,
136 scoped_ptr<HttpRequest> request); 136 scoped_ptr<HttpRequest> request);
137 137
138 // StreamListenSocket::Delegate overrides: 138 // StreamListenSocket::Delegate overrides:
139 virtual void DidAccept(StreamListenSocket* server, 139 virtual void DidAccept(StreamListenSocket* server,
140 StreamListenSocket* connection) OVERRIDE; 140 scoped_ptr<StreamListenSocket> connection) OVERRIDE;
141 virtual void DidRead(StreamListenSocket* connection, 141 virtual void DidRead(StreamListenSocket* connection,
142 const char* data, 142 const char* data,
143 int length) OVERRIDE; 143 int length) OVERRIDE;
144 virtual void DidClose(StreamListenSocket* connection) OVERRIDE; 144 virtual void DidClose(StreamListenSocket* connection) OVERRIDE;
145 145
146 HttpConnection* FindConnection(StreamListenSocket* socket); 146 HttpConnection* FindConnection(StreamListenSocket* socket);
147 147
148 scoped_refptr<base::SingleThreadTaskRunner> io_thread_; 148 scoped_refptr<base::SingleThreadTaskRunner> io_thread_;
149 149
150 scoped_refptr<HttpListenSocket> listen_socket_; 150 scoped_ptr<HttpListenSocket> listen_socket_;
151 int port_; 151 int port_;
152 GURL base_url_; 152 GURL base_url_;
153 153
154 // Owns the HttpConnection objects. 154 // Owns the HttpConnection objects.
155 std::map<StreamListenSocket*, HttpConnection*> connections_; 155 std::map<StreamListenSocket*, HttpConnection*> connections_;
156 156
157 // Vector of registered request handlers. 157 // Vector of registered request handlers.
158 std::vector<HandleRequestCallback> request_handlers_; 158 std::vector<HandleRequestCallback> request_handlers_;
159 159
160 // Note: This should remain the last member so it'll be destroyed and 160 // Note: This should remain the last member so it'll be destroyed and
161 // invalidate its weak pointers before any other members are destroyed. 161 // invalidate its weak pointers before any other members are destroyed.
162 base::WeakPtrFactory<EmbeddedTestServer> weak_factory_; 162 base::WeakPtrFactory<EmbeddedTestServer> weak_factory_;
163 163
164 base::ThreadChecker thread_checker_; 164 base::ThreadChecker thread_checker_;
165 165
166 DISALLOW_COPY_AND_ASSIGN(EmbeddedTestServer); 166 DISALLOW_COPY_AND_ASSIGN(EmbeddedTestServer);
167 }; 167 };
168 168
169 } // namespace test_servers 169 } // namespace test_servers
170 } // namespace net 170 } // namespace net
171 171
172 #endif // NET_TEST_EMBEDDED_TEST_SERVER_EMBEDDED_TEST_SERVER_H_ 172 #endif // NET_TEST_EMBEDDED_TEST_SERVER_EMBEDDED_TEST_SERVER_H_
OLDNEW
« no previous file with comments | « net/socket/unix_domain_socket_posix_unittest.cc ('k') | net/test/embedded_test_server/embedded_test_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698