| 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 // http://127.0.0.1:<port>/path?query=foo. | 129 // http://127.0.0.1:<port>/path?query=foo. |
| 130 GURL GetURL(const std::string& relative_url) const; | 130 GURL GetURL(const std::string& relative_url) const; |
| 131 | 131 |
| 132 // Similar to the above method with the difference that it uses the supplied | 132 // Similar to the above method with the difference that it uses the supplied |
| 133 // |hostname| for the URL instead of 127.0.0.1. The hostname should be | 133 // |hostname| for the URL instead of 127.0.0.1. The hostname should be |
| 134 // resolved to 127.0.0.1. | 134 // resolved to 127.0.0.1. |
| 135 GURL GetURL(const std::string& hostname, | 135 GURL GetURL(const std::string& hostname, |
| 136 const std::string& relative_url) const; | 136 const std::string& relative_url) const; |
| 137 | 137 |
| 138 // Returns the port number used by the server. | 138 // Returns the port number used by the server. |
| 139 int port() const { return port_; } | 139 uint16 port() const { return port_; } |
| 140 | 140 |
| 141 // Registers request handler which serves files from |directory|. | 141 // Registers request handler which serves files from |directory|. |
| 142 // For instance, a request to "/foo.html" is served by "foo.html" under | 142 // For instance, a request to "/foo.html" is served by "foo.html" under |
| 143 // |directory|. Files under sub directories are also handled in the same way | 143 // |directory|. Files under sub directories are also handled in the same way |
| 144 // (i.e. "/foo/bar.html" is served by "foo/bar.html" under |directory|). | 144 // (i.e. "/foo/bar.html" is served by "foo/bar.html" under |directory|). |
| 145 void ServeFilesFromDirectory(const base::FilePath& directory); | 145 void ServeFilesFromDirectory(const base::FilePath& directory); |
| 146 | 146 |
| 147 // The most general purpose method. Any request processing can be added using | 147 // The most general purpose method. Any request processing can be added using |
| 148 // this method. Takes ownership of the object. The |callback| is called | 148 // this method. Takes ownership of the object. The |callback| is called |
| 149 // on UI thread. | 149 // on UI thread. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 | 181 |
| 182 HttpConnection* FindConnection(StreamListenSocket* socket); | 182 HttpConnection* FindConnection(StreamListenSocket* socket); |
| 183 | 183 |
| 184 // Posts a task to the |io_thread_| and waits for a reply. | 184 // Posts a task to the |io_thread_| and waits for a reply. |
| 185 bool PostTaskToIOThreadAndWait( | 185 bool PostTaskToIOThreadAndWait( |
| 186 const base::Closure& closure) WARN_UNUSED_RESULT; | 186 const base::Closure& closure) WARN_UNUSED_RESULT; |
| 187 | 187 |
| 188 scoped_ptr<base::Thread> io_thread_; | 188 scoped_ptr<base::Thread> io_thread_; |
| 189 | 189 |
| 190 scoped_ptr<HttpListenSocket> listen_socket_; | 190 scoped_ptr<HttpListenSocket> listen_socket_; |
| 191 int port_; | 191 uint16 port_; |
| 192 GURL base_url_; | 192 GURL base_url_; |
| 193 | 193 |
| 194 // Owns the HttpConnection objects. | 194 // Owns the HttpConnection objects. |
| 195 std::map<StreamListenSocket*, HttpConnection*> connections_; | 195 std::map<StreamListenSocket*, HttpConnection*> connections_; |
| 196 | 196 |
| 197 // Vector of registered request handlers. | 197 // Vector of registered request handlers. |
| 198 std::vector<HandleRequestCallback> request_handlers_; | 198 std::vector<HandleRequestCallback> request_handlers_; |
| 199 | 199 |
| 200 base::ThreadChecker thread_checker_; | 200 base::ThreadChecker thread_checker_; |
| 201 | 201 |
| 202 // Note: This should remain the last member so it'll be destroyed and | 202 // Note: This should remain the last member so it'll be destroyed and |
| 203 // invalidate its weak pointers before any other members are destroyed. | 203 // invalidate its weak pointers before any other members are destroyed. |
| 204 base::WeakPtrFactory<EmbeddedTestServer> weak_factory_; | 204 base::WeakPtrFactory<EmbeddedTestServer> weak_factory_; |
| 205 | 205 |
| 206 DISALLOW_COPY_AND_ASSIGN(EmbeddedTestServer); | 206 DISALLOW_COPY_AND_ASSIGN(EmbeddedTestServer); |
| 207 }; | 207 }; |
| 208 | 208 |
| 209 } // namespace test_servers | 209 } // namespace test_servers |
| 210 } // namespace net | 210 } // namespace net |
| 211 | 211 |
| 212 #endif // NET_TEST_EMBEDDED_TEST_SERVER_EMBEDDED_TEST_SERVER_H_ | 212 #endif // NET_TEST_EMBEDDED_TEST_SERVER_EMBEDDED_TEST_SERVER_H_ |
| OLD | NEW |