1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 const STATE_STOPPED = 0;
6 const STATE_RUNNING = 1;
7 const STATE_QUITTING = 2;
8 const STATE_CLOSING = 3;
9 const STATE_CLOSED = 4;
11 // We're initially stopped.
12 var state = STATE_STOPPED;
15 * This module keeps track of SessionStore's current run state. We will
16 * always start out at STATE_STOPPED. After the session was read from disk and
17 * the initial browser window has loaded we switch to STATE_RUNNING. On the
18 * first notice that a browser shutdown was granted we switch to STATE_QUITTING.
20 export var RunState = Object.freeze({
21 // If we're stopped then SessionStore hasn't been initialized yet. As soon
22 // as the session is read from disk and the initial browser window has loaded
23 // the run state will change to STATE_RUNNING.
25 return state == STATE_STOPPED;
28 // STATE_RUNNING is our default mode of operation that we'll spend most of
29 // the time in. After the session was read from disk and the first browser
30 // window has loaded we remain running until the browser quits.
32 return state == STATE_RUNNING;
35 // We will enter STATE_QUITTING as soon as we receive notice that a browser
36 // shutdown was granted. SessionStore will use this information to prevent
37 // us from collecting partial information while the browser is shutting down
38 // as well as to allow a last single write to disk and block all writes after
41 return state >= STATE_QUITTING;
44 // We will enter STATE_CLOSING as soon as SessionStore is uninitialized.
45 // The SessionFile module will know that a last write will happen in this
46 // state and it can do some necessary cleanup.
48 return state == STATE_CLOSING;
51 // We will enter STATE_CLOSED as soon as SessionFile has written to disk for
52 // the last time before shutdown and will not accept any further writes.
54 return state == STATE_CLOSED;
57 // Switch the run state to STATE_RUNNING. This must be called after the
58 // session was read from, the initial browser window has loaded and we're
59 // now ready to restore session data.
62 state = STATE_RUNNING;
66 // Switch the run state to STATE_CLOSING. This must be called *before* the
67 // last SessionFile.write() call so that SessionFile knows we're closing and
68 // can do some last cleanups and write a proper sessionstore.js file.
70 if (this.isQuitting) {
71 state = STATE_CLOSING;
75 // Switch the run state to STATE_CLOSED. This must be called by SessionFile
76 // after the last write to disk was accepted and no further writes will be
77 // allowed. Any writes after this stage will cause exceptions.
84 // Switch the run state to STATE_QUITTING. This should be called once we're
85 // certain that the browser is going away and before we start collecting the
86 // final window states to save in the session file.
89 state = STATE_QUITTING;