Make NavigationScheduler post loading tasks instead of timers

Similar to https://codereview.chromium.org/1312353004/

We would like to be able to prioritize loading tasks, but in order to
do that we need to make sure loading tasks are posted to the right queue
to make sure tasks run in the expected order.  If this task is posted as
a timer, and loading tasks are prioritzed, it's possible
FrameHostMsg_DidStopLoading will be sent before the corresponding
FrameHostMsg_DidStartLoading ipc which causes various browser tests to
break.

Must be submitted after https://codereview.chromium.org/1303153005/

BUG=497761, 510398

Review URL: https://codereview.chromium.org/1305933007

git-svn-id: svn://svn.chromium.org/blink/trunk@201780 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 8b13f2d0
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
#include "core/page/Page.h" #include "core/page/Page.h"
#include "platform/SharedBuffer.h" #include "platform/SharedBuffer.h"
#include "platform/UserGestureIndicator.h" #include "platform/UserGestureIndicator.h"
#include "public/platform/Platform.h"
#include "wtf/CurrentTime.h" #include "wtf/CurrentTime.h"
namespace blink { namespace blink {
...@@ -266,7 +267,7 @@ private: ...@@ -266,7 +267,7 @@ private:
NavigationScheduler::NavigationScheduler(LocalFrame* frame) NavigationScheduler::NavigationScheduler(LocalFrame* frame)
: m_frame(frame) : m_frame(frame)
, m_timer(this, &NavigationScheduler::timerFired) , m_navigateTaskFactory(WTF::bind(&NavigationScheduler::navigateTask, this))
, m_navigationDisableCount(0) , m_navigationDisableCount(0)
{ {
} }
...@@ -371,7 +372,7 @@ void NavigationScheduler::scheduleReload() ...@@ -371,7 +372,7 @@ void NavigationScheduler::scheduleReload()
schedule(ScheduledReload::create()); schedule(ScheduledReload::create());
} }
void NavigationScheduler::timerFired(Timer<NavigationScheduler>*) void NavigationScheduler::navigateTask()
{ {
if (!m_frame->page()) if (!m_frame->page())
return; return;
...@@ -413,20 +414,22 @@ void NavigationScheduler::startTimer() ...@@ -413,20 +414,22 @@ void NavigationScheduler::startTimer()
return; return;
ASSERT(m_frame->page()); ASSERT(m_frame->page());
if (m_timer.isActive()) if (m_navigateTaskFactory.isPending())
return; return;
if (!m_redirect->shouldStartTimer(m_frame)) if (!m_redirect->shouldStartTimer(m_frame))
return; return;
m_timer.startOneShot(m_redirect->delay(), FROM_HERE); Platform::current()->currentThread()->scheduler()->loadingTaskRunner()->postDelayedTask(
FROM_HERE, m_navigateTaskFactory.cancelAndCreate(), m_redirect->delay());
InspectorInstrumentation::frameScheduledNavigation(m_frame, m_redirect->delay()); InspectorInstrumentation::frameScheduledNavigation(m_frame, m_redirect->delay());
} }
void NavigationScheduler::cancel() void NavigationScheduler::cancel()
{ {
if (m_timer.isActive()) if (m_navigateTaskFactory.isPending())
InspectorInstrumentation::frameClearedScheduledNavigation(m_frame); InspectorInstrumentation::frameClearedScheduledNavigation(m_frame);
m_timer.stop(); m_navigateTaskFactory.cancel();
m_redirect.clear(); m_redirect.clear();
} }
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "core/CoreExport.h" #include "core/CoreExport.h"
#include "platform/Timer.h" #include "platform/Timer.h"
#include "platform/heap/Handle.h" #include "platform/heap/Handle.h"
#include "platform/scheduler/CancellableTaskFactory.h"
#include "wtf/Forward.h" #include "wtf/Forward.h"
#include "wtf/HashMap.h" #include "wtf/HashMap.h"
#include "wtf/Noncopyable.h" #include "wtf/Noncopyable.h"
...@@ -113,13 +114,13 @@ private: ...@@ -113,13 +114,13 @@ private:
bool shouldScheduleReload() const; bool shouldScheduleReload() const;
bool shouldScheduleNavigation(const String& url) const; bool shouldScheduleNavigation(const String& url) const;
void timerFired(Timer<NavigationScheduler>*); void navigateTask();
void schedule(PassOwnPtrWillBeRawPtr<ScheduledNavigation>); void schedule(PassOwnPtrWillBeRawPtr<ScheduledNavigation>);
static bool mustReplaceCurrentItem(LocalFrame* targetFrame); static bool mustReplaceCurrentItem(LocalFrame* targetFrame);
RawPtrWillBeMember<LocalFrame> m_frame; RawPtrWillBeMember<LocalFrame> m_frame;
Timer<NavigationScheduler> m_timer; CancellableTaskFactory m_navigateTaskFactory;
OwnPtrWillBeMember<ScheduledNavigation> m_redirect; OwnPtrWillBeMember<ScheduledNavigation> m_redirect;
int m_navigationDisableCount; int m_navigationDisableCount;
}; };
......
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