refactor: migrate AdaptCallbackForRepeating to SplitOnceCallback (#29825)
This commit is contained in:
parent
0e465f1885
commit
98d2824c7f
1 changed files with 11 additions and 7 deletions
|
@ -67,7 +67,7 @@ absl::optional<base::FilePath> CreateTemporaryFileOnIO() {
|
||||||
|
|
||||||
void StopTracing(gin_helper::Promise<base::FilePath> promise,
|
void StopTracing(gin_helper::Promise<base::FilePath> promise,
|
||||||
absl::optional<base::FilePath> file_path) {
|
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,
|
[](gin_helper::Promise<base::FilePath> promise,
|
||||||
const base::FilePath& path, absl::optional<std::string> error) {
|
const base::FilePath& path, absl::optional<std::string> error) {
|
||||||
if (error) {
|
if (error) {
|
||||||
|
@ -76,17 +76,21 @@ void StopTracing(gin_helper::Promise<base::FilePath> promise,
|
||||||
promise.Resolve(path);
|
promise.Resolve(path);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
std::move(promise), *file_path));
|
std::move(promise), *file_path);
|
||||||
if (file_path) {
|
if (file_path) {
|
||||||
|
auto split_callback = base::SplitOnceCallback(std::move(resolve_or_reject));
|
||||||
auto endpoint = TracingController::CreateFileEndpoint(
|
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)) {
|
if (!TracingController::GetInstance()->StopTracing(endpoint)) {
|
||||||
resolve_or_reject.Run(absl::make_optional(
|
std::move(split_callback.second)
|
||||||
"Failed to stop tracing (was a trace in progress?)"));
|
.Run(absl::make_optional(
|
||||||
|
"Failed to stop tracing (was a trace in progress?)"));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
resolve_or_reject.Run(
|
std::move(resolve_or_reject)
|
||||||
absl::make_optional("Failed to create temporary file for trace data"));
|
.Run(absl::make_optional(
|
||||||
|
"Failed to create temporary file for trace data"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue