Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Unified Diff: ios/net/cookies/cookie_store_ios.mm

Issue 2937963003: Shift cookie system callbacks to OnceCallback to impedance match mojo. (Closed)
Patch Set: Finish Merge Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/net/cookies/cookie_store_ios.mm
diff --git a/ios/net/cookies/cookie_store_ios.mm b/ios/net/cookies/cookie_store_ios.mm
index f24def3184fcd5f7e1229244d44ac03341f405da..edb3bad1c6b2599672c07798dfbdd340217a7dab 100644
--- a/ios/net/cookies/cookie_store_ios.mm
+++ b/ios/net/cookies/cookie_store_ios.mm
@@ -303,7 +303,7 @@ void CookieStoreIOS::SetCookieWithOptionsAsync(
const GURL& url,
const std::string& cookie_line,
const net::CookieOptions& options,
- const SetCookiesCallback& callback) {
+ SetCookiesCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
// The exclude_httponly() option would only be used by a javascript
@@ -348,23 +348,22 @@ void CookieStoreIOS::SetCookieWithOptionsAsync(
}
if (!callback.is_null())
- callback.Run(success);
-}
-
-void CookieStoreIOS::SetCookieWithDetailsAsync(
- const GURL& url,
- const std::string& name,
- const std::string& value,
- const std::string& domain,
- const std::string& path,
- base::Time creation_time,
- base::Time expiration_time,
- base::Time last_access_time,
- bool secure,
- bool http_only,
- CookieSameSite same_site,
- CookiePriority priority,
- const SetCookiesCallback& callback) {
+ std::move(callback).Run(success);
+}
+
+void CookieStoreIOS::SetCookieWithDetailsAsync(const GURL& url,
+ const std::string& name,
+ const std::string& value,
+ const std::string& domain,
+ const std::string& path,
+ base::Time creation_time,
+ base::Time expiration_time,
+ base::Time last_access_time,
+ bool secure,
+ bool http_only,
+ CookieSameSite same_site,
+ CookiePriority priority,
+ SetCookiesCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
// If cookies are not allowed, they are stashed in the CookieMonster, and
// should be written there instead.
@@ -381,7 +380,7 @@ void CookieStoreIOS::SetCookieWithDetailsAsync(
ParsedCookie::ParseValueString(domain) != domain ||
ParsedCookie::ParseValueString(path) != path) {
if (!callback.is_null())
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
@@ -392,7 +391,7 @@ void CookieStoreIOS::SetCookieWithDetailsAsync(
!cookie_util::GetCookieDomainWithString(url, domain, &cookie_domain) ||
(!path.empty() && cookie_path != path)) {
if (!callback.is_null())
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
@@ -424,14 +423,14 @@ void CookieStoreIOS::SetCookieWithDetailsAsync(
}
if (!callback.is_null())
- callback.Run(success);
+ std::move(callback).Run(success);
}
void CookieStoreIOS::SetCanonicalCookieAsync(
std::unique_ptr<net::CanonicalCookie> cookie,
bool secure_source,
bool modify_http_only,
- const SetCookiesCallback& callback) {
+ SetCookiesCallback callback) {
DCHECK(cookie->IsCanonical());
// The exclude_httponly() option would only be used by a javascript
// engine.
@@ -439,7 +438,7 @@ void CookieStoreIOS::SetCanonicalCookieAsync(
if (cookie->IsSecure() && !secure_source) {
if (!callback.is_null())
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
@@ -453,18 +452,18 @@ void CookieStoreIOS::SetCanonicalCookieAsync(
cookie->CreationDate().is_null() ? base::Time::Now()
: cookie->CreationDate()));
if (!callback.is_null())
- callback.Run(true);
+ std::move(callback).Run(true);
return;
}
if (!callback.is_null())
- callback.Run(false);
+ std::move(callback).Run(false);
}
void CookieStoreIOS::GetCookiesWithOptionsAsync(
const GURL& url,
const net::CookieOptions& options,
- const GetCookiesCallback& callback) {
+ GetCookiesCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
// If cookies are not allowed, they are stashed in the CookieMonster, and
@@ -479,18 +478,19 @@ void CookieStoreIOS::GetCookiesWithOptionsAsync(
NSArray* cookies =
GetCookiesForURL(system_store_, url, creation_time_manager_.get());
if (!callback.is_null())
- callback.Run(BuildCookieLineWithOptions(cookies, options));
+ std::move(callback).Run(BuildCookieLineWithOptions(cookies, options));
}
void CookieStoreIOS::GetCookieListWithOptionsAsync(
const GURL& url,
const net::CookieOptions& options,
- const GetCookieListCallback& callback) {
+ GetCookieListCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
if (!SystemCookiesAllowed()) {
// If cookies are not allowed, the cookies are stashed in the
// CookieMonster, so get them from there.
- cookie_monster_->GetCookieListWithOptionsAsync(url, options, callback);
+ cookie_monster_->GetCookieListWithOptionsAsync(url, options,
+ std::move(callback));
return;
}
@@ -500,29 +500,29 @@ void CookieStoreIOS::GetCookieListWithOptionsAsync(
GetCookiesForURL(system_store_, url, creation_time_manager_.get());
net::CookieList cookie_list = CanonicalCookieListFromSystemCookies(cookies);
if (!callback.is_null())
- callback.Run(cookie_list);
+ std::move(callback).Run(cookie_list);
}
-void CookieStoreIOS::GetAllCookiesAsync(const GetCookieListCallback& callback) {
+void CookieStoreIOS::GetAllCookiesAsync(GetCookieListCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
if (!SystemCookiesAllowed()) {
// If cookies are not allowed, the cookies are stashed in the
// CookieMonster, so get them from there.
- cookie_monster_->GetAllCookiesAsync(callback);
+ cookie_monster_->GetAllCookiesAsync(std::move(callback));
return;
}
NSArray* cookies = GetAllCookies(system_store_, creation_time_manager_.get());
net::CookieList cookie_list = CanonicalCookieListFromSystemCookies(cookies);
if (!callback.is_null()) {
- callback.Run(cookie_list);
+ std::move(callback).Run(cookie_list);
}
}
void CookieStoreIOS::DeleteCookieAsync(const GURL& url,
const std::string& cookie_name,
- const base::Closure& callback) {
+ base::OnceClosure callback) {
DCHECK(thread_checker_.CalledOnValidThread());
NSArray* cookies =
@@ -535,24 +535,23 @@ void CookieStoreIOS::DeleteCookieAsync(const GURL& url,
}
if (!callback.is_null())
- callback.Run();
+ std::move(callback).Run();
}
-void CookieStoreIOS::DeleteCanonicalCookieAsync(
- const CanonicalCookie& cookie,
- const DeleteCallback& callback) {
+void CookieStoreIOS::DeleteCanonicalCookieAsync(const CanonicalCookie& cookie,
+ DeleteCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
// This relies on the fact cookies are given unique creation dates.
CookieFilterFunction filter = base::Bind(
IsCookieCreatedBetween, cookie.CreationDate(), cookie.CreationDate());
- DeleteCookiesWithFilter(filter, callback);
+ DeleteCookiesWithFilter(filter, std::move(callback));
}
void CookieStoreIOS::DeleteAllCreatedBetweenAsync(
const base::Time& delete_begin,
const base::Time& delete_end,
- const DeleteCallback& callback) {
+ DeleteCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
if (metrics_enabled_)
@@ -560,14 +559,14 @@ void CookieStoreIOS::DeleteAllCreatedBetweenAsync(
CookieFilterFunction filter = base::Bind(
&IsCookieCreatedBetween, delete_begin, delete_end);
- DeleteCookiesWithFilter(filter, callback);
+ DeleteCookiesWithFilter(filter, std::move(callback));
}
void CookieStoreIOS::DeleteAllCreatedBetweenWithPredicateAsync(
const base::Time& delete_begin,
const base::Time& delete_end,
const CookiePredicate& predicate,
- const DeleteCallback& callback) {
+ DeleteCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
if (metrics_enabled_)
@@ -575,20 +574,20 @@ void CookieStoreIOS::DeleteAllCreatedBetweenWithPredicateAsync(
CookieFilterFunction filter = base::Bind(
IsCookieCreatedBetweenWithPredicate, delete_begin, delete_end, predicate);
- DeleteCookiesWithFilter(filter, callback);
+ DeleteCookiesWithFilter(filter, std::move(callback));
}
-void CookieStoreIOS::DeleteSessionCookiesAsync(const DeleteCallback& callback) {
+void CookieStoreIOS::DeleteSessionCookiesAsync(DeleteCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
if (metrics_enabled_)
ResetCookieCountMetrics();
CookieFilterFunction filter = base::Bind(&IsCookieSessionCookie);
- DeleteCookiesWithFilter(filter, callback);
+ DeleteCookiesWithFilter(filter, std::move(callback));
}
-void CookieStoreIOS::FlushStore(const base::Closure& closure) {
+void CookieStoreIOS::FlushStore(base::OnceClosure closure) {
DCHECK(thread_checker_.CalledOnValidThread());
if (SystemCookiesAllowed()) {
@@ -596,7 +595,7 @@ void CookieStoreIOS::FlushStore(const base::Closure& closure) {
// stashed on disk. Do not delete the cookies on the disk in this case.
WriteToCookieMonster([system_store_ cookies]);
}
- cookie_monster_->FlushStore(closure);
+ cookie_monster_->FlushStore(std::move(closure));
flush_closure_.Cancel();
}
@@ -621,23 +620,23 @@ CookieStoreIOS::CookieStoreIOS(
}
CookieStoreIOS::SetCookiesCallback CookieStoreIOS::WrapSetCallback(
- const SetCookiesCallback& callback) {
+ SetCookiesCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
- return base::Bind(&CookieStoreIOS::UpdateCachesAfterSet,
- weak_factory_.GetWeakPtr(), callback);
+ return base::BindOnce(&CookieStoreIOS::UpdateCachesAfterSet,
+ weak_factory_.GetWeakPtr(), std::move(callback));
}
CookieStoreIOS::DeleteCallback CookieStoreIOS::WrapDeleteCallback(
- const DeleteCallback& callback) {
+ DeleteCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
- return base::Bind(&CookieStoreIOS::UpdateCachesAfterDelete,
- weak_factory_.GetWeakPtr(), callback);
+ return base::BindOnce(&CookieStoreIOS::UpdateCachesAfterDelete,
+ weak_factory_.GetWeakPtr(), std::move(callback));
}
-base::Closure CookieStoreIOS::WrapClosure(const base::Closure& callback) {
+base::OnceClosure CookieStoreIOS::WrapClosure(base::OnceClosure callback) {
DCHECK(thread_checker_.CalledOnValidThread());
- return base::Bind(&CookieStoreIOS::UpdateCachesAfterClosure,
- weak_factory_.GetWeakPtr(), callback);
+ return base::BindOnce(&CookieStoreIOS::UpdateCachesAfterClosure,
+ weak_factory_.GetWeakPtr(), std::move(callback));
}
#pragma mark -
@@ -677,7 +676,7 @@ void CookieStoreIOS::WriteToCookieMonster(NSArray* system_cookies) {
}
void CookieStoreIOS::DeleteCookiesWithFilter(const CookieFilterFunction& filter,
- const DeleteCallback& callback) {
+ DeleteCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
NSArray* cookies = [system_store_ cookies];
@@ -697,7 +696,7 @@ void CookieStoreIOS::DeleteCookiesWithFilter(const CookieFilterFunction& filter,
}
if (!callback.is_null())
- callback.Run([to_delete count]);
+ std::move(callback).Run([to_delete count]);
}
void CookieStoreIOS::OnSystemCookiesChanged() {
@@ -814,7 +813,7 @@ void CookieStoreIOS::GotCookieListFor(const std::pair<GURL, std::string> key,
}
void CookieStoreIOS::DidClearNSHTTPCookieStorageCookies(
- const DeleteCallback& delete_callback,
+ DeleteCallback delete_callback,
int num_deleted) {
DCHECK(thread_checker_.CalledOnValidThread());
@@ -822,15 +821,16 @@ void CookieStoreIOS::DidClearNSHTTPCookieStorageCookies(
DCHECK(client);
auto sequenced_task_runner = client->GetTaskRunner();
DCHECK(sequenced_task_runner);
- auto callback =
- base::Bind(&CookieStoreIOS::DidClearBinaryCookiesFileCookies,
- weak_factory_.GetWeakPtr(), delete_callback, num_deleted);
+ auto callback = base::BindOnce(
+ &CookieStoreIOS::DidClearBinaryCookiesFileCookies,
+ weak_factory_.GetWeakPtr(), std::move(delete_callback), num_deleted);
sequenced_task_runner.get()->PostTaskAndReply(
- FROM_HERE, base::Bind(&ClearAllCookiesFromBinaryCookiesFile), callback);
+ FROM_HERE, base::Bind(&ClearAllCookiesFromBinaryCookiesFile),
+ std::move(callback));
}
void CookieStoreIOS::DidClearBinaryCookiesFileCookies(
- const DeleteCallback& callback,
+ DeleteCallback callback,
int num_deleted_from_nshttp_cookie_storage) {
DCHECK(thread_checker_.CalledOnValidThread());
@@ -838,41 +838,41 @@ void CookieStoreIOS::DidClearBinaryCookiesFileCookies(
DCHECK(client);
client->DidChangeCookieStorage();
if (!callback.is_null())
- callback.Run(num_deleted_from_nshttp_cookie_storage);
+ std::move(callback).Run(num_deleted_from_nshttp_cookie_storage);
}
void CookieStoreIOS::UpdateCachesFromCookieMonster() {
DCHECK(thread_checker_.CalledOnValidThread());
for (const auto& hook_map_entry : hook_map_) {
std::pair<GURL, std::string> key = hook_map_entry.first;
- GetCookieListCallback callback = base::Bind(
+ GetCookieListCallback callback = base::BindOnce(
&CookieStoreIOS::GotCookieListFor, weak_factory_.GetWeakPtr(), key);
- cookie_monster_->GetAllCookiesForURLAsync(key.first, callback);
+ cookie_monster_->GetAllCookiesForURLAsync(key.first, std::move(callback));
}
}
-void CookieStoreIOS::UpdateCachesAfterSet(const SetCookiesCallback& callback,
+void CookieStoreIOS::UpdateCachesAfterSet(SetCookiesCallback callback,
bool success) {
DCHECK(thread_checker_.CalledOnValidThread());
if (success)
UpdateCachesFromCookieMonster();
if (!callback.is_null())
- callback.Run(success);
+ std::move(callback).Run(success);
}
-void CookieStoreIOS::UpdateCachesAfterDelete(const DeleteCallback& callback,
+void CookieStoreIOS::UpdateCachesAfterDelete(DeleteCallback callback,
int num_deleted) {
DCHECK(thread_checker_.CalledOnValidThread());
UpdateCachesFromCookieMonster();
if (!callback.is_null())
- callback.Run(num_deleted);
+ std::move(callback).Run(num_deleted);
}
-void CookieStoreIOS::UpdateCachesAfterClosure(const base::Closure& callback) {
+void CookieStoreIOS::UpdateCachesAfterClosure(base::OnceClosure callback) {
DCHECK(thread_checker_.CalledOnValidThread());
UpdateCachesFromCookieMonster();
if (!callback.is_null())
- callback.Run();
+ std::move(callback).Run();
}
net::CookieList

Powered by Google App Engine
This is Rietveld 408576698