diff options
Diffstat (limited to 'Source/WebCore/loader/ProgressTracker.cpp')
-rw-r--r-- | Source/WebCore/loader/ProgressTracker.cpp | 39 |
1 files changed, 17 insertions, 22 deletions
diff --git a/Source/WebCore/loader/ProgressTracker.cpp b/Source/WebCore/loader/ProgressTracker.cpp index 291c13643..fe0c7229e 100644 --- a/Source/WebCore/loader/ProgressTracker.cpp +++ b/Source/WebCore/loader/ProgressTracker.cpp @@ -10,10 +10,10 @@ * 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 COMPUTER, INC. ``AS IS'' AND ANY + * 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 COMPUTER, INC. OR + * 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 @@ -60,6 +60,8 @@ static const unsigned loadStalledHeartbeatCount = 4; // How many bytes are required between heartbeats to consider it progress. static const unsigned minumumBytesPerHeartbeatForProgress = 1024; +static const auto progressNotificationTimeInterval = 200ms; + struct ProgressItem { WTF_MAKE_NONCOPYABLE(ProgressItem); WTF_MAKE_FAST_ALLOCATED; public: @@ -80,16 +82,12 @@ ProgressTracker::ProgressTracker(ProgressTrackerClient& client) , m_totalPageAndResourceBytesToLoad(0) , m_totalBytesReceived(0) , m_lastNotifiedProgressValue(0) - , m_lastNotifiedProgressTime(0) - , m_progressNotificationInterval(0.02) - , m_progressNotificationTimeInterval(0.1) , m_finalProgressChangedSent(false) , m_progressValue(0) , m_numProgressTrackedFrames(0) - , m_progressHeartbeatTimer(this, &ProgressTracker::progressHeartbeatTimerFired) + , m_progressHeartbeatTimer(*this, &ProgressTracker::progressHeartbeatTimerFired) , m_heartbeatsWithNoProgress(0) , m_totalBytesReceivedBeforePreviousHeartbeat(0) - , m_mainLoadCompletionTimeStamp(0) , m_isMainLoad(false) { } @@ -112,10 +110,10 @@ void ProgressTracker::reset() m_totalBytesReceived = 0; m_progressValue = 0; m_lastNotifiedProgressValue = 0; - m_lastNotifiedProgressTime = 0; + m_lastNotifiedProgressTime = std::chrono::steady_clock::time_point(); m_finalProgressChangedSent = false; m_numProgressTrackedFrames = 0; - m_originatingProgressFrame = 0; + m_originatingProgressFrame = nullptr; m_heartbeatsWithNoProgress = 0; m_totalBytesReceivedBeforePreviousHeartbeat = 0; @@ -137,9 +135,9 @@ void ProgressTracker::progressStarted(Frame& frame) m_originatingProgressFrame->loader().loadProgressingStatusChanged(); bool isMainFrame = !m_originatingProgressFrame->tree().parent(); - double elapsedTimeSinceMainLoadComplete = monotonicallyIncreasingTime() - m_mainLoadCompletionTimeStamp; + auto elapsedTimeSinceMainLoadComplete = std::chrono::steady_clock::now() - m_mainLoadCompletionTime; - static const double subframePartOfMainLoadThreshold = 1; + static const auto subframePartOfMainLoadThreshold = 1s; m_isMainLoad = isMainFrame || elapsedTimeSinceMainLoadComplete < subframePartOfMainLoadThreshold; m_client.progressStarted(*m_originatingProgressFrame); @@ -170,7 +168,7 @@ void ProgressTracker::finalProgressComplete() { LOG(Progress, "Final progress complete (%p)", this); - RefPtr<Frame> frame = m_originatingProgressFrame.release(); + auto frame = WTFMove(m_originatingProgressFrame); // Before resetting progress value be sure to send client a least one notification // with final progress value. @@ -182,7 +180,7 @@ void ProgressTracker::finalProgressComplete() reset(); if (m_isMainLoad) - m_mainLoadCompletionTimeStamp = monotonicallyIncreasingTime(); + m_mainLoadCompletionTime = std::chrono::steady_clock::now(); frame->loader().client().setMainFrameDocumentReady(true); m_client.progressFinished(*frame); @@ -236,7 +234,7 @@ void ProgressTracker::incrementProgress(unsigned long identifier, unsigned bytes } int numPendingOrLoadingRequests = frame->loader().numPendingOrLoadingRequests(true); - estimatedBytesForPendingRequests = progressItemDefaultEstimatedLength * numPendingOrLoadingRequests; + estimatedBytesForPendingRequests = static_cast<long long>(progressItemDefaultEstimatedLength) * numPendingOrLoadingRequests; remainingBytes = ((m_totalPageAndResourceBytesToLoad + estimatedBytesForPendingRequests) - m_totalBytesReceived); if (remainingBytes > 0) // Prevent divide by 0. percentOfRemainingBytes = (double)bytesReceived / (double)remainingBytes; @@ -246,7 +244,7 @@ void ProgressTracker::incrementProgress(unsigned long identifier, unsigned bytes // For documents that use WebCore's layout system, treat first layout as the half-way point. // FIXME: The hasHTMLView function is a sort of roundabout way of asking "do you use WebCore's layout system". bool useClampedMaxProgress = frame->loader().client().hasHTMLView() - && !frame->loader().stateMachine()->firstLayoutDone(); + && !frame->loader().stateMachine().firstLayoutDone(); double maxProgressValue = useClampedMaxProgress ? 0.5 : finalProgressValue; increment = (maxProgressValue - m_progressValue) * percentOfRemainingBytes; m_progressValue += increment; @@ -255,14 +253,11 @@ void ProgressTracker::incrementProgress(unsigned long identifier, unsigned bytes m_totalBytesReceived += bytesReceived; - double now = monotonicallyIncreasingTime(); - double notifiedProgressTimeDelta = now - m_lastNotifiedProgressTime; + auto now = std::chrono::steady_clock::now(); + auto notifiedProgressTimeDelta = now - m_lastNotifiedProgressTime; LOG(Progress, "Progress incremented (%p) - value %f, tracked frames %d", this, m_progressValue, m_numProgressTrackedFrames); - double notificationProgressDelta = m_progressValue - m_lastNotifiedProgressValue; - if ((notificationProgressDelta >= m_progressNotificationInterval || - notifiedProgressTimeDelta >= m_progressNotificationTimeInterval) && - m_numProgressTrackedFrames > 0) { + if ((notifiedProgressTimeDelta >= progressNotificationTimeInterval || m_progressValue == 1) && m_numProgressTrackedFrames > 0) { if (!m_finalProgressChangedSent) { if (m_progressValue == 1) m_finalProgressChangedSent = true; @@ -310,7 +305,7 @@ bool ProgressTracker::isMainLoadProgressing() const return m_progressValue && m_progressValue < finalProgressValue && m_heartbeatsWithNoProgress < loadStalledHeartbeatCount; } -void ProgressTracker::progressHeartbeatTimerFired(Timer<ProgressTracker>&) +void ProgressTracker::progressHeartbeatTimerFired() { if (m_totalBytesReceived < m_totalBytesReceivedBeforePreviousHeartbeat + minumumBytesPerHeartbeatForProgress) ++m_heartbeatsWithNoProgress; |