Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(359)

Unified Diff: Source/core/frame/DeviceEventDispatcherBase.cpp

Issue 315573002: Generalize and refactor DeviceSensorEvent* architecture to support multi-event type targets. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: similarity=60 Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/frame/DeviceEventDispatcherBase.cpp
diff --git a/Source/core/frame/DeviceSensorEventDispatcher.cpp b/Source/core/frame/DeviceEventDispatcherBase.cpp
similarity index 71%
copy from Source/core/frame/DeviceSensorEventDispatcher.cpp
copy to Source/core/frame/DeviceEventDispatcherBase.cpp
index a992f0aa2e5246d1cce865668bee49ce393a8975..ef64cd1a8d99c6124c32a7eeb36478f79d500dd8 100644
--- a/Source/core/frame/DeviceSensorEventDispatcher.cpp
+++ b/Source/core/frame/DeviceEventDispatcherBase.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Google Inc. All rights reserved.
+ * Copyright (C) 2014 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -29,21 +29,24 @@
*/
#include "config.h"
-#include "core/frame/DeviceSensorEventDispatcher.h"
+#include "core/frame/DeviceEventDispatcherBase.h"
+
+#include "core/frame/DeviceEventControllerBase.h"
+#include "wtf/TemporaryChange.h"
namespace WebCore {
-DeviceSensorEventDispatcher::DeviceSensorEventDispatcher()
+DeviceEventDispatcherBase::DeviceEventDispatcherBase()
: m_needsPurge(false)
, m_isDispatching(false)
{
}
-DeviceSensorEventDispatcher::~DeviceSensorEventDispatcher()
+DeviceEventDispatcherBase::~DeviceEventDispatcherBase()
{
}
-void DeviceSensorEventDispatcher::addController(DeviceSensorEventController* controller)
+void DeviceEventDispatcherBase::addController(DeviceEventControllerBase* controller)
{
bool wasEmpty = m_controllers.isEmpty();
if (!m_controllers.contains(controller))
@@ -52,13 +55,12 @@ void DeviceSensorEventDispatcher::addController(DeviceSensorEventController* con
startListening();
}
-void DeviceSensorEventDispatcher::removeController(DeviceSensorEventController* controller)
+void DeviceEventDispatcherBase::removeController(DeviceEventControllerBase* controller)
{
// Do not actually remove the controller from the vector, instead zero them out.
// The zeros are removed in these two cases:
// 1. either immediately if we are not dispatching any events,
- // 2. or after events to all controllers have dispatched
- // (see e.g. DeviceOrientationDispatcher::didChangeDeviceOrientation).
+ // 2. or after events to all controllers have dispatched (see notifyControllers()).
// This is to correctly handle the re-entrancy case when a controller is destroyed
// while the events are still being dispatched.
size_t index = m_controllers.find(controller);
@@ -72,7 +74,7 @@ void DeviceSensorEventDispatcher::removeController(DeviceSensorEventController*
purgeControllers();
}
-void DeviceSensorEventDispatcher::purgeControllers()
+void DeviceEventDispatcherBase::purgeControllers()
{
ASSERT(m_needsPurge);
@@ -92,4 +94,20 @@ void DeviceSensorEventDispatcher::purgeControllers()
stopListening();
}
+void DeviceEventDispatcherBase::notifyControllers()
+{
+ {
+ TemporaryChange<bool> changeIsDispatching(m_isDispatching, true);
+ // Don't notify controllers removed or added during event dispatch.
+ size_t size = m_controllers.size();
+ for (size_t i = 0; i < size; ++i) {
+ if (m_controllers[i])
+ m_controllers[i]->didUpdateData();
+ }
+ }
+
+ if (m_needsPurge)
+ purgeControllers();
+}
+
} // namespace WebCore

Powered by Google App Engine
This is Rietveld 408576698