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

Unified Diff: Source/core/dom/ScriptedIdleTaskController.h

Issue 1119683003: Implement requestIdleCallback API (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add LayoutTest and fix minor spec violation Created 5 years, 5 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/dom/ScriptedIdleTaskController.h
diff --git a/Source/core/dom/ScriptedIdleTaskController.h b/Source/core/dom/ScriptedIdleTaskController.h
new file mode 100644
index 0000000000000000000000000000000000000000..6a3b87d95cf2b4c007042a6d6641a32ef03bda16
--- /dev/null
+++ b/Source/core/dom/ScriptedIdleTaskController.h
@@ -0,0 +1,72 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ScriptedIdleTaskController_h
+#define ScriptedIdleTaskController_h
+
+#include "core/dom/ActiveDOMObject.h"
+#include "platform/Timer.h"
+#include "platform/heap/Handle.h"
+#include "wtf/RefCounted.h"
+#include "wtf/RefPtr.h"
+
+namespace blink {
+
+class ExecutionContext;
+class IdleRequestCallback;
+class DocumentLoadTiming;
+
+class ScriptedIdleTaskController : public RefCountedWillBeGarbageCollected<ScriptedIdleTaskController>, public ActiveDOMObject {
+ DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(ScriptedIdleTaskController);
+
jochen (gone - plz use gerrit) 2015/07/31 09:19:19 nit. remove empty line
rmcilroy 2015/08/11 16:30:51 Done - git cl format does this though :(.
+public:
+ static PassRefPtrWillBeRawPtr<ScriptedIdleTaskController> create(ExecutionContext* context, const DocumentLoadTiming& timing)
+ {
+ return adoptRefWillBeNoop(new ScriptedIdleTaskController(context, timing));
+ }
+ DECLARE_TRACE();
+
+ using CallbackId = int;
+
+ int registerCallback(IdleRequestCallback*, double timeout);
+ void cancelCallback(CallbackId);
+
+ // ActiveDOMObject interface.
+ void stop() override;
Sami 2015/08/10 09:47:47 Do we need to support suspend/resume like with rAF
rmcilroy 2015/08/11 16:30:52 Good catch! This should now be addressed, thanks.
+ bool hasPendingActivity() const override;
+
+private:
+ class IdleRequestCallbackWrapper : public RefCounted<IdleRequestCallbackWrapper> {
+ public:
+ static PassRefPtr<IdleRequestCallbackWrapper> create(CallbackId id, PassRefPtrWillBeRawPtr<ScriptedIdleTaskController> controller)
+ {
+ return adoptRef(new IdleRequestCallbackWrapper(id, controller));
+ }
+ ~IdleRequestCallbackWrapper();
+
+ void setTimeout(double delay);
+
+ void timeoutFired(Timer<IdleRequestCallbackWrapper>*);
+ static void runCallback(PassRefPtr<IdleRequestCallbackWrapper>, double deadlineSeconds);
+
+ private:
+ explicit IdleRequestCallbackWrapper(CallbackId, PassRefPtrWillBeRawPtr<ScriptedIdleTaskController>);
+
+ CallbackId m_id;
+ Timer<IdleRequestCallbackWrapper> m_timeoutTimer;
+ RefPtrWillBePersistent<ScriptedIdleTaskController> m_controller;
+ };
+
+ ScriptedIdleTaskController(ExecutionContext*, const DocumentLoadTiming&);
+
+ void runCallback(CallbackId, double deadlineSeconds, bool didTimeout);
+
+ const DocumentLoadTiming& m_timing;
+ PersistentHeapHashMapWillBeHeapHashMap<CallbackId, Member<IdleRequestCallback>> m_callbacks;
+ CallbackId m_nextCallbackId;
+};
+
+} // namespace blink
+
+#endif // ScriptedIdleTaskController_h

Powered by Google App Engine
This is Rietveld 408576698