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

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: Address Review Comments 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 "core/dom/IdleCallbackDeadline.h"
10 #include "platform/Timer.h"
11 #include "platform/heap/Handle.h"
12 #include "wtf/RefCounted.h"
13 #include "wtf/RefPtr.h"
14
15 #include <queue>
16
17 namespace blink {
18
19 class ExecutionContext;
20 class IdleRequestCallback;
21 class DocumentLoadTiming;
22
23 class ScriptedIdleTaskController : public RefCountedWillBeGarbageCollected<Scrip tedIdleTaskController>, public ActiveDOMObject {
24 DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(ScriptedIdleTaskController);
25 public:
26 static PassRefPtrWillBeRawPtr<ScriptedIdleTaskController> create(ExecutionCo ntext* context, const DocumentLoadTiming& timing)
27 {
28 return adoptRefWillBeNoop(new ScriptedIdleTaskController(context, timing ));
29 }
30 DECLARE_TRACE();
31
32 using CallbackId = int;
33
34 int registerCallback(IdleRequestCallback*, double timeoutMillis);
35 void cancelCallback(CallbackId);
36
37 // ActiveDOMObject interface.
38 void stop() override;
39 void suspend() override;
40 void resume() override;
41 bool hasPendingActivity() const override;
42
43 private:
44 class IdleRequestCallbackWrapper : public RefCounted<IdleRequestCallbackWrap per> {
45 public:
46 static PassRefPtr<IdleRequestCallbackWrapper> create(CallbackId id, Pass RefPtrWillBeRawPtr<ScriptedIdleTaskController> controller)
47 {
48 return adoptRef(new IdleRequestCallbackWrapper(id, controller));
49 }
50 virtual ~IdleRequestCallbackWrapper();
51
52 void setTimeout(double timeoutMillis);
53 void cancelTimeout();
54
55 static void idleTaskFired(PassRefPtr<IdleRequestCallbackWrapper>, double deadlineSeconds);
56
57 CallbackId id() { return m_id; }
58 PassRefPtrWillBeRawPtr<ScriptedIdleTaskController> controller() { return m_controller; }
59
60 private:
61 class IdleRequestTimoutTimer : public Timer<IdleRequestTimoutTimer> {
Sami 2015/08/11 18:03:00 typo: Timeout
rmcilroy 2015/08/12 14:17:31 Done.
62 public:
63 IdleRequestTimoutTimer(PassRefPtr<IdleRequestCallbackWrapper>);
64 virtual ~IdleRequestTimoutTimer();
65
66 void timeoutFired(Timer<IdleRequestTimoutTimer>*);
67
68 private:
69 RefPtr<IdleRequestCallbackWrapper> m_callbackWrapper;
70 };
71
72 explicit IdleRequestCallbackWrapper(CallbackId, PassRefPtrWillBeRawPtr<S criptedIdleTaskController>);
73
74 CallbackId m_id;
75 OwnPtr<IdleRequestTimoutTimer> m_timeoutTimer;
76 RefPtrWillBePersistent<ScriptedIdleTaskController> m_controller;
77 };
78
79 ScriptedIdleTaskController(ExecutionContext*, const DocumentLoadTiming&);
80
81 void callbackFired(IdleRequestCallbackWrapper*, double deadlineSeconds, Idle CallbackDeadline::CallbackType);
82 void runCallback(CallbackId, double deadlineMillis, IdleCallbackDeadline::Ca llbackType);
83
84 const DocumentLoadTiming& m_timing;
85 PersistentHeapHashMapWillBeHeapHashMap<CallbackId, Member<IdleRequestCallbac k>> m_callbacks;
86 std::queue<CallbackId> m_pendingTimeouts;
87 CallbackId m_nextCallbackId;
88 bool m_suspended;
89 };
90
91 } // namespace blink
92
93 #endif // ScriptedIdleTaskController_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698