Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ads] AdsServiceImpl code health #27044

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading