From 2ad942323ceb275dd3f6b8930f5c2fee92d59ca0 Mon Sep 17 00:00:00 2001 From: Robo Date: Thu, 25 Apr 2019 10:51:48 -0700 Subject: [PATCH] refactor: session.clearHostResolverCache with network service (#17935) --- atom/browser/api/atom_api_session.cc | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/atom/browser/api/atom_api_session.cc b/atom/browser/api/atom_api_session.cc index d4192b29e114..6ed4d9025e7f 100644 --- a/atom/browser/api/atom_api_session.cc +++ b/atom/browser/api/atom_api_session.cc @@ -287,20 +287,6 @@ void SetCertVerifyProcInIO( ->SetVerifyProc(proc); } -void ClearHostResolverCacheInIO( - const scoped_refptr& context_getter, - util::Promise promise) { - auto* request_context = context_getter->GetURLRequestContext(); - auto* cache = request_context->host_resolver()->GetHostCache(); - if (cache) { - cache->clear(); - DCHECK_EQ(0u, cache->size()); - base::PostTaskWithTraits( - FROM_HERE, {BrowserThread::UI}, - base::BindOnce(util::Promise::ResolveEmptyPromise, std::move(promise))); - } -} - void ClearAuthCacheInIO( const scoped_refptr& context_getter, const ClearAuthCacheOptions& options, @@ -610,11 +596,15 @@ v8::Local Session::ClearHostResolverCache(mate::Arguments* args) { util::Promise promise(isolate); v8::Local handle = promise.GetHandle(); - base::PostTaskWithTraits( - FROM_HERE, {BrowserThread::IO}, - base::BindOnce(&ClearHostResolverCacheInIO, - WrapRefCounted(browser_context_->GetRequestContext()), - std::move(promise))); + content::BrowserContext::GetDefaultStoragePartition(browser_context_.get()) + ->GetNetworkContext() + ->ClearHostCache( + nullptr, base::BindOnce( + [](util::Promise promise) { + util::Promise::ResolveEmptyPromise(std::move(promise)); + }, + std::move(promise))); + return handle; }