refactor: move impl functions into private namespace (#43372)

This commit is contained in:
Charles Kerr 2024-08-21 15:26:06 -05:00 committed by GitHub
parent f366caac84
commit 4fbf18a021
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 40 additions and 8 deletions

View file

@ -102,10 +102,6 @@ void SetCrashKeyStub(const std::string& key, const std::string& value) {}
void ClearCrashKeyStub(const std::string& key) {} void ClearCrashKeyStub(const std::string& key) {}
#endif #endif
} // namespace
namespace electron {
v8::Local<v8::Value> GetParameters(v8::Isolate* isolate) { v8::Local<v8::Value> GetParameters(v8::Isolate* isolate) {
std::map<std::string, std::string> keys; std::map<std::string, std::string> keys;
#if !IS_MAS_BUILD() #if !IS_MAS_BUILD()
@ -114,6 +110,10 @@ v8::Local<v8::Value> GetParameters(v8::Isolate* isolate) {
return gin::ConvertToV8(isolate, keys); return gin::ConvertToV8(isolate, keys);
} }
} // namespace
namespace electron {
int NodeMain(int argc, char* argv[]) { int NodeMain(int argc, char* argv[]) {
bool initialized = base::CommandLine::Init(argc, argv); bool initialized = base::CommandLine::Init(argc, argv);
if (!initialized) { if (!initialized) {

View file

@ -81,6 +81,8 @@ const std::map<std::string, std::string>& GetGlobalCrashKeys() {
return GetGlobalCrashKeysMutable(); return GetGlobalCrashKeysMutable();
} }
namespace {
bool GetClientIdPath(base::FilePath* path) { bool GetClientIdPath(base::FilePath* path) {
if (base::PathService::Get(electron::DIR_CRASH_DUMPS, path)) { if (base::PathService::Get(electron::DIR_CRASH_DUMPS, path)) {
*path = path->Append("client_id"); *path = path->Append("client_id");
@ -109,6 +111,8 @@ void WriteClientId(const std::string& client_id) {
base::WriteFile(client_id_path, client_id); base::WriteFile(client_id_path, client_id);
} }
} // namespace
std::string GetClientId() { std::string GetClientId() {
static base::NoDestructor<std::string> client_id; static base::NoDestructor<std::string> client_id;
if (!client_id->empty()) if (!client_id->empty())

View file

@ -46,6 +46,7 @@
#include "ui/base/cocoa/permissions_utils.h" #include "ui/base/cocoa/permissions_utils.h"
#endif #endif
namespace {
#if BUILDFLAG(IS_LINUX) #if BUILDFLAG(IS_LINUX)
// Private function in ui/base/x/x11_display_util.cc // Private function in ui/base/x/x11_display_util.cc
base::flat_map<x11::RandR::Output, int> GetMonitors( base::flat_map<x11::RandR::Output, int> GetMonitors(
@ -142,8 +143,6 @@ base::flat_map<int32_t, uint32_t> MonitorAtomIdToDisplayId() {
} }
#endif #endif
namespace {
std::unique_ptr<ThumbnailCapturer> MakeWindowCapturer() { std::unique_ptr<ThumbnailCapturer> MakeWindowCapturer() {
#if BUILDFLAG(IS_MAC) #if BUILDFLAG(IS_MAC)
if (ShouldUseThumbnailCapturerMac(DesktopMediaList::Type::kWindow)) { if (ShouldUseThumbnailCapturerMac(DesktopMediaList::Type::kWindow)) {

View file

@ -874,6 +874,8 @@ void ElectronBrowserClient::RenderProcessExited(
} }
} }
namespace {
void OnOpenExternal(const GURL& escaped_url, bool allowed) { void OnOpenExternal(const GURL& escaped_url, bool allowed) {
if (allowed) { if (allowed) {
platform_util::OpenExternal( platform_util::OpenExternal(
@ -910,6 +912,8 @@ void HandleExternalProtocolInUI(
has_user_gesture, url); has_user_gesture, url);
} }
} // namespace
bool ElectronBrowserClient::HandleExternalProtocol( bool ElectronBrowserClient::HandleExternalProtocol(
const GURL& url, const GURL& url,
content::WebContents::Getter web_contents_getter, content::WebContents::Getter web_contents_getter,
@ -1539,6 +1543,7 @@ void ElectronBrowserClient::BindHostReceiverForRenderer(
} }
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS) #if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
namespace {
void BindMimeHandlerService( void BindMimeHandlerService(
content::RenderFrameHost* frame_host, content::RenderFrameHost* frame_host,
mojo::PendingReceiver<extensions::mime_handler::MimeHandlerService> mojo::PendingReceiver<extensions::mime_handler::MimeHandlerService>
@ -1567,6 +1572,7 @@ void BindBeforeUnloadControl(
return; return;
guest_view->FuseBeforeUnloadControl(std::move(receiver)); guest_view->FuseBeforeUnloadControl(std::move(receiver));
} }
} // namespace
#endif #endif
void ElectronBrowserClient::ExposeInterfacesToRenderer( void ElectronBrowserClient::ExposeInterfacesToRenderer(
@ -1706,6 +1712,8 @@ content::UsbDelegate* ElectronBrowserClient::GetUsbDelegate() {
return usb_delegate_.get(); return usb_delegate_.get();
} }
namespace {
void BindBadgeServiceForServiceWorker( void BindBadgeServiceForServiceWorker(
const content::ServiceWorkerVersionBaseInfo& info, const content::ServiceWorkerVersionBaseInfo& info,
mojo::PendingReceiver<blink::mojom::BadgeService> receiver) { mojo::PendingReceiver<blink::mojom::BadgeService> receiver) {
@ -1720,6 +1728,8 @@ void BindBadgeServiceForServiceWorker(
render_process_host, info.scope, std::move(receiver)); render_process_host, info.scope, std::move(receiver));
} }
} // namespace
void ElectronBrowserClient::RegisterBrowserInterfaceBindersForServiceWorker( void ElectronBrowserClient::RegisterBrowserInterfaceBindersForServiceWorker(
content::BrowserContext* browser_context, content::BrowserContext* browser_context,
const content::ServiceWorkerVersionBaseInfo& service_worker_version_info, const content::ServiceWorkerVersionBaseInfo& service_worker_version_info,

View file

@ -468,6 +468,8 @@ ExtensionFunction::ResponseAction TabsSetZoomSettingsFunction::Run() {
return RespondNow(NoArguments()); return RespondNow(NoArguments());
} }
namespace {
bool IsKillURL(const GURL& url) { bool IsKillURL(const GURL& url) {
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
// Caller should ensure that |url| is already "fixed up" by // Caller should ensure that |url| is already "fixed up" by
@ -587,6 +589,8 @@ base::expected<GURL, std::string> PrepareURLForNavigation(
return url; return url;
} }
} // namespace
TabsUpdateFunction::TabsUpdateFunction() : web_contents_(nullptr) {} TabsUpdateFunction::TabsUpdateFunction() : web_contents_(nullptr) {}
ExtensionFunction::ResponseAction TabsUpdateFunction::Run() { ExtensionFunction::ResponseAction TabsUpdateFunction::Run() {

View file

@ -37,6 +37,8 @@ constexpr char kUsbDriverKey[] = "usb_driver";
#endif // BUILDFLAG(IS_MAC) #endif // BUILDFLAG(IS_MAC)
#endif // BUILDFLAG(IS_WIN) #endif // BUILDFLAG(IS_WIN)
namespace {
std::string EncodeToken(const base::UnguessableToken& token) { std::string EncodeToken(const base::UnguessableToken& token) {
const uint64_t data[2] = {token.GetHighForSerialization(), const uint64_t data[2] = {token.GetHighForSerialization(),
token.GetLowForSerialization()}; token.GetLowForSerialization()};
@ -81,6 +83,8 @@ base::Value PortInfoToValue(const device::mojom::SerialPortInfo& port) {
return base::Value(std::move(value)); return base::Value(std::move(value));
} }
} // namespace
SerialChooserContext::SerialChooserContext(ElectronBrowserContext* context) SerialChooserContext::SerialChooserContext(ElectronBrowserContext* context)
: browser_context_(context) {} : browser_context_(context) {}

View file

@ -45,8 +45,6 @@ bool IsDirectoryCached(const base::FilePath& path) {
return is_directory_cache[path] = base::DirectoryExists(path); return is_directory_cache[path] = base::DirectoryExists(path);
} }
} // namespace
ArchiveMap& GetArchiveCache() { ArchiveMap& GetArchiveCache() {
static base::NoDestructor<ArchiveMap> s_archive_map; static base::NoDestructor<ArchiveMap> s_archive_map;
return *s_archive_map; return *s_archive_map;
@ -57,6 +55,8 @@ base::Lock& GetArchiveCacheLock() {
return *lock; return *lock;
} }
} // namespace
std::shared_ptr<Archive> GetOrCreateAsarArchive(const base::FilePath& path) { std::shared_ptr<Archive> GetOrCreateAsarArchive(const base::FilePath& path) {
base::AutoLock auto_lock(GetArchiveCacheLock()); base::AutoLock auto_lock(GetArchiveCacheLock());
ArchiveMap& map = GetArchiveCache(); ArchiveMap& map = GetArchiveCache();

View file

@ -27,6 +27,7 @@
#include "shell/common/extensions/api/permission_features.h" #include "shell/common/extensions/api/permission_features.h"
namespace extensions { namespace extensions {
namespace {
constexpr APIPermissionInfo::InitInfo permissions_to_register[] = { constexpr APIPermissionInfo::InitInfo permissions_to_register[] = {
{mojom::APIPermissionID::kDevtools, "devtools", {mojom::APIPermissionID::kDevtools, "devtools",
@ -51,6 +52,7 @@ base::span<const Alias> GetPermissionAliases() {
return base::span<const Alias>(); return base::span<const Alias>();
} }
} // namespace
} // namespace extensions } // namespace extensions
namespace electron { namespace electron {

View file

@ -11,10 +11,15 @@
namespace gin_helper { namespace gin_helper {
namespace {
std::vector<CleanedUpAtExit*>& GetDoomed() { std::vector<CleanedUpAtExit*>& GetDoomed() {
static base::NoDestructor<std::vector<CleanedUpAtExit*>> doomed; static base::NoDestructor<std::vector<CleanedUpAtExit*>> doomed;
return *doomed; return *doomed;
} }
} // namespace
CleanedUpAtExit::CleanedUpAtExit() { CleanedUpAtExit::CleanedUpAtExit() {
GetDoomed().emplace_back(this); GetDoomed().emplace_back(this);
} }

View file

@ -41,6 +41,8 @@ base::FilePath GetLogFileName(const base::CommandLine& command_line) {
} }
} }
namespace {
bool HasExplicitLogFile(const base::CommandLine& command_line) { bool HasExplicitLogFile(const base::CommandLine& command_line) {
std::string filename = command_line.GetSwitchValueASCII(switches::kLogFile); std::string filename = command_line.GetSwitchValueASCII(switches::kLogFile);
if (filename.empty()) if (filename.empty())
@ -95,6 +97,8 @@ LoggingDestination DetermineLoggingDestination(
return LOG_TO_SYSTEM_DEBUG_LOG | LOG_TO_STDERR; return LOG_TO_SYSTEM_DEBUG_LOG | LOG_TO_STDERR;
} }
} // namespace
void InitElectronLogging(const base::CommandLine& command_line, void InitElectronLogging(const base::CommandLine& command_line,
bool is_preinit) { bool is_preinit) {
const std::string process_type = const std::string process_type =