Skip to content

Commit

Permalink
Change RunSystemCookieCallbackOnIOThread prototype
Browse files Browse the repository at this point in the history
The function was only ever called with a block wrapped into a
base::Closure via base::BindBlockArc, so change the function
to take a block directly and create the closure internally.

Rename the function to RunBlockOnIOThread to reflect its new
prototype.

Bug: none
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I42fd666f51b21a345d99b866d72984fcb2292cca
Reviewed-on: https://chromium-review.googlesource.com/1020455
Commit-Queue: Mohammad Refaat <mrefaat@chromium.org>
Reviewed-by: Mohammad Refaat <mrefaat@chromium.org>
Cr-Commit-Position: refs/heads/master@{#552483}
  • Loading branch information
sdefresne authored and Commit Bot committed Apr 20, 2018
1 parent c24c236 commit 8f479b4
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions ios/web/net/cookies/wk_http_system_cookie_store.mm
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
namespace web {
namespace {

// Posts |callback| to run on IO Thread, this is needed because
// Posts a task to run |block| on IO Thread. This is needed because
// WKHTTPCookieStore executes callbacks on the main thread, while
// SystemCookieStore should operate on IO thread.
void RunSystemCookieCallbackOnIOThread(base::OnceClosure callback) {
DCHECK(!callback.is_null());
web::WebThread::PostTask(web::WebThread::IO, FROM_HERE, std::move(callback));
void RunBlockOnIOThread(ProceduralBlock block) {
DCHECK(block != nil);
web::WebThread::PostTask(web::WebThread::IO, FROM_HERE,
base::BindBlockArc(block));
}

// Returns wether |cookie| should be included for queries about |url|.
Expand Down Expand Up @@ -111,12 +112,12 @@ bool ShouldIncludeForRequestUrl(NSHTTPCookie* cookie, const GURL& url) {
web::WebThread::UI, FROM_HERE, base::BindBlockArc(^{
[cookie_store_ deleteCookie:block_cookie
completionHandler:^{
RunSystemCookieCallbackOnIOThread(base::BindBlockArc(^{
RunBlockOnIOThread(^{
if (weak_time_manager)
weak_time_manager->DeleteCreationTime(block_cookie);
if (!shared_callback.is_null())
std::move(shared_callback).Run();
}));
});
}];
}));
}
Expand All @@ -139,15 +140,15 @@ bool ShouldIncludeForRequestUrl(NSHTTPCookie* cookie, const GURL& url) {
[cookie_store_
setCookie:block_cookie
completionHandler:^{
RunSystemCookieCallbackOnIOThread(base::BindBlockArc(^{
RunBlockOnIOThread(^{
if (weak_time_manager) {
weak_time_manager->SetCreationTime(
block_cookie,
weak_time_manager->MakeUniqueCreationTime(cookie_time));
}
if (!shared_callback.is_null())
std::move(shared_callback).Run();
}));
});
}];
}));
}
Expand All @@ -160,11 +161,11 @@ bool ShouldIncludeForRequestUrl(NSHTTPCookie* cookie, const GURL& url) {
web::WebThread::UI, FROM_HERE, base::BindBlockArc(^{
[cookie_store_ getAllCookies:^(NSArray<NSHTTPCookie*>* cookies) {
ProceduralBlock completionHandler = ^{
RunSystemCookieCallbackOnIOThread(base::BindBlockArc(^{
RunBlockOnIOThread(^{
if (weak_time_manager)
weak_time_manager->Clear();
std::move(shared_callback).Run();
}));
});
};

// If there are no cookies to clear, immediately invoke the
Expand Down Expand Up @@ -208,7 +209,7 @@ bool ShouldIncludeForRequestUrl(NSHTTPCookie* cookie, const GURL& url) {
NSArray* block_cookies = cookies;
__block net::SystemCookieStore::SystemCookieCallbackForCookies
shared_callback = std::move(callback);
RunSystemCookieCallbackOnIOThread(base::BindBlockArc(^{
RunBlockOnIOThread(^{
if (weak_time_manager) {
NSArray* result = [block_cookies
sortedArrayUsingFunction:net::SystemCookieStore::CompareCookies
Expand All @@ -217,7 +218,7 @@ bool ShouldIncludeForRequestUrl(NSHTTPCookie* cookie, const GURL& url) {
} else {
std::move(shared_callback).Run(block_cookies);
}
}));
});
}

} // namespace web
Expand Down

0 comments on commit 8f479b4

Please sign in to comment.