Skip to content

Commit

Permalink
[ads] AdsServiceImpl code health
Browse files Browse the repository at this point in the history
  • Loading branch information
aseren committed Dec 17, 2024
1 parent 73be2eb commit b29f0ca
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions components/brave_ads/browser/ads_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> LoadOnFileTaskRunner(const base::FilePath& path) {
std::string value;
if (!base::ReadFileToString(path, &value)) {
Expand Down Expand Up @@ -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));
}

Expand All @@ -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<std::string>& value) {
std::move(callback).Run(value);
},
std::move(callback)));
std::move(callback));
}

void AdsServiceImpl::LoadResourceComponent(
Expand Down

0 comments on commit b29f0ca

Please sign in to comment.