summaryrefslogtreecommitdiffstats
path: root/toolkit/components/asyncshutdown/nsIAsyncShutdown.idl
blob: 216c8047e0771ff9ea38925041d757caf1fdf441 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

/**
 * A mechanism for specifying shutdown dependencies between
 * asynchronous services.
 *
 * Note that this XPCOM component is designed primarily for C++
 * clients. JavaScript clients should rather use AsyncShutdown.jsm,
 * which provides a better API and better error reporting for them.
 */


#include "nsISupports.idl"
#include "nsIPropertyBag.idl"
#include "nsIVariant.idl"

interface nsIAsyncShutdownClient;

/**
 * A blocker installed by a client to be informed during some stage of
 * shutdown and block shutdown asynchronously until some condition is
 * complete.
 *
 * If you wish to use AsyncShutdown, you will need to implement this
 * interface (and only this interface).
 */
[scriptable, uuid(4ef43f29-6715-4b57-a750-2ff83695ddce)]
interface nsIAsyncShutdownBlocker: nsISupports {
  /**
   * The *unique* name of the blocker.
   *
   * By convention, it should respect the following format:
   * "MyModuleName: Doing something while it's time"
   * e.g.
   * "OS.File: Flushing before profile-before-change"
   *
   * This attribute is uploaded as part of crash reports.
   */
  readonly attribute AString name;

  /**
   * Inform the blocker that the stage of shutdown has started.
   * Shutdown will NOT proceed until `aBarrierClient.removeBlocker(this)`
   * has been called.
   */
  void blockShutdown(in nsIAsyncShutdownClient aBarrierClient);

  /**
   * The current state of the blocker.
   *
   * In case of crash, this is converted to JSON and attached to
   * the crash report.
   *
   * This field may be used to provide JSON-style data structures.
   * For this purpose, use
   * - nsIPropertyBag to represent objects;
   * - nsIVariant to represent field values (which may hold nsIPropertyBag
   * themselves).
   */
  readonly attribute nsIPropertyBag state;
};

/**
 * A client for a nsIAsyncShutdownBarrier.
 */
[scriptable, uuid(d2031049-b990-43a2-95be-59f8a3ca5954)]
interface nsIAsyncShutdownClient: nsISupports {
  /**
   * The name of the barrier.
   */
  readonly attribute AString name;

  /**
   * Add a blocker.
   *
   * After a `blocker` has been added with `addBlocker`, if it is not
   * removed with `removeBlocker`, this will, by design, eventually
   * CAUSE A CRASH.
   *
   * Calling `addBlocker` once nsIAsyncShutdownBarrier::wait() has been
   * called on the owning barrier returns an error.
   *
   * @param aBlocker The blocker to add. Once
   * nsIAsyncShutdownBarrier::wait() has been called, it will not
   * call its `aOnReady` callback until all blockers have been
   * removed, each  by a call to `removeBlocker`.
   * @param aFileName The filename of the callsite, as given by `__FILE__`.
   * @param aLineNumber The linenumber of the callsite, as given by `__LINE__`.
   * @param aStack Information on the stack that lead to this call. Generally
   * empty when called from C++.
   */
  void addBlocker(in nsIAsyncShutdownBlocker aBlocker,
                  in AString aFileName,
                  in long aLineNumber,
                  in AString aStack);

  /**
   * Remove a blocker.
   *
   * @param aBlocker A blocker previously added to this client through
   * `addBlocker`. Noop if the blocker has never been added or has been
   * removed already.
   */
  void removeBlocker(in nsIAsyncShutdownBlocker aBlocker);

  /**
   * The JS implementation of the client.
   *
   * It is strongly recommended that JS clients of this API use
   * `jsclient` instead of the `nsIAsyncShutdownClient`. See
   * AsyncShutdown.jsm for more information on the JS version of
   * this API.
   */
  readonly attribute jsval jsclient;
};

/**
 * Callback invoked once all blockers of a barrier have been removed.
 */
[scriptable, function, uuid(910c9309-1da0-4dd0-8bdb-a325a38c604e)]
interface nsIAsyncShutdownCompletionCallback: nsISupports {
  /**
   * The operation has been completed.
   */
  void done();
};

/**
 * A stage of shutdown that supports blocker registration.
 */
[scriptable, uuid(50fa8a86-9c91-4256-8389-17d310adec90)]
interface nsIAsyncShutdownBarrier: nsISupports {

  /**
   * The blocker registration capability.  Most services may wish to
   * publish this capability to let services that depend on it register
   * blockers.
   */
  readonly attribute nsIAsyncShutdownClient client;

  /**
   * The state of all the blockers of the barrier.
   *
   * See the documentation of `nsIAsyncShutdownBlocker` for the
   * format.
   */
  readonly attribute nsIPropertyBag state;

  /**
   * Wait for all blockers to complete.
   *
   * Method `aOnReady` will be called once all blockers have finished.
   * The callback always receives NS_OK.
   */
  void wait(in nsIAsyncShutdownCompletionCallback aOnReady);
};

/**
 * A service that allows registering shutdown-time dependencies.
 */
[scriptable, uuid(db365c78-c860-4e64-9a63-25b73f89a016)]
interface nsIAsyncShutdownService: nsISupports {
  /**
   * Create a new barrier.
   *
   * By convention, the name should respect the following format:
   * "MyModuleName: Doing something while it's time"
   * e.g.
   * "OS.File: Waiting for clients to flush before shutting down"
   *
   * This attribute is uploaded as part of crash reports.
   */
  nsIAsyncShutdownBarrier makeBarrier(in AString aName);


  // Barriers for global shutdown stages in the parent process.

  /**
   * Barrier for notification profile-before-change.
   */
  readonly attribute nsIAsyncShutdownClient profileBeforeChange;

  /**
   * Barrier for notification profile-change-teardown.
   */
  readonly attribute nsIAsyncShutdownClient profileChangeTeardown;

  /**
   * Barrier for notification quit-application-granted.
   */
  readonly attribute nsIAsyncShutdownClient quitApplicationGranted;

  /**
   * Barrier for notification profile-before-change-telemetry.
   */
  readonly attribute nsIAsyncShutdownClient sendTelemetry;


  // Barriers for global shutdown stages in all processes.

  /**
   * Barrier for notification web-workers-shutdown.
   */
  readonly attribute nsIAsyncShutdownClient webWorkersShutdown;

  /**
   * Barrier for notification xpcom-will-shutdown.
   */
  readonly attribute nsIAsyncShutdownClient xpcomWillShutdown;

  // Don't add a barrier for content-child-shutdown because this
  // makes it easier to cause shutdown hangs.

};

%{C++
#define NS_ASYNCSHUTDOWNSERVICE_CONTRACTID "@mozilla.org/async-shutdown-service;1"
%}