haikuwebkit/Source/WTF/wtf/LogChannels.h

56 lines
2.1 KiB
C
Raw Permalink Normal View History

Deduplicate logging channel algorithms https://bugs.webkit.org/show_bug.cgi?id=228809 Reviewed by Fujii Hironori. Source/WebCore: No new tests because there is no behavior change. * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * accessibility/AXLogger.cpp: * inspector/agents/page/PageConsoleAgent.cpp: * page/Page.cpp: * platform/LogInitialization.cpp: Copied from Source/WebCore/platform/LogInitialization.h. (WebCore::logChannels): (WebCore::getLogChannel): * platform/LogInitialization.h: * platform/Logging.cpp: (WebCore::isLogChannelEnabled): Deleted. (WebCore::setLogChannelToAccumulate): Deleted. (WebCore::clearAllLogChannelsToAccumulate): Deleted. (WebCore::initializeLogChannelsIfNecessary): Deleted. (WebCore::getLogChannel): Deleted. * platform/Logging.h: * testing/js/WebCoreTestSupport.cpp: (WebCoreTestSupport::setLogChannelToAccumulate): (WebCoreTestSupport::clearAllLogChannelsToAccumulate): (WebCoreTestSupport::initializeLogChannelsIfNecessary): Source/WebKit: * GPUProcess/GPUConnectionToWebProcess.cpp: * GPUProcess/GPUProcess.cpp: (WebKit::GPUProcess::initializeGPUProcess): * Platform/LogInitialization.cpp: Copied from Source/WebKit/Shared/WebKit2Initialize.cpp. (WebKit::logChannels): (WebKit::getLogChannel): * Platform/LogInitialization.h: * Platform/Logging.cpp: (WebKit::initializeLogChannelsIfNecessary): Deleted. (WebKit::getLogChannel): Deleted. * Platform/Logging.h: * Shared/AuxiliaryProcess.cpp: (WebKit::AuxiliaryProcess::initialize): * Shared/WebKit2Initialize.cpp: (WebKit::InitializeWebKit2): * Sources.txt: * UIProcess/WebPageProxy.cpp: * UIProcess/WebProcessPool.cpp: * WebKit.xcodeproj/project.pbxproj: * WebProcess/cocoa/WebProcessCocoa.mm: (WebKit::WebProcess::platformInitializeWebProcess): Source/WebKitLegacy: * WebKitLegacy.xcodeproj/project.pbxproj: Source/WebKitLegacy/mac: * Misc/WebKitLogInitialization.h: Copied from Source/WebKit/Platform/LogInitialization.h. * Misc/WebKitLogInitialization.mm: Copied from Source/WebKitLegacy/mac/Misc/WebKitLogging.m. (WebKit::logChannels): (ReportDiscardedDelegateException): * Misc/WebKitLogging.h: * Misc/WebKitLogging.m: (ReportDiscardedDelegateException): Deleted. * WebCoreSupport/WebDragClient.mm: * WebView/WebDelegateImplementationCaching.mm: * WebView/WebView.mm: (-[WebView _commonInitializationWithFrameName:groupName:]): Source/WTF: The current infrastructure (before this patch) had the following duplicated for each framework: - A .cpp file declared the list of logging channels for that framework - The .cpp file also had algorithms to search, modify, and initialize these logging channels Each framework's .cpp file had duplicate algorithms. (The initialization algorithm was even duplicated 3 times!) Because the algorithms directly name their specific list of logging channels, a naive deduplication would have had to add new parameters to these algorithms to pass in the appropriate framework's list. That's fine, but this is exactly the sort of thing classes were designed for - classes are an association of algorithms and data. The algorithms are shared but the data isn't, which really just means we should have 3 instances of a shared class - one for the 3 sets of data. So, this patch creates the LogChannels class which contains the deduplicated algorithms, and each framework has a NeverDestroyed singleton instance of that class. There is a single virtual method in the class, so the appropriate "default write" variable can be queried for each framework. The instances cannot be declared in the Logging.h files in the frameworks, because certain WebKit2 files want to initialize all 3 instances of LogChannels, but you can't #include multiple Logging.h files at the same time because their LOG_CHANNEL_PREFIX #defines will collide with each other. Luckily, LogInitialization.h files exist exactly to solve this purpose, so that's where the LogChannels instances are declared in. After this change, the Logging.h files are just for the declarations of the logging channels themselves, and the LogInitialization.h files are for the LogChannels instances which contain the searching/modifying/initializing algorithms on the list of logging channels. If you just want to LOG(...) something, #include the relevant Logging.h file, and if you want to search/modify/initialize across the entire list of channels, then #include the relevant LogInitialization.h file. * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/LogChannels.cpp: Copied from Source/WebCore/platform/Logging.cpp. (WTF::LogChannels::isLogChannelEnabled): (WTF::LogChannels::setLogChannelToAccumulate): (WTF::LogChannels::clearAllLogChannelsToAccumulate): (WTF::LogChannels::initializeLogChannelsIfNecessary): (WTF::LogChannels::getLogChannel): * wtf/LogChannels.h: Copied from Source/WebCore/platform/LogInitialization.h. Canonical link: https://commits.webkit.org/240343@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@280758 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-08-07 18:50:12 +00:00
/*
* Copyright (C) 2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <optional>
#include <wtf/Assertions.h>
#include <wtf/Forward.h>
#include <wtf/text/WTFString.h>
namespace WTF {
#if !LOG_DISABLED || !RELEASE_LOG_DISABLED
class LogChannels {
public:
virtual ~LogChannels() = default;
virtual String logLevelString() = 0;
bool isLogChannelEnabled(const String& name);
WTF_EXPORT_PRIVATE void setLogChannelToAccumulate(const String& name);
WTF_EXPORT_PRIVATE void clearAllLogChannelsToAccumulate();
WTF_EXPORT_PRIVATE void initializeLogChannelsIfNecessary(std::optional<String> = std::nullopt);
WTF_EXPORT_PRIVATE WTFLogChannel* getLogChannel(const String& name);
protected:
Vector<WTFLogChannel*> m_logChannels;
bool m_logChannelsNeedInitialization { true };
};
#endif // !LOG_DISABLED || !RELEASE_LOG_DISABLED
} // namespace WTF