| 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> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
| 17 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 18 #include "net/socket/tcp_listen_socket.h" | 18 #include "net/socket/tcp_listen_socket.h" |
| 19 | 19 |
| 20 namespace base { | 20 namespace base { |
| 21 class FilePath; | 21 class FilePath; |
| 22 } | 22 } |
| 23 | 23 |
| 24 namespace net { | 24 namespace net { |
| 25 namespace test_server { | 25 namespace test_server { |
| 26 | 26 |
| 27 class HttpConnection; | 27 class HttpConnection; |
| 28 class HttpResponse; | 28 class HttpResponseInterface; |
| 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 void Listen(); | 36 virtual void Listen(); |
| 37 | 37 |
| 38 private: | 38 private: |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 // | 70 // |
| 71 // scoped_ptr<HttpResponse> http_response(new HttpResponse()); | 71 // scoped_ptr<HttpResponse> http_response(new HttpResponse()); |
| 72 // http_response->set_code(test_server::SUCCESS); | 72 // http_response->set_code(test_server::SUCCESS); |
| 73 // http_response->set_content("hello"); | 73 // http_response->set_content("hello"); |
| 74 // http_response->set_content_type("text/plain"); | 74 // http_response->set_content_type("text/plain"); |
| 75 // return http_response.Pass(); | 75 // return http_response.Pass(); |
| 76 // } | 76 // } |
| 77 // | 77 // |
| 78 class EmbeddedTestServer : public StreamListenSocket::Delegate { | 78 class EmbeddedTestServer : public StreamListenSocket::Delegate { |
| 79 public: | 79 public: |
| 80 typedef base::Callback<scoped_ptr<HttpResponse>(const HttpRequest& request)> | 80 typedef base::Callback<scoped_ptr<HttpResponseInterface>( |
| 81 HandleRequestCallback; | 81 const HttpRequest& request)> HandleRequestCallback; |
| 82 | 82 |
| 83 // Creates a http test server. |io_thread| is a task runner | 83 // Creates a http test server. |io_thread| is a task runner |
| 84 // with IO message loop, used as a backend thread. | 84 // with IO message loop, used as a backend thread. |
| 85 // InitializeAndWaitUntilReady() must be called to start the server. | 85 // InitializeAndWaitUntilReady() must be called to start the server. |
| 86 explicit EmbeddedTestServer( | 86 explicit EmbeddedTestServer( |
| 87 const scoped_refptr<base::SingleThreadTaskRunner>& io_thread); | 87 const scoped_refptr<base::SingleThreadTaskRunner>& io_thread); |
| 88 virtual ~EmbeddedTestServer(); | 88 virtual ~EmbeddedTestServer(); |
| 89 | 89 |
| 90 // Initializes and waits until the server is ready to accept requests. | 90 // Initializes and waits until the server is ready to accept requests. |
| 91 bool InitializeAndWaitUntilReady() WARN_UNUSED_RESULT; | 91 bool InitializeAndWaitUntilReady() WARN_UNUSED_RESULT; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_ |
| OLD | NEW |