From 2a848813c87dec781e0c4efd3686c750d571bd75 Mon Sep 17 00:00:00 2001 From: Andrey Kosyakov Date: Tue, 2 Oct 2018 16:30:40 +0000 Subject: [PATCH] Headless: remove devtools protocol network handler Network conditions management is now done in content, so support for this in headless is redundant. This is a re-land of https://chromium-review.googlesource.com/c/chromium/src/+/1255610 fix network_dp.{h,cc} being removed from BUILD.gn. Change-Id: I6903c58f72bfc20588bf795da7b9f2e647dd0801 Reviewed-on: https://chromium-review.googlesource.com/1255726 Reviewed-by: Dmitry Gozman Commit-Queue: Andrey Kosyakov Cr-Commit-Position: refs/heads/master@{#595870} --- headless/BUILD.gn | 6 -- .../browser/headless_browser_context_impl.cc | 9 --- .../browser/headless_browser_context_impl.h | 6 -- .../browser/headless_network_conditions.cc | 26 -------- .../lib/browser/headless_network_conditions.h | 36 ----------- .../protocol/headless_devtools_session.cc | 2 - .../lib/browser/protocol/network_handler.cc | 61 ------------------- .../lib/browser/protocol/network_handler.h | 44 ------------- headless/protocol_config.json | 5 -- headless/public/headless_browser_context.h | 3 - 10 files changed, 198 deletions(-) delete mode 100644 headless/lib/browser/headless_network_conditions.cc delete mode 100644 headless/lib/browser/headless_network_conditions.h delete mode 100644 headless/lib/browser/protocol/network_handler.cc delete mode 100644 headless/lib/browser/protocol/network_handler.h diff --git a/headless/BUILD.gn b/headless/BUILD.gn index 93c5758f7eaeba..5260da784dad78 100644 --- a/headless/BUILD.gn +++ b/headless/BUILD.gn @@ -272,8 +272,6 @@ inspector_protocol_generate("protocol_sources") { "lib/browser/protocol/dp_browser.h", "lib/browser/protocol/dp_headless_experimental.cc", "lib/browser/protocol/dp_headless_experimental.h", - "lib/browser/protocol/dp_network.cc", - "lib/browser/protocol/dp_network.h", "lib/browser/protocol/dp_page.cc", "lib/browser/protocol/dp_page.h", "lib/browser/protocol/dp_target.cc", @@ -304,8 +302,6 @@ jumbo_component("headless") { "lib/browser/headless_devtools_client_impl.cc", "lib/browser/headless_devtools_manager_delegate.cc", "lib/browser/headless_devtools_manager_delegate.h", - "lib/browser/headless_network_conditions.cc", - "lib/browser/headless_network_conditions.h", "lib/browser/headless_permission_manager.cc", "lib/browser/headless_permission_manager.h", "lib/browser/headless_platform_event_source.cc", @@ -327,8 +323,6 @@ jumbo_component("headless") { "lib/browser/protocol/headless_devtools_session.h", "lib/browser/protocol/headless_handler.cc", "lib/browser/protocol/headless_handler.h", - "lib/browser/protocol/network_handler.cc", - "lib/browser/protocol/network_handler.h", "lib/browser/protocol/page_handler.cc", "lib/browser/protocol/page_handler.h", "lib/browser/protocol/protocol_string.cc", diff --git a/headless/lib/browser/headless_browser_context_impl.cc b/headless/lib/browser/headless_browser_context_impl.cc index 4a19349549381a..d90b6a6fa729d8 100644 --- a/headless/lib/browser/headless_browser_context_impl.cc +++ b/headless/lib/browser/headless_browser_context_impl.cc @@ -363,15 +363,6 @@ const std::string& HeadlessBrowserContextImpl::Id() const { return UniqueId(); } -void HeadlessBrowserContextImpl::SetNetworkConditions( - HeadlessNetworkConditions conditions) { - network_conditions_ = conditions; -} - -HeadlessNetworkConditions HeadlessBrowserContextImpl::GetNetworkConditions() { - return network_conditions_; -} - HeadlessBrowserContext::Builder::Builder(HeadlessBrowserImpl* browser) : browser_(browser), options_(new HeadlessBrowserContextOptions(browser->options())) {} diff --git a/headless/lib/browser/headless_browser_context_impl.h b/headless/lib/browser/headless_browser_context_impl.h index 25b9cf26067d6c..120a37cbd2c21d 100644 --- a/headless/lib/browser/headless_browser_context_impl.h +++ b/headless/lib/browser/headless_browser_context_impl.h @@ -16,7 +16,6 @@ #include "content/public/browser/global_routing_id.h" #include "content/public/browser/resource_context.h" #include "headless/lib/browser/headless_browser_context_options.h" -#include "headless/lib/browser/headless_network_conditions.h" #include "headless/lib/browser/headless_url_request_context_getter.h" #include "headless/public/headless_browser.h" #include "headless/public/headless_browser_context.h" @@ -110,9 +109,6 @@ class HEADLESS_EXPORT HeadlessBrowserContextImpl final const base::UnguessableToken* GetDevToolsFrameTokenForFrameTreeNodeId( int frame_tree_node_id) const; - void SetNetworkConditions(HeadlessNetworkConditions conditions); - HeadlessNetworkConditions GetNetworkConditions() override; - private: HeadlessBrowserContextImpl( HeadlessBrowserImpl* browser, @@ -144,8 +140,6 @@ class HEADLESS_EXPORT HeadlessBrowserContextImpl final std::unique_ptr permission_controller_delegate_; - HeadlessNetworkConditions network_conditions_; - DISALLOW_COPY_AND_ASSIGN(HeadlessBrowserContextImpl); }; diff --git a/headless/lib/browser/headless_network_conditions.cc b/headless/lib/browser/headless_network_conditions.cc deleted file mode 100644 index 208208c90209a4..00000000000000 --- a/headless/lib/browser/headless_network_conditions.cc +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "headless/lib/browser/headless_network_conditions.h" - -namespace headless { - -HeadlessNetworkConditions::HeadlessNetworkConditions() - : HeadlessNetworkConditions(false) {} - -HeadlessNetworkConditions::HeadlessNetworkConditions(bool offline) - : HeadlessNetworkConditions(offline, 0, 0, 0) {} - -HeadlessNetworkConditions::HeadlessNetworkConditions(bool offline, - double latency, - double download_throughput, - double upload_throughput) - : offline(offline), - latency(latency), - download_throughput(download_throughput), - upload_throughput(upload_throughput) {} - -HeadlessNetworkConditions::~HeadlessNetworkConditions() = default; - -} // namespace headless diff --git a/headless/lib/browser/headless_network_conditions.h b/headless/lib/browser/headless_network_conditions.h deleted file mode 100644 index 041847d5064109..00000000000000 --- a/headless/lib/browser/headless_network_conditions.h +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef HEADLESS_LIB_BROWSER_HEADLESS_NETWORK_CONDITIONS_H_ -#define HEADLESS_LIB_BROWSER_HEADLESS_NETWORK_CONDITIONS_H_ - -#include -#include - -#include "base/macros.h" - -#include "headless/public/headless_export.h" - -namespace headless { - -// HeadlessNetworkConditions holds information about desired network conditions. -struct HEADLESS_EXPORT HeadlessNetworkConditions { - HeadlessNetworkConditions(); - ~HeadlessNetworkConditions(); - - explicit HeadlessNetworkConditions(bool offline); - HeadlessNetworkConditions(bool offline, - double latency, - double download_throughput, - double upload_throughput); - - bool offline; - double latency; - double download_throughput; - double upload_throughput; -}; - -} // namespace headless - -#endif // HEADLESS_LIB_BROWSER_HEADLESS_NETWORK_CONDITIONS_H_ diff --git a/headless/lib/browser/protocol/headless_devtools_session.cc b/headless/lib/browser/protocol/headless_devtools_session.cc index d7cc307449f38f..7eb37595ceb7a7 100644 --- a/headless/lib/browser/protocol/headless_devtools_session.cc +++ b/headless/lib/browser/protocol/headless_devtools_session.cc @@ -8,7 +8,6 @@ #include "content/public/browser/devtools_agent_host_client.h" #include "headless/lib/browser/protocol/browser_handler.h" #include "headless/lib/browser/protocol/headless_handler.h" -#include "headless/lib/browser/protocol/network_handler.h" #include "headless/lib/browser/protocol/page_handler.h" #include "headless/lib/browser/protocol/target_handler.h" @@ -32,7 +31,6 @@ HeadlessDevToolsSession::HeadlessDevToolsSession( } if (agent_host->GetType() == content::DevToolsAgentHost::kTypeBrowser) AddHandler(std::make_unique(browser_)); - AddHandler(std::make_unique(browser_)); AddHandler(std::make_unique(browser_)); } diff --git a/headless/lib/browser/protocol/network_handler.cc b/headless/lib/browser/protocol/network_handler.cc deleted file mode 100644 index ff8a1bd815301a..00000000000000 --- a/headless/lib/browser/protocol/network_handler.cc +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "headless/lib/browser/protocol/network_handler.h" - -#include "headless/lib/browser/headless_browser_context_impl.h" -#include "headless/lib/browser/headless_browser_impl.h" - -namespace headless { -namespace protocol { - -NetworkHandler::NetworkHandler(base::WeakPtr browser) - : DomainHandler(Network::Metainfo::domainName, browser) {} - -NetworkHandler::~NetworkHandler() = default; - -void NetworkHandler::Wire(UberDispatcher* dispatcher) { - Network::Dispatcher::wire(dispatcher, this); -} - -Response NetworkHandler::EmulateNetworkConditions( - bool offline, - double latency, - double download_throughput, - double upload_throughput, - Maybe) { - // Associate NetworkConditions to context - std::vector browser_contexts = - browser()->GetAllBrowserContexts(); - HeadlessNetworkConditions conditions(HeadlessNetworkConditions( - offline, std::max(latency, 0.0), std::max(download_throughput, 0.0), - std::max(upload_throughput, 0.0))); - SetNetworkConditions(browser_contexts, conditions); - return Response::FallThrough(); -} - -Response NetworkHandler::Disable() { - // Can be a part of the shutdown cycle. - if (!browser()) - return Response::OK(); - std::vector browser_contexts = - browser()->GetAllBrowserContexts(); - SetNetworkConditions(browser_contexts, HeadlessNetworkConditions()); - return Response::FallThrough(); -} - -void NetworkHandler::SetNetworkConditions( - std::vector browser_contexts, - HeadlessNetworkConditions conditions) { - for (std::vector::iterator it = - browser_contexts.begin(); - it != browser_contexts.end(); ++it) { - HeadlessBrowserContextImpl* context = - static_cast(*it); - context->SetNetworkConditions(conditions); - } -} - -} // namespace protocol -} // namespace headless diff --git a/headless/lib/browser/protocol/network_handler.h b/headless/lib/browser/protocol/network_handler.h deleted file mode 100644 index b9c3e30d4ee7ce..00000000000000 --- a/headless/lib/browser/protocol/network_handler.h +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef HEADLESS_LIB_BROWSER_PROTOCOL_NETWORK_HANDLER_H_ -#define HEADLESS_LIB_BROWSER_PROTOCOL_NETWORK_HANDLER_H_ - -#include "headless/lib/browser/headless_network_conditions.h" -#include "headless/lib/browser/protocol/domain_handler.h" -#include "headless/lib/browser/protocol/dp_network.h" - -namespace headless { - -class HeadlessBrowserContext; - -namespace protocol { - -class NetworkHandler : public DomainHandler, public Network::Backend { - public: - explicit NetworkHandler(base::WeakPtr browser); - ~NetworkHandler() override; - - void Wire(UberDispatcher* dispatcher) override; - - // Network::Backend implementation - Response EmulateNetworkConditions( - bool offline, - double latency, - double download_throughput, - double upload_throughput, - Maybe connection_type) override; - Response Disable() override; - - private: - void SetNetworkConditions( - std::vector browser_contexts, - HeadlessNetworkConditions conditions); - DISALLOW_COPY_AND_ASSIGN(NetworkHandler); -}; - -} // namespace protocol -} // namespace headless - -#endif // HEADLESS_LIB_BROWSER_PROTOCOL_NETWORK_HANDLER_H_ diff --git a/headless/protocol_config.json b/headless/protocol_config.json index 80fc13a2c4e28a..78bba001ffb04e 100644 --- a/headless/protocol_config.json +++ b/headless/protocol_config.json @@ -24,11 +24,6 @@ "domain": "HeadlessExperimental", "async": ["beginFrame"] }, - { - "domain": "Network", - "include": ["emulateNetworkConditions", "disable"], - "include_events": [] - }, { "domain": "Page", "include": ["printToPDF"], diff --git a/headless/public/headless_browser_context.h b/headless/public/headless_browser_context.h index 8c2ecb674034a3..0a21c55c3d5a94 100644 --- a/headless/public/headless_browser_context.h +++ b/headless/public/headless_browser_context.h @@ -15,7 +15,6 @@ #include "base/optional.h" #include "content/public/browser/browser_context.h" #include "content/public/common/web_preferences.h" -#include "headless/lib/browser/headless_network_conditions.h" #include "headless/public/headless_export.h" #include "headless/public/headless_web_contents.h" #include "net/proxy_resolution/proxy_resolution_service.h" @@ -65,8 +64,6 @@ class HEADLESS_EXPORT HeadlessBrowserContext { // GUID for this browser context. virtual const std::string& Id() const = 0; - virtual HeadlessNetworkConditions GetNetworkConditions() = 0; - // TODO(skyostil): Allow saving and restoring contexts (crbug.com/617931). protected: