Skip to content

Commit

Permalink
refactor: session.{clearCache,getCacheSize} nws13n (#18921)
Browse files Browse the repository at this point in the history
  • Loading branch information
trop[bot] authored and codebytere committed Jun 21, 2019
1 parent 4c468a9 commit 65c53cc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion atom/browser/api/atom_api_session.cc
Expand Up @@ -419,6 +419,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 <Session::CacheAction action>
void Session::DoCacheAction(const net::CompletionCallback& callback) {
BrowserThread::PostTask(
Expand Down Expand Up @@ -747,7 +758,7 @@ void Session::BuildPrototype(v8::Isolate* isolate,
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.MakeDestroyable()
.SetMethod("resolveProxy", &Session::ResolveProxy)
.SetMethod("getCacheSize", &Session::DoCacheAction<CacheAction::STATS>)
.SetMethod("getCacheSize", &Session::GetCacheSize)
.SetMethod("clearCache", &Session::DoCacheAction<CacheAction::CLEAR>)
.SetMethod("clearStorageData", &Session::ClearStorageData)
.SetMethod("flushStorageData", &Session::FlushStorageData)
Expand Down
1 change: 1 addition & 0 deletions atom/browser/api/atom_api_session.h
Expand Up @@ -66,6 +66,7 @@ class Session : public mate::TrackableObject<Session>,
const ResolveProxyHelper::ResolveProxyCallback& callback);
template <CacheAction action>
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);
Expand Down

0 comments on commit 65c53cc

Please sign in to comment.