WorkerHolder.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef mozilla_dom_workers_WorkerHolder_h
  6. #define mozilla_dom_workers_WorkerHolder_h
  7. #include "mozilla/dom/workers/Workers.h"
  8. BEGIN_WORKERS_NAMESPACE
  9. /**
  10. * Use this chart to help figure out behavior during each of the closing
  11. * statuses. Details below.
  12. *
  13. * +==============================================================+
  14. * | Closing Statuses |
  15. * +=============+=============+=================+================+
  16. * | status | clear queue | abort execution | close handler |
  17. * +=============+=============+=================+================+
  18. * | Closing | yes | no | no timeout |
  19. * +-------------+-------------+-----------------+----------------+
  20. * | Terminating | yes | yes | no timeout |
  21. * +-------------+-------------+-----------------+----------------+
  22. * | Canceling | yes | yes | short duration |
  23. * +-------------+-------------+-----------------+----------------+
  24. * | Killing | yes | yes | doesn't run |
  25. * +-------------+-------------+-----------------+----------------+
  26. */
  27. #ifdef Status
  28. /* Xlib headers insist on this for some reason... Nuke it because
  29. it'll override our member name */
  30. #undef Status
  31. #endif
  32. enum Status
  33. {
  34. // Not yet scheduled.
  35. Pending = 0,
  36. // This status means that the close handler has not yet been scheduled.
  37. Running,
  38. // Inner script called close() on the worker global scope. Setting this
  39. // status causes the worker to clear its queue of events but does not abort
  40. // the currently running script. The close handler is also scheduled with
  41. // no expiration time.
  42. Closing,
  43. // Outer script called terminate() on the worker or the worker object was
  44. // garbage collected in its outer script. Setting this status causes the
  45. // worker to abort immediately, clear its queue of events, and schedules the
  46. // close handler with no expiration time.
  47. Terminating,
  48. // Either the user navigated away from the owning page or the owning page fell
  49. // out of bfcache. Setting this status causes the worker to abort immediately
  50. // and schedules the close handler with a short expiration time. Since the
  51. // page has gone away the worker may not post any messages.
  52. Canceling,
  53. // The application is shutting down. Setting this status causes the worker to
  54. // abort immediately and the close handler is never scheduled.
  55. Killing,
  56. // The close handler has run and the worker is effectively dead.
  57. Dead
  58. };
  59. class WorkerHolder
  60. {
  61. public:
  62. NS_DECL_OWNINGTHREAD
  63. WorkerHolder();
  64. virtual ~WorkerHolder();
  65. bool HoldWorker(WorkerPrivate* aWorkerPrivate, Status aFailStatus);
  66. void ReleaseWorker();
  67. virtual bool Notify(Status aStatus) = 0;
  68. protected:
  69. void ReleaseWorkerInternal();
  70. WorkerPrivate* MOZ_NON_OWNING_REF mWorkerPrivate;
  71. private:
  72. void AssertIsOwningThread() const;
  73. };
  74. END_WORKERS_NAMESPACE
  75. #endif /* mozilla_dom_workers_WorkerHolder_h */