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

Side by Side Diff: sky/engine/tonic/dart_timer_heap.cc

Issue 1160763004: Add support for testing content in SkyView (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 6 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
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 #include "sky/engine/config.h"
6 #include "sky/engine/tonic/dart_timer_heap.h"
7
8 #include "base/bind.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/time/time.h"
11 #include "sky/engine/tonic/dart_api_scope.h"
12 #include "sky/engine/tonic/dart_invoke.h"
13 #include "sky/engine/tonic/dart_isolate_scope.h"
14 #include "sky/engine/tonic/dart_state.h"
15
16 namespace blink {
17
18 DartTimerHeap::DartTimerHeap() : next_timer_id_(1), weak_factory_(this) {
19 }
20
21 DartTimerHeap::~DartTimerHeap() {
22 }
23
24 int DartTimerHeap::Add(PassOwnPtr<Task> task) {
25 int id = next_timer_id_++;
26 Schedule(id, task);
27 return id;
28 }
29
30 void DartTimerHeap::Remove(int id) {
31 heap_.remove(id);
32 }
33
34 void DartTimerHeap::Schedule(int id, PassOwnPtr<Task> task) {
35 base::TimeDelta delay = task->delay;
36 heap_.add(id, task);
37 base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
38 base::Bind(&DartTimerHeap::Run, weak_factory_.GetWeakPtr(), id), delay);
39 }
40
41 void DartTimerHeap::Run(int id) {
42 auto it = heap_.find(id);
43 if (it == heap_.end())
44 return;
45 OwnPtr<Task> task = it->value.release();
46 heap_.remove(it);
47 if (!task->closure.dart_state())
48 return;
49 DartIsolateScope scope(task->closure.dart_state()->isolate());
50 DartApiScope api_scope;
51 DartInvokeAppClosure(task->closure.value(), 0, nullptr);
52 if (task->repeating)
53 Schedule(id, task.release());
54 }
55
56 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698