refactor: in StopTracing()
, use string literals instead of optional<string>
(#45270)
refactor: simplify StopTracing() a little by using a string_view instead of an optional<string> 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<string> scaffolding
This commit is contained in:
parent
f5eba67f0d
commit
fe9031eb23
1 changed files with 9 additions and 11 deletions
|
@ -5,6 +5,7 @@
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "base/files/file_util.h"
|
#include "base/files/file_util.h"
|
||||||
|
@ -20,6 +21,7 @@
|
||||||
#include "shell/common/node_includes.h"
|
#include "shell/common/node_includes.h"
|
||||||
|
|
||||||
using content::TracingController;
|
using content::TracingController;
|
||||||
|
using namespace std::literals;
|
||||||
|
|
||||||
namespace gin {
|
namespace gin {
|
||||||
|
|
||||||
|
@ -69,9 +71,9 @@ void StopTracing(gin_helper::Promise<base::FilePath> promise,
|
||||||
std::optional<base::FilePath> file_path) {
|
std::optional<base::FilePath> file_path) {
|
||||||
auto resolve_or_reject = base::BindOnce(
|
auto resolve_or_reject = base::BindOnce(
|
||||||
[](gin_helper::Promise<base::FilePath> promise,
|
[](gin_helper::Promise<base::FilePath> promise,
|
||||||
const base::FilePath& path, std::optional<std::string> error) {
|
const base::FilePath& path, const std::string_view error) {
|
||||||
if (error) {
|
if (!std::empty(error)) {
|
||||||
promise.RejectWithErrorMessage(error.value());
|
promise.RejectWithErrorMessage(error);
|
||||||
} else {
|
} else {
|
||||||
promise.Resolve(path);
|
promise.Resolve(path);
|
||||||
}
|
}
|
||||||
|
@ -81,21 +83,17 @@ void StopTracing(gin_helper::Promise<base::FilePath> promise,
|
||||||
auto* instance = TracingController::GetInstance();
|
auto* instance = TracingController::GetInstance();
|
||||||
if (!instance->IsTracing()) {
|
if (!instance->IsTracing()) {
|
||||||
std::move(resolve_or_reject)
|
std::move(resolve_or_reject)
|
||||||
.Run(std::make_optional(
|
.Run("Failed to stop tracing - no trace in progress"sv);
|
||||||
"Failed to stop tracing - no trace in progress"));
|
|
||||||
} else if (file_path) {
|
} else if (file_path) {
|
||||||
auto split_callback = base::SplitOnceCallback(std::move(resolve_or_reject));
|
auto split_callback = base::SplitOnceCallback(std::move(resolve_or_reject));
|
||||||
auto endpoint = TracingController::CreateFileEndpoint(
|
auto endpoint = TracingController::CreateFileEndpoint(
|
||||||
*file_path,
|
*file_path, base::BindOnce(std::move(split_callback.first), ""sv));
|
||||||
base::BindOnce(std::move(split_callback.first), std::nullopt));
|
|
||||||
if (!instance->StopTracing(endpoint)) {
|
if (!instance->StopTracing(endpoint)) {
|
||||||
std::move(split_callback.second)
|
std::move(split_callback.second).Run("Failed to stop tracing"sv);
|
||||||
.Run(std::make_optional("Failed to stop tracing"));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
std::move(resolve_or_reject)
|
std::move(resolve_or_reject)
|
||||||
.Run(std::make_optional(
|
.Run("Failed to create temporary file for trace data"sv);
|
||||||
"Failed to create temporary file for trace data"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue