Commit 1d78c8f2 authored by Reilly Grant's avatar Reilly Grant Committed by Chromium LUCI CQ

Convert callbacks in //chrome/browser/chromeos/arc

This change converts callbacks from base::Bind and base::Callback to
Once/Repeating in //chrome/browser/chromeos/arc.

Code previously using base::AdaptCallbackForRepeating now uses the more
purpose-specific base::SplitOnceCallback.

Bug: 1148570
Change-Id: Ie087afe3f6be92b267f2e36a7785052107344580
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2644344
Commit-Queue: Reilly Grant <reillyg@chromium.org>
Commit-Queue: Yuichiro Hanada <yhanada@chromium.org>
Reviewed-by: default avatarYuichiro Hanada <yhanada@chromium.org>
Auto-Submit: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845952}
parent c17e30b6
...@@ -55,7 +55,7 @@ void ArcSnapshotRebootNotificationImpl::Show() { ...@@ -55,7 +55,7 @@ void ArcSnapshotRebootNotificationImpl::Show() {
base::string16() /* display_source */, GURL(), notifier_id, base::string16() /* display_source */, GURL(), notifier_id,
optional_fields, optional_fields,
new message_center::HandleNotificationClickDelegate( new message_center::HandleNotificationClickDelegate(
base::Bind(&ArcSnapshotRebootNotificationImpl::HandleClick, base::BindRepeating(&ArcSnapshotRebootNotificationImpl::HandleClick,
weak_ptr_factory_.GetWeakPtr())), weak_ptr_factory_.GetWeakPtr())),
vector_icons::kBusinessIcon, vector_icons::kBusinessIcon,
message_center::SystemNotificationWarningLevel::NORMAL); message_center::SystemNotificationWarningLevel::NORMAL);
......
...@@ -351,17 +351,17 @@ class CertStoreServiceTest : public MixinBasedInProcessBrowserTest { ...@@ -351,17 +351,17 @@ class CertStoreServiceTest : public MixinBasedInProcessBrowserTest {
void OnKeyRegisteredForCorporateUsage( void OnKeyRegisteredForCorporateUsage(
std::unique_ptr<chromeos::platform_keys::ExtensionKeyPermissionsService> std::unique_ptr<chromeos::platform_keys::ExtensionKeyPermissionsService>
extension_key_permissions_service, extension_key_permissions_service,
const base::Closure& done_callback, base::OnceClosure done_callback,
chromeos::platform_keys::Status status) { chromeos::platform_keys::Status status) {
ASSERT_EQ(status, chromeos::platform_keys::Status::kSuccess); ASSERT_EQ(status, chromeos::platform_keys::Status::kSuccess);
done_callback.Run(); std::move(done_callback).Run();
} }
// Register only client_cert1_ for corporate usage to test that // Register only client_cert1_ for corporate usage to test that
// client_cert2_ is not allowed. // client_cert2_ is not allowed.
void GotPermissionsForExtension( void GotPermissionsForExtension(
CERTCertificate* cert, CERTCertificate* cert,
const base::Closure& done_callback, base::OnceClosure done_callback,
std::unique_ptr<chromeos::platform_keys::ExtensionKeyPermissionsService> std::unique_ptr<chromeos::platform_keys::ExtensionKeyPermissionsService>
extension_key_permissions_service) { extension_key_permissions_service) {
auto* extension_key_permissions_service_unowned = auto* extension_key_permissions_service_unowned =
...@@ -374,11 +374,11 @@ class CertStoreServiceTest : public MixinBasedInProcessBrowserTest { ...@@ -374,11 +374,11 @@ class CertStoreServiceTest : public MixinBasedInProcessBrowserTest {
base::BindOnce(&CertStoreServiceTest::OnKeyRegisteredForCorporateUsage, base::BindOnce(&CertStoreServiceTest::OnKeyRegisteredForCorporateUsage,
base::Unretained(this), base::Unretained(this),
std::move(extension_key_permissions_service), std::move(extension_key_permissions_service),
done_callback)); std::move(done_callback)));
} }
void SetUpTestClientCerts(const std::vector<std::string>& key_file_names, void SetUpTestClientCerts(const std::vector<std::string>& key_file_names,
const base::Closure& done_callback, base::OnceClosure done_callback,
net::NSSCertDatabase* cert_db) { net::NSSCertDatabase* cert_db) {
for (const auto& file_name : key_file_names) { for (const auto& file_name : key_file_names) {
base::ScopedAllowBlockingForTesting allow_io; base::ScopedAllowBlockingForTesting allow_io;
...@@ -391,31 +391,31 @@ class CertStoreServiceTest : public MixinBasedInProcessBrowserTest { ...@@ -391,31 +391,31 @@ class CertStoreServiceTest : public MixinBasedInProcessBrowserTest {
net::X509Certificate::FORMAT_AUTO); net::X509Certificate::FORMAT_AUTO);
EXPECT_EQ(1U, certs.size()); EXPECT_EQ(1U, certs.size());
if (certs.size() != 1U) { if (certs.size() != 1U) {
done_callback.Run(); std::move(done_callback).Run();
return; return;
} }
client_certs_.emplace_back( client_certs_.emplace_back(
net::x509_util::DupCERTCertificate(certs[0].get())); net::x509_util::DupCERTCertificate(certs[0].get()));
} }
done_callback.Run(); std::move(done_callback).Run();
} }
void ImportTestClientCerts(const base::Closure& done_callback, void ImportTestClientCerts(base::OnceClosure done_callback,
net::NSSCertDatabase* cert_db) { net::NSSCertDatabase* cert_db) {
for (const auto& cert : client_certs_) { for (const auto& cert : client_certs_) {
// Import user certificate properly how it's done in PlatfromKeys. // Import user certificate properly how it's done in PlatfromKeys.
cert_db->ImportUserCert(cert.get()); cert_db->ImportUserCert(cert.get());
} }
done_callback.Run(); std::move(done_callback).Run();
} }
void DeleteCertAndKey(CERTCertificate* cert, void DeleteCertAndKey(CERTCertificate* cert,
const base::Closure& done_callback, base::OnceClosure done_callback,
net::NSSCertDatabase* cert_db) { net::NSSCertDatabase* cert_db) {
base::ScopedAllowBlockingForTesting allow_io; base::ScopedAllowBlockingForTesting allow_io;
EXPECT_TRUE(cert_db->DeleteCertAndKey(cert)); EXPECT_TRUE(cert_db->DeleteCertAndKey(cert));
done_callback.Run(); std::move(done_callback).Run();
} }
std::unique_ptr<policy::UserPolicyTestHelper> policy_helper_; std::unique_ptr<policy::UserPolicyTestHelper> policy_helper_;
......
...@@ -91,31 +91,32 @@ void ArcDocumentsProviderFileStreamReader::RunPendingRead( ...@@ -91,31 +91,32 @@ void ArcDocumentsProviderFileStreamReader::RunPendingRead(
net::CompletionOnceCallback callback) { net::CompletionOnceCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(content_url_resolved_); DCHECK(content_url_resolved_);
// Create |copyable_callback| which is copyable, though it can still only // Create two copies of |callback| though it can still only called at most
// called at most once. This is safe, because Read() is guaranteed not to // once. This is safe because Read() is guaranteed not to call |callback| if
// call |callback| if it returns synchronously. // it returns synchronously.
auto copyable_callback = base::AdaptCallbackForRepeating(std::move(callback)); auto split_callback = base::SplitOnceCallback(std::move(callback));
int result = underlying_reader_ int result = underlying_reader_
? underlying_reader_->Read(buffer.get(), buffer_length, ? underlying_reader_->Read(buffer.get(), buffer_length,
copyable_callback) std::move(split_callback.first))
: net::ERR_FILE_NOT_FOUND; : net::ERR_FILE_NOT_FOUND;
if (result != net::ERR_IO_PENDING) if (result != net::ERR_IO_PENDING)
copyable_callback.Run(result); std::move(split_callback.second).Run(result);
} }
void ArcDocumentsProviderFileStreamReader::RunPendingGetLength( void ArcDocumentsProviderFileStreamReader::RunPendingGetLength(
net::Int64CompletionOnceCallback callback) { net::Int64CompletionOnceCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(content_url_resolved_); DCHECK(content_url_resolved_);
// Create |copyable_callback| which is copyable, though it can still only // Create two copies of |callback| though it can still only called at most
// called at most once. This is safe, because GetLength() is guaranteed not // once. This is safe because GetLength() is guaranteed not to call |callback|
// to call |callback| if it returns synchronously. // if it returns synchronously.
auto copyable_callback = base::AdaptCallbackForRepeating(std::move(callback)); auto split_callback = base::SplitOnceCallback(std::move(callback));
int64_t result = underlying_reader_ int64_t result =
? underlying_reader_->GetLength(copyable_callback) underlying_reader_
? underlying_reader_->GetLength(std::move(split_callback.first))
: net::ERR_FILE_NOT_FOUND; : net::ERR_FILE_NOT_FOUND;
if (result != net::ERR_IO_PENDING) if (result != net::ERR_IO_PENDING)
copyable_callback.Run(result); std::move(split_callback.second).Run(result);
} }
} // namespace arc } // namespace arc
...@@ -110,45 +110,46 @@ void ArcDocumentsProviderFileStreamWriter::RunPendingWrite( ...@@ -110,45 +110,46 @@ void ArcDocumentsProviderFileStreamWriter::RunPendingWrite(
net::CompletionOnceCallback callback) { net::CompletionOnceCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(content_url_resolved_); DCHECK(content_url_resolved_);
// Create |copyable_callback| which is copyable, though it can still only // Create two copies of |callback| though it can still only called at most
// called at most once. This is safe, because Write() is guaranteed not to // once. This is safe because Write() is guaranteed not to call |callback| if
// call |callback| if it returns synchronously. // it returns synchronously.
auto copyable_callback = base::AdaptCallbackForRepeating(std::move(callback)); auto split_callback = base::SplitOnceCallback(std::move(callback));
int result = underlying_writer_ int result = underlying_writer_
? underlying_writer_->Write(buffer.get(), buffer_length, ? underlying_writer_->Write(buffer.get(), buffer_length,
copyable_callback) std::move(split_callback.first))
: net::ERR_FILE_NOT_FOUND; : net::ERR_FILE_NOT_FOUND;
if (result != net::ERR_IO_PENDING) if (result != net::ERR_IO_PENDING)
copyable_callback.Run(result); std::move(split_callback.second).Run(result);
} }
void ArcDocumentsProviderFileStreamWriter::RunPendingCancel( void ArcDocumentsProviderFileStreamWriter::RunPendingCancel(
net::CompletionOnceCallback callback) { net::CompletionOnceCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(content_url_resolved_); DCHECK(content_url_resolved_);
// Create |copyable_callback| which is copyable, though it can still only // Create two copies of |callback| though it can still only called at most
// called at most once. This is safe, because Cancel() is guaranteed not to // once. This is safe because Cancel() is guaranteed not to call |callback| if
// call |callback| if it returns synchronously. // it returns synchronously.
auto copyable_callback = base::AdaptCallbackForRepeating(std::move(callback)); auto split_callback = base::SplitOnceCallback(std::move(callback));
int result = underlying_writer_ int result = underlying_writer_
? underlying_writer_->Cancel(copyable_callback) ? underlying_writer_->Cancel(std::move(split_callback.first))
: net::ERR_FILE_NOT_FOUND; : net::ERR_FILE_NOT_FOUND;
if (result != net::ERR_IO_PENDING) if (result != net::ERR_IO_PENDING)
copyable_callback.Run(result); std::move(split_callback.second).Run(result);
} }
void ArcDocumentsProviderFileStreamWriter::RunPendingFlush( void ArcDocumentsProviderFileStreamWriter::RunPendingFlush(
net::CompletionOnceCallback callback) { net::CompletionOnceCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(content_url_resolved_); DCHECK(content_url_resolved_);
// Create |copyable_callback| which is copyable, though it can still only // Create two copies of |callback| though it can still only called at most
// called at most once. This is safe, because Flush() is guaranteed not to // once. This is safe because Flush() is guaranteed not to call |callback| if
// call |callback| if it returns synchronously. // it returns synchronously.
auto copyable_callback = base::AdaptCallbackForRepeating(std::move(callback)); auto split_callback = base::SplitOnceCallback(std::move(callback));
int result = underlying_writer_ ? underlying_writer_->Flush(copyable_callback) int result = underlying_writer_
? underlying_writer_->Flush(std::move(split_callback.first))
: net::ERR_FILE_NOT_FOUND; : net::ERR_FILE_NOT_FOUND;
if (result != net::ERR_IO_PENDING) if (result != net::ERR_IO_PENDING)
copyable_callback.Run(result); std::move(split_callback.second).Run(result);
} }
} // namespace arc } // namespace arc
...@@ -173,13 +173,13 @@ void ExpectString(std::unique_ptr<CheckedBoolean> was_run, ...@@ -173,13 +173,13 @@ void ExpectString(std::unique_ptr<CheckedBoolean> was_run,
was_run->set_value(true); was_run->set_value(true);
} }
void ExpectStringWithClosure(base::Closure quit_closure, void ExpectStringWithClosure(base::OnceClosure quit_closure,
std::unique_ptr<CheckedBoolean> was_run, std::unique_ptr<CheckedBoolean> was_run,
const std::string& expected, const std::string& expected,
const std::string& received) { const std::string& received) {
EXPECT_EQ(expected, received); EXPECT_EQ(expected, received);
was_run->set_value(true); was_run->set_value(true);
quit_closure.Run(); std::move(quit_closure).Run();
} }
arc::ArcPolicyBridge::GetPoliciesCallback PolicyStringCallback( arc::ArcPolicyBridge::GetPoliciesCallback PolicyStringCallback(
...@@ -189,10 +189,10 @@ arc::ArcPolicyBridge::GetPoliciesCallback PolicyStringCallback( ...@@ -189,10 +189,10 @@ arc::ArcPolicyBridge::GetPoliciesCallback PolicyStringCallback(
} }
arc::ArcPolicyBridge::ReportComplianceCallback PolicyComplianceCallback( arc::ArcPolicyBridge::ReportComplianceCallback PolicyComplianceCallback(
base::Closure quit_closure, base::OnceClosure quit_closure,
const std::string& expected) { const std::string& expected) {
auto was_run = std::make_unique<CheckedBoolean>(); auto was_run = std::make_unique<CheckedBoolean>();
return base::BindOnce(&ExpectStringWithClosure, quit_closure, return base::BindOnce(&ExpectStringWithClosure, std::move(quit_closure),
std::move(was_run), expected); std::move(was_run), expected);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment