REVIEW: Re-use devtools network throttling from content layer

https://chromium-review.googlesource.com/c/chromium/src/+/664356
This commit is contained in:
deepak1556 2017-12-19 23:47:48 +05:30 committed by Aleksei Kuzmin
parent 490b1e2532
commit 007ea500d0
26 changed files with 23 additions and 1651 deletions

View file

@ -31,11 +31,11 @@
#include "base/strings/string_util.h"
#include "base/threading/thread_task_runner_handle.h"
#include "brightray/browser/media/media_device_id_salt.h"
#include "brightray/browser/net/devtools_network_conditions.h"
#include "brightray/browser/net/devtools_network_controller_handle.h"
#include "chrome/browser/browser_process.h"
#include "chrome/common/pref_names.h"
#include "components/prefs/pref_service.h"
#include "content/common/devtools/devtools_network_conditions.h"
#include "content/common/devtools/devtools_network_controller.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/download_manager_delegate.h"
#include "content/public/browser/storage_partition.h"
@ -543,23 +543,20 @@ void Session::SetDownloadPath(const base::FilePath& path) {
}
void Session::EnableNetworkEmulation(const mate::Dictionary& options) {
std::unique_ptr<brightray::DevToolsNetworkConditions> conditions;
std::unique_ptr<content::DevToolsNetworkConditions> conditions;
bool offline = false;
double latency = 0.0, download_throughput = 0.0, upload_throughput = 0.0;
if (options.Get("offline", &offline) && offline) {
conditions.reset(new brightray::DevToolsNetworkConditions(offline));
conditions.reset(new content::DevToolsNetworkConditions(offline));
} else {
options.Get("latency", &latency);
options.Get("downloadThroughput", &download_throughput);
options.Get("uploadThroughput", &upload_throughput);
conditions.reset(
new brightray::DevToolsNetworkConditions(false,
latency,
download_throughput,
upload_throughput));
conditions.reset(new content::DevToolsNetworkConditions(
false, latency, download_throughput, upload_throughput));
}
browser_context_->network_controller_handle()->SetNetworkState(
content::DevToolsNetworkController::SetNetworkState(
devtools_network_emulation_client_id_, std::move(conditions));
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
@ -570,8 +567,8 @@ void Session::EnableNetworkEmulation(const mate::Dictionary& options) {
}
void Session::DisableNetworkEmulation() {
std::unique_ptr<brightray::DevToolsNetworkConditions> conditions;
browser_context_->network_controller_handle()->SetNetworkState(
auto conditions = base::MakeUnique<content::DevToolsNetworkConditions>();
content::DevToolsNetworkController::SetNetworkState(
devtools_network_emulation_client_id_, std::move(conditions));
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,

View file

@ -10,12 +10,12 @@
#include "atom/common/native_mate_converters/net_converter.h"
#include "base/stl_util.h"
#include "base/strings/string_util.h"
#include "brightray/browser/net/devtools_network_transaction.h"
#include "content/common/devtools/devtools_network_transaction.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_frame_host.h"
#include "net/url_request/url_request.h"
using brightray::DevToolsNetworkTransaction;
using content::DevToolsNetworkTransaction;
using content::BrowserThread;
namespace atom {
@ -266,9 +266,9 @@ int AtomNetworkDelegate::OnBeforeStartTransaction(
const net::CompletionCallback& callback,
net::HttpRequestHeaders* headers) {
if (!client_id_.empty())
headers->SetHeader(
DevToolsNetworkTransaction::kDevToolsEmulateNetworkConditionsClientId,
client_id_);
headers->SetHeader(content::DevToolsNetworkTransaction::
kDevToolsEmulateNetworkConditionsClientId,
client_id_);
if (!base::ContainsKey(response_listeners_, kOnBeforeSendHeaders))
return brightray::NetworkDelegate::OnBeforeStartTransaction(
request, callback, headers);

View file

@ -96,9 +96,9 @@ void URLRequestFetchJob::BeforeStartInUI(
if (val->IsNull()) {
// We have to create the URLRequestContextGetter on UI thread.
url_request_context_getter_ = new brightray::URLRequestContextGetter(
this, nullptr, nullptr, base::FilePath(), true,
BrowserThread::GetTaskRunnerForThread(BrowserThread::IO),
nullptr, content::URLRequestInterceptorScopedVector());
this, nullptr, base::FilePath(), true,
BrowserThread::GetTaskRunnerForThread(BrowserThread::IO), nullptr,
content::URLRequestInterceptorScopedVector());
} else {
mate::Handle<api::Session> session;
if (mate::ConvertFromV8(isolate, val, &session) && !session.IsEmpty()) {