refactor: migrate AdaptCallbackForRepeating to SplitOnceCallback (#29825)

This commit is contained in:
David Sanders 2021-06-21 18:04:31 -07:00 committed by GitHub
parent 0e465f1885
commit 98d2824c7f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -67,7 +67,7 @@ absl::optional<base::FilePath> CreateTemporaryFileOnIO() {
void StopTracing(gin_helper::Promise<base::FilePath> promise,
absl::optional<base::FilePath> file_path) {
auto resolve_or_reject = base::AdaptCallbackForRepeating(base::BindOnce(
auto resolve_or_reject = base::BindOnce(
[](gin_helper::Promise<base::FilePath> promise,
const base::FilePath& path, absl::optional<std::string> error) {
if (error) {
@ -76,17 +76,21 @@ void StopTracing(gin_helper::Promise<base::FilePath> promise,
promise.Resolve(path);
}
},
std::move(promise), *file_path));
std::move(promise), *file_path);
if (file_path) {
auto split_callback = base::SplitOnceCallback(std::move(resolve_or_reject));
auto endpoint = TracingController::CreateFileEndpoint(
*file_path, base::BindRepeating(resolve_or_reject, absl::nullopt));
*file_path,
base::BindOnce(std::move(split_callback.first), absl::nullopt));
if (!TracingController::GetInstance()->StopTracing(endpoint)) {
resolve_or_reject.Run(absl::make_optional(
"Failed to stop tracing (was a trace in progress?)"));
std::move(split_callback.second)
.Run(absl::make_optional(
"Failed to stop tracing (was a trace in progress?)"));
}
} else {
resolve_or_reject.Run(
absl::make_optional("Failed to create temporary file for trace data"));
std::move(resolve_or_reject)
.Run(absl::make_optional(
"Failed to create temporary file for trace data"));
}
}