refactor: prefer inline constexpr string_view
for string constants (#44405)
* refactor: BaseWindow::OnExecuteAppCommand() now takes a std::string_view * refactor: NativeWindow::NotifyWindowExecuteAppCommand() takes a std::string_view * refactor: AppCommandToString() returns a std::string_view, is now constexpr * refactor: make kBrowserBackward, kBrowserForward inline constexpr std::string_view Xref: https://abseil.io/tips/140 https://groups.google.com/a/chromium.org/g/chromium-dev/c/jROTxMo_m2Q/m/HgciN2KsAgAJ * refactor: use inline constexpr string_view for kDevice*Key constants Xref: https://abseil.io/tips/140 https://groups.google.com/a/chromium.org/g/chromium-dev/c/jROTxMo_m2Q/m/HgciN2KsAgAJ * refactor: IsEnvSet now takes a base::cstring_view * refactor: use inline constexpr cstring_view for kRunAsNode * refactor: use inline constexpr string_view for kPDF*PluginName * refactor: use base::FilePath::FromASCII() since "internal-pdf-viewer" is ascii * chore: remove unused shell/common/electron_constants.cc * fixup! refactor: IsEnvSet now takes a base::cstring_view
This commit is contained in:
parent
cc3359f126
commit
b3c2e83243
14 changed files with 41 additions and 59 deletions
|
@ -187,7 +187,8 @@ void ElectronContentClient::AddPlugins(
|
|||
pdf_info.name = kPDFInternalPluginName;
|
||||
pdf_info.description = kPDFPluginDescription;
|
||||
// This isn't a real file path; it's just used as a unique identifier.
|
||||
pdf_info.path = base::FilePath(kPdfPluginPath);
|
||||
static constexpr std::string_view kPdfPluginPath = "internal-pdf-viewer";
|
||||
pdf_info.path = base::FilePath::FromASCII(kPdfPluginPath);
|
||||
content::WebPluginMimeType pdf_mime_type(
|
||||
pdf::kInternalPluginMimeType, kPDFPluginExtension, kPDFPluginDescription);
|
||||
pdf_info.mime_types.push_back(pdf_mime_type);
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "base/at_exit.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/i18n/icu_util.h"
|
||||
#include "base/strings/cstring_view.h"
|
||||
#include "content/public/app/content_main.h"
|
||||
#include "electron/fuses.h"
|
||||
#include "shell/app/electron_main_delegate.h" // NOLINT
|
||||
|
@ -18,9 +19,9 @@
|
|||
|
||||
namespace {
|
||||
|
||||
bool IsEnvSet(const char* name) {
|
||||
char* indicator = getenv(name);
|
||||
return indicator && indicator[0] != '\0';
|
||||
[[nodiscard]] bool IsEnvSet(const base::cstring_view name) {
|
||||
const char* const indicator = getenv(name.c_str());
|
||||
return indicator && *indicator;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -5,10 +5,12 @@
|
|||
#include <cstdlib>
|
||||
#include <memory>
|
||||
|
||||
#include "base/strings/cstring_view.h"
|
||||
#include "electron/fuses.h"
|
||||
#include "electron/mas.h"
|
||||
#include "shell/app/electron_library_main.h"
|
||||
#include "shell/app/uv_stdio_fix.h"
|
||||
#include "shell/common/electron_constants.h"
|
||||
|
||||
#if defined(HELPER_EXECUTABLE) && !IS_MAS_BUILD()
|
||||
#include <mach-o/dyld.h>
|
||||
|
@ -27,9 +29,9 @@ void abort_report_np(const char* fmt, ...);
|
|||
|
||||
namespace {
|
||||
|
||||
bool IsEnvSet(const char* name) {
|
||||
char* indicator = getenv(name);
|
||||
return indicator && indicator[0] != '\0';
|
||||
[[nodiscard]] bool IsEnvSet(const base::cstring_view name) {
|
||||
const char* const indicator = getenv(name.c_str());
|
||||
return indicator && *indicator;
|
||||
}
|
||||
|
||||
#if defined(HELPER_EXECUTABLE) && !IS_MAS_BUILD()
|
||||
|
@ -51,8 +53,7 @@ bool IsEnvSet(const char* name) {
|
|||
int main(int argc, char* argv[]) {
|
||||
FixStdioStreams();
|
||||
|
||||
if (electron::fuses::IsRunAsNodeEnabled() &&
|
||||
IsEnvSet("ELECTRON_RUN_AS_NODE")) {
|
||||
if (electron::fuses::IsRunAsNodeEnabled() && IsEnvSet(electron::kRunAsNode)) {
|
||||
return ElectronInitializeICUandStartNode(argc, argv);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "base/i18n/icu_util.h"
|
||||
#include "base/memory/raw_ptr_exclusion.h"
|
||||
#include "base/process/launch.h"
|
||||
#include "base/strings/cstring_view.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "base/win/dark_mode_support.h"
|
||||
#include "chrome/app/exit_code_watcher_win.h"
|
||||
|
@ -45,9 +46,9 @@ namespace {
|
|||
const char kUserDataDir[] = "user-data-dir";
|
||||
const char kProcessType[] = "type";
|
||||
|
||||
bool IsEnvSet(const char* name) {
|
||||
size_t required_size;
|
||||
getenv_s(&required_size, nullptr, 0, name);
|
||||
[[nodiscard]] bool IsEnvSet(const base::cstring_view name) {
|
||||
size_t required_size = 0;
|
||||
getenv_s(&required_size, nullptr, 0, name.c_str());
|
||||
return required_size != 0;
|
||||
}
|
||||
|
||||
|
@ -139,7 +140,7 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
|
|||
|
||||
#ifdef _DEBUG
|
||||
// Don't display assert dialog boxes in CI test runs
|
||||
static const char kCI[] = "CI";
|
||||
static constexpr base::cstring_view kCI = "CI";
|
||||
if (IsEnvSet(kCI)) {
|
||||
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE);
|
||||
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue