Add nparker to safe_browsing/OWNERS.
[chromium-blink-merge.git] / gin / v8_platform.cc
blobbd32977d651e066d607d91a66f58d24d57f4fe52
1 // Copyright 2014 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.
5 #include "gin/public/v8_platform.h"
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/threading/worker_pool.h"
10 #include "gin/per_isolate_data.h"
12 namespace gin {
14 namespace {
16 base::LazyInstance<V8Platform>::Leaky g_v8_platform = LAZY_INSTANCE_INITIALIZER;
18 } // namespace
20 // static
21 V8Platform* V8Platform::Get() { return g_v8_platform.Pointer(); }
23 V8Platform::V8Platform() {}
25 V8Platform::~V8Platform() {}
27 void V8Platform::CallOnBackgroundThread(
28 v8::Task* task,
29 v8::Platform::ExpectedRuntime expected_runtime) {
30 base::WorkerPool::PostTask(
31 FROM_HERE,
32 base::Bind(&v8::Task::Run, base::Owned(task)),
33 expected_runtime == v8::Platform::kLongRunningTask);
36 void V8Platform::CallOnForegroundThread(v8::Isolate* isolate, v8::Task* task) {
37 PerIsolateData::From(isolate)->task_runner()->PostTask(
38 FROM_HERE, base::Bind(&v8::Task::Run, base::Owned(task)));
41 void V8Platform::CallDelayedOnForegroundThread(v8::Isolate* isolate,
42 v8::Task* task,
43 double delay_in_seconds) {
44 PerIsolateData::From(isolate)->task_runner()->PostDelayedTask(
45 FROM_HERE, base::Bind(&v8::Task::Run, base::Owned(task)),
46 base::TimeDelta::FromSecondsD(delay_in_seconds));
49 void V8Platform::CallIdleOnForegroundThread(v8::Isolate* isolate,
50 v8::IdleTask* task) {
51 DCHECK(PerIsolateData::From(isolate)->idle_task_runner());
52 PerIsolateData::From(isolate)->idle_task_runner()->PostIdleTask(task);
55 bool V8Platform::IdleTasksEnabled(v8::Isolate* isolate) {
56 return PerIsolateData::From(isolate)->idle_task_runner() != nullptr;
59 double V8Platform::MonotonicallyIncreasingTime() {
60 return base::TimeTicks::Now().ToInternalValue() /
61 static_cast<double>(base::Time::kMicrosecondsPerSecond);
64 } // namespace gin