refactor: session.clearHostResolverCache with network service (#17935)

This commit is contained in:
Robo 2019-04-25 10:51:48 -07:00 committed by Jeremy Apthorp
parent a2e5cb82fc
commit 2ad942323c

View file

@ -287,20 +287,6 @@ void SetCertVerifyProcInIO(
->SetVerifyProc(proc); ->SetVerifyProc(proc);
} }
void ClearHostResolverCacheInIO(
const scoped_refptr<net::URLRequestContextGetter>& 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( void ClearAuthCacheInIO(
const scoped_refptr<net::URLRequestContextGetter>& context_getter, const scoped_refptr<net::URLRequestContextGetter>& context_getter,
const ClearAuthCacheOptions& options, const ClearAuthCacheOptions& options,
@ -610,11 +596,15 @@ v8::Local<v8::Promise> Session::ClearHostResolverCache(mate::Arguments* args) {
util::Promise promise(isolate); util::Promise promise(isolate);
v8::Local<v8::Promise> handle = promise.GetHandle(); v8::Local<v8::Promise> handle = promise.GetHandle();
base::PostTaskWithTraits( content::BrowserContext::GetDefaultStoragePartition(browser_context_.get())
FROM_HERE, {BrowserThread::IO}, ->GetNetworkContext()
base::BindOnce(&ClearHostResolverCacheInIO, ->ClearHostCache(
WrapRefCounted(browser_context_->GetRequestContext()), nullptr, base::BindOnce(
std::move(promise))); [](util::Promise promise) {
util::Promise::ResolveEmptyPromise(std::move(promise));
},
std::move(promise)));
return handle; return handle;
} }