Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(394)

Side by Side Diff: chrome/test/chromedriver/server/http_handler.h

Issue 19616008: [chromedriver] Allow commands to be async. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 CHROME_TEST_CHROMEDRIVER_SERVER_HTTP_HANDLER_H_ 5 #ifndef CHROME_TEST_CHROMEDRIVER_SERVER_HTTP_HANDLER_H_
6 #define CHROME_TEST_CHROMEDRIVER_SERVER_HTTP_HANDLER_H_ 6 #define CHROME_TEST_CHROMEDRIVER_SERVER_HTTP_HANDLER_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
14 #include "base/threading/thread.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/threading/thread_checker.h"
15 #include "chrome/test/chromedriver/command.h" 17 #include "chrome/test/chromedriver/command.h"
18 #include "chrome/test/chromedriver/commands.h"
16 #include "chrome/test/chromedriver/element_commands.h" 19 #include "chrome/test/chromedriver/element_commands.h"
17 #include "chrome/test/chromedriver/net/sync_websocket_factory.h" 20 #include "chrome/test/chromedriver/net/sync_websocket_factory.h"
18 #include "chrome/test/chromedriver/session_commands.h" 21 #include "chrome/test/chromedriver/session_commands.h"
19 #include "chrome/test/chromedriver/session_map.h" 22 #include "chrome/test/chromedriver/session_thread_map.h"
20 #include "chrome/test/chromedriver/window_commands.h" 23 #include "chrome/test/chromedriver/window_commands.h"
21 24
22 namespace base { 25 namespace base {
23 class DictionaryValue; 26 class DictionaryValue;
27 class SingleThreadTaskRunner;
24 } 28 }
25 29
26 namespace net { 30 namespace net {
27 class HttpServerRequestInfo; 31 class HttpServerRequestInfo;
28 } 32 }
29 33
30 class Adb; 34 class Adb;
31 class DeviceManager; 35 class DeviceManager;
32 class Log; 36 class Log;
33 class HttpResponse; 37 class HttpResponse;
34 class URLRequestContextGetter; 38 class URLRequestContextGetter;
35 39
36 enum HttpMethod { 40 enum HttpMethod {
37 kGet, 41 kGet,
38 kPost, 42 kPost,
39 kDelete, 43 kDelete,
40 }; 44 };
41 45
42 struct CommandMapping { 46 struct CommandMapping {
43 CommandMapping(HttpMethod method, 47 CommandMapping(HttpMethod method,
44 const std::string& path_pattern, 48 const std::string& path_pattern,
45 const Command& command); 49 const Command& command);
46 ~CommandMapping(); 50 ~CommandMapping();
47 51
48 HttpMethod method; 52 HttpMethod method;
49 std::string path_pattern; 53 std::string path_pattern;
50 Command command; 54 Command command;
51 }; 55 };
52 56
57 typedef base::Callback<void(scoped_ptr<HttpResponse>)> HttpResponseSenderFunc;
58
53 class HttpHandler { 59 class HttpHandler {
54 public: 60 public:
55 HttpHandler(Log* log, const std::string& url_base); 61 HttpHandler(Log* log, const std::string& url_base);
62 HttpHandler(const scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
63 Log* log,
64 const std::string& url_base);
56 ~HttpHandler(); 65 ~HttpHandler();
57 66
58 void Handle(const net::HttpServerRequestInfo& request, 67 void Handle(const net::HttpServerRequestInfo& request,
59 HttpResponse* response); 68 const HttpResponseSenderFunc& send_response_func);
60 bool ShouldShutdown(const net::HttpServerRequestInfo& request); 69 bool ShouldShutdown(const net::HttpServerRequestInfo& request);
61 70
62 private: 71 private:
63 FRIEND_TEST_ALL_PREFIXES(HttpHandlerTest, HandleUnknownCommand); 72 FRIEND_TEST_ALL_PREFIXES(HttpHandlerTest, HandleUnknownCommand);
64 FRIEND_TEST_ALL_PREFIXES(HttpHandlerTest, HandleNewSession); 73 FRIEND_TEST_ALL_PREFIXES(HttpHandlerTest, HandleNewSession);
65 FRIEND_TEST_ALL_PREFIXES(HttpHandlerTest, HandleInvalidPost); 74 FRIEND_TEST_ALL_PREFIXES(HttpHandlerTest, HandleInvalidPost);
66 FRIEND_TEST_ALL_PREFIXES(HttpHandlerTest, HandleUnimplementedCommand); 75 FRIEND_TEST_ALL_PREFIXES(HttpHandlerTest, HandleUnimplementedCommand);
67 FRIEND_TEST_ALL_PREFIXES(HttpHandlerTest, HandleCommand); 76 FRIEND_TEST_ALL_PREFIXES(HttpHandlerTest, HandleCommand);
68 typedef std::vector<CommandMapping> CommandMap; 77 typedef std::vector<CommandMapping> CommandMap;
69 78
70 Command WrapToCommand(const SessionCommand& session_command); 79 Command WrapToCommand(const SessionCommand& session_command);
71 Command WrapToCommand(const WindowCommand& window_command); 80 Command WrapToCommand(const WindowCommand& window_command);
72 Command WrapToCommand(const ElementCommand& element_command); 81 Command WrapToCommand(const ElementCommand& element_command);
73 void HandleInternal(const net::HttpServerRequestInfo& request, 82 void HandleCommand(const net::HttpServerRequestInfo& request,
74 HttpResponse* response); 83 const std::string& trimmed_path,
75 bool HandleWebDriverCommand( 84 const HttpResponseSenderFunc& send_response_func);
76 const net::HttpServerRequestInfo& request, 85 void PrepareResponse(const std::string& trimmed_path,
86 const HttpResponseSenderFunc& send_response_func,
87 const Status& status,
88 scoped_ptr<base::Value> value,
89 const std::string& session_id);
90 scoped_ptr<HttpResponse> PrepareResponseHelper(
77 const std::string& trimmed_path, 91 const std::string& trimmed_path,
78 HttpResponse* response); 92 const Status& status,
93 scoped_ptr<base::Value> value,
94 const std::string& session_id);
79 95
96 base::ThreadChecker thread_checker_;
80 Log* log_; 97 Log* log_;
81 base::Thread io_thread_;
82 std::string url_base_; 98 std::string url_base_;
99 bool received_shutdown_;
83 scoped_refptr<URLRequestContextGetter> context_getter_; 100 scoped_refptr<URLRequestContextGetter> context_getter_;
84 SyncWebSocketFactory socket_factory_; 101 SyncWebSocketFactory socket_factory_;
85 SessionMap session_map_; 102 SessionThreadMap session_thread_map_;
86 scoped_ptr<CommandMap> command_map_; 103 scoped_ptr<CommandMap> command_map_;
87 scoped_ptr<Adb> adb_; 104 scoped_ptr<Adb> adb_;
88 scoped_ptr<DeviceManager> device_manager_; 105 scoped_ptr<DeviceManager> device_manager_;
89 106
107 base::WeakPtrFactory<HttpHandler> weak_ptr_factory_;
108
90 DISALLOW_COPY_AND_ASSIGN(HttpHandler); 109 DISALLOW_COPY_AND_ASSIGN(HttpHandler);
91 }; 110 };
92 111
93 namespace internal { 112 namespace internal {
94 113
95 extern const char kNewSessionPathPattern[]; 114 extern const char kNewSessionPathPattern[];
96 115
97 bool MatchesCommand(const std::string& method, 116 bool MatchesCommand(const std::string& method,
98 const std::string& path, 117 const std::string& path,
99 const CommandMapping& command, 118 const CommandMapping& command,
100 std::string* session_id, 119 std::string* session_id,
101 base::DictionaryValue* out_params); 120 base::DictionaryValue* out_params);
102 121
103 } // namespace internal 122 } // namespace internal
104 123
105 #endif // CHROME_TEST_CHROMEDRIVER_SERVER_HTTP_HANDLER_H_ 124 #endif // CHROME_TEST_CHROMEDRIVER_SERVER_HTTP_HANDLER_H_
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/server/chromedriver_server.cc ('k') | chrome/test/chromedriver/server/http_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698