Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: session.{clearCache,getCacheSize} nws13n #18898

Merged
merged 1 commit into from Jun 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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