thread.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2022 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.
  4. // Represents a thread making a debug call to
  5. // the visual debugger.
  6. //
  7. class Thread {
  8. // Keeps track of all threads that debug calls came in from
  9. // while the app is running.
  10. static registered_threads = {};
  11. constructor(json) {
  12. this.threadName_ = json.thread_name;
  13. // Calls from each thread is enabled by default.
  14. this.enabled_ = true;
  15. // Thread color overriding filter colors is disabled by default.
  16. this.overrideFilters_ = false;
  17. this.drawColor_ = '#000000';
  18. this.fillAlpha_ = "10";
  19. // Add new thread to a pool of thread objects.
  20. Thread.registered_threads[this.threadName_] = this;
  21. // Create thread filter chip.
  22. const threadChip = createThreadChip(this);
  23. const threadFilters = document.querySelector('#threads');
  24. threadFilters.appendChild(threadChip);
  25. }
  26. static isThreadRegistered(threadName) {
  27. // If thread already registered, return true.
  28. return (threadName in Thread.registered_threads);
  29. }
  30. static getThread(threadName) {
  31. return Thread.registered_threads[threadName];
  32. }
  33. toggleEnableThread() {
  34. this.enabled_ = !this.enabled_;
  35. }
  36. }