Chromium Code Reviews| Index: Source/modules/screen_orientation/ScreenOrientationController.cpp |
| diff --git a/Source/modules/screen_orientation/ScreenOrientationController.cpp b/Source/modules/screen_orientation/ScreenOrientationController.cpp |
| index 740ee7569069062affffba763454fb9425d9b38a..0820474f073e7db10f66ec4a4058887cf10b4a33 100644 |
| --- a/Source/modules/screen_orientation/ScreenOrientationController.cpp |
| +++ b/Source/modules/screen_orientation/ScreenOrientationController.cpp |
| @@ -5,8 +5,6 @@ |
| #include "config.h" |
| #include "modules/screen_orientation/ScreenOrientationController.h" |
| -#include "core/dom/Document.h" |
| -#include "core/dom/ExecutionContextTask.h" |
| #include "core/events/Event.h" |
| #include "core/frame/FrameHost.h" |
| #include "core/frame/FrameView.h" |
| @@ -42,7 +40,7 @@ ScreenOrientationController::ScreenOrientationController(LocalFrame& frame, WebS |
| : LocalFrameLifecycleObserver(&frame) |
| , PlatformEventController(frame.page()) |
| , m_client(client) |
| - , m_isDispatchingEvent(false) |
| + , m_dispatchEventTimer(this, &ScreenOrientationController::dispatchEventTimerFired) |
| { |
| } |
| @@ -140,12 +138,8 @@ void ScreenOrientationController::notifyOrientationChanged() |
| } |
| // Notify current orientation object. |
| - if (!m_isDispatchingEvent) { |
| - if (Document* document = frame()->document()) { |
| - document->postTask(FROM_HERE, createSameThreadTask(&ScreenOrientationController::dispatchChangeEvent, this)); |
| - m_isDispatchingEvent = true; |
| - } |
| - } |
| + if (!m_dispatchEventTimer.isActive()) |
| + m_dispatchEventTimer.startOneShot(0, FROM_HERE); |
|
haraken
2015/06/19 11:04:15
Would you help me understand why the new code is s
sof
2015/06/19 11:08:27
This controller owns the timer, so it'll be finali
haraken
2015/06/19 11:11:40
Ah, makes sense. LGTM.
|
| // ... and child frames, if they have a ScreenOrientationController. |
| for (size_t i = 0; i < childFrames.size(); ++i) { |
| @@ -178,9 +172,8 @@ void ScreenOrientationController::unlock() |
| m_client->unlockOrientation(); |
| } |
| -void ScreenOrientationController::dispatchChangeEvent() |
| +void ScreenOrientationController::dispatchEventTimerFired(Timer<ScreenOrientationController>*) |
| { |
| - m_isDispatchingEvent = false; |
| if (!m_orientation) |
| return; |
| m_orientation->dispatchEvent(Event::create(EventTypeNames::change)); |