From 4a1c029f946623df86d79f77d718adbd394ccb58 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Wed, 22 Jan 2025 09:43:19 -0600 Subject: [PATCH] refactor: in `StopTracing()`, use string literals instead of `optional` (#45291) refactor: simplify StopTracing() a little by using a string_view instead of an optional We have compile-time string literals that we're passing to a method that takes a string_view argument, so we don't need all this extra optional scaffolding Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr --- .../api/electron_api_content_tracing.cc | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/shell/browser/api/electron_api_content_tracing.cc b/shell/browser/api/electron_api_content_tracing.cc index 384a16e1b3a7..70215fb7650b 100644 --- a/shell/browser/api/electron_api_content_tracing.cc +++ b/shell/browser/api/electron_api_content_tracing.cc @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "base/files/file_util.h" @@ -20,6 +21,7 @@ #include "shell/common/node_includes.h" using content::TracingController; +using namespace std::literals; namespace gin { @@ -69,9 +71,9 @@ void StopTracing(gin_helper::Promise promise, std::optional file_path) { auto resolve_or_reject = base::BindOnce( [](gin_helper::Promise promise, - const base::FilePath& path, std::optional error) { - if (error) { - promise.RejectWithErrorMessage(error.value()); + const base::FilePath& path, const std::string_view error) { + if (!std::empty(error)) { + promise.RejectWithErrorMessage(error); } else { promise.Resolve(path); } @@ -81,21 +83,17 @@ void StopTracing(gin_helper::Promise promise, auto* instance = TracingController::GetInstance(); if (!instance->IsTracing()) { std::move(resolve_or_reject) - .Run(std::make_optional( - "Failed to stop tracing - no trace in progress")); + .Run("Failed to stop tracing - no trace in progress"sv); } else if (file_path) { auto split_callback = base::SplitOnceCallback(std::move(resolve_or_reject)); auto endpoint = TracingController::CreateFileEndpoint( - *file_path, - base::BindOnce(std::move(split_callback.first), std::nullopt)); + *file_path, base::BindOnce(std::move(split_callback.first), ""sv)); if (!instance->StopTracing(endpoint)) { - std::move(split_callback.second) - .Run(std::make_optional("Failed to stop tracing")); + std::move(split_callback.second).Run("Failed to stop tracing"sv); } } else { std::move(resolve_or_reject) - .Run(std::make_optional( - "Failed to create temporary file for trace data")); + .Run("Failed to create temporary file for trace data"sv); } }