forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Headless: remove devtools protocol network handler"
This reverts commit a8d13c1. Reason for revert: Suspected causing build failure on win32-rel: https://ci.chromium.org/p/chromium/builders/luci.chromium.ci/win32-rel/3631 Original change's description: > Headless: remove devtools protocol network handler > > Network conditions management is now done in content, so support for > this in headless is redundant. > > Change-Id: I559de2c65e659c026b7e8e9d9021340e6271af92 > Reviewed-on: https://chromium-review.googlesource.com/1255610 > Reviewed-by: Dmitry Gozman <dgozman@chromium.org> > Commit-Queue: Andrey Kosyakov <caseq@chromium.org> > Cr-Commit-Position: refs/heads/master@{#595637} TBR=dgozman@chromium.org,caseq@chromium.org,pfeldman@chromium.org Change-Id: I0601d25a065e06cff731df50e1dae614ee194dc8 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://chromium-review.googlesource.com/1256166 Reviewed-by: Thomas Anderson <thomasanderson@chromium.org> Commit-Queue: Thomas Anderson <thomasanderson@chromium.org> Cr-Commit-Position: refs/heads/master@{#595650}
- Loading branch information
1 parent
a38e472
commit e87c094
Showing
10 changed files
with
196 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// 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 <string> | ||
#include <vector> | ||
|
||
#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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// 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<HeadlessBrowserImpl> 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<Network::ConnectionType>) { | ||
// Associate NetworkConditions to context | ||
std::vector<HeadlessBrowserContext*> 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<HeadlessBrowserContext*> browser_contexts = | ||
browser()->GetAllBrowserContexts(); | ||
SetNetworkConditions(browser_contexts, HeadlessNetworkConditions()); | ||
return Response::FallThrough(); | ||
} | ||
|
||
void NetworkHandler::SetNetworkConditions( | ||
std::vector<HeadlessBrowserContext*> browser_contexts, | ||
HeadlessNetworkConditions conditions) { | ||
for (std::vector<HeadlessBrowserContext*>::iterator it = | ||
browser_contexts.begin(); | ||
it != browser_contexts.end(); ++it) { | ||
HeadlessBrowserContextImpl* context = | ||
static_cast<HeadlessBrowserContextImpl*>(*it); | ||
context->SetNetworkConditions(conditions); | ||
} | ||
} | ||
|
||
} // namespace protocol | ||
} // namespace headless |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// 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<HeadlessBrowserImpl> browser); | ||
~NetworkHandler() override; | ||
|
||
void Wire(UberDispatcher* dispatcher) override; | ||
|
||
// Network::Backend implementation | ||
Response EmulateNetworkConditions( | ||
bool offline, | ||
double latency, | ||
double download_throughput, | ||
double upload_throughput, | ||
Maybe<Network::ConnectionType> connection_type) override; | ||
Response Disable() override; | ||
|
||
private: | ||
void SetNetworkConditions( | ||
std::vector<HeadlessBrowserContext*> browser_contexts, | ||
HeadlessNetworkConditions conditions); | ||
DISALLOW_COPY_AND_ASSIGN(NetworkHandler); | ||
}; | ||
|
||
} // namespace protocol | ||
} // namespace headless | ||
|
||
#endif // HEADLESS_LIB_BROWSER_PROTOCOL_NETWORK_HANDLER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters