Skip to content

Commit

Permalink
[ios] Migrate to Get(UI|IO)ThreadTaskRunner() step chromium#2
Browse files Browse the repository at this point in the history
Migrate base task APIs callers using WebThread without qualifying it
with web:: namespace. Same script as used for content, tweaked for
web: crbug.com/1026641#c92

Bug: 1026641
Change-Id: Ifbce9fd66fabceb324f8419349f224ba2a8321b8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3512744
Reviewed-by: Rohit Rao <rohitrao@chromium.org>
Commit-Queue: Gabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/main@{#980830}
  • Loading branch information
Gabriel Charette authored and Chromium LUCI CQ committed Mar 14, 2022
1 parent 6289ec7 commit f9e78e3
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 52 deletions.
17 changes: 8 additions & 9 deletions ios/web/download/download_session_task_impl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#import "base/mac/foundation_util.h"
#include "base/strings/sys_string_conversions.h"
#include "base/task/post_task.h"
#include "base/task/thread_pool.h"
#import "ios/net/cookies/system_cookie_util.h"
#include "ios/web/download/download_result.h"
Expand Down Expand Up @@ -112,8 +111,8 @@ - (instancetype)initWithDataCallback:(DataCallback)dataCallback
- (void)URLSession:(NSURLSession*)session
task:(NSURLSessionTask*)task
didCompleteWithError:(NSError*)error {
base::PostTask(FROM_HERE, {WebThread::UI},
base::BindOnce(_doneCallback, task, error));
web::GetUIThreadTaskRunner({})->PostTask(
FROM_HERE, base::BindOnce(_doneCallback, task, error));
}

- (void)URLSession:(NSURLSession*)session
Expand All @@ -125,8 +124,8 @@ - (void)URLSession:(NSURLSession*)session
// thread (in net::URLFetcherFileWriter::Write()).
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);

base::PostTask(
FROM_HERE, {WebThread::UI},
web::GetUIThreadTaskRunner({})->PostTask(
FROM_HERE,
base::BindOnce(
[](dispatch_semaphore_t semaphore, DataCallback innerDataCallback,
NSURLSessionTask* task, NSData* data) {
Expand Down Expand Up @@ -306,8 +305,8 @@ - (void)URLSession:(NSURLSession*)session
web_state_->GetBrowserState()->GetRequestContext());

// net::URLRequestContextGetter must be used in the IO thread.
base::PostTask(
FROM_HERE, {WebThread::IO},
GetIOThreadTaskRunner({})->PostTask(
FROM_HERE,
base::BindOnce(&DownloadSessionTaskImpl::GetCookiesFromContextGetter,
context_getter, std::move(callback)));
}
Expand All @@ -322,8 +321,8 @@ - (void)URLSession:(NSURLSession*)session
const net::CookieList& cookie_list) {
NSArray<NSHTTPCookie*>* cookies =
SystemCookiesFromCanonicalCookieList(cookie_list);
base::PostTask(FROM_HERE, {WebThread::UI},
base::BindOnce(std::move(callback), cookies));
GetUIThreadTaskRunner({})->PostTask(
FROM_HERE, base::BindOnce(std::move(callback), cookies));
},
std::move(callback)));
}
Expand Down
10 changes: 5 additions & 5 deletions ios/web/find_in_page/find_in_page_manager_impl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h"
#import "base/strings/sys_string_conversions.h"
#include "base/task/post_task.h"
#include "base/values.h"
#import "ios/web/find_in_page/find_in_page_constants.h"
#import "ios/web/find_in_page/find_in_page_java_script_feature.h"
Expand All @@ -16,6 +15,7 @@
#include "ios/web/public/js_messaging/web_frame_util.h"
#import "ios/web/public/js_messaging/web_frames_manager.h"
#include "ios/web/public/thread/web_task_traits.h"
#include "ios/web/public/thread/web_thread.h"
#import "ios/web/web_state/web_state_impl.h"

#if !defined(__has_feature) || !__has_feature(objc_arc)
Expand Down Expand Up @@ -102,8 +102,8 @@
if (all_frames.size() == 0) {
// No frames to search in.
// Call asyncronously to match behavior if find was successful in frames.
base::PostTask(
FROM_HERE, {WebThread::UI},
GetUIThreadTaskRunner({})->PostTask(
FROM_HERE,
base::BindOnce(&FindInPageManagerImpl::LastFindRequestCompleted,
weak_factory_.GetWeakPtr()));
return;
Expand All @@ -122,8 +122,8 @@
last_find_request_.DidReceiveFindResponseFromOneFrame();
if (last_find_request_.AreAllFindResponsesReturned()) {
// Call asyncronously to match behavior if find was done in frames.
base::PostTask(
FROM_HERE, {WebThread::UI},
GetUIThreadTaskRunner({})->PostTask(
FROM_HERE,
base::BindOnce(&FindInPageManagerImpl::LastFindRequestCompleted,
weak_factory_.GetWeakPtr()));
}
Expand Down
10 changes: 5 additions & 5 deletions ios/web/init/web_main_loop.mm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "base/power_monitor/power_monitor.h"
#include "base/power_monitor/power_monitor_device_source.h"
#include "base/process/process_metrics.h"
#include "base/task/post_task.h"
#include "base/task/single_thread_task_executor.h"
#include "base/task/thread_pool/thread_pool_instance.h"
#include "base/threading/thread_restrictions.h"
Expand All @@ -26,6 +25,7 @@
#include "ios/web/public/init/ios_global_state.h"
#include "ios/web/public/init/web_main_parts.h"
#include "ios/web/public/thread/web_task_traits.h"
#include "ios/web/public/thread/web_thread.h"
#import "ios/web/public/web_client.h"
#include "ios/web/web_sub_thread.h"
#include "ios/web/web_thread_impl.h"
Expand Down Expand Up @@ -156,8 +156,8 @@
// Teardown may start in PostMainMessageLoopRun, and during teardown we
// need to be able to perform IO.
base::PermanentThreadAllowance::AllowBlocking();
base::PostTask(FROM_HERE, {WebThread::IO},
base::BindOnce(base::IgnoreResult(
GetIOThreadTaskRunner({})->PostTask(
FROM_HERE, base::BindOnce(base::IgnoreResult(
&base::PermanentThreadAllowance::AllowBlocking)));

// Also allow waiting to join threads.
Expand All @@ -166,8 +166,8 @@
// persistent work is being done after ThreadPoolInstance::Shutdown() in order
// to move towards atomic shutdown.
base::PermanentThreadAllowance::AllowBaseSyncPrimitives();
base::PostTask(
FROM_HERE, {WebThread::IO},
GetIOThreadTaskRunner({})->PostTask(
FROM_HERE,
base::BindOnce(base::IgnoreResult(
&base::PermanentThreadAllowance::AllowBaseSyncPrimitives)));

Expand Down
3 changes: 1 addition & 2 deletions ios/web/network_context_owner_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include "base/bind.h"
#include "base/run_loop.h"
#include "base/task/post_task.h"
#include "ios/web/public/test/web_task_environment.h"
#include "ios/web/public/thread/web_task_traits.h"
#include "ios/web/public/thread/web_thread.h"
Expand All @@ -27,7 +26,7 @@ class NetworkContextOwnerTest : public PlatformTest {
NetworkContextOwnerTest()
: saw_connection_error_(false),
context_getter_(base::MakeRefCounted<net::TestURLRequestContextGetter>(
base::CreateSingleThreadTaskRunner({WebThread::IO}))) {}
GetIOThreadTaskRunner({}))) {}

~NetworkContextOwnerTest() override {
// Tests should cleanup after themselves.
Expand Down
5 changes: 2 additions & 3 deletions ios/web/public/test/fakes/fake_cookie_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "ios/web/public/test/fakes/fake_cookie_store.h"

#include "base/task/post_task.h"
#include "ios/web/public/thread/web_task_traits.h"
#include "ios/web/public/thread/web_thread.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
Expand All @@ -21,8 +20,8 @@ void FakeCookieStore::SetAllCookies(const net::CookieList& all_cookies) {

void FakeCookieStore::GetAllCookiesAsync(GetAllCookiesCallback callback) {
DCHECK_CURRENTLY_ON(WebThread::IO);
base::PostTask(FROM_HERE, {WebThread::IO},
base::BindOnce(std::move(callback), all_cookies_));
GetIOThreadTaskRunner({})->PostTask(
FROM_HERE, base::BindOnce(std::move(callback), all_cookies_));
}

void FakeCookieStore::SetCanonicalCookieAsync(
Expand Down
9 changes: 5 additions & 4 deletions ios/web/security/crw_cert_verification_controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,11 @@ - (void)allowCert:(scoped_refptr<net::X509Certificate>)cert
DCHECK(cert);
}
DCHECK(cert->intermediate_buffers().empty());
base::PostTask(FROM_HERE, {WebThread::IO}, base::BindOnce(^{
self->_certPolicyCache->AllowCertForHost(
cert.get(), base::SysNSStringToUTF8(host), status);
}));
web::GetIOThreadTaskRunner({})->PostTask(
FROM_HERE, base::BindOnce(^{
self->_certPolicyCache->AllowCertForHost(
cert.get(), base::SysNSStringToUTF8(host), status);
}));
}

#pragma mark - Private
Expand Down
18 changes: 9 additions & 9 deletions ios/web/session/session_certificate_policy_cache_impl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#import "ios/web/session/session_certificate_policy_cache_impl.h"

#include "base/bind.h"
#include "base/task/post_task.h"
#include "ios/web/public/browser_state.h"
#include "ios/web/public/security/certificate_policy_cache.h"
#import "ios/web/public/session/crw_session_certificate_policy_cache_storage.h"
Expand Down Expand Up @@ -62,12 +61,13 @@
DCHECK(cache.get());
NSSet* allowed_certs = [NSSet setWithSet:allowed_certs_];
const scoped_refptr<CertificatePolicyCache> cache_copy = cache;
base::PostTask(FROM_HERE, {WebThread::IO}, base::BindOnce(^{
for (CRWSessionCertificateStorage* cert in allowed_certs) {
cache_copy->AllowCertForHost(cert.certificate, cert.host,
cert.status);
}
}));
GetIOThreadTaskRunner({})->PostTask(
FROM_HERE, base::BindOnce(^{
for (CRWSessionCertificateStorage* cert in allowed_certs) {
cache_copy->AllowCertForHost(cert.certificate, cert.host,
cert.status);
}
}));
}

void SessionCertificatePolicyCacheImpl::RegisterAllowedCertificate(
Expand All @@ -93,8 +93,8 @@
status:status]];
const scoped_refptr<CertificatePolicyCache> cache =
GetCertificatePolicyCache();
base::PostTask(
FROM_HERE, {WebThread::IO},
GetIOThreadTaskRunner({})->PostTask(
FROM_HERE,
base::BindOnce(&CertificatePolicyCache::AllowCertForHost, cache,
base::RetainedRef(certificate.get()), host, status));
}
Expand Down
5 changes: 2 additions & 3 deletions ios/web/test/fakes/fake_web_frame_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "base/bind.h"
#include "base/callback.h"
#include "base/json/json_writer.h"
#include "base/task/post_task.h"
#include "base/values.h"
#include "ios/web/public/thread/web_task_traits.h"
#include "ios/web/public/thread/web_thread.h"
Expand Down Expand Up @@ -121,8 +120,8 @@ bool FakeWebFrameImpl::CallJavaScriptFunction(
web::GetUIThreadTaskRunner({})->PostDelayedTask(
FROM_HERE, base::BindOnce(std::move(callback), nullptr), timeout);
} else {
base::PostTask(FROM_HERE, {WebThread::UI},
base::BindOnce(std::move(callback), result_map_[name]));
GetUIThreadTaskRunner({})->PostTask(
FROM_HERE, base::BindOnce(std::move(callback), result_map_[name]));
}
return true;
}
Expand Down
15 changes: 6 additions & 9 deletions ios/web/web_thread_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "ios/web/public/thread/web_thread.h"

#include "base/bind.h"
#include "base/task/post_task.h"
#include "ios/web/public/test/web_task_environment.h"
#include "ios/web/public/thread/web_task_traits.h"
#include "ios/web/public/thread/web_thread.h"
Expand All @@ -31,10 +30,9 @@ class WebThreadTest : public PlatformTest {

TEST_F(WebThreadTest, BasePostTask) {
base::RunLoop run_loop;
EXPECT_TRUE(base::PostTask(
FROM_HERE, {WebThread::IO},
base::BindOnce(&BasicFunction, run_loop.QuitWhenIdleClosure(),
WebThread::IO)));
EXPECT_TRUE(GetIOThreadTaskRunner({})->PostTask(
FROM_HERE, base::BindOnce(&BasicFunction, run_loop.QuitWhenIdleClosure(),
WebThread::IO)));
run_loop.Run();
}

Expand All @@ -55,8 +53,7 @@ TEST_F(WebThreadTest, GetIOTaskRunnerPostTask) {
}

TEST_F(WebThreadTest, PostTaskViaTaskRunner) {
scoped_refptr<base::TaskRunner> task_runner =
base::CreateTaskRunner({WebThread::IO});
scoped_refptr<base::TaskRunner> task_runner = GetIOThreadTaskRunner({});
base::RunLoop run_loop;
EXPECT_TRUE(task_runner->PostTask(
FROM_HERE, base::BindOnce(&BasicFunction, run_loop.QuitWhenIdleClosure(),
Expand All @@ -66,7 +63,7 @@ TEST_F(WebThreadTest, PostTaskViaTaskRunner) {

TEST_F(WebThreadTest, PostTaskViaSequencedTaskRunner) {
scoped_refptr<base::SequencedTaskRunner> task_runner =
base::CreateSequencedTaskRunner({WebThread::IO});
GetIOThreadTaskRunner({});
base::RunLoop run_loop;
EXPECT_TRUE(task_runner->PostTask(
FROM_HERE, base::BindOnce(&BasicFunction, run_loop.QuitWhenIdleClosure(),
Expand All @@ -76,7 +73,7 @@ TEST_F(WebThreadTest, PostTaskViaSequencedTaskRunner) {

TEST_F(WebThreadTest, PostTaskViaSingleThreadTaskRunner) {
scoped_refptr<base::SingleThreadTaskRunner> task_runner =
base::CreateSingleThreadTaskRunner({WebThread::IO});
GetIOThreadTaskRunner({});
base::RunLoop run_loop;
EXPECT_TRUE(task_runner->PostTask(
FROM_HERE, base::BindOnce(&BasicFunction, run_loop.QuitWhenIdleClosure(),
Expand Down
5 changes: 2 additions & 3 deletions ios/web/webui/url_data_manager_ios_backend.mm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "base/memory/ref_counted_memory.h"
#include "base/memory/weak_ptr.h"
#include "base/strings/string_util.h"
#include "base/task/post_task.h"
#include "base/task/single_thread_task_runner.h"
#include "base/trace_event/trace_event.h"
#include "ios/web/public/browser_state.h"
Expand Down Expand Up @@ -400,8 +399,8 @@ void GetMimeTypeOnUI(URLDataSourceIOSImpl* source,
const base::WeakPtr<URLRequestChromeJob>& job) {
DCHECK_CURRENTLY_ON(WebThread::UI);
std::string mime_type = source->source()->GetMimeType(path);
base::PostTask(FROM_HERE, {WebThread::IO},
base::BindOnce(&URLRequestChromeJob::MimeTypeAvailable, job,
GetIOThreadTaskRunner({})->PostTask(
FROM_HERE, base::BindOnce(&URLRequestChromeJob::MimeTypeAvailable, job,
base::RetainedRef(source), mime_type));
}

Expand Down

0 comments on commit f9e78e3

Please sign in to comment.