/src/mozilla-central/dom/workers/WorkerHolder.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef mozilla_dom_workers_WorkerHolder_h |
8 | | #define mozilla_dom_workers_WorkerHolder_h |
9 | | |
10 | | #include "mozilla/dom/WorkerCommon.h" |
11 | | |
12 | | namespace mozilla { |
13 | | namespace dom { |
14 | | |
15 | | class WorkerPrivate; |
16 | | |
17 | | /** |
18 | | * Use this chart to help figure out behavior during each of the closing |
19 | | * statuses. Details below. |
20 | | * |
21 | | * +========================================================+ |
22 | | * | Closing Statuses | |
23 | | * +=============+=============+=================+==========+ |
24 | | * | status | clear queue | abort execution | notified | |
25 | | * +=============+=============+=================+==========+ |
26 | | * | Closing | yes | no | no | |
27 | | * +-------------+-------------+-----------------+----------+ |
28 | | * | Canceling | yes | yes | yes | |
29 | | * +-------------+-------------+-----------------+----------+ |
30 | | * | Killing | yes | yes | yes | |
31 | | * +-------------+-------------+-----------------+----------+ |
32 | | */ |
33 | | |
34 | | enum WorkerStatus |
35 | | { |
36 | | // Not yet scheduled. |
37 | | Pending = 0, |
38 | | |
39 | | // This status means that the worker is active. |
40 | | Running, |
41 | | |
42 | | // Inner script called close() on the worker global scope. Setting this |
43 | | // status causes the worker to clear its queue of events but does not abort |
44 | | // the currently running script. WorkerHolder/WorkerRef objects are not going |
45 | | // to be notified because the behavior of APIs/Components should not change |
46 | | // during this status yet. |
47 | | Closing, |
48 | | |
49 | | // Either the user navigated away from the owning page or the owning page fell |
50 | | // out of bfcache. Setting this status causes the worker to abort immediately. |
51 | | // Since the page has gone away the worker may not post any messages. |
52 | | Canceling, |
53 | | |
54 | | // The application is shutting down. Setting this status causes the worker to |
55 | | // abort immediately. |
56 | | Killing, |
57 | | |
58 | | // The worker is effectively dead. |
59 | | Dead |
60 | | }; |
61 | | |
62 | | class WorkerHolder |
63 | | { |
64 | | public: |
65 | | enum Behavior { |
66 | | AllowIdleShutdownStart, |
67 | | PreventIdleShutdownStart, |
68 | | }; |
69 | | |
70 | | explicit WorkerHolder(const char* aName, |
71 | | Behavior aBehavior = PreventIdleShutdownStart); |
72 | | virtual ~WorkerHolder(); |
73 | | |
74 | | bool HoldWorker(WorkerPrivate* aWorkerPrivate, WorkerStatus aFailStatus); |
75 | | void ReleaseWorker(); |
76 | | |
77 | | virtual bool Notify(WorkerStatus aStatus) = 0; |
78 | | |
79 | | Behavior GetBehavior() const; |
80 | | |
81 | | const char* |
82 | | Name() const |
83 | 0 | { |
84 | 0 | return mName; |
85 | 0 | } |
86 | | |
87 | | protected: |
88 | | void ReleaseWorkerInternal(); |
89 | | |
90 | | WorkerPrivate* MOZ_NON_OWNING_REF mWorkerPrivate; |
91 | | |
92 | | private: |
93 | | void AssertIsOwningThread() const; |
94 | | |
95 | | const Behavior mBehavior; |
96 | | |
97 | | // For debugging only. |
98 | | void* mThread; |
99 | | const char* mName; |
100 | | }; |
101 | | |
102 | | } // dom namespace |
103 | | } // mozilla namespace |
104 | | |
105 | | #endif /* mozilla_dom_workers_WorkerHolder_h */ |