Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Commit

Permalink
NetworkService: Add ClearHostCache() method
Browse files Browse the repository at this point in the history
  • Loading branch information
hferreiro authored and ltilve committed Aug 15, 2018
1 parent 7bbf5bc commit cdb0144
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 31 deletions.
11 changes: 8 additions & 3 deletions brave/browser/brave_browser_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
#include "content/public/browser/site_instance.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/common/service_manager_connection.h"
#include "services/service_manager/public/cpp/connector.h"
#include "extensions/browser/pref_names.h"
#include "extensions/buildflags/buildflags.h"
#include "net/base/escape.h"
Expand All @@ -64,6 +63,8 @@
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
#include "net/url_request/url_request_job_factory_impl.h"
#include "services/network/public/mojom/network_context.mojom.h"
#include "services/service_manager/public/cpp/connector.h"
#include "vendor/brightray/browser/browser_client.h"
#include "vendor/brightray/browser/net_log.h"

Expand Down Expand Up @@ -265,6 +266,12 @@ BraveBrowserContext::~BraveBrowserContext() {
}
}

// Clears any data the network stack contains that may be related to the
// OTR session. Must be done before DestroyBrowserContextServices, since
// the NetworkContext is managed by one such service.
GetDefaultStoragePartition(this)->GetNetworkContext()->ClearHostCache(
nullptr, network::mojom::NetworkContext::ClearHostCacheCallback());

BrowserContextDependencyManager::GetInstance()->
DestroyBrowserContextServices(this);

Expand All @@ -277,8 +284,6 @@ BraveBrowserContext::~BraveBrowserContext() {
#endif
}

g_browser_process->io_thread()->ChangedToOnTheRecord();

ShutdownStoragePartitions();
}

Expand Down
32 changes: 4 additions & 28 deletions chromium_src/chrome/browser/io_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,6 @@ void IOThread::CleanUp() {
net_log_->ShutDownBeforeTaskScheduler();
}

void IOThread::ChangedToOnTheRecord() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::BindOnce(&IOThread::ChangedToOnTheRecordOnIOThread,
base::Unretained(this)));
}

net::URLRequestContextGetter* IOThread::system_url_request_context_getter() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (!system_url_request_context_getter_.get()) {
Expand All @@ -237,28 +229,11 @@ net::URLRequestContextGetter* IOThread::system_url_request_context_getter() {
return system_url_request_context_getter_.get();
}

void IOThread::ClearHostCache(
const base::Callback<bool(const std::string&)>& host_filter) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);

globals_->system_request_context->host_resolver()
->GetHostCache()
->ClearForHosts(host_filter);
}

void IOThread::DisableQuic() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
globals_->quic_disabled = true;
}

void IOThread::ChangedToOnTheRecordOnIOThread() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);

// Clear the host cache to avoid showing entries from the OTR session
// in about:net-internals.
ClearHostCache(base::Callback<bool(const std::string&)>());
}

// static

// static
Expand Down Expand Up @@ -363,8 +338,6 @@ void IOThread::ConstructSystemRequestContext() {
builder->SetHttpAuthHandlerFactory(
CreateDefaultAuthHandlerFactory(host_resolver.get()));

builder->set_host_resolver(std::move(host_resolver));

std::unique_ptr<net::CertVerifier> cert_verifier;
cert_verifier = net::CertVerifier::CreateDefault();

Expand All @@ -384,12 +357,15 @@ void IOThread::ConstructSystemRequestContext() {
std::make_unique<net::NetworkQualityEstimatorParams>(
std::map<std::string, std::string>()),
net_log_);
globals_->deprecated_host_resolver = std::move(host_resolver);
globals_->system_request_context_owner = std::move(builder)->Create(
std::move(network_context_params_).get(), !is_quic_allowed_on_init_,
net_log_, globals_->deprecated_network_quality_estimator.get());
net_log_, globals_->deprecated_host_resolver.get(),
globals_->deprecated_network_quality_estimator.get());
globals_->system_request_context =
globals_->system_request_context_owner.url_request_context.get();
} else {
content::GetNetworkServiceImpl()->SetHostResolver(std::move(host_resolver));
globals_->system_network_context =
content::GetNetworkServiceImpl()->CreateNetworkContextWithBuilder(
std::move(network_context_request_),
Expand Down

0 comments on commit cdb0144

Please sign in to comment.