flutter_flutter/sky/engine/tonic/dart_microtask_queue.cc
Adam Barth 4888996b1b Clean up DartInvoke
Remove the non-initializer version of DartInvokeAppClosure and rename
the function to the simpler DartInvoke. Also, add a special case for
DartInvokeVoid to make the callers prettier.
2016-01-18 20:47:47 -08:00

45 lines
1.2 KiB
C++

// Copyright 2016 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.
#include "sky/engine/tonic/dart_microtask_queue.h"
#include "base/trace_event/trace_event.h"
#include "sky/engine/tonic/dart_invoke.h"
#include "sky/engine/tonic/dart_state.h"
namespace blink {
namespace {
typedef std::vector<DartPersistentValue> MicrotaskQueue;
static MicrotaskQueue& GetQueue() {
static MicrotaskQueue* queue = new MicrotaskQueue();
return *queue;
}
} // namespace
void DartMicrotaskQueue::ScheduleMicrotask(Dart_Handle callback) {
GetQueue().emplace_back(DartState::Current(), callback);
}
void DartMicrotaskQueue::RunMicrotasks() {
MicrotaskQueue& queue = GetQueue();
while(!queue.empty()) {
TRACE_EVENT0("flutter", "DartMicrotaskQueue::RunMicrotasks");
MicrotaskQueue local;
std::swap(queue, local);
for (const auto& callback : local) {
base::WeakPtr<DartState> dart_state = callback.dart_state();
if (!dart_state.get())
continue;
DartState::Scope dart_scope(dart_state.get());
DartInvokeVoid(callback.value());
}
}
}
}