Skip to content

Commit

Permalink
Make HttpNetworkSession::host_mapping_rules no longer a pointer.
Browse files Browse the repository at this point in the history
TBR=dimich@chromium.org
BUG=725653

Review-Url: https://codereview.chromium.org/2906463002
Cr-Commit-Position: refs/heads/master@{#475111}
  • Loading branch information
mmenke authored and Commit bot committed May 26, 2017
1 parent 1635d1c commit 0d700dd
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 29 deletions.
6 changes: 3 additions & 3 deletions chrome/browser/io_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -649,15 +649,15 @@ void IOThread::Init() {
net::ProxyService::CreateDirectWithNetLog(net_log_);
globals_->dns_probe_service.reset(new chrome_browser_net::DnsProbeService());
globals_->host_mapping_rules.reset(new net::HostMappingRules());
params_.host_mapping_rules = globals_->host_mapping_rules.get();
globals_->http_user_agent_settings.reset(
new net::StaticHttpUserAgentSettings(std::string(), GetUserAgent()));
if (command_line.HasSwitch(switches::kHostRules)) {
TRACE_EVENT_BEGIN0("startup", "IOThread::InitAsync:SetRulesFromString");
globals_->host_mapping_rules->SetRulesFromString(
command_line.GetSwitchValueASCII(switches::kHostRules));
TRACE_EVENT_END0("startup", "IOThread::InitAsync:SetRulesFromString");
}
params_.host_mapping_rules = *globals_->host_mapping_rules.get();
globals_->http_user_agent_settings.reset(
new net::StaticHttpUserAgentSettings(std::string(), GetUserAgent()));
globals_->enable_brotli =
base::FeatureList::IsEnabled(features::kBrotliEncoding);
params_.enable_token_binding =
Expand Down
4 changes: 0 additions & 4 deletions google_apis/gcm/tools/mcs_probe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include "google_apis/gcm/engine/gservices_settings.h"
#include "google_apis/gcm/engine/mcs_client.h"
#include "google_apis/gcm/monitoring/fake_gcm_stats_recorder.h"
#include "net/base/host_mapping_rules.h"
#include "net/cert/cert_verifier.h"
#include "net/cert/ct_policy_enforcer.h"
#include "net/cert/multi_log_ct_verifier.h"
Expand Down Expand Up @@ -257,7 +256,6 @@ class MCSProbe {
MCSProbeAuthPreferences http_auth_preferences_;
std::unique_ptr<net::HttpAuthHandlerFactory> http_auth_handler_factory_;
std::unique_ptr<net::HttpServerPropertiesImpl> http_server_properties_;
std::unique_ptr<net::HostMappingRules> host_mapping_rules_;
std::unique_ptr<net::HttpNetworkSession> network_session_;
std::unique_ptr<net::ProxyService> proxy_service_;

Expand Down Expand Up @@ -406,7 +404,6 @@ void MCSProbe::InitializeNetworkState() {
http_auth_handler_factory_ = net::HttpAuthHandlerRegistryFactory::Create(
&http_auth_preferences_, host_resolver_.get());
http_server_properties_.reset(new net::HttpServerPropertiesImpl());
host_mapping_rules_.reset(new net::HostMappingRules());
proxy_service_ = net::ProxyService::CreateDirectWithNetLog(&net_log_);
}

Expand All @@ -421,7 +418,6 @@ void MCSProbe::BuildNetworkSession() {
session_params.ssl_config_service = new net::SSLConfigServiceDefaults();
session_params.http_auth_handler_factory = http_auth_handler_factory_.get();
session_params.http_server_properties = http_server_properties_.get();
session_params.host_mapping_rules = host_mapping_rules_.get();
session_params.ignore_certificate_errors = true;
session_params.testing_fixed_http_port = 0;
session_params.testing_fixed_https_port = 0;
Expand Down
25 changes: 13 additions & 12 deletions net/base/host_mapping_rules.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,17 @@ struct HostMappingRules::ExclusionRule {

HostMappingRules::HostMappingRules() {}

HostMappingRules::HostMappingRules(const HostMappingRules& host_mapping_rules) =
default;

HostMappingRules::~HostMappingRules() {}

bool HostMappingRules::RewriteHost(HostPortPair* host_port) const {
// Check if the hostname was excluded.
for (ExclusionRuleList::const_iterator it = exclusion_rules_.begin();
it != exclusion_rules_.end(); ++it) {
const ExclusionRule& rule = *it;
if (base::MatchPattern(host_port->host(), rule.hostname_pattern))
return false;
}
HostMappingRules& HostMappingRules::operator=(
const HostMappingRules& host_mapping_rules) = default;

bool HostMappingRules::RewriteHost(HostPortPair* host_port) const {
// Check if the hostname was remapped.
for (MapRuleList::const_iterator it = map_rules_.begin();
it != map_rules_.end(); ++it) {
const MapRule& rule = *it;

for (const auto& rule : map_rules_) {
// The rule's hostname_pattern will be something like:
// www.foo.com
// *.foo.com
Expand All @@ -57,6 +52,12 @@ bool HostMappingRules::RewriteHost(HostPortPair* host_port) const {
continue; // This rule doesn't apply.
}

// Check if the hostname was excluded.
for (const auto& rule : exclusion_rules_) {
if (base::MatchPattern(host_port->host(), rule.hostname_pattern))
return false;
}

host_port->set_host(rule.replacement_hostname);
if (rule.replacement_port != -1)
host_port->set_port(static_cast<uint16_t>(rule.replacement_port));
Expand Down
5 changes: 3 additions & 2 deletions net/base/host_mapping_rules.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ class HostPortPair;
class NET_EXPORT_PRIVATE HostMappingRules {
public:
HostMappingRules();
HostMappingRules(const HostMappingRules& host_mapping_rules);
~HostMappingRules();

HostMappingRules& operator=(const HostMappingRules& host_mapping_rules);

// Modifies |*host_port| based on the current rules. Returns true if
// |*host_port| was modified, false otherwise.
bool RewriteHost(HostPortPair* host_port) const;
Expand All @@ -46,8 +49,6 @@ class NET_EXPORT_PRIVATE HostMappingRules {

MapRuleList map_rules_;
ExclusionRuleList exclusion_rules_;

DISALLOW_COPY_AND_ASSIGN(HostMappingRules);
};

} // namespace net
Expand Down
1 change: 0 additions & 1 deletion net/http/http_network_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ HttpNetworkSession::Params::Params()
ssl_config_service(nullptr),
http_auth_handler_factory(nullptr),
net_log(nullptr),
host_mapping_rules(nullptr),
socket_performance_watcher_factory(nullptr),
ignore_certificate_errors(false),
testing_fixed_http_port(0),
Expand Down
3 changes: 2 additions & 1 deletion net/http/http_network_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/threading/non_thread_safe.h"
#include "net/base/host_mapping_rules.h"
#include "net/base/host_port_pair.h"
#include "net/base/net_export.h"
#include "net/dns/host_resolver.h"
Expand Down Expand Up @@ -95,7 +96,7 @@ class NET_EXPORT HttpNetworkSession
HttpAuthHandlerFactory* http_auth_handler_factory;
HttpServerProperties* http_server_properties;
NetLog* net_log;
HostMappingRules* host_mapping_rules;
HostMappingRules host_mapping_rules;
SocketPerformanceWatcherFactory* socket_performance_watcher_factory;
bool ignore_certificate_errors;
uint16_t testing_fixed_http_port;
Expand Down
2 changes: 1 addition & 1 deletion net/http/http_stream_factory_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ void HttpStreamFactoryImpl::PreconnectStreams(
}

const HostMappingRules* HttpStreamFactoryImpl::GetHostMappingRules() const {
return session_->params().host_mapping_rules;
return &session_->params().host_mapping_rules;
}

void HttpStreamFactoryImpl::OnNewSpdySessionReady(
Expand Down
3 changes: 1 addition & 2 deletions net/http/http_stream_factory_impl_job_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -892,8 +892,7 @@ void HttpStreamFactoryImpl::JobController::MaybeNotifyFactoryOfCompletion() {
GURL HttpStreamFactoryImpl::JobController::ApplyHostMappingRules(
const GURL& url,
HostPortPair* endpoint) {
const HostMappingRules* mapping_rules = session_->params().host_mapping_rules;
if (mapping_rules && mapping_rules->RewriteHost(endpoint)) {
if (session_->params().host_mapping_rules.RewriteHost(endpoint)) {
url::Replacements<char> replacements;
const std::string port_str = base::UintToString(endpoint->port());
replacements.SetPort(port_str.c_str(), url::Component(0, port_str.size()));
Expand Down
3 changes: 1 addition & 2 deletions net/url_request/url_request_context_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,7 @@ URLRequestContextBuilder::HttpCacheParams::HttpCacheParams()
URLRequestContextBuilder::HttpCacheParams::~HttpCacheParams() {}

URLRequestContextBuilder::HttpNetworkSessionParams::HttpNetworkSessionParams()
: host_mapping_rules(nullptr),
ignore_certificate_errors(false),
: ignore_certificate_errors(false),
testing_fixed_http_port(0),
testing_fixed_https_port(0),
enable_http2(true),
Expand Down
2 changes: 1 addition & 1 deletion net/url_request/url_request_context_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class NET_EXPORT URLRequestContextBuilder {
void ConfigureSessionParams(HttpNetworkSession::Params* params) const;

// These fields mirror those in HttpNetworkSession::Params;
HostMappingRules* host_mapping_rules;
HostMappingRules host_mapping_rules;
bool ignore_certificate_errors;
uint16_t testing_fixed_http_port;
uint16_t testing_fixed_https_port;
Expand Down

0 comments on commit 0d700dd

Please sign in to comment.