feat: promisify ses.clearHostResolverCache() (#17229)
This commit is contained in:
parent
9d8619f305
commit
e5e6aa207c
6 changed files with 23 additions and 11 deletions
|
@ -277,14 +277,15 @@ void SetCertVerifyProcInIO(
|
|||
|
||||
void ClearHostResolverCacheInIO(
|
||||
const scoped_refptr<net::URLRequestContextGetter>& context_getter,
|
||||
const base::Closure& callback) {
|
||||
util::Promise promise) {
|
||||
auto* request_context = context_getter->GetURLRequestContext();
|
||||
auto* cache = request_context->host_resolver()->GetHostCache();
|
||||
if (cache) {
|
||||
cache->clear();
|
||||
DCHECK_EQ(0u, cache->size());
|
||||
if (!callback.is_null())
|
||||
RunCallbackInUI(callback);
|
||||
base::PostTaskWithTraits(
|
||||
FROM_HERE, {BrowserThread::UI},
|
||||
base::BindOnce(util::Promise::ResolveEmptyPromise, std::move(promise)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -564,15 +565,17 @@ void Session::SetPermissionCheckHandler(v8::Local<v8::Value> val,
|
|||
permission_manager->SetPermissionCheckHandler(handler);
|
||||
}
|
||||
|
||||
void Session::ClearHostResolverCache(mate::Arguments* args) {
|
||||
base::Closure callback;
|
||||
args->GetNext(&callback);
|
||||
v8::Local<v8::Promise> Session::ClearHostResolverCache(mate::Arguments* args) {
|
||||
v8::Isolate* isolate = args->isolate();
|
||||
util::Promise promise(isolate);
|
||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||
|
||||
base::PostTaskWithTraits(
|
||||
FROM_HERE, {BrowserThread::IO},
|
||||
base::BindOnce(&ClearHostResolverCacheInIO,
|
||||
WrapRefCounted(browser_context_->GetRequestContext()),
|
||||
callback));
|
||||
std::move(promise)));
|
||||
return handle;
|
||||
}
|
||||
|
||||
void Session::ClearAuthCache(mate::Arguments* args) {
|
||||
|
|
|
@ -77,7 +77,7 @@ class Session : public mate::TrackableObject<Session>,
|
|||
mate::Arguments* args);
|
||||
void SetPermissionCheckHandler(v8::Local<v8::Value> val,
|
||||
mate::Arguments* args);
|
||||
void ClearHostResolverCache(mate::Arguments* args);
|
||||
v8::Local<v8::Promise> ClearHostResolverCache(mate::Arguments* args);
|
||||
void ClearAuthCache(mate::Arguments* args);
|
||||
void AllowNTLMCredentialsForDomains(const std::string& domains);
|
||||
void SetUserAgent(const std::string& user_agent, mate::Arguments* args);
|
||||
|
|
|
@ -17,7 +17,6 @@ When a majority of affected functions are migrated, this flag will be enabled by
|
|||
- [ses.clearCache(callback)](https://github.com/electron/electron/blob/master/docs/api/session.md#clearCache)
|
||||
- [ses.setProxy(config, callback)](https://github.com/electron/electron/blob/master/docs/api/session.md#setProxy)
|
||||
- [ses.resolveProxy(url, callback)](https://github.com/electron/electron/blob/master/docs/api/session.md#resolveProxy)
|
||||
- [ses.clearHostResolverCache([callback])](https://github.com/electron/electron/blob/master/docs/api/session.md#clearHostResolverCache)
|
||||
- [ses.getBlobData(identifier, callback)](https://github.com/electron/electron/blob/master/docs/api/session.md#getBlobData)
|
||||
- [ses.clearAuthCache(options[, callback])](https://github.com/electron/electron/blob/master/docs/api/session.md#clearAuthCache)
|
||||
- [contents.executeJavaScript(code[, userGesture, callback])](https://github.com/electron/electron/blob/master/docs/api/web-contents.md#executeJavaScript)
|
||||
|
@ -46,6 +45,7 @@ When a majority of affected functions are migrated, this flag will be enabled by
|
|||
- [dialog.showSaveDialog([browserWindow, ]options[, callback])](https://github.com/electron/electron/blob/master/docs/api/dialog.md#showSaveDialog)
|
||||
- [netLog.stopLogging([callback])](https://github.com/electron/electron/blob/master/docs/api/net-log.md#stopLogging)
|
||||
- [protocol.isProtocolHandled(scheme, callback)](https://github.com/electron/electron/blob/master/docs/api/protocol.md#isProtocolHandled)
|
||||
- [ses.clearHostResolverCache([callback])](https://github.com/electron/electron/blob/master/docs/api/session.md#clearHostResolverCache)
|
||||
- [ses.clearStorageData([options, callback])](https://github.com/electron/electron/blob/master/docs/api/session.md#clearStorageData)
|
||||
- [shell.openExternal(url[, options, callback])](https://github.com/electron/electron/blob/master/docs/api/shell.md#openExternal)
|
||||
- [webviewTag.capturePage([rect, ]callback)](https://github.com/electron/electron/blob/master/docs/api/webview-tag.md#capturePage)
|
||||
|
|
|
@ -354,12 +354,20 @@ session.fromPartition('some-partition').setPermissionCheckHandler((webContents,
|
|||
})
|
||||
```
|
||||
|
||||
#### `ses.clearHostResolverCache([callback])`
|
||||
#### `ses.clearHostResolverCache(callback)`
|
||||
|
||||
* `callback` Function (optional) - Called when operation is done.
|
||||
|
||||
Clears the host resolver cache.
|
||||
|
||||
**[Deprecated Soon](promisification.md)**
|
||||
|
||||
#### `ses.clearHostResolverCache()`
|
||||
|
||||
Returns `Promise<void>` - Resolves when the operation is complete.
|
||||
|
||||
Clears the host resolver cache.
|
||||
|
||||
#### `ses.allowNTLMCredentialsForDomains(domains)`
|
||||
|
||||
* `domains` String - A comma-separated list of servers for which
|
||||
|
|
|
@ -24,6 +24,7 @@ Session.prototype._init = function () {
|
|||
}
|
||||
|
||||
Session.prototype.clearStorageData = deprecate.promisify(Session.prototype.clearStorageData)
|
||||
Session.prototype.clearHostResolverCache = deprecate.promisify(Session.prototype.clearHostResolverCache)
|
||||
|
||||
Cookies.prototype.flushStore = deprecate.promisify(Cookies.prototype.flushStore)
|
||||
Cookies.prototype.get = deprecate.promisify(Cookies.prototype.get)
|
||||
|
|
|
@ -643,7 +643,7 @@ describe('session module', () => {
|
|||
// creation of request context which in turn initializes
|
||||
// the network context, can be removed with network
|
||||
// service enabled.
|
||||
customSession.clearHostResolverCache(() => done())
|
||||
customSession.clearHostResolverCache().then(() => done())
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
|
|
Loading…
Reference in a new issue