Add --ignore-connections-limit switch

This commit is contained in:
Cheng Zhao 2015-06-16 16:03:43 +08:00
parent cb6fba94fc
commit ca021d030f
2 changed files with 33 additions and 0 deletions

View file

@ -4,11 +4,30 @@
#include "browser/network_delegate.h" #include "browser/network_delegate.h"
#include <string>
#include <vector>
#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/base/net_errors.h"
#include "net/url_request/url_request.h"
namespace brightray { namespace brightray {
namespace {
// Ignore the limit of 6 connections per host.
const char kIgnoreConnectionsLimit[] = "ignore-connections-limit";
} // namespace
NetworkDelegate::NetworkDelegate() { 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() { NetworkDelegate::~NetworkDelegate() {
@ -18,6 +37,15 @@ int NetworkDelegate::OnBeforeURLRequest(
net::URLRequest* request, net::URLRequest* request,
const net::CompletionCallback& callback, const net::CompletionCallback& callback,
GURL* new_url) { 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; return net::OK;
} }

View file

@ -5,6 +5,9 @@
#ifndef BRIGHTRAY_BROWSER_NETWORK_DELEGATE_H_ #ifndef BRIGHTRAY_BROWSER_NETWORK_DELEGATE_H_
#define BRIGHTRAY_BROWSER_NETWORK_DELEGATE_H_ #define BRIGHTRAY_BROWSER_NETWORK_DELEGATE_H_
#include <string>
#include <vector>
#include "net/base/network_delegate.h" #include "net/base/network_delegate.h"
namespace brightray { namespace brightray {
@ -69,6 +72,8 @@ class NetworkDelegate : public net::NetworkDelegate {
const GURL& referrer_url) const override; const GURL& referrer_url) const override;
private: private:
std::vector<std::string> ignore_connections_limit_domains_;
DISALLOW_COPY_AND_ASSIGN(NetworkDelegate); DISALLOW_COPY_AND_ASSIGN(NetworkDelegate);
}; };