Merge pull request #6502 from liusy182/optional-callback-6491

Make the callback of session.clearStorageData optional
This commit is contained in:
Cheng Zhao 2016-07-15 22:45:49 +09:00 committed by GitHub
commit 43b5e655a4
2 changed files with 13 additions and 9 deletions

View file

@ -323,6 +323,12 @@ void AllowNTLMCredentialsForDomainsInIO(
} }
} }
void OnClearStorageDataDone(const base::Closure& callback) {
if(callback.is_null())
return;
callback.Run();
}
} // namespace } // namespace
Session::Session(v8::Isolate* isolate, AtomBrowserContext* browser_context) 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) { void Session::ClearStorageData(mate::Arguments* args) {
// clearStorageData([options, ]callback) // clearStorageData([options, callback])
ClearStorageDataOptions options; ClearStorageDataOptions options;
args->GetNext(&options); args->GetNext(&options);
base::Closure callback; base::Closure callback;
if (!args->GetNext(&callback)) { args->GetNext(&callback);
args->ThrowError();
return;
}
auto storage_partition = auto storage_partition =
content::BrowserContext::GetStoragePartition(browser_context(), nullptr); content::BrowserContext::GetStoragePartition(browser_context(), nullptr);
storage_partition->ClearData( storage_partition->ClearData(
options.storage_types, options.quota_types, options.origin, options.storage_types, options.quota_types, options.origin,
content::StoragePartition::OriginMatcherFunction(), content::StoragePartition::OriginMatcherFunction(),
base::Time(), base::Time::Max(), callback); base::Time(), base::Time::Max(), base::Bind(&OnClearStorageDataDone, callback));
} }
void Session::FlushStorageData() { void Session::FlushStorageData() {

View file

@ -98,7 +98,7 @@ Returns the session's current cache size.
Clears the sessions HTTP cache. Clears the sessions HTTP cache.
#### `ses.clearStorageData([options, ]callback)` #### `ses.clearStorageData([options, callback])`
* `options` Object (optional) * `options` Object (optional)
* `origin` String - Should follow `window.location.origin`s representation * `origin` String - Should follow `window.location.origin`s representation
@ -108,7 +108,7 @@ Clears the sessions HTTP cache.
`shadercache`, `websql`, `serviceworkers` `shadercache`, `websql`, `serviceworkers`
* `quotas` Array - The types of quotas to clear, can contain: * `quotas` Array - The types of quotas to clear, can contain:
`temporary`, `persistent`, `syncable`. `temporary`, `persistent`, `syncable`.
* `callback` Function - Called when operation is done. * `callback` Function (optional) - Called when operation is done.
Clears the data of web storages. Clears the data of web storages.