microtasks_runner.cc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright (c) 2018 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #include "shell/browser/microtasks_runner.h"
  5. #include "shell/browser/electron_browser_main_parts.h"
  6. #include "shell/common/node_includes.h"
  7. #include "v8/include/v8.h"
  8. namespace electron {
  9. MicrotasksRunner::MicrotasksRunner(v8::Isolate* isolate) : isolate_(isolate) {}
  10. void MicrotasksRunner::WillProcessTask(const base::PendingTask& pending_task,
  11. bool was_blocked_or_low_priority) {}
  12. void MicrotasksRunner::DidProcessTask(const base::PendingTask& pending_task) {
  13. // In the browser process we follow Node.js microtask policy of kExplicit
  14. // and let the MicrotaskRunner which is a task observer for chromium UI thread
  15. // scheduler run the microtask checkpoint. This worked fine because Node.js
  16. // also runs microtasks through its task queue, but after
  17. // https://github.com/electron/electron/issues/20013 Node.js now performs its
  18. // own microtask checkpoint and it may happen is some situations that there is
  19. // contention for performing checkpoint between Node.js and chromium, ending
  20. // up Node.js delaying its callbacks. To fix this, now we always lets Node.js
  21. // handle the checkpoint in the browser process.
  22. {
  23. v8::HandleScope handle_scope(isolate_);
  24. node::CallbackScope microtasks_scope(isolate_, v8::Object::New(isolate_),
  25. {0, 0});
  26. }
  27. }
  28. } // namespace electron