From ca021d030f81ffef979125ecc6657458c9ee2537 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 16 Jun 2015 16:03:43 +0800 Subject: [PATCH] Add --ignore-connections-limit switch --- brightray/browser/network_delegate.cc | 28 +++++++++++++++++++++++++++ brightray/browser/network_delegate.h | 5 +++++ 2 files changed, 33 insertions(+) diff --git a/brightray/browser/network_delegate.cc b/brightray/browser/network_delegate.cc index 9d586d72cf..373b5819a7 100644 --- a/brightray/browser/network_delegate.cc +++ b/brightray/browser/network_delegate.cc @@ -4,11 +4,30 @@ #include "browser/network_delegate.h" +#include +#include + +#include "base/command_line.h" +#include "base/strings/string_split.h" +#include "net/base/load_flags.h" #include "net/base/net_errors.h" +#include "net/url_request/url_request.h" namespace brightray { +namespace { + +// Ignore the limit of 6 connections per host. +const char kIgnoreConnectionsLimit[] = "ignore-connections-limit"; + +} // namespace + NetworkDelegate::NetworkDelegate() { + auto command_line = base::CommandLine::ForCurrentProcess(); + if (command_line->HasSwitch(kIgnoreConnectionsLimit)) { + std::string value = command_line->GetSwitchValueASCII(kIgnoreConnectionsLimit); + base::SplitString(value, ',', &ignore_connections_limit_domains_); + } } NetworkDelegate::~NetworkDelegate() { @@ -18,6 +37,15 @@ int NetworkDelegate::OnBeforeURLRequest( net::URLRequest* request, const net::CompletionCallback& callback, GURL* new_url) { + for (const auto& domain : ignore_connections_limit_domains_) { + if (request->url().DomainIs(domain.c_str(), domain.size())) { + // Allow unlimited concurrent connections. + request->SetPriority(net::MAXIMUM_PRIORITY); + request->SetLoadFlags(request->load_flags() | net::LOAD_IGNORE_LIMITS); + break; + } + } + return net::OK; } diff --git a/brightray/browser/network_delegate.h b/brightray/browser/network_delegate.h index 55835622ac..642b0b4cac 100644 --- a/brightray/browser/network_delegate.h +++ b/brightray/browser/network_delegate.h @@ -5,6 +5,9 @@ #ifndef BRIGHTRAY_BROWSER_NETWORK_DELEGATE_H_ #define BRIGHTRAY_BROWSER_NETWORK_DELEGATE_H_ +#include +#include + #include "net/base/network_delegate.h" namespace brightray { @@ -69,6 +72,8 @@ class NetworkDelegate : public net::NetworkDelegate { const GURL& referrer_url) const override; private: + std::vector ignore_connections_limit_domains_; + DISALLOW_COPY_AND_ASSIGN(NetworkDelegate); };