OLD | NEW |
| (Empty) |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef SYNC_TEST_FAKE_SERVER_FAKE_SERVER_HTTP_HANDLER_H_ | |
6 #define SYNC_TEST_FAKE_SERVER_FAKE_SERVER_HTTP_HANDLER_H_ | |
7 | |
8 #include "net/server/http_server.h" | |
9 #include "sync/test/fake_server/fake_server.h" | |
10 | |
11 namespace fake_server { | |
12 | |
13 // An HTTP server that forwards requests to FakeServer, providing a quick way | |
14 // to test Sync client code. | |
15 class FakeSyncServerHttpHandler : public net::HttpServer::Delegate { | |
16 public: | |
17 // Creates a fake sync server that listens on an available port. | |
18 FakeSyncServerHttpHandler(); | |
19 | |
20 // Creates a fake sync server that listens on a specified port. | |
21 explicit FakeSyncServerHttpHandler(int port); | |
22 | |
23 virtual ~FakeSyncServerHttpHandler(); | |
24 | |
25 // Begin accepting HTTP requests. Must be called from an IO MessageLoop. | |
26 void Start(); | |
27 | |
28 // Overridden from net::HttpServer::Delegate. | |
29 // HTTP requests are processed and WebSocket requests are currently | |
30 // unimplemented. | |
31 virtual void OnHttpRequest(int connection_id, | |
32 const net::HttpServerRequestInfo& info) OVERRIDE; | |
33 virtual void OnWebSocketRequest( | |
34 int connection_id, | |
35 const net::HttpServerRequestInfo& info) OVERRIDE; | |
36 | |
37 virtual void OnWebSocketMessage(int connection_id, | |
38 const std::string& data) OVERRIDE; | |
39 | |
40 virtual void OnClose(int connection_id) OVERRIDE; | |
41 | |
42 private: | |
43 int requested_port_; | |
44 | |
45 scoped_refptr<net::HttpServer> server_; | |
46 | |
47 fake_server::FakeServer fake_sync_server_; | |
48 | |
49 DISALLOW_COPY_AND_ASSIGN(FakeSyncServerHttpHandler); | |
50 }; | |
51 | |
52 } // namespace fake_server | |
53 | |
54 #endif // SYNC_TEST_FAKE_SERVER_FAKE_SERVER_HTTP_HANDLER_H_ | |
OLD | NEW |