#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <locale>
#include <memory>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include "base/at_exit.h"
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/json/json_reader.h"
#include "base/logging.h"
#include "base/message_loop/message_pump_type.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/to_string.h"
#include "base/synchronization/waitable_event.h"
#include "base/task/single_thread_task_executor.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/thread_pool/thread_pool_instance.h"
#include "base/threading/thread.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/test/chromedriver/constants/version.h"
#include "chrome/test/chromedriver/keycode_text_conversion.h"
#include "chrome/test/chromedriver/logging.h"
#include "chrome/test/chromedriver/server/http_handler.h"
#include "chrome/test/chromedriver/server/http_server.h"
#include "mojo/core/embedder/embedder.h"
#include "net/base/ip_address.h"
#include "net/base/ip_endpoint.h"
#include "net/base/net_errors.h"
#include "net/log/net_log_source.h"
#include "third_party/abseil-cpp/absl/base/attributes.h"
namespace {
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
void EnsureSharedMemory(base::CommandLine* cmd_line) { … }
#endif
void SendResponseOnCmdThread(
const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
const HttpResponseSenderFunc& send_response_on_io_func,
std::unique_ptr<net::HttpServerResponseInfo> response) { … }
void HandleRequestOnCmdThread(
HttpHandler* handler,
const std::vector<net::IPAddress>& allowed_ips,
const net::HttpServerRequestInfo& request,
const HttpResponseSenderFunc& send_response_func) { … }
void HandleRequestOnIOThread(
const scoped_refptr<base::SingleThreadTaskRunner>& cmd_task_runner,
const HttpRequestHandlerFunc& handle_request_on_cmd_func,
const net::HttpServerRequestInfo& request,
const HttpResponseSenderFunc& send_response_func) { … }
ABSL_CONST_INIT thread_local HttpServer* server_ipv4 = …;
ABSL_CONST_INIT thread_local HttpServer* server_ipv6 = …;
void StopServerOnIOThread() { … }
void StartServerOnIOThread(
uint16_t port,
bool allow_remote,
const std::string& url_base,
const std::vector<net::IPAddress>& allowed_ips,
const std::vector<std::string>& allowed_origins,
const HttpRequestHandlerFunc& handle_request_func,
base::WeakPtr<HttpHandler> handler,
const scoped_refptr<base::SingleThreadTaskRunner>& cmd_task_runner) { … }
void RunServer(uint16_t port,
bool allow_remote,
const std::vector<net::IPAddress>& allowed_ips,
const std::vector<std::string>& allowed_origins,
const std::string& url_base,
int adb_port) { … }
}
int main(int argc, char *argv[]) { … }