diff --git a/atom/browser/api/atom_api_session.cc b/atom/browser/api/atom_api_session.cc index c1f4a1934ffd..f147d227d9c3 100644 --- a/atom/browser/api/atom_api_session.cc +++ b/atom/browser/api/atom_api_session.cc @@ -323,6 +323,12 @@ void AllowNTLMCredentialsForDomainsInIO( } } +void OnClearStorageDataDone(const base::Closure& callback) { + if(callback.is_null()) + return; + callback.Run(); +} + } // namespace Session::Session(v8::Isolate* isolate, AtomBrowserContext* browser_context) @@ -372,21 +378,19 @@ void Session::DoCacheAction(const net::CompletionCallback& callback) { } void Session::ClearStorageData(mate::Arguments* args) { - // clearStorageData([options, ]callback) + // clearStorageData([options, callback]) ClearStorageDataOptions options; args->GetNext(&options); - base::Closure callback; - if (!args->GetNext(&callback)) { - args->ThrowError(); - return; - } + base::Closure callback; + args->GetNext(&callback); + auto storage_partition = content::BrowserContext::GetStoragePartition(browser_context(), nullptr); storage_partition->ClearData( options.storage_types, options.quota_types, options.origin, content::StoragePartition::OriginMatcherFunction(), - base::Time(), base::Time::Max(), callback); + base::Time(), base::Time::Max(), base::Bind(&OnClearStorageDataDone, callback)); } void Session::FlushStorageData() { diff --git a/docs/api/session.md b/docs/api/session.md index 91ff30ad6ae4..2053a44a5f50 100644 --- a/docs/api/session.md +++ b/docs/api/session.md @@ -98,7 +98,7 @@ Returns the session's current cache size. Clears the session’s HTTP cache. -#### `ses.clearStorageData([options, ]callback)` +#### `ses.clearStorageData([options, callback])` * `options` Object (optional) * `origin` String - Should follow `window.location.origin`’s representation @@ -108,7 +108,7 @@ Clears the session’s HTTP cache. `shadercache`, `websql`, `serviceworkers` * `quotas` Array - The types of quotas to clear, can contain: `temporary`, `persistent`, `syncable`. -* `callback` Function - Called when operation is done. +* `callback` Function (optional) - Called when operation is done. Clears the data of web storages.