Commit 67a028be authored by timothy@apple.com's avatar timothy@apple.com
Browse files

Make the defered data loading timer honor the Page's scheduled runloop pairs.

        Introduces a new RunLoopTimer class that has an API mimicking Timer but
        allows it to be scheduled with one or more SchedulePairs.

        <rdar://problem/6687342> -[WebView scheduleInRunLoop:forMode:] has no affect on timers

        Reviewed by Darin Adler.

        * WebCore.xcodeproj/project.pbxproj: Adds the new RunLoopTimer.{cpp,h} files.
        * loader/MainResourceLoader.cpp:
        (WebCore::MainResourceLoader::handleDataLoadNow): Use the MainResourceLoaderTimer typedef.
        (WebCore::MainResourceLoader::startDataLoadTimer): Added. Start the timer and on
        Mac platforms also schedule with the Page's SchedulePairs.
        (WebCore::MainResourceLoader::handleDataLoadSoon): Call startDataLoadTimer().
        (WebCore::MainResourceLoader::setDefersLoading): Ditto.
        * loader/MainResourceLoader.h:
        * platform/cf/RunLoopTimerCF.cpp: Added.
        (WebCore::RunLoopTimerBase::~RunLoopTimerBase):
        (WebCore::timerFired):
        (WebCore::RunLoopTimerBase::start):
        (WebCore::RunLoopTimerBase::schedule):
        (WebCore::RunLoopTimerBase::stop):
        (WebCore::RunLoopTimerBase::isActive):
        * platform/RunLoopTimer.h: Added.
        (WebCore::RunLoopTimerBase::RunLoopTimerBase):
        (WebCore::RunLoopTimerBase::startRepeating):
        (WebCore::RunLoopTimerBase::startOneShot):
        (WebCore::RunLoopTimer::RunLoopTimer):
        (WebCore::RunLoopTimer::fired):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@41845 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 1ee94e08
2009-03-19 Timothy Hatcher <timothy@apple.com>
<rdar://problem/6687342> -[WebView scheduleInRunLoop:forMode:] has no affect on timers
Reviewed by Darin Adler.
* wtf/Platform.h: Added HAVE_RUNLOOP_TIMER for PLATFORM(MAC).
2009-03-19 Geoffrey Garen <ggaren@apple.com>
 
Reviewed by Sam Weinig.
......@@ -311,6 +311,7 @@
#define ENABLE_DASHBOARD_SUPPORT 1
#endif
#define HAVE_READLINE 1
#define HAVE_RUNLOOP_TIMER 1
#endif
#if PLATFORM(CHROMIUM) && PLATFORM(DARWIN)
......
2009-03-18 Timothy Hatcher <timothy@apple.com>
Make the defered data loading timer honor the Page's scheduled runloop pairs.
Introduces a new RunLoopTimer class that has an API mimicking Timer but
allows it to be scheduled with one or more SchedulePairs.
<rdar://problem/6687342> -[WebView scheduleInRunLoop:forMode:] has no affect on timers
Reviewed by Darin Adler.
* WebCore.xcodeproj/project.pbxproj: Adds the new RunLoopTimer.{cpp,h} files.
* loader/MainResourceLoader.cpp:
(WebCore::MainResourceLoader::handleDataLoadNow): Use the MainResourceLoaderTimer typedef.
(WebCore::MainResourceLoader::startDataLoadTimer): Added. Start the timer and on
Mac platforms also schedule with the Page's SchedulePairs.
(WebCore::MainResourceLoader::handleDataLoadSoon): Call startDataLoadTimer().
(WebCore::MainResourceLoader::setDefersLoading): Ditto.
* loader/MainResourceLoader.h:
* platform/cf/RunLoopTimerCF.cpp: Added.
(WebCore::RunLoopTimerBase::~RunLoopTimerBase):
(WebCore::timerFired):
(WebCore::RunLoopTimerBase::start):
(WebCore::RunLoopTimerBase::schedule):
(WebCore::RunLoopTimerBase::stop):
(WebCore::RunLoopTimerBase::isActive):
* platform/RunLoopTimer.h: Added.
(WebCore::RunLoopTimerBase::RunLoopTimerBase):
(WebCore::RunLoopTimerBase::startRepeating):
(WebCore::RunLoopTimerBase::startOneShot):
(WebCore::RunLoopTimer::RunLoopTimer):
(WebCore::RunLoopTimer::fired):
2009-03-19 Dimitri Glazkov <dglazkov@chromium.org>
 
Reviewed by Darin Fisher.
......@@ -480,6 +480,8 @@
1C5FAED10DCFD90100D58F78 /* JSJavaScriptCallFrame.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C5FAECF0DCFD90100D58F78 /* JSJavaScriptCallFrame.cpp */; };
1C5FAED20DCFD90100D58F78 /* JSJavaScriptCallFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C5FAED00DCFD90100D58F78 /* JSJavaScriptCallFrame.h */; };
1C5FAEE70DCFDA6800D58F78 /* JSJavaScriptCallFrameCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C5FAEE60DCFDA6800D58F78 /* JSJavaScriptCallFrameCustom.cpp */; };
1C63A2480F71646600C09D5A /* RunLoopTimer.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C63A2460F71646600C09D5A /* RunLoopTimer.h */; };
1C63A2490F71646600C09D5A /* RunLoopTimerCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C63A2470F71646600C09D5A /* RunLoopTimerCF.cpp */; };
1C81B95A0E97330800266E07 /* InspectorController.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C81B9560E97330800266E07 /* InspectorController.h */; settings = {ATTRIBUTES = (Private, ); }; };
1C81B95B0E97330800266E07 /* InspectorController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C81B9570E97330800266E07 /* InspectorController.cpp */; };
1C81B95C0E97330800266E07 /* InspectorClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C81B9580E97330800266E07 /* InspectorClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
......@@ -5430,6 +5432,8 @@
1C5FAECF0DCFD90100D58F78 /* JSJavaScriptCallFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSJavaScriptCallFrame.cpp; sourceTree = "<group>"; };
1C5FAED00DCFD90100D58F78 /* JSJavaScriptCallFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSJavaScriptCallFrame.h; sourceTree = "<group>"; };
1C5FAEE60DCFDA6800D58F78 /* JSJavaScriptCallFrameCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSJavaScriptCallFrameCustom.cpp; sourceTree = "<group>"; };
1C63A2460F71646600C09D5A /* RunLoopTimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RunLoopTimer.h; sourceTree = "<group>"; };
1C63A2470F71646600C09D5A /* RunLoopTimerCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RunLoopTimerCF.cpp; sourceTree = "<group>"; };
1C81B9560E97330800266E07 /* InspectorController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorController.h; sourceTree = "<group>"; };
1C81B9570E97330800266E07 /* InspectorController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorController.cpp; sourceTree = "<group>"; };
1C81B9580E97330800266E07 /* InspectorClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorClient.h; sourceTree = "<group>"; };
......@@ -9664,6 +9668,7 @@
children = (
5160306B0CC4362300C8AC25 /* FileSystemCF.cpp */,
1A98956A0AA78F80005EF5EF /* KURLCFNet.cpp */,
1C63A2470F71646600C09D5A /* RunLoopTimerCF.cpp */,
1CEFC9B80D78DC8C007D2579 /* SchedulePair.cpp */,
1CEFC9B70D78DC8C007D2579 /* SchedulePair.h */,
512DD8E20D91E2B4000F89EE /* SharedBufferCF.cpp */,
......@@ -13888,6 +13893,7 @@
ABC128760B33AA6D00C693D5 /* PopupMenuClient.h */,
BC3BE12A0E98092F00835588 /* PopupMenuStyle.h */,
E4D687780ED7AE4F006EA978 /* PurgeableBuffer.h */,
1C63A2460F71646600C09D5A /* RunLoopTimer.h */,
F587866202DE3B1101EA4122 /* SSLKeyGenerator.h */,
93C09C850B0657AA005ABD4D /* ScrollTypes.h */,
BC2441C30E8B65D00055320F /* ScrollView.cpp */,
......@@ -16902,6 +16908,7 @@
A7D6B3490F61104500B79FD1 /* WorkerImportScriptsClient.h in Headers */,
FE6FD4880F676E5700092873 /* Coordinates.h in Headers */,
FE6FD48E0F676E9300092873 /* JSCoordinates.h in Headers */,
1C63A2480F71646600C09D5A /* RunLoopTimer.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -18905,6 +18912,7 @@
A7D6B34A0F61104500B79FD1 /* WorkerImportScriptsClient.cpp in Sources */,
FE6FD4870F676E5700092873 /* Coordinates.cpp in Sources */,
FE6FD48D0F676E9300092873 /* JSCoordinates.cpp in Sources */,
1C63A2490F71646600C09D5A /* RunLoopTimerCF.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -411,7 +411,7 @@ void MainResourceLoader::handleEmptyLoad(const KURL& url, bool forURLScheme)
didReceiveResponse(response);
}
void MainResourceLoader::handleDataLoadNow(Timer<MainResourceLoader>*)
void MainResourceLoader::handleDataLoadNow(MainResourceLoaderTimer*)
{
RefPtr<MainResourceLoader> protect(this);
......@@ -423,12 +423,22 @@ void MainResourceLoader::handleDataLoadNow(Timer<MainResourceLoader>*)
didReceiveResponse(response);
}
void MainResourceLoader::startDataLoadTimer()
{
m_dataLoadTimer.startOneShot(0);
#if HAVE(RUNLOOP_TIMER)
if (SchedulePairHashSet* scheduledPairs = m_frame->page()->scheduledRunLoopPairs())
m_dataLoadTimer.schedule(*scheduledPairs);
#endif
}
void MainResourceLoader::handleDataLoadSoon(ResourceRequest& r)
{
m_initialRequest = r;
if (m_documentLoader->deferMainResourceDataLoad())
m_dataLoadTimer.startOneShot(0);
startDataLoadTimer();
else
handleDataLoadNow(0);
}
......@@ -512,17 +522,16 @@ bool MainResourceLoader::load(const ResourceRequest& r, const SubstituteData& su
void MainResourceLoader::setDefersLoading(bool defers)
{
ResourceLoader::setDefersLoading(defers);
if (defers) {
if (m_dataLoadTimer.isActive())
m_dataLoadTimer.stop();
} else {
if (m_initialRequest.isNull())
return;
if (m_substituteData.isValid() &&
m_documentLoader->deferMainResourceDataLoad())
m_dataLoadTimer.startOneShot(0);
if (m_substituteData.isValid() && m_documentLoader->deferMainResourceDataLoad())
startDataLoadTimer();
else {
ResourceRequest r(m_initialRequest);
m_initialRequest = ResourceRequest();
......
......@@ -29,9 +29,14 @@
#include "FrameLoaderTypes.h"
#include "ResourceLoader.h"
#include "SubstituteData.h"
#include "Timer.h"
#include <wtf/Forward.h>
#if HAVE(RUNLOOP_TIMER)
#include "RunLoopTimer.h"
#else
#include "Timer.h"
#endif
namespace WebCore {
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
......@@ -56,7 +61,13 @@ namespace WebCore {
virtual void didFinishLoading();
virtual void didFail(const ResourceError&);
void handleDataLoadNow(Timer<MainResourceLoader>*);
#if HAVE(RUNLOOP_TIMER)
typedef RunLoopTimer<MainResourceLoader> MainResourceLoaderTimer;
#else
typedef Timer<MainResourceLoader> MainResourceLoaderTimer;
#endif
void handleDataLoadNow(MainResourceLoaderTimer*);
bool isLoadingMultipartContent() const { return m_loadingMultipartContent; }
......@@ -74,6 +85,7 @@ namespace WebCore {
void handleEmptyLoad(const KURL&, bool forURLScheme);
void handleDataLoadSoon(ResourceRequest& r);
void startDataLoadTimer();
void handleDataLoad(ResourceRequest&);
void receivedError(const ResourceError&);
......@@ -90,7 +102,8 @@ namespace WebCore {
ResourceRequest m_initialRequest;
SubstituteData m_substituteData;
Timer<MainResourceLoader> m_dataLoadTimer;
MainResourceLoaderTimer m_dataLoadTimer;
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
// The application cache that the main resource was loaded from (if any).
......
/*
* Copyright (C) 2009 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.
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 OR ITS 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.
*/
#ifndef RunLoopTimer_h
#define RunLoopTimer_h
#include "SchedulePair.h"
#include <wtf/Noncopyable.h>
#include <wtf/RetainPtr.h>
namespace WebCore {
// Time intervals are all in seconds.
class RunLoopTimerBase : Noncopyable {
public:
virtual ~RunLoopTimerBase();
void schedule(const SchedulePair*);
void schedule(const SchedulePairHashSet&);
void start(double nextFireInterval, double repeatInterval);
void startRepeating(double repeatInterval) { start(repeatInterval, repeatInterval); }
void startOneShot(double interval) { start(interval, 0); }
void stop();
bool isActive() const;
virtual void fired() = 0;
private:
#if PLATFORM(CF)
RetainPtr<CFRunLoopTimerRef> m_timer;
#endif
};
template <typename TimerFiredClass> class RunLoopTimer : public RunLoopTimerBase {
public:
typedef void (TimerFiredClass::*TimerFiredFunction)(RunLoopTimer*);
RunLoopTimer(TimerFiredClass* o, TimerFiredFunction f)
: m_object(o), m_function(f) { }
virtual void fired() { (m_object->*m_function)(this); }
private:
TimerFiredClass* m_object;
TimerFiredFunction m_function;
};
} // namespace WebCore
#endif
/*
* Copyright (C) 2009 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.
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 OR ITS 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.
*/
#include "config.h"
#include "RunLoopTimer.h"
#if PLATFORM(MAC)
namespace WebCore {
RunLoopTimerBase::~RunLoopTimerBase()
{
stop();
}
static void timerFired(CFRunLoopTimerRef, void* context)
{
RunLoopTimerBase* timer = static_cast<RunLoopTimerBase*>(context);
timer->fired();
}
void RunLoopTimerBase::start(double nextFireInterval, double repeatInterval)
{
if (m_timer)
CFRunLoopTimerInvalidate(m_timer.get());
CFRunLoopTimerContext context = { 0, this, 0, 0, 0 };
m_timer.adoptCF(CFRunLoopTimerCreate(0, CFAbsoluteTimeGetCurrent() + nextFireInterval, repeatInterval, 0, 0, timerFired, &context));
}
void RunLoopTimerBase::schedule(const SchedulePair* schedulePair)
{
ASSERT_ARG(schedulePair, schedulePair);
ASSERT_WITH_MESSAGE(m_timer, "Timer must have one of the start functions called before calling schedule().");
CFRunLoopAddTimer(schedulePair->runLoop(), m_timer.get(), schedulePair->mode());
}
void RunLoopTimerBase::schedule(const SchedulePairHashSet& schedulePairs)
{
SchedulePairHashSet::const_iterator end = schedulePairs.end();
for (SchedulePairHashSet::const_iterator it = schedulePairs.begin(); it != end; ++it)
schedule((*it).get());
}
void RunLoopTimerBase::stop()
{
if (!m_timer)
return;
CFRunLoopTimerInvalidate(m_timer.get());
m_timer = 0;
}
bool RunLoopTimerBase::isActive() const
{
return m_timer && CFRunLoopTimerIsValid(m_timer.get());
}
} // namespace WebCore
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment