From 4d1d4361a23de553b57626bdc4ff1ab6802f9dfa Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 19 Jun 2019 23:42:11 -0700 Subject: [PATCH] refactor: session.{clearCache,getCacheSize} nws13n --- atom/browser/api/atom_api_session.cc | 13 ++++++++++++- atom/browser/api/atom_api_session.h | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/atom/browser/api/atom_api_session.cc b/atom/browser/api/atom_api_session.cc index b48071b45de6d..ddfe34017eb11 100644 --- a/atom/browser/api/atom_api_session.cc +++ b/atom/browser/api/atom_api_session.cc @@ -420,6 +420,17 @@ void Session::ResolveProxy( browser_context_->GetResolveProxyHelper()->ResolveProxy(url, callback); } +void Session::GetCacheSize(const net::CompletionCallback& callback) { + content::BrowserContext::GetDefaultStoragePartition(browser_context_.get()) + ->GetNetworkContext() + ->ComputeHttpCacheSize( + base::Time(), base::Time::Max(), + base::BindOnce( + [](const net::CompletionCallback& cb, bool is_upper_bound, + int64_t size_or_error) { cb.Run(size_or_error); }, + callback)); +} + template void Session::DoCacheAction(const net::CompletionCallback& callback) { base::PostTaskWithTraits( @@ -748,7 +759,7 @@ void Session::BuildPrototype(v8::Isolate* isolate, mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) .MakeDestroyable() .SetMethod("resolveProxy", &Session::ResolveProxy) - .SetMethod("getCacheSize", &Session::DoCacheAction) + .SetMethod("getCacheSize", &Session::GetCacheSize) .SetMethod("clearCache", &Session::DoCacheAction) .SetMethod("clearStorageData", &Session::ClearStorageData) .SetMethod("flushStorageData", &Session::FlushStorageData) diff --git a/atom/browser/api/atom_api_session.h b/atom/browser/api/atom_api_session.h index 3a6216a031813..8b4eb06bfbc58 100644 --- a/atom/browser/api/atom_api_session.h +++ b/atom/browser/api/atom_api_session.h @@ -66,6 +66,7 @@ class Session : public mate::TrackableObject, const ResolveProxyHelper::ResolveProxyCallback& callback); template void DoCacheAction(const net::CompletionCallback& callback); + void GetCacheSize(const net::CompletionCallback& callback); void ClearStorageData(mate::Arguments* args); void FlushStorageData(); void SetProxy(const mate::Dictionary& options, const base::Closure& callback);