[gin] Implement v8::TaskRunners

With this CL the gin platform implements the new v8::Platform API
functions {GetForegroundTaskRunner} and {GetBackgroundTaskRunner}.

The existing task posting function of the V8Platform now also use these
taskrunners to post tasks. Thereby we can move some of the
implementation from the V8Platform and the PerIsolateData to the new
taskrunners.

[email protected]

Change-Id: I27ea6dd5f6ef8409e394f23ad914f468c09ded4a
Reviewed-on: https://chromium-review.googlesource.com/758578
Commit-Queue: Andreas Haas <[email protected]>
Reviewed-by: François Doray <[email protected]>
Reviewed-by: Ross McIlroy <[email protected]>
Cr-Commit-Position: refs/heads/master@{#517067}
diff --git a/gin/per_isolate_data.h b/gin/per_isolate_data.h
index ac0cf95..31a5cb4 100644
--- a/gin/per_isolate_data.h
+++ b/gin/per_isolate_data.h
@@ -12,16 +12,13 @@
 #include "base/memory/ref_counted.h"
 #include "gin/gin_export.h"
 #include "gin/public/isolate_holder.h"
-#include "gin/public/v8_idle_task_runner.h"
 #include "gin/public/wrapper_info.h"
+#include "gin/v8_foreground_task_runner_base.h"
 #include "v8/include/v8.h"
 
-namespace base {
-class SingleThreadTaskRunner;
-}
-
 namespace gin {
 
+class V8IdleTaskRunner;
 class IndexedPropertyInterceptor;
 class NamedPropertyInterceptor;
 class WrappableBase;
@@ -73,12 +70,7 @@
 
   v8::Isolate* isolate() { return isolate_; }
   v8::ArrayBuffer::Allocator* allocator() { return allocator_; }
-  base::SingleThreadTaskRunner* task_runner() { return task_runner_.get(); }
-  V8IdleTaskRunner* idle_task_runner() {
-    return idle_task_runner_.get();
-  }
-
-  IsolateHolder::AccessMode access_mode() const { return access_mode_; }
+  std::shared_ptr<v8::TaskRunner> task_runner() { return task_runner_; }
 
  private:
   typedef std::map<
@@ -94,13 +86,11 @@
   // owned by the IsolateHolder, which also owns the PerIsolateData.
   v8::Isolate* isolate_;
   v8::ArrayBuffer::Allocator* allocator_;
-  IsolateHolder::AccessMode access_mode_;
   ObjectTemplateMap object_templates_;
   FunctionTemplateMap function_templates_;
   IndexedPropertyInterceptorMap indexed_interceptors_;
   NamedPropertyInterceptorMap named_interceptors_;
-  scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
-  std::unique_ptr<V8IdleTaskRunner> idle_task_runner_;
+  std::shared_ptr<V8ForegroundTaskRunnerBase> task_runner_;
 
   DISALLOW_COPY_AND_ASSIGN(PerIsolateData);
 };