From b29f0caefd112879f63f8c4892477491a3a225ba Mon Sep 17 00:00:00 2001 From: Aleksei Seren Date: Tue, 17 Dec 2024 08:59:58 -0500 Subject: [PATCH] [ads] AdsServiceImpl code health --- .../brave_ads/browser/ads_service_impl.cc | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/components/brave_ads/browser/ads_service_impl.cc b/components/brave_ads/browser/ads_service_impl.cc index af38141b0f7d..5f446b51228f 100644 --- a/components/brave_ads/browser/ads_service_impl.cc +++ b/components/brave_ads/browser/ads_service_impl.cc @@ -106,6 +106,13 @@ std::string URLMethodToRequestType( } } +bool WriteOnFileTaskRunner(const base::FilePath& path, + const std::string& data) { + return base::ImportantFileWriter::WriteFileAtomically( + path, data, + /*histogram_suffix=*/std::string_view()); +} + std::optional LoadOnFileTaskRunner(const base::FilePath& path) { std::string value; if (!base::ReadFileToString(path, &value)) { @@ -1631,9 +1638,8 @@ void AdsServiceImpl::Save(const std::string& name, SaveCallback callback) { file_task_runner_->PostTaskAndReplyWithResult( FROM_HERE, - base::BindOnce(&base::ImportantFileWriter::WriteFileAtomically, - ads_service_path_.AppendASCII(name), value, - std::string_view()), + base::BindOnce(&WriteOnFileTaskRunner, + ads_service_path_.AppendASCII(name), value), std::move(callback)); } @@ -1642,11 +1648,7 @@ void AdsServiceImpl::Load(const std::string& name, LoadCallback callback) { FROM_HERE, base::BindOnce(&LoadOnFileTaskRunner, ads_service_path_.AppendASCII(name)), - base::BindOnce( - [](LoadCallback callback, const std::optional& value) { - std::move(callback).Run(value); - }, - std::move(callback))); + std::move(callback)); } void AdsServiceImpl::LoadResourceComponent(