Adding cookie flush store api
This commit is contained in:
parent
190fc46e77
commit
19709a50e9
3 changed files with 20 additions and 1 deletions
|
@ -179,6 +179,12 @@ void OnSetCookie(const Cookies::SetCallback& callback, bool success) {
|
||||||
base::Bind(callback, success ? Cookies::SUCCESS : Cookies::FAILED));
|
base::Bind(callback, success ? Cookies::SUCCESS : Cookies::FAILED));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Flushes cookie store in IO thread.
|
||||||
|
void FlushCookieStoreOnIOThread(scoped_refptr<net::URLRequestContextGetter> getter,
|
||||||
|
const base::Closure& callback) {
|
||||||
|
GetCookieStore(getter)->FlushStore(base::Bind(RunCallbackInUI, callback));
|
||||||
|
}
|
||||||
|
|
||||||
// Sets cookie with |details| in IO thread.
|
// Sets cookie with |details| in IO thread.
|
||||||
void SetCookieOnIO(scoped_refptr<net::URLRequestContextGetter> getter,
|
void SetCookieOnIO(scoped_refptr<net::URLRequestContextGetter> getter,
|
||||||
std::unique_ptr<base::DictionaryValue> details,
|
std::unique_ptr<base::DictionaryValue> details,
|
||||||
|
@ -265,6 +271,13 @@ void Cookies::Set(const base::DictionaryValue& details,
|
||||||
base::Bind(SetCookieOnIO, getter, Passed(&copied), callback));
|
base::Bind(SetCookieOnIO, getter, Passed(&copied), callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Cookies::FlushStore(const base::Closure& callback) {
|
||||||
|
auto getter = make_scoped_refptr(request_context_getter_);
|
||||||
|
content::BrowserThread::PostTask(
|
||||||
|
BrowserThread::IO, FROM_HERE,
|
||||||
|
base::Bind(FlushCookieStoreOnIOThread, getter, callback));
|
||||||
|
}
|
||||||
|
|
||||||
void Cookies::OnCookieChanged(const net::CanonicalCookie& cookie,
|
void Cookies::OnCookieChanged(const net::CanonicalCookie& cookie,
|
||||||
bool removed,
|
bool removed,
|
||||||
net::CookieStore::ChangeCause cause) {
|
net::CookieStore::ChangeCause cause) {
|
||||||
|
@ -286,7 +299,8 @@ void Cookies::BuildPrototype(v8::Isolate* isolate,
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||||
.SetMethod("get", &Cookies::Get)
|
.SetMethod("get", &Cookies::Get)
|
||||||
.SetMethod("remove", &Cookies::Remove)
|
.SetMethod("remove", &Cookies::Remove)
|
||||||
.SetMethod("set", &Cookies::Set);
|
.SetMethod("set", &Cookies::Set)
|
||||||
|
.SetMethod("flushStore", &Cookies::FlushStore);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace api
|
} // namespace api
|
||||||
|
|
|
@ -53,6 +53,7 @@ class Cookies : public mate::TrackableObject<Cookies>,
|
||||||
void Remove(const GURL& url, const std::string& name,
|
void Remove(const GURL& url, const std::string& name,
|
||||||
const base::Closure& callback);
|
const base::Closure& callback);
|
||||||
void Set(const base::DictionaryValue& details, const SetCallback& callback);
|
void Set(const base::DictionaryValue& details, const SetCallback& callback);
|
||||||
|
void FlushStore(const base::Closure& callback);
|
||||||
|
|
||||||
// AtomCookieDelegate::Observer:
|
// AtomCookieDelegate::Observer:
|
||||||
void OnCookieChanged(const net::CanonicalCookie& cookie,
|
void OnCookieChanged(const net::CanonicalCookie& cookie,
|
||||||
|
|
|
@ -104,3 +104,7 @@ on complete.
|
||||||
|
|
||||||
Removes the cookies matching `url` and `name`, `callback` will called with
|
Removes the cookies matching `url` and `name`, `callback` will called with
|
||||||
`callback()` on complete.
|
`callback()` on complete.
|
||||||
|
|
||||||
|
#### `cookies.flushStore()`
|
||||||
|
|
||||||
|
Writes any unwritten cookies data to disk.
|
||||||
|
|
Loading…
Reference in a new issue