Commit f7c18d02 authored by pfeldman's avatar pfeldman Committed by Commit bot

DevTools: reuse ephemeral port from http handler in the shell front-end.

BUG=

Review-Url: https://codereview.chromium.org/2320003002
Cr-Commit-Position: refs/heads/master@{#417371}
parent 5407ae12
......@@ -6,7 +6,6 @@
#include <stddef.h>
#include "base/command_line.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/json/string_escape.h"
......@@ -21,13 +20,11 @@
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_client.h"
#include "content/public/common/content_switches.h"
#include "content/shell/browser/shell.h"
#include "content/shell/browser/shell_browser_context.h"
#include "content/shell/browser/shell_browser_main_parts.h"
#include "content/shell/browser/shell_content_browser_client.h"
#include "content/shell/browser/shell_devtools_manager_delegate.h"
#include "content/shell/common/shell_switches.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/http/http_response_headers.h"
......@@ -98,20 +95,7 @@ int ResponseWriter::Finish(const net::CompletionCallback& callback) {
}
static GURL GetFrontendURL() {
const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
uint16_t port = 0;
if (command_line.HasSwitch(switches::kRemoteDebuggingPort)) {
int temp_port;
std::string port_str =
command_line.GetSwitchValueASCII(switches::kRemoteDebuggingPort);
if (base::StringToInt(port_str, &temp_port) &&
temp_port >= 0 && temp_port < 65535) {
port = static_cast<uint16_t>(temp_port);
} else {
DLOG(WARNING) << "Invalid http debugger port number " << temp_port;
}
}
int port = ShellDevToolsManagerDelegate::GetHttpHandlerPort();
return GURL(
base::StringPrintf("http://127.0.0.1:%d/devtools/inspector.html", port));
}
......
......@@ -8,6 +8,7 @@
#include <vector>
#include "base/atomicops.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
......@@ -51,6 +52,8 @@ const char kFrontEndURL[] =
const int kBackLog = 10;
base::subtle::Atomic32 g_last_used_port;
#if defined(OS_ANDROID)
class UnixDomainServerSocketFactory : public content::DevToolsSocketFactory {
public:
......@@ -92,6 +95,10 @@ class TCPServerSocketFactory : public content::DevToolsSocketFactory {
if (socket->ListenWithAddressAndPort(address_, port_, kBackLog) != net::OK)
return std::unique_ptr<net::ServerSocket>();
net::IPEndPoint endpoint;
if (socket->GetLocalAddress(&endpoint) == net::OK)
base::subtle::NoBarrier_Store(&g_last_used_port, endpoint.port());
return socket;
}
......@@ -142,6 +149,11 @@ std::unique_ptr<content::DevToolsSocketFactory> CreateSocketFactory() {
// ShellDevToolsManagerDelegate ----------------------------------------------
// static
int ShellDevToolsManagerDelegate::GetHttpHandlerPort() {
return base::subtle::NoBarrier_Load(&g_last_used_port);
}
// static
void ShellDevToolsManagerDelegate::StartHttpHandler(
BrowserContext* browser_context) {
......
......@@ -17,6 +17,7 @@ class ShellDevToolsManagerDelegate : public DevToolsManagerDelegate {
public:
static void StartHttpHandler(BrowserContext* browser_context);
static void StopHttpHandler();
static int GetHttpHandlerPort();
explicit ShellDevToolsManagerDelegate(BrowserContext* browser_context);
~ShellDevToolsManagerDelegate() override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment