Skip to content

Commit

Permalink
refactor: session.{clearCache,getCacheSize} nws13n
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Jun 20, 2019
1 parent 401f664 commit 4d1d436
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 @@ -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 <Session::CacheAction action>
void Session::DoCacheAction(const net::CompletionCallback& callback) {
base::PostTaskWithTraits(
Expand Down Expand Up @@ -748,7 +759,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 4d1d436

Please sign in to comment.