Reviewers: rmcilroy,

Message:
PTAL. Discussion doc contains links to other CLs in gin and blink:
https://goo.gl/V0ZoP9.

Thanks!

Description:
Add IdleTask API to v8::Platform.

BUG=chromium:490559
LOG=NO

Please review this at https://codereview.chromium.org/1225713003/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+45, -1 lines):
  M include/v8-platform.h
  M src/libplatform/default-platform.h
  M src/libplatform/default-platform.cc


Index: include/v8-platform.h
diff --git a/include/v8-platform.h b/include/v8-platform.h
index be9e5c0c6b46ed122de88253e96f0cbaf8a0d98a..c6cba0f982929aa8795e214c89f9fc1adc4ffb11 100644
--- a/include/v8-platform.h
+++ b/include/v8-platform.h
@@ -19,6 +19,20 @@ class Task {
   virtual void Run() = 0;
 };

+
+/**
+* An IdleTask represents a unit of work to be performed in idle time.
+* The Run method is invoked with an argument that specifies the deadline in
+* seconds returned by MonotonicallyIncreasingTime().
+* The idle task is expected to complete by this deadline.
+*/
+class IdleTask {
+ public:
+  virtual ~IdleTask() {}
+  virtual void Run(double deadline_in_seconds) = 0;
+};
+
+
 /**
  * V8 Platform abstraction layer.
  *
@@ -63,8 +77,26 @@ class Platform {
    * scheduling. The definition of "foreground" is opaque to V8.
    */
   virtual void CallDelayedOnForegroundThread(Isolate* isolate, Task* task,
-                                             double delay_in_seconds) {
+                                             double delay_in_seconds) = 0;
+
+  /**
+   * Schedules a task to be invoked on a foreground thread wrt a specific
+   * |isolate| when the embedder is idle.
+   * Requires that SupportsIdleTasks(isolate) is true.
+   * Idle tasks may be reordered relative to other task types and may be
+   * starved for an arbitrarily long time if no idle time is available.
+   * The definition of "foreground" is opaque to V8.
+   */
+ virtual void CallIdleOnForegroundThread(Isolate* isolate, IdleTask* task) {
+    // TODO(ulan): Make this function abstract after V8 roll in Chromium.
+  }
+
+  /**
+   * Returns true if idle tasks are enabled for the given |isolate|.
+   */
+  virtual bool IdleTasksEnabled(Isolate* isolate) {
     // TODO(ulan): Make this function abstract after V8 roll in Chromium.
+    return false;
   }

   /**
Index: src/libplatform/default-platform.cc
diff --git a/src/libplatform/default-platform.cc b/src/libplatform/default-platform.cc index b41c5852a82119aaa074e6b74b7b5c47e957df97..ddceab54572d12f3a4f5ce6db9ced6675e8f6ed4 100644
--- a/src/libplatform/default-platform.cc
+++ b/src/libplatform/default-platform.cc
@@ -155,6 +155,15 @@ void DefaultPlatform::CallDelayedOnForegroundThread(Isolate* isolate,
 }


+void DefaultPlatform::CallIdleOnForegroundThread(Isolate* isolate,
+                                                 IdleTask* task) {
+  UNREACHABLE();
+}
+
+
+bool DefaultPlatform::IdleTasksEnabled(Isolate* isolate) { return false; }
+
+
 double DefaultPlatform::MonotonicallyIncreasingTime() {
   return base::TimeTicks::HighResolutionNow().ToInternalValue() /
          static_cast<double>(base::Time::kMicrosecondsPerSecond);
Index: src/libplatform/default-platform.h
diff --git a/src/libplatform/default-platform.h b/src/libplatform/default-platform.h index fba5803f406054647b3d376527c9f9136b2a3765..94ef9c5055de333a85bc0245d46d8779c324f218 100644
--- a/src/libplatform/default-platform.h
+++ b/src/libplatform/default-platform.h
@@ -40,6 +40,9 @@ class DefaultPlatform : public Platform {
                                       Task* task) override;
   virtual void CallDelayedOnForegroundThread(Isolate* isolate, Task* task,
double delay_in_seconds) override;
+  virtual void CallIdleOnForegroundThread(Isolate* isolate,
+                                          IdleTask* task) override;
+  virtual bool IdleTasksEnabled(Isolate* isolate) override;
   double MonotonicallyIncreasingTime() override;

  private:


--
--
v8-dev mailing list
v8-dev@googlegroups.com
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to