OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "gin/public/v8_platform.h" | 5 #include "gin/public/v8_platform.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
10 #include "base/threading/worker_pool.h" | 10 #include "base/threading/thread.h" |
11 #include "gin/per_isolate_data.h" | 11 #include "gin/per_isolate_data.h" |
12 | 12 |
13 namespace gin { | 13 namespace gin { |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 base::LazyInstance<V8Platform>::Leaky g_v8_platform = LAZY_INSTANCE_INITIALIZER; | 17 base::LazyInstance<V8Platform>::Leaky g_v8_platform = LAZY_INSTANCE_INITIALIZER; |
18 | 18 |
19 } // namespace | 19 } // namespace |
20 | 20 |
21 // static | 21 // static |
22 V8Platform* V8Platform::Get() { return g_v8_platform.Pointer(); } | 22 V8Platform* V8Platform::Get() { return g_v8_platform.Pointer(); } |
23 | 23 |
24 V8Platform::V8Platform() {} | 24 V8Platform::V8Platform() {} |
25 | 25 |
26 V8Platform::~V8Platform() {} | 26 V8Platform::~V8Platform() {} |
27 | 27 |
28 void V8Platform::CallOnBackgroundThread( | 28 void V8Platform::CallOnBackgroundThread( |
29 v8::Task* task, | 29 v8::Task* task, |
30 v8::Platform::ExpectedRuntime expected_runtime) { | 30 v8::Platform::ExpectedRuntime expected_runtime) { |
31 base::WorkerPool::PostTask( | 31 if (!background_thread_) { |
| 32 background_thread_.reset(new base::Thread("gin_background")); |
| 33 background_thread_->Start(); |
| 34 } |
| 35 background_thread_->message_loop_proxy()->PostTask( |
32 FROM_HERE, | 36 FROM_HERE, |
33 base::Bind(&v8::Task::Run, base::Owned(task)), | 37 base::Bind(&v8::Task::Run, base::Owned(task))); |
34 expected_runtime == v8::Platform::kLongRunningTask); | |
35 } | 38 } |
36 | 39 |
37 void V8Platform::CallOnForegroundThread(v8::Isolate* isolate, v8::Task* task) { | 40 void V8Platform::CallOnForegroundThread(v8::Isolate* isolate, v8::Task* task) { |
38 PerIsolateData::From(isolate)->message_loop_proxy()->PostTask( | 41 PerIsolateData::From(isolate)->message_loop_proxy()->PostTask( |
39 FROM_HERE, base::Bind(&v8::Task::Run, base::Owned(task))); | 42 FROM_HERE, base::Bind(&v8::Task::Run, base::Owned(task))); |
40 } | 43 } |
41 | 44 |
42 double V8Platform::MonotonicallyIncreasingTime() { | 45 double V8Platform::MonotonicallyIncreasingTime() { |
43 return base::TimeTicks::Now().ToInternalValue() / | 46 return base::TimeTicks::Now().ToInternalValue() / |
44 static_cast<double>(base::Time::kMicrosecondsPerSecond); | 47 static_cast<double>(base::Time::kMicrosecondsPerSecond); |
45 } | 48 } |
46 | 49 |
47 } // namespace gin | 50 } // namespace gin |
OLD | NEW |