OLD | NEW |
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 17 matching lines...) Expand all Loading... |
28 | 28 |
29 class HttpConnection; | 29 class HttpConnection; |
30 class HttpResponse; | 30 class HttpResponse; |
31 struct HttpRequest; | 31 struct HttpRequest; |
32 | 32 |
33 // This class is required to be able to have composition instead of inheritance, | 33 // This class is required to be able to have composition instead of inheritance, |
34 class HttpListenSocket : public TCPListenSocket { | 34 class HttpListenSocket : public TCPListenSocket { |
35 public: | 35 public: |
36 HttpListenSocket(const SocketDescriptor socket_descriptor, | 36 HttpListenSocket(const SocketDescriptor socket_descriptor, |
37 StreamListenSocket::Delegate* delegate); | 37 StreamListenSocket::Delegate* delegate); |
38 virtual ~HttpListenSocket(); | 38 ~HttpListenSocket() override; |
39 virtual void Listen(); | 39 virtual void Listen(); |
40 | 40 |
41 // Listen on the current IO thread. If the IO thread has changed since this | 41 // Listen on the current IO thread. If the IO thread has changed since this |
42 // object is constructed, call |ListenOnIOThread| to make sure it listens on | 42 // object is constructed, call |ListenOnIOThread| to make sure it listens on |
43 // the right thread. Otherwise must call |Listen| instead. | 43 // the right thread. Otherwise must call |Listen| instead. |
44 void ListenOnIOThread(); | 44 void ListenOnIOThread(); |
45 | 45 |
46 private: | 46 private: |
47 friend class EmbeddedTestServer; | 47 friend class EmbeddedTestServer; |
48 | 48 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 // } | 99 // } |
100 // | 100 // |
101 class EmbeddedTestServer : public StreamListenSocket::Delegate { | 101 class EmbeddedTestServer : public StreamListenSocket::Delegate { |
102 public: | 102 public: |
103 typedef base::Callback<scoped_ptr<HttpResponse>( | 103 typedef base::Callback<scoped_ptr<HttpResponse>( |
104 const HttpRequest& request)> HandleRequestCallback; | 104 const HttpRequest& request)> HandleRequestCallback; |
105 | 105 |
106 // Creates a http test server. InitializeAndWaitUntilReady() must be called | 106 // Creates a http test server. InitializeAndWaitUntilReady() must be called |
107 // to start the server. | 107 // to start the server. |
108 EmbeddedTestServer(); | 108 EmbeddedTestServer(); |
109 virtual ~EmbeddedTestServer(); | 109 ~EmbeddedTestServer() override; |
110 | 110 |
111 // Initializes and waits until the server is ready to accept requests. | 111 // Initializes and waits until the server is ready to accept requests. |
112 bool InitializeAndWaitUntilReady() WARN_UNUSED_RESULT; | 112 bool InitializeAndWaitUntilReady() WARN_UNUSED_RESULT; |
113 | 113 |
114 // Shuts down the http server and waits until the shutdown is complete. | 114 // Shuts down the http server and waits until the shutdown is complete. |
115 bool ShutdownAndWaitUntilComplete() WARN_UNUSED_RESULT; | 115 bool ShutdownAndWaitUntilComplete() WARN_UNUSED_RESULT; |
116 | 116 |
117 // Checks if the server is started. | 117 // Checks if the server is started. |
118 bool Started() const { | 118 bool Started() const { |
119 return listen_socket_.get() != NULL; | 119 return listen_socket_.get() != NULL; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 | 159 |
160 // Shuts down the server. | 160 // Shuts down the server. |
161 void ShutdownOnIOThread(); | 161 void ShutdownOnIOThread(); |
162 | 162 |
163 // Handles a request when it is parsed. It passes the request to registed | 163 // Handles a request when it is parsed. It passes the request to registed |
164 // request handlers and sends a http response. | 164 // request handlers and sends a http response. |
165 void HandleRequest(HttpConnection* connection, | 165 void HandleRequest(HttpConnection* connection, |
166 scoped_ptr<HttpRequest> request); | 166 scoped_ptr<HttpRequest> request); |
167 | 167 |
168 // StreamListenSocket::Delegate overrides: | 168 // StreamListenSocket::Delegate overrides: |
169 virtual void DidAccept(StreamListenSocket* server, | 169 void DidAccept(StreamListenSocket* server, |
170 scoped_ptr<StreamListenSocket> connection) override; | 170 scoped_ptr<StreamListenSocket> connection) override; |
171 virtual void DidRead(StreamListenSocket* connection, | 171 void DidRead(StreamListenSocket* connection, |
172 const char* data, | 172 const char* data, |
173 int length) override; | 173 int length) override; |
174 virtual void DidClose(StreamListenSocket* connection) override; | 174 void DidClose(StreamListenSocket* connection) override; |
175 | 175 |
176 HttpConnection* FindConnection(StreamListenSocket* socket); | 176 HttpConnection* FindConnection(StreamListenSocket* socket); |
177 | 177 |
178 // Posts a task to the |io_thread_| and waits for a reply. | 178 // Posts a task to the |io_thread_| and waits for a reply. |
179 bool PostTaskToIOThreadAndWait( | 179 bool PostTaskToIOThreadAndWait( |
180 const base::Closure& closure) WARN_UNUSED_RESULT; | 180 const base::Closure& closure) WARN_UNUSED_RESULT; |
181 | 181 |
182 scoped_ptr<base::Thread> io_thread_; | 182 scoped_ptr<base::Thread> io_thread_; |
183 | 183 |
184 scoped_ptr<HttpListenSocket> listen_socket_; | 184 scoped_ptr<HttpListenSocket> listen_socket_; |
(...skipping 12 matching lines...) Expand all Loading... |
197 // invalidate its weak pointers before any other members are destroyed. | 197 // invalidate its weak pointers before any other members are destroyed. |
198 base::WeakPtrFactory<EmbeddedTestServer> weak_factory_; | 198 base::WeakPtrFactory<EmbeddedTestServer> weak_factory_; |
199 | 199 |
200 DISALLOW_COPY_AND_ASSIGN(EmbeddedTestServer); | 200 DISALLOW_COPY_AND_ASSIGN(EmbeddedTestServer); |
201 }; | 201 }; |
202 | 202 |
203 } // namespace test_servers | 203 } // namespace test_servers |
204 } // namespace net | 204 } // namespace net |
205 | 205 |
206 #endif // NET_TEST_EMBEDDED_TEST_SERVER_EMBEDDED_TEST_SERVER_H_ | 206 #endif // NET_TEST_EMBEDDED_TEST_SERVER_EMBEDDED_TEST_SERVER_H_ |
OLD | NEW |