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

Side by Side 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, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef ScriptedIdleTaskController_h
6 #define ScriptedIdleTaskController_h
7
8 #include "core/dom/ActiveDOMObject.h"
9 #include "platform/Timer.h"
10 #include "platform/heap/Handle.h"
11 #include "wtf/RefCounted.h"
12 #include "wtf/RefPtr.h"
13
14 namespace blink {
15
16 class ExecutionContext;
17 class IdleRequestCallback;
18 class DocumentLoadTiming;
19
20 class ScriptedIdleTaskController : public RefCountedWillBeGarbageCollected<Scrip tedIdleTaskController>, public ActiveDOMObject {
21 DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(ScriptedIdleTaskController);
22
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 :(.
23 public:
24 static PassRefPtrWillBeRawPtr<ScriptedIdleTaskController> create(ExecutionCo ntext* context, const DocumentLoadTiming& timing)
25 {
26 return adoptRefWillBeNoop(new ScriptedIdleTaskController(context, timing ));
27 }
28 DECLARE_TRACE();
29
30 using CallbackId = int;
31
32 int registerCallback(IdleRequestCallback*, double timeout);
33 void cancelCallback(CallbackId);
34
35 // ActiveDOMObject interface.
36 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.
37 bool hasPendingActivity() const override;
38
39 private:
40 class IdleRequestCallbackWrapper : public RefCounted<IdleRequestCallbackWrap per> {
41 public:
42 static PassRefPtr<IdleRequestCallbackWrapper> create(CallbackId id, Pass RefPtrWillBeRawPtr<ScriptedIdleTaskController> controller)
43 {
44 return adoptRef(new IdleRequestCallbackWrapper(id, controller));
45 }
46 ~IdleRequestCallbackWrapper();
47
48 void setTimeout(double delay);
49
50 void timeoutFired(Timer<IdleRequestCallbackWrapper>*);
51 static void runCallback(PassRefPtr<IdleRequestCallbackWrapper>, double d eadlineSeconds);
52
53 private:
54 explicit IdleRequestCallbackWrapper(CallbackId, PassRefPtrWillBeRawPtr<S criptedIdleTaskController>);
55
56 CallbackId m_id;
57 Timer<IdleRequestCallbackWrapper> m_timeoutTimer;
58 RefPtrWillBePersistent<ScriptedIdleTaskController> m_controller;
59 };
60
61 ScriptedIdleTaskController(ExecutionContext*, const DocumentLoadTiming&);
62
63 void runCallback(CallbackId, double deadlineSeconds, bool didTimeout);
64
65 const DocumentLoadTiming& m_timing;
66 PersistentHeapHashMapWillBeHeapHashMap<CallbackId, Member<IdleRequestCallbac k>> m_callbacks;
67 CallbackId m_nextCallbackId;
68 };
69
70 } // namespace blink
71
72 #endif // ScriptedIdleTaskController_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698