Skip to content

Commit

Permalink
Merge pull request #27044 from brave/ads_service_code_health
Browse files Browse the repository at this point in the history
[ads] AdsServiceImpl code health
  • Loading branch information
aseren authored Dec 17, 2024
2 parents a59e04c + b29f0ca commit d4aacd3
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 d4aacd3

Please sign in to comment.