Browse Source

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

Shelley Vohr 5 years ago
parent
commit
385e548073
2 changed files with 13 additions and 1 deletions
  1. 12 1
      atom/browser/api/atom_api_session.cc
  2. 1 0
      atom/browser/api/atom_api_session.h

+ 12 - 1
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 <Session::CacheAction action>
 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<CacheAction::STATS>)
+      .SetMethod("getCacheSize", &Session::GetCacheSize)
       .SetMethod("clearCache", &Session::DoCacheAction<CacheAction::CLEAR>)
       .SetMethod("clearStorageData", &Session::ClearStorageData)
       .SetMethod("flushStorageData", &Session::FlushStorageData)

+ 1 - 0
atom/browser/api/atom_api_session.h

@@ -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);