Changeset 206875 in webkit


Ignore:
Timestamp:
Oct 6, 2016 12:45:52 PM (8 years ago)
Author:
BJ Burg
Message:

Web Inspector: RemoteInspector should cache client capabilities for off-main thread usage
https://bugs.webkit.org/show_bug.cgi?id=163039
<rdar://problem/28571460>

Reviewed by Timothy Hatcher.

The fix in r206797 was incorrect because listings are always pushed out on the XPC connection queue.
Instead of delaying the listing needlessly, RemoteInspector should cache the capabilities of its
client while on the main thread, then use the cached struct data on the XPC connection queue rather
than directly accessing m_client. This is similar to how RemoteConnectionToTarget marshalls listing
information from arbitrary queues into m_targetListingMap, which can then be read from any queue.

  • inspector/remote/RemoteInspector.h:
  • inspector/remote/RemoteInspector.mm:

(Inspector::RemoteInspector::updateClientCapabilities): Cache the capabilities.
(Inspector::RemoteInspector::setRemoteInspectorClient):
Re-cache the capabilities. Scope the lock to avoid reentrant locking.

(Inspector::RemoteInspector::clientCapabilitiesDidChange): Cache the capabilities.
(Inspector::RemoteInspector::pushListingsNow): Use cached client capabilities.
(Inspector::RemoteInspector::receivedGetListingMessage): Revert the change in r206797.
(Inspector::RemoteInspector::receivedAutomationSessionRequestMessage):

Location:
trunk/Source/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r206870 r206875  
     12016-10-06  Brian Burg  <bburg@apple.com>
     2
     3        Web Inspector: RemoteInspector should cache client capabilities for off-main thread usage
     4        https://bugs.webkit.org/show_bug.cgi?id=163039
     5        <rdar://problem/28571460>
     6
     7        Reviewed by Timothy Hatcher.
     8
     9        The fix in r206797 was incorrect because listings are always pushed out on the XPC connection queue.
     10        Instead of delaying the listing needlessly, RemoteInspector should cache the capabilities of its
     11        client while on the main thread, then use the cached struct data on the XPC connection queue rather
     12        than directly accessing m_client. This is similar to how RemoteConnectionToTarget marshalls listing
     13        information from arbitrary queues into m_targetListingMap, which can then be read from any queue.
     14
     15        * inspector/remote/RemoteInspector.h:
     16        * inspector/remote/RemoteInspector.mm:
     17        (Inspector::RemoteInspector::updateClientCapabilities): Cache the capabilities.
     18        (Inspector::RemoteInspector::setRemoteInspectorClient):
     19        Re-cache the capabilities. Scope the lock to avoid reentrant locking.
     20
     21        (Inspector::RemoteInspector::clientCapabilitiesDidChange): Cache the capabilities.
     22        (Inspector::RemoteInspector::pushListingsNow): Use cached client capabilities.
     23        (Inspector::RemoteInspector::receivedGetListingMessage): Revert the change in r206797.
     24        (Inspector::RemoteInspector::receivedAutomationSessionRequestMessage):
     25
    1262016-10-06  Yusuke Suzuki  <utatane.tea@gmail.com>
    227
  • trunk/Source/JavaScriptCore/inspector/remote/RemoteInspector.h

    r204479 r206875  
    4949    class Client {
    5050    public:
     51        struct Capabilities {
     52            bool remoteAutomationAllowed : 1;
     53        };
     54
    5155        virtual ~Client() { }
    5256        virtual bool remoteAutomationAllowed() const = 0;
     
    6367    void sendMessageToRemote(unsigned targetIdentifier, const String& message);
    6468
    65     void updateAutomaticInspectionCandidate(RemoteInspectionTarget*);
    6669    void setRemoteInspectorClient(RemoteInspector::Client*);
     70    void clientCapabilitiesDidChange();
    6771
    6872    void setupFailed(unsigned targetIdentifier);
    6973    void setupCompleted(unsigned targetIdentifier);
    7074    bool waitingForAutomaticInspection(unsigned targetIdentifier);
    71     void clientCapabilitiesDidChange() { pushListingsSoon(); }
     75    void updateAutomaticInspectionCandidate(RemoteInspectionTarget*);
    7276
    7377    bool enabled() const { return m_enabled; }
     
    100104
    101105    void updateHasActiveDebugSession();
     106    void updateClientCapabilities();
    102107
    103108    void sendAutomaticInspectionCandidateMessage();
     
    133138
    134139    RemoteInspector::Client* m_client { nullptr };
     140    Optional<RemoteInspector::Client::Capabilities> m_clientCapabilities;
    135141
    136142    dispatch_queue_t m_xpcQueue;
  • trunk/Source/JavaScriptCore/inspector/remote/RemoteInspector.mm

    r206797 r206875  
    250250}
    251251
     252void RemoteInspector::updateClientCapabilities()
     253{
     254    ASSERT(isMainThread());
     255
     256    std::lock_guard<Lock> lock(m_mutex);
     257
     258    if (!m_client)
     259        m_clientCapabilities = Nullopt;
     260    else {
     261        RemoteInspector::Client::Capabilities updatedCapabilities = {
     262            m_client->remoteAutomationAllowed() // remoteAutomationAllowed
     263        };
     264
     265        m_clientCapabilities = updatedCapabilities;
     266    }
     267}
     268
    252269void RemoteInspector::setRemoteInspectorClient(RemoteInspector::Client* client)
    253270{
     
    255272    ASSERT(!m_client);
    256273
    257     std::lock_guard<Lock> lock(m_mutex);
    258     m_client = client;
     274    {
     275        std::lock_guard<Lock> lock(m_mutex);
     276        m_client = client;
     277    }
    259278
    260279    // Send an updated listing that includes whether the client allows remote automation.
     280    updateClientCapabilities();
    261281    pushListingsSoon();
    262282}
     
    320340    // We don't take the lock to check this because we assume it will be checked repeatedly.
    321341    return m_automaticInspectionPaused;
     342}
     343
     344void RemoteInspector::clientCapabilitiesDidChange()
     345{
     346    updateClientCapabilities();
     347    pushListingsSoon();
    322348}
    323349
     
    568594    [message setObject:listings.get() forKey:WIRListingKey];
    569595
    570     BOOL isAllowed = m_client && m_client->remoteAutomationAllowed();
     596    BOOL isAllowed = m_clientCapabilities && m_clientCapabilities->remoteAutomationAllowed;
    571597    [message setObject:@(isAllowed) forKey:WIRRemoteAutomationEnabledKey];
    572598
     
    697723void RemoteInspector::receivedGetListingMessage(NSDictionary *)
    698724{
    699     pushListingsSoon();
     725    pushListingsNow();
    700726}
    701727
     
    795821        return;
    796822
    797     if (!m_client->remoteAutomationAllowed())
     823    if (!m_clientCapabilities || !m_clientCapabilities->remoteAutomationAllowed)
    798824        return;
    799825
Note: See TracChangeset for help on using the changeset viewer.