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

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

Issue 23566018: [chromedriver] Remove Logger and just use base LOG. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 #include "chrome/test/chromedriver/server/http_handler.h" 5 #include "chrome/test/chromedriver/server/http_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
11 #include "base/logging.h" // For CHECK macros. 11 #include "base/logging.h" // For CHECK macros.
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/message_loop/message_loop_proxy.h" 14 #include "base/message_loop/message_loop_proxy.h"
15 #include "base/strings/string_split.h" 15 #include "base/strings/string_split.h"
16 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
17 #include "base/strings/stringprintf.h" 17 #include "base/strings/stringprintf.h"
18 #include "base/sys_info.h" 18 #include "base/sys_info.h"
19 #include "base/values.h" 19 #include "base/values.h"
20 #include "chrome/test/chromedriver/alert_commands.h" 20 #include "chrome/test/chromedriver/alert_commands.h"
21 #include "chrome/test/chromedriver/chrome/adb_impl.h" 21 #include "chrome/test/chromedriver/chrome/adb_impl.h"
22 #include "chrome/test/chromedriver/chrome/device_manager.h" 22 #include "chrome/test/chromedriver/chrome/device_manager.h"
23 #include "chrome/test/chromedriver/chrome/log.h"
24 #include "chrome/test/chromedriver/chrome/status.h" 23 #include "chrome/test/chromedriver/chrome/status.h"
25 #include "chrome/test/chromedriver/chrome/version.h" 24 #include "chrome/test/chromedriver/chrome/version.h"
26 #include "chrome/test/chromedriver/net/url_request_context_getter.h" 25 #include "chrome/test/chromedriver/net/url_request_context_getter.h"
27 #include "chrome/test/chromedriver/session.h" 26 #include "chrome/test/chromedriver/session.h"
28 #include "chrome/test/chromedriver/session_thread_map.h" 27 #include "chrome/test/chromedriver/session_thread_map.h"
29 #include "chrome/test/chromedriver/util.h" 28 #include "chrome/test/chromedriver/util.h"
30 #include "net/server/http_server_request_info.h" 29 #include "net/server/http_server_request_info.h"
31 #include "net/server/http_server_response_info.h" 30 #include "net/server/http_server_response_info.h"
32 31
33 #if defined(OS_MACOSX) 32 #if defined(OS_MACOSX)
(...skipping 15 matching lines...) Expand all
49 48
50 } // namespace 49 } // namespace
51 50
52 CommandMapping::CommandMapping(HttpMethod method, 51 CommandMapping::CommandMapping(HttpMethod method,
53 const std::string& path_pattern, 52 const std::string& path_pattern,
54 const Command& command) 53 const Command& command)
55 : method(method), path_pattern(path_pattern), command(command) {} 54 : method(method), path_pattern(path_pattern), command(command) {}
56 55
57 CommandMapping::~CommandMapping() {} 56 CommandMapping::~CommandMapping() {}
58 57
59 HttpHandler::HttpHandler(Log* log, const std::string& url_base) 58 HttpHandler::HttpHandler(const std::string& url_base)
60 : log_(log), 59 : url_base_(url_base),
61 url_base_(url_base),
62 received_shutdown_(false), 60 received_shutdown_(false),
63 command_map_(new CommandMap()), 61 command_map_(new CommandMap()),
64 weak_ptr_factory_(this) {} 62 weak_ptr_factory_(this) {}
65 63
66 HttpHandler::HttpHandler( 64 HttpHandler::HttpHandler(
67 const base::Closure& quit_func, 65 const base::Closure& quit_func,
68 const scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, 66 const scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
69 Log* log,
70 const std::string& url_base, 67 const std::string& url_base,
71 int adb_port) 68 int adb_port)
72 : quit_func_(quit_func), 69 : quit_func_(quit_func),
73 log_(log),
74 url_base_(url_base), 70 url_base_(url_base),
75 received_shutdown_(false), 71 received_shutdown_(false),
76 weak_ptr_factory_(this) { 72 weak_ptr_factory_(this) {
77 #if defined(OS_MACOSX) 73 #if defined(OS_MACOSX)
78 base::mac::ScopedNSAutoreleasePool autorelease_pool; 74 base::mac::ScopedNSAutoreleasePool autorelease_pool;
79 #endif 75 #endif
80 context_getter_ = new URLRequestContextGetter(io_task_runner); 76 context_getter_ = new URLRequestContextGetter(io_task_runner);
81 socket_factory_ = CreateSyncWebSocketFactory(context_getter_.get()); 77 socket_factory_ = CreateSyncWebSocketFactory(context_getter_.get());
82 adb_.reset(new AdbImpl(io_task_runner, log_, adb_port)); 78 adb_.reset(new AdbImpl(io_task_runner, adb_port));
83 device_manager_.reset(new DeviceManager(adb_.get())); 79 device_manager_.reset(new DeviceManager(adb_.get()));
84 80
85 CommandMapping commands[] = { 81 CommandMapping commands[] = {
86 CommandMapping(kPost, 82 CommandMapping(kPost,
87 internal::kNewSessionPathPattern, 83 internal::kNewSessionPathPattern,
88 base::Bind(&ExecuteNewSession, 84 base::Bind(&ExecuteNewSession,
89 NewSessionParams(log_, 85 NewSessionParams(&session_thread_map_,
90 &session_thread_map_,
91 context_getter_, 86 context_getter_,
92 socket_factory_, 87 socket_factory_,
93 device_manager_.get()))), 88 device_manager_.get()))),
94 CommandMapping(kGet, 89 CommandMapping(kGet,
95 "session/:sessionId", 90 "session/:sessionId",
96 WrapToCommand(base::Bind(&ExecuteGetSessionCapabilities))), 91 WrapToCommand(base::Bind(&ExecuteGetSessionCapabilities))),
97 CommandMapping(kDelete, 92 CommandMapping(kDelete,
98 "session/:sessionId", 93 "session/:sessionId",
99 base::Bind(&ExecuteSessionCommand, 94 base::Bind(&ExecuteSessionCommand,
100 &session_thread_map_, 95 &session_thread_map_,
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 Command HttpHandler::WrapToCommand( 479 Command HttpHandler::WrapToCommand(
485 const ElementCommand& element_command) { 480 const ElementCommand& element_command) {
486 return WrapToCommand( 481 return WrapToCommand(
487 base::Bind(&ExecuteElementCommand, element_command)); 482 base::Bind(&ExecuteElementCommand, element_command));
488 } 483 }
489 484
490 void HttpHandler::HandleCommand( 485 void HttpHandler::HandleCommand(
491 const net::HttpServerRequestInfo& request, 486 const net::HttpServerRequestInfo& request,
492 const std::string& trimmed_path, 487 const std::string& trimmed_path,
493 const HttpResponseSenderFunc& send_response_func) { 488 const HttpResponseSenderFunc& send_response_func) {
494 log_->AddEntry(Log::kLog, 489 VLOG(0) << "Handling command: " << request.method << " " << trimmed_path
495 base::StringPrintf("handling command: %s %s %s", 490 << " " << request.data;
496 request.method.c_str(),
497 trimmed_path.c_str(),
498 request.data.c_str()));
499 491
500 base::DictionaryValue params; 492 base::DictionaryValue params;
501 std::string session_id; 493 std::string session_id;
502 CommandMap::const_iterator iter = command_map_->begin(); 494 CommandMap::const_iterator iter = command_map_->begin();
503 while (true) { 495 while (true) {
504 if (iter == command_map_->end()) { 496 if (iter == command_map_->end()) {
505 scoped_ptr<net::HttpServerResponseInfo> response( 497 scoped_ptr<net::HttpServerResponseInfo> response(
506 new net::HttpServerResponseInfo(net::HTTP_NOT_FOUND)); 498 new net::HttpServerResponseInfo(net::HTTP_NOT_FOUND));
507 response->SetBody("unknown command: " + trimmed_path, "text/plain"); 499 response->SetBody("unknown command: " + trimmed_path, "text/plain");
508 send_response_func.Run(response.Pass()); 500 send_response_func.Run(response.Pass());
(...skipping 29 matching lines...) Expand all
538 530
539 void HttpHandler::PrepareResponse( 531 void HttpHandler::PrepareResponse(
540 const std::string& trimmed_path, 532 const std::string& trimmed_path,
541 const HttpResponseSenderFunc& send_response_func, 533 const HttpResponseSenderFunc& send_response_func,
542 const Status& status, 534 const Status& status,
543 scoped_ptr<base::Value> value, 535 scoped_ptr<base::Value> value,
544 const std::string& session_id) { 536 const std::string& session_id) {
545 CHECK(thread_checker_.CalledOnValidThread()); 537 CHECK(thread_checker_.CalledOnValidThread());
546 scoped_ptr<net::HttpServerResponseInfo> response = 538 scoped_ptr<net::HttpServerResponseInfo> response =
547 PrepareResponseHelper(trimmed_path, status, value.Pass(), session_id); 539 PrepareResponseHelper(trimmed_path, status, value.Pass(), session_id);
548 log_->AddEntry(Log::kLog, 540 VLOG(0) << "Sending response: " << response->status_code() << " "
549 base::StringPrintf("sending response: %d %s", 541 << response->body();
550 response->status_code(),
551 response->body().c_str()));
552 send_response_func.Run(response.Pass()); 542 send_response_func.Run(response.Pass());
553 if (trimmed_path == kShutdownPath) 543 if (trimmed_path == kShutdownPath)
554 quit_func_.Run(); 544 quit_func_.Run();
555 } 545 }
556 546
557 scoped_ptr<net::HttpServerResponseInfo> HttpHandler::PrepareResponseHelper( 547 scoped_ptr<net::HttpServerResponseInfo> HttpHandler::PrepareResponseHelper(
558 const std::string& trimmed_path, 548 const std::string& trimmed_path,
559 const Status& status, 549 const Status& status,
560 scoped_ptr<base::Value> value, 550 scoped_ptr<base::Value> value,
561 const std::string& session_id) { 551 const std::string& session_id) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 params.SetString(name, path_parts[i]); 638 params.SetString(name, path_parts[i]);
649 } else if (command_path_parts[i] != path_parts[i]) { 639 } else if (command_path_parts[i] != path_parts[i]) {
650 return false; 640 return false;
651 } 641 }
652 } 642 }
653 out_params->MergeDictionary(&params); 643 out_params->MergeDictionary(&params);
654 return true; 644 return true;
655 } 645 }
656 646
657 } // namespace internal 647 } // namespace internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698