12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file.
42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#ifndef NET_TEST_EMBEDDED_TEST_SERVER_EMBEDDED_TEST_SERVER_H_
6b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#define NET_TEST_EMBEDDED_TEST_SERVER_EMBEDDED_TEST_SERVER_H_
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <map>
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <string>
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <vector>
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/basictypes.h"
1358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "base/callback.h"
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/compiler_specific.h"
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/memory/ref_counted.h"
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/memory/weak_ptr.h"
171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/threading/thread.h"
18c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "base/threading/thread_checker.h"
19c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "net/socket/tcp_listen_socket.h"
207dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "url/gurl.h"
212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace base {
2390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class FilePath;
2490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
2590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
26b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)namespace net {
272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace test_server {
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class HttpConnection;
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class HttpResponse;
312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)struct HttpRequest;
322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// This class is required to be able to have composition instead of inheritance,
34b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)class HttpListenSocket : public TCPListenSocket {
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  HttpListenSocket(const SocketDescriptor socket_descriptor,
37b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)                   StreamListenSocket::Delegate* delegate);
3858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  virtual ~HttpListenSocket();
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void Listen();
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
411320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Listen on the current IO thread. If the IO thread has changed since this
421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // object is constructed, call |ListenOnIOThread| to make sure it listens on
431320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // the right thread. Otherwise must call |Listen| instead.
441320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void ListenOnIOThread();
451320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
47a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  friend class EmbeddedTestServer;
48a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
49a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Detaches the current from |thread_checker_|.
50a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  void DetachFromThread();
51c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
52c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  base::ThreadChecker thread_checker_;
532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Class providing an HTTP server for testing purpose. This is a basic server
562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// providing only an essential subset of HTTP/1.1 protocol. Especially,
572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// it assumes that the request syntax is correct. It *does not* support
582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// a Chunked Transfer Encoding.
592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//
60a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// The common use case for unit tests is below:
612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//
622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// void SetUp() {
63a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)//   test_server_.reset(new EmbeddedTestServer());
64c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)//   ASSERT_TRUE(test_server_.InitializeAndWaitUntilReady());
652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//   test_server_->RegisterRequestHandler(
662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//       base::Bind(&FooTest::HandleRequest, base::Unretained(this)));
672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// }
682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//
692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// scoped_ptr<HttpResponse> HandleRequest(const HttpRequest& request) {
702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//   GURL absolute_url = test_server_->GetURL(request.relative_url);
712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//   if (absolute_url.path() != "/test")
722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//     return scoped_ptr<HttpResponse>();
732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//
742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//   scoped_ptr<HttpResponse> http_response(new HttpResponse());
752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//   http_response->set_code(test_server::SUCCESS);
762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//   http_response->set_content("hello");
772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//   http_response->set_content_type("text/plain");
782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//   return http_response.Pass();
792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// }
802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//
81a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// For a test that spawns another process such as browser_tests, it is
82a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// suggested to call InitializeAndWaitUntilReady in SetUpOnMainThread after
83a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// the process is spawned. If you have to do it before the process spawns,
84a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// you need to stop the server's thread so that there is no no other
85a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// threads running while spawning the process. To do so, please follow
86a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// the following example:
87a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)//
88a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// void SetUp() {
89a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)//   ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
90a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)//   // EmbeddedTestServer spawns a thread to initialize socket.
91a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)//   // Stop the thread in preparation for fork and exec.
92a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)//   embedded_test_server()->StopThread();
93a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)//   ...
94a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)//   InProcessBrowserTest::SetUp();
95a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// }
96a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)//
97a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// void SetUpOnMainThread() {
98a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)//   embedded_test_server()->RestartThreadAndListen();
99a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// }
100a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)//
101b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)class EmbeddedTestServer : public StreamListenSocket::Delegate {
1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
10390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  typedef base::Callback<scoped_ptr<HttpResponse>(
10490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      const HttpRequest& request)> HandleRequestCallback;
1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1061e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Creates a http test server. InitializeAndWaitUntilReady() must be called
1071e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // to start the server.
1081e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EmbeddedTestServer();
109b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  virtual ~EmbeddedTestServer();
1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Initializes and waits until the server is ready to accept requests.
112c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool InitializeAndWaitUntilReady() WARN_UNUSED_RESULT;
1132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Shuts down the http server and waits until the shutdown is complete.
115c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool ShutdownAndWaitUntilComplete() WARN_UNUSED_RESULT;
1162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Checks if the server is started.
1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool Started() const {
1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return listen_socket_.get() != NULL;
1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns the base URL to the server, which looks like
1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // http://127.0.0.1:<port>/, where <port> is the actual port number used by
1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // the server.
1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const GURL& base_url() const { return base_url_; }
1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns a URL to the server based on the given relative URL, which
1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // should start with '/'. For example: GetURL("/path?query=foo") =>
1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // http://127.0.0.1:<port>/path?query=foo.
1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  GURL GetURL(const std::string& relative_url) const;
1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns the port number used by the server.
1332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int port() const { return port_; }
1342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
13590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Registers request handler which serves files from |directory|.
13690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // For instance, a request to "/foo.html" is served by "foo.html" under
13790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // |directory|. Files under sub directories are also handled in the same way
13890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // (i.e. "/foo/bar.html" is served by "foo/bar.html" under |directory|).
13990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  void ServeFilesFromDirectory(const base::FilePath& directory);
14090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // The most general purpose method. Any request processing can be added using
1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // this method. Takes ownership of the object. The |callback| is called
1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // on UI thread.
1442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void RegisterRequestHandler(const HandleRequestCallback& callback);
1452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
146a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Stops IO thread that handles http requests.
147a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  void StopThread();
148a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
149a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Restarts IO thread and listen on the socket.
150a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  void RestartThreadAndListen();
151a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
153a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  void StartThread();
154a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
1552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Initializes and starts the server. If initialization succeeds, Starts()
1562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // will return true.
1572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void InitializeOnIOThread();
158a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  void ListenOnIOThread();
1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Shuts down the server.
1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void ShutdownOnIOThread();
1622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Handles a request when it is parsed. It passes the request to registed
1642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // request handlers and sends a http response.
1652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void HandleRequest(HttpConnection* connection,
1662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                     scoped_ptr<HttpRequest> request);
1672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
168b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // StreamListenSocket::Delegate overrides:
169b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  virtual void DidAccept(StreamListenSocket* server,
17058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                         scoped_ptr<StreamListenSocket> connection) OVERRIDE;
171b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  virtual void DidRead(StreamListenSocket* connection,
1722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                       const char* data,
1732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                       int length) OVERRIDE;
174b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  virtual void DidClose(StreamListenSocket* connection) OVERRIDE;
1752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
176b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  HttpConnection* FindConnection(StreamListenSocket* socket);
1772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
17858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Posts a task to the |io_thread_| and waits for a reply.
17958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  bool PostTaskToIOThreadAndWait(
18058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      const base::Closure& closure) WARN_UNUSED_RESULT;
18158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
182f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  scoped_ptr<base::Thread> io_thread_;
183c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
18458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  scoped_ptr<HttpListenSocket> listen_socket_;
1852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int port_;
1862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  GURL base_url_;
1872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Owns the HttpConnection objects.
189b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  std::map<StreamListenSocket*, HttpConnection*> connections_;
1902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Vector of registered request handlers.
1922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::vector<HandleRequestCallback> request_handlers_;
1932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1941320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  base::ThreadChecker thread_checker_;
1951320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
1962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Note: This should remain the last member so it'll be destroyed and
1972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // invalidate its weak pointers before any other members are destroyed.
198b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  base::WeakPtrFactory<EmbeddedTestServer> weak_factory_;
1992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
200b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(EmbeddedTestServer);
2012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
2022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace test_servers
204b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}  // namespace net
2052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
206b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#endif  // NET_TEST_EMBEDDED_TEST_SERVER_EMBEDDED_TEST_SERVER_H_
207