⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 280758 in webkit


Ignore:
Timestamp:
Aug 7, 2021, 11:50:12 AM (5 years ago)
Author:
mmaxfield@apple.com
Message:

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.
Location:
trunk/Source
Files:
36 edited
6 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r280757 r280758  
     12021-08-07  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        Deduplicate logging channel algorithms
     4        https://bugs.webkit.org/show_bug.cgi?id=228809
     5
     6        Reviewed by Fujii Hironori.
     7
     8        The current infrastructure (before this patch) had the following duplicated for each framework:
     9          - A .cpp file declared the list of logging channels for that framework
     10          - The .cpp file also had algorithms to search, modify, and initialize these logging channels
     11
     12        Each framework's .cpp file had duplicate algorithms. (The initialization algorithm was even
     13        duplicated 3 times!)
     14
     15        Because the algorithms directly name their specific list of logging channels, a naive deduplication
     16        would have had to add new parameters to these algorithms to pass in the appropriate framework's
     17        list. That's fine, but this is exactly the sort of thing classes were designed for - classes are
     18        an association of algorithms and data. The algorithms are shared but the data isn't, which really
     19        just means we should have 3 instances of a shared class - one for the 3 sets of data.
     20
     21        So, this patch creates the LogChannels class which contains the deduplicated algorithms, and each
     22        framework has a NeverDestroyed singleton instance of that class. There is a single virtual method
     23        in the class, so the appropriate "default write" variable can be queried for each framework.
     24
     25        The instances cannot be declared in the Logging.h files in the frameworks, because certain WebKit2
     26        files want to initialize all 3 instances of LogChannels, but you can't #include multiple Logging.h
     27        files at the same time because their LOG_CHANNEL_PREFIX #defines will collide with each other.
     28        Luckily, LogInitialization.h files exist exactly to solve this purpose, so that's where the
     29        LogChannels instances are declared in. After this change, the Logging.h files are just for the
     30        declarations of the logging channels themselves, and the LogInitialization.h files are for the
     31        LogChannels instances which contain the searching/modifying/initializing algorithms on the list of
     32        logging channels. If you just want to LOG(...) something, #include the relevant Logging.h file, and
     33        if you want to search/modify/initialize across the entire list of channels, then #include the
     34        relevant LogInitialization.h file.
     35
     36        * WTF.xcodeproj/project.pbxproj:
     37        * wtf/CMakeLists.txt:
     38        * wtf/LogChannels.cpp: Copied from Source/WebCore/platform/Logging.cpp.
     39        (WTF::LogChannels::isLogChannelEnabled):
     40        (WTF::LogChannels::setLogChannelToAccumulate):
     41        (WTF::LogChannels::clearAllLogChannelsToAccumulate):
     42        (WTF::LogChannels::initializeLogChannelsIfNecessary):
     43        (WTF::LogChannels::getLogChannel):
     44        * wtf/LogChannels.h: Copied from Source/WebCore/platform/LogInitialization.h.
     45
    1462021-08-07  Commit Queue  <commit-queue@webkit.org>
    247
  • trunk/Source/WTF/WTF.xcodeproj/project.pbxproj

    r280757 r280758  
    6262                1C503BE623AAE0AE0072E66B /* LanguageCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C503BE523AAE0AE0072E66B /* LanguageCocoa.mm */; };
    6363                1CA85CA9241B0B260071C2F5 /* RuntimeApplicationChecksCocoa.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1CA85CA8241B0B260071C2F5 /* RuntimeApplicationChecksCocoa.cpp */; };
     64                1CF18F3B26BB579E004B1722 /* LogChannels.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1CF18F3926BB579E004B1722 /* LogChannels.cpp */; };
    6465                1FA47C8A152502DA00568D1B /* WebCoreThread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1FA47C88152502DA00568D1B /* WebCoreThread.cpp */; };
    6566                2CCD892A15C0390200285083 /* GregorianDateTime.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2CCD892915C0390200285083 /* GregorianDateTime.cpp */; };
     
    352353                1CCDB14D1E566898006C73C0 /* TextBreakIteratorICU.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextBreakIteratorICU.h; sourceTree = "<group>"; };
    353354                1CCDB1511E566BC5006C73C0 /* CFStringSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CFStringSPI.h; sourceTree = "<group>"; };
     355                1CF18F3926BB579E004B1722 /* LogChannels.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = LogChannels.cpp; sourceTree = "<group>"; };
     356                1CF18F3A26BB579E004B1722 /* LogChannels.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LogChannels.h; sourceTree = "<group>"; };
    354357                1FA47C88152502DA00568D1B /* WebCoreThread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebCoreThread.cpp; sourceTree = "<group>"; };
    355358                1FA47C89152502DA00568D1B /* WebCoreThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebCoreThread.h; sourceTree = "<group>"; };
     
    513516                9BC70F04176C379D00101DEC /* AtomStringTable.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AtomStringTable.cpp; sourceTree = "<group>"; };
    514517                9BD8F40A176C2AD80002D865 /* AtomStringTable.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AtomStringTable.h; sourceTree = "<group>"; };
     518                9BE153352671F00F00C7D096 /* WeakHashMap.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WeakHashMap.h; sourceTree = "<group>"; };
    515519                9BF00134267C4CCF00DCFB3F /* CheckedRef.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CheckedRef.h; sourceTree = "<group>"; };
    516                 9BE153352671F00F00C7D096 /* WeakHashMap.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WeakHashMap.h; sourceTree = "<group>"; };
    517520                9C67C542589348E285B49699 /* IndexedContainerIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IndexedContainerIterator.h; sourceTree = "<group>"; };
    518521                A1B89B87221E000F00EB4CEA /* SDKVariant.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = SDKVariant.xcconfig; sourceTree = "<group>"; };
     
    11231126                                A8A472C3151A825A004123FF /* Locker.h */,
    11241127                                5311BD551EA7E15A00525281 /* LocklessBag.h */,
     1128                                1CF18F3926BB579E004B1722 /* LogChannels.cpp */,
     1129                                1CF18F3A26BB579E004B1722 /* LogChannels.h */,
    11251130                                93B5B45022171EE9004B7AA7 /* Logger.cpp */,
    11261131                                077CD86A1FD9CFD200828587 /* Logger.h */,
     
    17391744                                0FE1646A1B6FFC9600400E7C /* Lock.cpp in Sources */,
    17401745                                0F60F32F1DFCBD1B00416D6C /* LockedPrintStream.cpp in Sources */,
     1746                                1CF18F3B26BB579E004B1722 /* LogChannels.cpp in Sources */,
    17411747                                93B5B45122171EEA004B7AA7 /* Logger.cpp in Sources */,
    17421748                                53534F2A1EC0E10E00141B2F /* MachExceptions.defs in Sources */,
  • trunk/Source/WTF/wtf/CMakeLists.txt

    r280757 r280758  
    124124    Locker.h
    125125    LocklessBag.h
     126    LogChannels.h
    126127    Logger.h
    127128    LoggerHelper.h
     
    423424    Lock.cpp
    424425    LockedPrintStream.cpp
     426    LogChannels.cpp
    425427    Logger.cpp
    426428    MainThread.cpp
  • trunk/Source/WTF/wtf/LogChannels.cpp

    r280757 r280758  
    11/*
    2  * Copyright (C) 2003, 2006, 2013 Apple Inc.  All rights reserved.
     2 * Copyright (C) 2021 Apple Inc.  All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2525
    2626#include "config.h"
    27 #include "Logging.h"
    28 #include "LogInitialization.h"
     27#include "LogChannels.h"
    2928
    3029#include <wtf/LoggingAccumulator.h>
    31 #include <wtf/StdLibExtras.h>
    32 #include <wtf/text/CString.h>
    33 #include <wtf/text/WTFString.h>
    3430
    35 #if PLATFORM(COCOA)
    36 #include <notify.h>
    37 #include <wtf/BlockPtr.h>
    38 #endif
    39 
    40 namespace WebCore {
     31namespace WTF {
    4132
    4233#if !LOG_DISABLED || !RELEASE_LOG_DISABLED
    4334
    44 #define DEFINE_WEBCORE_LOG_CHANNEL(name) DEFINE_LOG_CHANNEL(name, LOG_CHANNEL_WEBKIT_SUBSYSTEM)
    45 WEBCORE_LOG_CHANNELS(DEFINE_WEBCORE_LOG_CHANNEL)
    46 
    47 static WTFLogChannel* logChannels[] = {
    48     WEBCORE_LOG_CHANNELS(LOG_CHANNEL_ADDRESS)
    49 };
    50 
    51 static const size_t logChannelCount = WTF_ARRAY_LENGTH(logChannels);
    52 
    53 bool isLogChannelEnabled(const String& name)
     35bool LogChannels::isLogChannelEnabled(const String& name)
    5436{
    55     WTFLogChannel* channel = WTFLogChannelByName(logChannels, logChannelCount, name.utf8().data());
     37    WTFLogChannel* channel = getLogChannel(name);
    5638    if (!channel)
    5739        return false;
     
    5941}
    6042
    61 static bool logChannelsNeedInitialization = true;
    62 
    63 void setLogChannelToAccumulate(const String& name)
     43void LogChannels::setLogChannelToAccumulate(const String& name)
    6444{
    65     WTFLogChannel* channel = WTFLogChannelByName(logChannels, logChannelCount, name.utf8().data());
     45    WTFLogChannel* channel = getLogChannel(name);
    6646    if (!channel)
    6747        return;
    6848
    6949    channel->state = WTFLogChannelState::OnWithAccumulation;
    70     logChannelsNeedInitialization = true;
     50    m_logChannelsNeedInitialization = true;
    7151}
    7252
    73 void clearAllLogChannelsToAccumulate()
     53void LogChannels::clearAllLogChannelsToAccumulate()
    7454{
    7555    resetAccumulatedLogs();
    76     for (auto* channel : logChannels) {
     56    for (auto* channel : m_logChannels) {
    7757        if (channel->state == WTFLogChannelState::OnWithAccumulation)
    7858            channel->state = WTFLogChannelState::Off;
    7959    }
    8060
    81     logChannelsNeedInitialization = true;
     61    m_logChannelsNeedInitialization = true;
    8262}
    8363
    84 void initializeLogChannelsIfNecessary(std::optional<String> logChannelString)
     64void LogChannels::initializeLogChannelsIfNecessary(std::optional<String> logChannelString)
    8565{
    86     if (!logChannelsNeedInitialization && !logChannelString)
     66    if (!m_logChannelsNeedInitialization && !logChannelString)
    8767        return;
    8868
    89     logChannelsNeedInitialization = false;
     69    m_logChannelsNeedInitialization = false;
    9070
    9171    String enabledChannelsString = logChannelString ? logChannelString.value() : logLevelString();
    92     WTFInitializeLogChannelStatesFromString(logChannels, logChannelCount, enabledChannelsString.utf8().data());
    93 //    LogEventLoop.state = WTFLogChannelState::On;
     72    WTFInitializeLogChannelStatesFromString(m_logChannels.data(), m_logChannels.size(), enabledChannelsString.utf8().data());
    9473}
    9574
    96 WTFLogChannel* getLogChannel(const String& name)
     75WTFLogChannel* LogChannels::getLogChannel(const String& name)
    9776{
    98     return WTFLogChannelByName(logChannels, logChannelCount, name.utf8().data());
    99 }
    100 
    101 #else
    102 
    103 WTFLogChannel* getLogChannel(const String&)
    104 {
    105     return nullptr;
     77    return WTFLogChannelByName(m_logChannels.data(), m_logChannels.size(), name.utf8().data());
    10678}
    10779
    10880#endif // !LOG_DISABLED || !RELEASE_LOG_DISABLED
    10981
    110 } // namespace WebCore
     82} // namespace WTF
  • trunk/Source/WTF/wtf/LogChannels.h

    r280757 r280758  
    11/*
    2  * Copyright (C) 2003, 2006, 2013, 2015, 2016 Apple Inc.  All rights reserved.
     2 * Copyright (C) 2021 Apple Inc.  All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2626#pragma once
    2727
     28#include <optional>
    2829#include <wtf/Assertions.h>
    2930#include <wtf/Forward.h>
    3031#include <wtf/text/WTFString.h>
    3132
    32 namespace WebCore {
     33namespace WTF {
    3334
    3435#if !LOG_DISABLED || !RELEASE_LOG_DISABLED
    3536
    36 WEBCORE_EXPORT String logLevelString();
    37 bool isLogChannelEnabled(const String& name);
    38 WEBCORE_EXPORT void setLogChannelToAccumulate(const String& name);
    39 WEBCORE_EXPORT void clearAllLogChannelsToAccumulate();
    40 WEBCORE_EXPORT void initializeLogChannelsIfNecessary(std::optional<String> = std::nullopt);
     37class LogChannels {
     38public:
     39    virtual ~LogChannels() = default;
     40    virtual String logLevelString() = 0;
     41
     42    bool isLogChannelEnabled(const String& name);
     43    WTF_EXPORT_PRIVATE void setLogChannelToAccumulate(const String& name);
     44    WTF_EXPORT_PRIVATE void clearAllLogChannelsToAccumulate();
     45    WTF_EXPORT_PRIVATE void initializeLogChannelsIfNecessary(std::optional<String> = std::nullopt);
     46    WTF_EXPORT_PRIVATE WTFLogChannel* getLogChannel(const String& name);
     47
     48protected:
     49    Vector<WTFLogChannel*> m_logChannels;
     50    bool m_logChannelsNeedInitialization { true };
     51};
    4152
    4253#endif // !LOG_DISABLED || !RELEASE_LOG_DISABLED
    4354
    44 } // namespace WebCore
     55} // namespace WTF
  • trunk/Source/WTF/wtf/ThreadSpecific.h

    r252687 r280758  
    4747#include <wtf/Threading.h>
    4848
     49// X11 headers define a bunch of macros with common terms, interfering with WebCore and WTF enum values.
     50// As a workaround, we explicitly undef them here.
     51#if defined(False)
     52#undef False
     53#endif
     54#if defined(True)
     55#undef True
     56#endif
     57
    4958namespace WTF {
    5059
  • trunk/Source/WTF/wtf/Threading.h

    r278253 r280758  
    6262#endif
    6363
     64// X11 headers define a bunch of macros with common terms, interfering with WebCore and WTF enum values.
     65// As a workaround, we explicitly undef them here.
     66#if defined(None)
     67#undef None
     68#endif
     69
    6470namespace WTF {
    6571
  • trunk/Source/WebCore/ChangeLog

    r280757 r280758  
     12021-08-07  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        Deduplicate logging channel algorithms
     4        https://bugs.webkit.org/show_bug.cgi?id=228809
     5
     6        Reviewed by Fujii Hironori.
     7
     8        No new tests because there is no behavior change.
     9
     10        * Sources.txt:
     11        * WebCore.xcodeproj/project.pbxproj:
     12        * accessibility/AXLogger.cpp:
     13        * inspector/agents/page/PageConsoleAgent.cpp:
     14        * page/Page.cpp:
     15        * platform/LogInitialization.cpp: Copied from Source/WebCore/platform/LogInitialization.h.
     16        (WebCore::logChannels):
     17        (WebCore::getLogChannel):
     18        * platform/LogInitialization.h:
     19        * platform/Logging.cpp:
     20        (WebCore::isLogChannelEnabled): Deleted.
     21        (WebCore::setLogChannelToAccumulate): Deleted.
     22        (WebCore::clearAllLogChannelsToAccumulate): Deleted.
     23        (WebCore::initializeLogChannelsIfNecessary): Deleted.
     24        (WebCore::getLogChannel): Deleted.
     25        * platform/Logging.h:
     26        * testing/js/WebCoreTestSupport.cpp:
     27        (WebCoreTestSupport::setLogChannelToAccumulate):
     28        (WebCoreTestSupport::clearAllLogChannelsToAccumulate):
     29        (WebCoreTestSupport::initializeLogChannelsIfNecessary):
     30
    1312021-08-07  Commit Queue  <commit-queue@webkit.org>
    232
  • trunk/Source/WebCore/Sources.txt

    r280757 r280758  
    17561756platform/LengthSize.cpp
    17571757platform/LocalizedStrings.cpp
     1758platform/LogInitialization.cpp
    17581759platform/Logging.cpp
    17591760platform/LowPowerModeNotifier.cpp
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r280757 r280758  
    69786978                1CE8D12C2618616400FC3AEF /* DisplayListIterator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DisplayListIterator.h; sourceTree = "<group>"; };
    69796979                1CF0BFD42298706800ED2074 /* TextSizeAdjustment.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TextSizeAdjustment.cpp; sourceTree = "<group>"; };
     6980                1CF18F3C26BB5AF2004B1722 /* LogInitialization.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = LogInitialization.cpp; sourceTree = "<group>"; };
    69806981                1CFAE3220A6D6A3F0032593D /* libobjc.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libobjc.dylib; path = /usr/lib/libobjc.dylib; sourceTree = "<absolute>"; };
    69816982                1D0026A22374D62300CA6CDF /* JSPictureInPictureWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSPictureInPictureWindow.h; sourceTree = "<group>"; };
     
    2758827589                                A8239DFE09B3CF8A00B60641 /* Logging.cpp */,
    2758927590                                A8239DFF09B3CF8A00B60641 /* Logging.h */,
     27591                                1CF18F3C26BB5AF2004B1722 /* LogInitialization.cpp */,
    2759027592                                0FDCD7F21D47E655009F08BC /* LogInitialization.h */,
    2759127593                                46EFAF0F1E5FB9E100E7F34B /* LowPowerModeNotifier.cpp */,
  • trunk/Source/WebCore/accessibility/AXLogger.cpp

    r280757 r280758  
    3737#include "AXObjectCache.h"
    3838#include "FrameView.h"
     39#include "LogInitialization.h"
    3940#include "Logging.h"
    4041#include <wtf/text/TextStream.h>
  • trunk/Source/WebCore/inspector/agents/page/PageConsoleAgent.cpp

    r280757 r280758  
    3636#include "InspectorDOMAgent.h"
    3737#include "InstrumentingAgents.h"
     38#include "LogInitialization.h"
    3839#include "Logging.h"
    3940#include "Node.h"
  • trunk/Source/WebCore/page/Page.cpp

    r280757 r280758  
    8484#include "LibWebRTCProvider.h"
    8585#include "LoaderStrategy.h"
     86#include "LogInitialization.h"
    8687#include "Logging.h"
    8788#include "LowPowerModeNotifier.h"
  • trunk/Source/WebCore/platform/LogInitialization.cpp

    r280757 r280758  
    11/*
    2  * Copyright (C) 2003, 2006, 2013, 2015, 2016 Apple Inc.  All rights reserved.
     2 * Copyright (C) 2003-2021 Apple Inc.  All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #pragma once
     26#include "config.h"
     27#include "LogInitialization.h"
    2728
    28 #include <wtf/Assertions.h>
    29 #include <wtf/Forward.h>
     29#include "Logging.h"
     30#include <wtf/NeverDestroyed.h>
    3031#include <wtf/text/WTFString.h>
    3132
     
    3435#if !LOG_DISABLED || !RELEASE_LOG_DISABLED
    3536
    36 WEBCORE_EXPORT String logLevelString();
    37 bool isLogChannelEnabled(const String& name);
    38 WEBCORE_EXPORT void setLogChannelToAccumulate(const String& name);
    39 WEBCORE_EXPORT void clearAllLogChannelsToAccumulate();
    40 WEBCORE_EXPORT void initializeLogChannelsIfNecessary(std::optional<String> = std::nullopt);
     37class LogChannels final : public WTF::LogChannels {
     38public:
     39    LogChannels()
     40    {
     41        m_logChannels = {
     42            WEBCORE_LOG_CHANNELS(LOG_CHANNEL_ADDRESS)
     43        };
     44    }
     45
     46private:
     47    String logLevelString() final
     48    {
     49        return WebCore::logLevelString();
     50    }
     51};
     52
     53WTF::LogChannels& logChannels()
     54{
     55    static NeverDestroyed<LogChannels> logChannels;
     56    return logChannels.get();
     57}
     58
     59WTFLogChannel* getLogChannel(const String& name)
     60{
     61    return logChannels().getLogChannel(name);
     62}
     63
     64#else
     65
     66WTFLogChannel* getLogChannel(const String& name)
     67{
     68    return nullptr;
     69}
    4170
    4271#endif // !LOG_DISABLED || !RELEASE_LOG_DISABLED
  • trunk/Source/WebCore/platform/LogInitialization.h

    r280757 r280758  
    11/*
    2  * Copyright (C) 2003, 2006, 2013, 2015, 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2010-2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2626#pragma once
    2727
    28 #include <wtf/Assertions.h>
    29 #include <wtf/Forward.h>
     28#include <wtf/LogChannels.h>
    3029#include <wtf/text/WTFString.h>
    3130
     
    3433#if !LOG_DISABLED || !RELEASE_LOG_DISABLED
    3534
    36 WEBCORE_EXPORT String logLevelString();
    37 bool isLogChannelEnabled(const String& name);
    38 WEBCORE_EXPORT void setLogChannelToAccumulate(const String& name);
    39 WEBCORE_EXPORT void clearAllLogChannelsToAccumulate();
    40 WEBCORE_EXPORT void initializeLogChannelsIfNecessary(std::optional<String> = std::nullopt);
     35WEBCORE_EXPORT WTF::LogChannels& logChannels();
     36String logLevelString();
    4137
    4238#endif // !LOG_DISABLED || !RELEASE_LOG_DISABLED
    4339
     40WEBCORE_EXPORT WTFLogChannel* getLogChannel(const String& name);
     41
    4442} // namespace WebCore
  • trunk/Source/WebCore/platform/Logging.cpp

    r280757 r280758  
    11/*
    2  * Copyright (C) 2003, 2006, 2013 Apple Inc.  All rights reserved.
     2 * Copyright (C) 2003-2021 Apple Inc.  All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2626#include "config.h"
    2727#include "Logging.h"
    28 #include "LogInitialization.h"
    29 
    30 #include <wtf/LoggingAccumulator.h>
    31 #include <wtf/StdLibExtras.h>
    32 #include <wtf/text/CString.h>
    33 #include <wtf/text/WTFString.h>
    34 
    35 #if PLATFORM(COCOA)
    36 #include <notify.h>
    37 #include <wtf/BlockPtr.h>
    38 #endif
    3928
    4029namespace WebCore {
     
    4534WEBCORE_LOG_CHANNELS(DEFINE_WEBCORE_LOG_CHANNEL)
    4635
    47 static WTFLogChannel* logChannels[] = {
    48     WEBCORE_LOG_CHANNELS(LOG_CHANNEL_ADDRESS)
    49 };
    50 
    51 static const size_t logChannelCount = WTF_ARRAY_LENGTH(logChannels);
    52 
    53 bool isLogChannelEnabled(const String& name)
    54 {
    55     WTFLogChannel* channel = WTFLogChannelByName(logChannels, logChannelCount, name.utf8().data());
    56     if (!channel)
    57         return false;
    58     return channel->state != WTFLogChannelState::Off;
    59 }
    60 
    61 static bool logChannelsNeedInitialization = true;
    62 
    63 void setLogChannelToAccumulate(const String& name)
    64 {
    65     WTFLogChannel* channel = WTFLogChannelByName(logChannels, logChannelCount, name.utf8().data());
    66     if (!channel)
    67         return;
    68 
    69     channel->state = WTFLogChannelState::OnWithAccumulation;
    70     logChannelsNeedInitialization = true;
    71 }
    72 
    73 void clearAllLogChannelsToAccumulate()
    74 {
    75     resetAccumulatedLogs();
    76     for (auto* channel : logChannels) {
    77         if (channel->state == WTFLogChannelState::OnWithAccumulation)
    78             channel->state = WTFLogChannelState::Off;
    79     }
    80 
    81     logChannelsNeedInitialization = true;
    82 }
    83 
    84 void initializeLogChannelsIfNecessary(std::optional<String> logChannelString)
    85 {
    86     if (!logChannelsNeedInitialization && !logChannelString)
    87         return;
    88 
    89     logChannelsNeedInitialization = false;
    90 
    91     String enabledChannelsString = logChannelString ? logChannelString.value() : logLevelString();
    92     WTFInitializeLogChannelStatesFromString(logChannels, logChannelCount, enabledChannelsString.utf8().data());
    93 //    LogEventLoop.state = WTFLogChannelState::On;
    94 }
    95 
    96 WTFLogChannel* getLogChannel(const String& name)
    97 {
    98     return WTFLogChannelByName(logChannels, logChannelCount, name.utf8().data());
    99 }
    100 
    101 #else
    102 
    103 WTFLogChannel* getLogChannel(const String&)
    104 {
    105     return nullptr;
    106 }
    107 
    10836#endif // !LOG_DISABLED || !RELEASE_LOG_DISABLED
    10937
  • trunk/Source/WebCore/platform/Logging.h

    r280757 r280758  
    134134#endif // !LOG_DISABLED || !RELEASE_LOG_DISABLED
    135135
    136 WEBCORE_EXPORT WTFLogChannel* getLogChannel(const String& name);
    137 
    138136} // namespace WebCore
  • trunk/Source/WebCore/testing/js/WebCoreTestSupport.cpp

    r280757 r280758  
    3737#include "JSWorkerGlobalScope.h"
    3838#include "LogInitialization.h"
     39#include "Logging.h"
    3940#include "MockGamepadProvider.h"
    4041#include "Page.h"
     
    123124{
    124125#if !LOG_DISABLED
    125     WebCore::setLogChannelToAccumulate(name);
     126    logChannels().setLogChannelToAccumulate(name);
    126127#else
    127128    UNUSED_PARAM(name);
     
    132133{
    133134#if !LOG_DISABLED
    134     WebCore::clearAllLogChannelsToAccumulate();
     135    logChannels().clearAllLogChannelsToAccumulate();
    135136#endif
    136137}
     
    139140{
    140141#if !LOG_DISABLED || !RELEASE_LOG_DISABLED
    141     WebCore::initializeLogChannelsIfNecessary();
     142    logChannels().initializeLogChannelsIfNecessary();
    142143#endif
    143144}
  • trunk/Source/WebKit/ChangeLog

    r280757 r280758  
     12021-08-07  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        Deduplicate logging channel algorithms
     4        https://bugs.webkit.org/show_bug.cgi?id=228809
     5
     6        Reviewed by Fujii Hironori.
     7
     8        * GPUProcess/GPUConnectionToWebProcess.cpp:
     9        * GPUProcess/GPUProcess.cpp:
     10        (WebKit::GPUProcess::initializeGPUProcess):
     11        * Platform/LogInitialization.cpp: Copied from Source/WebKit/Shared/WebKit2Initialize.cpp.
     12        (WebKit::logChannels):
     13        (WebKit::getLogChannel):
     14        * Platform/LogInitialization.h:
     15        * Platform/Logging.cpp:
     16        (WebKit::initializeLogChannelsIfNecessary): Deleted.
     17        (WebKit::getLogChannel): Deleted.
     18        * Platform/Logging.h:
     19        * Shared/AuxiliaryProcess.cpp:
     20        (WebKit::AuxiliaryProcess::initialize):
     21        * Shared/WebKit2Initialize.cpp:
     22        (WebKit::InitializeWebKit2):
     23        * Sources.txt:
     24        * UIProcess/WebPageProxy.cpp:
     25        * UIProcess/WebProcessPool.cpp:
     26        * WebKit.xcodeproj/project.pbxproj:
     27        * WebProcess/cocoa/WebProcessCocoa.mm:
     28        (WebKit::WebProcess::platformInitializeWebProcess):
     29
    1302021-08-07  Commit Queue  <commit-queue@webkit.org>
    231
  • trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp

    r280757 r280758  
    6565#include "WebErrors.h"
    6666#include "WebProcessMessages.h"
     67#include <WebCore/LogInitialization.h>
    6768#include <WebCore/Logging.h>
    6869#include <WebCore/MockRealtimeMediaSourceCenter.h>
  • trunk/Source/WebKit/GPUProcess/GPUProcess.cpp

    r280757 r280758  
    244244
    245245#if !LOG_DISABLED || !RELEASE_LOG_DISABLED
    246     WebCore::initializeLogChannelsIfNecessary(parameters.webCoreLoggingChannels);
    247     WebKit::initializeLogChannelsIfNecessary(parameters.webKitLoggingChannels);
     246    WebCore::logChannels().initializeLogChannelsIfNecessary(parameters.webCoreLoggingChannels);
     247    WebKit::logChannels().initializeLogChannelsIfNecessary(parameters.webKitLoggingChannels);
    248248#endif
    249249
  • trunk/Source/WebKit/Platform/LogInitialization.cpp

    r280757 r280758  
    11/*
    2  * Copyright (C) 2013 Apple Inc. All rights reserved.
     2 * Copyright (C) 2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2525
    2626#include "config.h"
    27 #include "WebKit2Initialize.h"
     27#include "LogInitialization.h"
    2828
    29 #include "LogInitialization.h"
    30 #include <JavaScriptCore/InitializeThreading.h>
    31 #include <WebCore/LogInitialization.h>
    32 #include <WebCore/WebCoreJITOperations.h>
    33 #include <wtf/MainThread.h>
    34 #include <wtf/RefCounted.h>
    35 #include <wtf/RunLoop.h>
     29#include "Logging.h"
     30#include <wtf/text/CString.h>
    3631
    3732namespace WebKit {
    3833
    39 #if !PLATFORM(COCOA)
     34#if !LOG_DISABLED || !RELEASE_LOG_DISABLED
    4035
    41 void InitializeWebKit2()
     36class LogChannels final : public WTF::LogChannels {
     37public:
     38    LogChannels()
     39    {
     40        m_logChannels = {
     41            WEBKIT2_LOG_CHANNELS(LOG_CHANNEL_ADDRESS)
     42        };
     43    }
     44
     45private:
     46    String logLevelString() final
     47    {
     48        return WebKit::logLevelString();
     49    }
     50};
     51
     52WTF::LogChannels& logChannels()
    4253{
    43     JSC::initialize();
    44     WTF::initializeMainThread();
    45     AtomString::init();
     54    static NeverDestroyed<LogChannels> logChannels;
     55    return logChannels.get();
     56}
    4657
    47     WTF::RefCountedBase::enableThreadingChecksGlobally();
     58WTFLogChannel* getLogChannel(const String& name)
     59{
     60    return logChannels().getLogChannel(name);
     61}
    4862
    49 #if !LOG_DISABLED || !RELEASE_LOG_DISABLED
    50     WebCore::initializeLogChannelsIfNecessary();
    51     WebKit::initializeLogChannelsIfNecessary();
     63#else
     64
     65WTFLogChannel* getLogChannel(const String& name)
     66{
     67    return nullptr;
     68}
     69
    5270#endif // !LOG_DISABLED || !RELEASE_LOG_DISABLED
    5371
    54     WebCore::populateJITOperations();
    55 }
    56 
    57 #endif // !PLATFORM(COCOA)
    58 
    5972} // namespace WebKit
  • trunk/Source/WebKit/Platform/LogInitialization.h

    r280757 r280758  
    11/*
    2  * Copyright (C) 2010, 2013, 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2626#pragma once
    2727
     28#include <wtf/LogChannels.h>
    2829#include <wtf/text/WTFString.h>
     30
     31namespace WebKit {
    2932
    3033#if !LOG_DISABLED || !RELEASE_LOG_DISABLED
    3134
    32 namespace WebKit {
    33 
    34 void initializeLogChannelsIfNecessary(std::optional<String> = std::nullopt);
     35WTF::LogChannels& logChannels();
    3536String logLevelString();
    3637
     38#endif // !LOG_DISABLED || !RELEASE_LOG_DISABLED
     39
     40WTFLogChannel* getLogChannel(const String& name);
     41
    3742} // namespace WebKit
    38 
    39 #endif // !LOG_DISABLED || !RELEASE_LOG_DISABLED
  • trunk/Source/WebKit/Platform/Logging.cpp

    r280757 r280758  
    11/*
    2  * Copyright (C) 2010, 2013 Apple Inc. All rights reserved.
     2 * Copyright (C) 2021 Apple Inc. All rights reserved.
    33 * Copyright (C) 2011 Samsung Electronics
    44 *
     
    2727#include "config.h"
    2828#include "Logging.h"
    29 #include "LogInitialization.h"
    30 
    31 #include <wtf/text/CString.h>
    3229
    3330#if !LOG_DISABLED || !RELEASE_LOG_DISABLED
     
    3633WEBKIT2_LOG_CHANNELS(DEFINE_WEBKIT2_LOG_CHANNEL)
    3734
    38 static WTFLogChannel* logChannels[] = {
    39     WEBKIT2_LOG_CHANNELS(LOG_CHANNEL_ADDRESS)
    40 };
    41 
    42 namespace WebKit {
    43 
    44 static const size_t logChannelCount = WTF_ARRAY_LENGTH(logChannels);
    45 static bool logChannelsNeedInitialization = true;
    46 
    47 void initializeLogChannelsIfNecessary(std::optional<String> logChannelString)
    48 {
    49     if (!logChannelsNeedInitialization && !logChannelString)
    50         return;
    51 
    52     logChannelsNeedInitialization = false;
    53 
    54     String enabledChannelsString = logChannelString ? logChannelString.value() : logLevelString();
    55     WTFInitializeLogChannelStatesFromString(logChannels, logChannelCount, enabledChannelsString.utf8().data());
    56 }
    57 
    58 WTFLogChannel* getLogChannel(const String& name)
    59 {
    60     return WTFLogChannelByName(logChannels, logChannelCount, name.utf8().data());
    61 }
    62 
    63 } // namespace WebKit
    64 
    6535#endif // !LOG_DISABLED || !RELEASE_LOG_DISABLED
  • trunk/Source/WebKit/Platform/Logging.h

    r280757 r280758  
    113113#undef DECLARE_LOG_CHANNEL
    114114
    115 namespace WebKit {
    116 WTFLogChannel* getLogChannel(const String&);
    117 } // namespace WebKit
    118 
    119115#ifdef __cplusplus
    120116}
     
    122118
    123119#endif // !LOG_DISABLED || !RELEASE_LOG_DISABLED
    124 
  • trunk/Source/WebKit/Shared/AuxiliaryProcess.cpp

    r280757 r280758  
    8383
    8484#if !LOG_DISABLED || !RELEASE_LOG_DISABLED
    85     WebCore::initializeLogChannelsIfNecessary();
    86     WebKit::initializeLogChannelsIfNecessary();
     85    WebCore::logChannels().initializeLogChannelsIfNecessary();
     86    WebKit::logChannels().initializeLogChannelsIfNecessary();
    8787#endif // !LOG_DISABLED || !RELEASE_LOG_DISABLED
    8888
  • trunk/Source/WebKit/Shared/WebKit2Initialize.cpp

    r280757 r280758  
    4848
    4949#if !LOG_DISABLED || !RELEASE_LOG_DISABLED
    50     WebCore::initializeLogChannelsIfNecessary();
    51     WebKit::initializeLogChannelsIfNecessary();
     50    WebCore::logChannels().initializeLogChannelsIfNecessary();
     51    WebKit::logChannels().initializeLogChannelsIfNecessary();
    5252#endif // !LOG_DISABLED || !RELEASE_LOG_DISABLED
    5353
  • trunk/Source/WebKit/Sources.txt

    r280757 r280758  
    136136
    137137// TODO: We should unify these files once GTK's PluginProcess2 is removed.
     138Platform/LogInitialization.cpp @no-unify
    138139Platform/Logging.cpp @no-unify
    139140Platform/Module.cpp @no-unify
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r280757 r280758  
    6969#include "LegacyGlobalSettings.h"
    7070#include "LoadParameters.h"
     71#include "LogInitialization.h"
    7172#include "Logging.h"
    7273#include "NativeWebGestureEvent.h"
  • trunk/Source/WebKit/UIProcess/WebProcessPool.cpp

    r280757 r280758  
    252252
    253253#if !LOG_DISABLED || !RELEASE_LOG_DISABLED
    254     WebCore::initializeLogChannelsIfNecessary();
    255     WebKit::initializeLogChannelsIfNecessary();
     254    WebCore::logChannels().initializeLogChannelsIfNecessary();
     255    WebKit::logChannels().initializeLogChannelsIfNecessary();
    256256#endif // !LOG_DISABLED || !RELEASE_LOG_DISABLED
    257257
  • trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj

    r280757 r280758  
    44        classes = {
    55        };
    6         objectVersion = 52;
     6        objectVersion = 54;
    77        objects = {
    88
     
    442442                1CBBE4A019B66C53006B7D81 /* WebInspectorUIMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1CBBE49E19B66C53006B7D81 /* WebInspectorUIMessageReceiver.cpp */; };
    443443                1CBBE4A119B66C53006B7D81 /* WebInspectorUIMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 1CBBE49F19B66C53006B7D81 /* WebInspectorUIMessages.h */; };
     444                1CF18F3F26BB5D95004B1722 /* LogInitialization.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1CF18F3E26BB5D90004B1722 /* LogInitialization.cpp */; };
    444445                1D4D737023A9E54700717A25 /* RemoteMediaResourceManagerMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1D4D736B23A9DF5500717A25 /* RemoteMediaResourceManagerMessageReceiver.cpp */; };
    445446                1D4D737123A9E56200717A25 /* RemoteMediaResourceManagerMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D4D736C23A9DF6000717A25 /* RemoteMediaResourceManagerMessages.h */; };
     
    30503051                1CBBE49E19B66C53006B7D81 /* WebInspectorUIMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WebInspectorUIMessageReceiver.cpp; path = DerivedSources/WebKit2/WebInspectorUIMessageReceiver.cpp; sourceTree = BUILT_PRODUCTS_DIR; };
    30513052                1CBBE49F19B66C53006B7D81 /* WebInspectorUIMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebInspectorUIMessages.h; path = DerivedSources/WebKit2/WebInspectorUIMessages.h; sourceTree = BUILT_PRODUCTS_DIR; };
     3053                1CF18F3E26BB5D90004B1722 /* LogInitialization.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = LogInitialization.cpp; sourceTree = "<group>"; };
    30523054                1D0530C9258EAB4400E436F7 /* combine-feature-flags-plist.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = "combine-feature-flags-plist.py"; sourceTree = "<group>"; };
    30533055                1D0530D1259162C800E436F7 /* WebKit-ios.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "WebKit-ios.plist"; sourceTree = "<group>"; };
     
    60016003                F40D1B68220BDC0F00B49A01 /* WebAutocorrectionContext.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = WebAutocorrectionContext.h; path = ios/WebAutocorrectionContext.h; sourceTree = "<group>"; };
    60026004                F41056612130699A0092281D /* APIAttachmentCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = APIAttachmentCocoa.mm; sourceTree = "<group>"; };
    6003                 F414CE2A269DDED100BD216A /* GPUProcessCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = GPUProcessCocoa.mm; path = cocoa/GPUProcessCocoa.mm; sourceTree = "<group>"; };
    60046005                F414CE2C269DE6EA00BD216A /* RemoteRenderingBackendState.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RemoteRenderingBackendState.h; sourceTree = "<group>"; };
    60056006                F42D633F22A0EFD300D2FB3A /* WebAutocorrectionData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebAutocorrectionData.h; path = ios/WebAutocorrectionData.h; sourceTree = "<group>"; };
     
    1069810699                                51A7F2F4125BF8D4008AEB1D /* Logging.cpp */,
    1069910700                                51A7F2F2125BF820008AEB1D /* Logging.h */,
     10701                                1CF18F3E26BB5D90004B1722 /* LogInitialization.cpp */,
    1070010702                                0FDCD7F61D47E92A009F08BC /* LogInitialization.h */,
    1070110703                                C0E3AA451209E2BA00A49D01 /* Module.cpp */,
     
    1171511717                        );
    1171611718                        path = cache;
    11717                         sourceTree = "<group>";
    11718                 };
    11719                 F414CE27269DDE8000BD216A /* cocoa */ = {
    11720                         isa = PBXGroup;
    11721                         children = (
    11722                                 F414CE2A269DDED100BD216A /* GPUProcessCocoa.mm */,
    11723                         );
    11724                         name = cocoa;
    1172511719                        sourceTree = "<group>";
    1172611720                };
     
    1423614230                                449D90DA21FDC30B00F677C0 /* LocalAuthenticationSoftLink.mm in Sources */,
    1423714231                                2D92A779212B6A6100F493FD /* Logging.cpp in Sources */,
     14232                                1CF18F3F26BB5D95004B1722 /* LogInitialization.cpp in Sources */,
    1423814233                                07E19EFB23D401F10094FFB4 /* MediaPlayerPrivateRemoteMessageReceiver.cpp in Sources */,
    1423914234                                1DF29E64257F37A3003C28AF /* MediaSourcePrivateRemoteMessageReceiver.cpp in Sources */,
  • trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm

    r280757 r280758  
    282282
    283283#if !LOG_DISABLED || !RELEASE_LOG_DISABLED
    284     WebCore::initializeLogChannelsIfNecessary(parameters.webCoreLoggingChannels);
    285     WebKit::initializeLogChannelsIfNecessary(parameters.webKitLoggingChannels);
     284    WebCore::logChannels().initializeLogChannelsIfNecessary(parameters.webCoreLoggingChannels);
     285    WebKit::logChannels().initializeLogChannelsIfNecessary(parameters.webKitLoggingChannels);
    286286#endif
    287287
  • trunk/Source/WebKitLegacy/ChangeLog

    r280757 r280758  
     12021-08-07  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        Deduplicate logging channel algorithms
     4        https://bugs.webkit.org/show_bug.cgi?id=228809
     5
     6        Reviewed by Fujii Hironori.
     7
     8        * WebKitLegacy.xcodeproj/project.pbxproj:
     9
    1102021-08-07  Commit Queue  <commit-queue@webkit.org>
    211
  • trunk/Source/WebKitLegacy/WebKitLegacy.xcodeproj/project.pbxproj

    r280757 r280758  
    112112                1C7B0C660EB2464D00A28502 /* WebInspectorClientCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C7B0C650EB2464D00A28502 /* WebInspectorClientCF.cpp */; };
    113113                1C8CB07A0AE9830C00B1F6E9 /* WebEditingDelegatePrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C8CB0790AE9830C00B1F6E9 /* WebEditingDelegatePrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
     114                1CF18F4126BB71B7004B1722 /* WebKitLogInitialization.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1CF18F4026BB71B7004B1722 /* WebKitLogInitialization.mm */; };
    114115                22F219CC08D236730030E078 /* WebBackForwardListPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 22F219CB08D236730030E078 /* WebBackForwardListPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
    115116                29AEF960134C76FB00FE5096 /* OutlookQuirksUserScript.js in Resources */ = {isa = PBXBuildFile; fileRef = 29AEF95D134C755400FE5096 /* OutlookQuirksUserScript.js */; };
     
    832833                1C904FD40BA9DD0F0081E9D0 /* DebugRelease.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = DebugRelease.xcconfig; sourceTree = "<group>"; };
    833834                1C904FD50BA9DD0F0081E9D0 /* Base.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Base.xcconfig; sourceTree = "<group>"; };
     835                1CF18F4026BB71B7004B1722 /* WebKitLogInitialization.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WebKitLogInitialization.mm; sourceTree = "<group>"; };
     836                1CF18F4226BB71D3004B1722 /* WebKitLogInitialization.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebKitLogInitialization.h; sourceTree = "<group>"; };
    834837                22F219CB08D236730030E078 /* WebBackForwardListPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = WebBackForwardListPrivate.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
    835838                2568C72C0174912D0ECA149E /* WebKit.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = WebKit.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
     
    17881791                                93AEB17D032C1735008635CE /* WebKitLogging.h */,
    17891792                                93AEB17E032C1735008635CE /* WebKitLogging.m */,
     1793                                1CF18F4226BB71D3004B1722 /* WebKitLogInitialization.h */,
     1794                                1CF18F4026BB71B7004B1722 /* WebKitLogInitialization.mm */,
    17901795                                7082F56F038EADAA00A80180 /* WebKitNSStringExtras.h */,
    17911796                                7082F570038EADAA00A80180 /* WebKitNSStringExtras.mm */,
     
    36523657                                CD8BFCE715531224005AFB25 /* WebKitFullScreenListener.mm in Sources */,
    36533658                                939810C30824BF01008DF038 /* WebKitLogging.m in Sources */,
     3659                                1CF18F4126BB71B7004B1722 /* WebKitLogInitialization.mm in Sources */,
    36543660                                939810C40824BF01008DF038 /* WebKitNSStringExtras.mm in Sources */,
    36553661                                1AAF5D0F0EDDE7A7008D883D /* WebKitPluginAgent.defs in Sources */,
  • trunk/Source/WebKitLegacy/mac/ChangeLog

    r280757 r280758  
     12021-08-07  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        Deduplicate logging channel algorithms
     4        https://bugs.webkit.org/show_bug.cgi?id=228809
     5
     6        Reviewed by Fujii Hironori.
     7
     8        * Misc/WebKitLogInitialization.h: Copied from Source/WebKit/Platform/LogInitialization.h.
     9        * Misc/WebKitLogInitialization.mm: Copied from Source/WebKitLegacy/mac/Misc/WebKitLogging.m.
     10        (WebKit::logChannels):
     11        (ReportDiscardedDelegateException):
     12        * Misc/WebKitLogging.h:
     13        * Misc/WebKitLogging.m:
     14        (ReportDiscardedDelegateException): Deleted.
     15        * WebCoreSupport/WebDragClient.mm:
     16        * WebView/WebDelegateImplementationCaching.mm:
     17        * WebView/WebView.mm:
     18        (-[WebView _commonInitializationWithFrameName:groupName:]):
     19
    1202021-08-07  Commit Queue  <commit-queue@webkit.org>
    221
  • trunk/Source/WebKitLegacy/mac/Misc/WebKitLogInitialization.h

    r280757 r280758  
    11/*
    2  * Copyright (C) 2010, 2013, 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2626#pragma once
    2727
     28#include <wtf/LogChannels.h>
    2829#include <wtf/text/WTFString.h>
     30
     31namespace WebKit {
    2932
    3033#if !LOG_DISABLED || !RELEASE_LOG_DISABLED
    3134
    32 namespace WebKit {
     35WTF::LogChannels& logChannels();
    3336
    34 void initializeLogChannelsIfNecessary(std::optional<String> = std::nullopt);
    35 String logLevelString();
     37#endif // !LOG_DISABLED || !RELEASE_LOG_DISABLED
     38
     39WTFLogChannel* getLogChannel(const String& name);
    3640
    3741} // namespace WebKit
    3842
    39 #endif // !LOG_DISABLED || !RELEASE_LOG_DISABLED
     43void ReportDiscardedDelegateException(SEL delegateSelector, id exception);
  • trunk/Source/WebKitLegacy/mac/Misc/WebKitLogInitialization.mm

    r280757 r280758  
    11/*
    2  * Copyright (C) 2005, 2007, 2013 Apple Inc. All rights reserved.
     2 * Copyright (C) 2005-2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    77 *
    88 * 1.  Redistributions of source code must retain the above copyright
    9  *     notice, this list of conditions and the following disclaimer. 
     9 *     notice, this list of conditions and the following disclaimer.
    1010 * 2.  Redistributions in binary form must reproduce the above copyright
    1111 *     notice, this list of conditions and the following disclaimer in the
    12  *     documentation and/or other materials provided with the distribution. 
     12 *     documentation and/or other materials provided with the distribution.
    1313 * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
    1414 *     its contributors may be used to endorse or promote products derived
    15  *     from this software without specific prior written permission. 
     15 *     from this software without specific prior written permission.
    1616 *
    1717 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
     
    2727 */
    2828
    29 #import "WebKitLogging.h"
     29#include "WebKitLogInitialization.h"
     30
     31#include "WebKitLogging.h"
     32#include <wtf/text/CString.h>
     33
     34namespace WebKit {
    3035
    3136#if !LOG_DISABLED || !RELEASE_LOG_DISABLED
    3237
    33 #define DEFINE_WEBKIT_LOG_CHANNEL(name) DEFINE_LOG_CHANNEL(name, LOG_CHANNEL_WEBKIT_SUBSYSTEM)
    34 WEBKIT_LOG_CHANNELS(DEFINE_WEBKIT_LOG_CHANNEL)
     38class LogChannels final : public WTF::LogChannels {
     39public:
     40    LogChannels()
     41    {
     42        m_logChannels = {
     43            WEBKIT_LOG_CHANNELS(LOG_CHANNEL_ADDRESS)
     44        };
     45    }
    3546
    36 static WTFLogChannel* logChannels[] = {
    37     WEBKIT_LOG_CHANNELS(LOG_CHANNEL_ADDRESS)
     47private:
     48    String logLevelString() final
     49    {
     50        static NSString * const defaultsDomain = @"WebKitLogging";
     51        return [[NSUserDefaults standardUserDefaults] stringForKey:defaultsDomain];
     52    }
    3853};
    3954
    40 static const size_t logChannelCount = sizeof(logChannels) / sizeof(logChannels[0]);
    41 
    42 
    43 static NSString * const defaultsDomain = @"WebKitLogging";
    44 
    45 void WebKitInitializeLogChannelsIfNecessary()
     55WTF::LogChannels& logChannels()
    4656{
    47     static bool haveInitializedLoggingChannels = false;
    48     if (haveInitializedLoggingChannels)
    49         return;
    50     haveInitializedLoggingChannels = true;
    51 
    52     NSString *logLevel = [[NSUserDefaults standardUserDefaults] stringForKey:defaultsDomain];
    53     if (!logLevel)
    54         return;
    55    
    56     WTFInitializeLogChannelStatesFromString(logChannels, logChannelCount, [logLevel UTF8String]);
     57    static NeverDestroyed<LogChannels> logChannels;
     58    return logChannels.get();
    5759}
    5860
    5961#endif // !LOG_DISABLED || !RELEASE_LOG_DISABLED
    6062
     63} // namespace WebKit
     64
    6165void ReportDiscardedDelegateException(SEL delegateSelector, id exception)
    6266{
    63     if ([exception isKindOfClass:[NSException class]])
     67    if ([exception isKindOfClass:[NSException class]]) {
    6468        NSLog(@"*** WebKit discarded an uncaught exception in the %s delegate: <%@> %@",
    6569            sel_getName(delegateSelector), [exception name], [exception reason]);
    66     else
     70    } else {
    6771        NSLog(@"*** WebKit discarded an uncaught exception in the %s delegate: %@",
    6872            sel_getName(delegateSelector), exception);
     73    }
    6974}
  • trunk/Source/WebKitLegacy/mac/Misc/WebKitLogging.h

    r280757 r280758  
    11/*
    2  * Copyright (C) 2005, 2007, 2008, 2013 Apple Inc. All rights reserved.
     2 * Copyright (C) 2005-2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    6969#undef DECLARE_LOG_CHANNEL
    7070
    71 void WebKitInitializeLogChannelsIfNecessary(void);
    7271#endif // !LOG_DISABLED || !RELEASE_LOG_DISABLED
    73 
    74 void ReportDiscardedDelegateException(SEL delegateSelector, id exception);
    7572
    7673#ifdef __cplusplus
  • trunk/Source/WebKitLegacy/mac/Misc/WebKitLogging.m

    r280757 r280758  
    3434WEBKIT_LOG_CHANNELS(DEFINE_WEBKIT_LOG_CHANNEL)
    3535
    36 static WTFLogChannel* logChannels[] = {
    37     WEBKIT_LOG_CHANNELS(LOG_CHANNEL_ADDRESS)
    38 };
    39 
    40 static const size_t logChannelCount = sizeof(logChannels) / sizeof(logChannels[0]);
    41 
    42 
    43 static NSString * const defaultsDomain = @"WebKitLogging";
    44 
    45 void WebKitInitializeLogChannelsIfNecessary()
    46 {
    47     static bool haveInitializedLoggingChannels = false;
    48     if (haveInitializedLoggingChannels)
    49         return;
    50     haveInitializedLoggingChannels = true;
    51 
    52     NSString *logLevel = [[NSUserDefaults standardUserDefaults] stringForKey:defaultsDomain];
    53     if (!logLevel)
    54         return;
    55    
    56     WTFInitializeLogChannelStatesFromString(logChannels, logChannelCount, [logLevel UTF8String]);
    57 }
    58 
    5936#endif // !LOG_DISABLED || !RELEASE_LOG_DISABLED
    60 
    61 void ReportDiscardedDelegateException(SEL delegateSelector, id exception)
    62 {
    63     if ([exception isKindOfClass:[NSException class]])
    64         NSLog(@"*** WebKit discarded an uncaught exception in the %s delegate: <%@> %@",
    65             sel_getName(delegateSelector), [exception name], [exception reason]);
    66     else
    67         NSLog(@"*** WebKit discarded an uncaught exception in the %s delegate: %@",
    68             sel_getName(delegateSelector), exception);
    69 }
  • trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebDragClient.mm

    r280757 r280758  
    3535#import "WebFrameView.h"
    3636#import "WebHTMLViewInternal.h"
     37#import "WebKitLogInitialization.h"
    3738#import "WebKitLogging.h"
    3839#import "WebKitNSStringExtras.h"
  • trunk/Source/WebKitLegacy/mac/WebView/WebDelegateImplementationCaching.mm

    r280757 r280758  
    11/*
    2  * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
     2 * Copyright (C) 2005-2021 Apple Inc. All rights reserved.
    33 * Copyright (C) 2006 David Smith (catfish.man@gmail.com)
    44 *
     
    3030#import "WebDelegateImplementationCaching.h"
    3131
     32#import "WebKitLogInitialization.h"
    3233#import "WebKitLogging.h"
    3334#import "WebView.h"
  • trunk/Source/WebKitLegacy/mac/WebView/WebView.mm

    r280757 r280758  
    8282#import "WebKitErrors.h"
    8383#import "WebKitFullScreenListener.h"
     84#import "WebKitLogInitialization.h"
    8485#import "WebKitLogging.h"
    8586#import "WebKitNSStringExtras.h"
     
    14811482    if (!didOneTimeInitialization) {
    14821483#if !LOG_DISABLED || !RELEASE_LOG_DISABLED
    1483         WebKitInitializeLogChannelsIfNecessary();
    1484         WebCore::initializeLogChannelsIfNecessary();
     1484        WebCore::logChannels().initializeLogChannelsIfNecessary();
     1485        WebKit::logChannels().initializeLogChannelsIfNecessary();
    14851486#endif
    14861487
Note: See TracChangeset for help on using the changeset viewer.