89 lines, 40 LOC, 39 covered (97%)
3 | 1 | /***************************** BEGIN LICENSE BLOCK ***************************** |
2 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
|
3 | * |
|
4 | * The contents of this file are subject to the Mozilla Public License Version |
|
5 | * 1.1 (the "License"); you may not use this file except in compliance with the |
|
6 | * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ |
|
7 | * |
|
8 | * Software distributed under the License is distributed on an "AS IS" basis, |
|
9 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for |
|
10 | * the specific language governing rights and limitations under the License. |
|
11 | * |
|
12 | * The Original Code is Weave Status. |
|
13 | * |
|
14 | * The Initial Developer of the Original Code is Mozilla Corporation. |
|
15 | * Portions created by the Initial Developer are Copyright (C) 2009 the Initial |
|
16 | * Developer. All Rights Reserved. |
|
17 | * |
|
18 | * Contributor(s): |
|
19 | * Edward Lee <edilee@mozilla.com> (original author) |
|
20 | * |
|
21 | * Alternatively, the contents of this file may be used under the terms of either |
|
22 | * the GNU General Public License Version 2 or later (the "GPL"), or the GNU |
|
23 | * Lesser General Public License Version 2.1 or later (the "LGPL"), in which case |
|
24 | * the provisions of the GPL or the LGPL are applicable instead of those above. |
|
25 | * If you wish to allow use of your version of this file only under the terms of |
|
26 | * either the GPL or the LGPL, and not to allow others to use your version of |
|
27 | * this file under the terms of the MPL, indicate your decision by deleting the |
|
28 | * provisions above and replace them with the notice and other provisions |
|
29 | * required by the GPL or the LGPL. If you do not delete the provisions above, a |
|
30 | * recipient may use your version of this file under the terms of any one of the |
|
31 | * MPL, the GPL or the LGPL. |
|
32 | * |
|
33 | ****************************** END LICENSE BLOCK ******************************/ |
|
34 | ||
21 | 35 | const EXPORTED_SYMBOLS = ["Status"]; |
36 | ||
12 | 37 | const Cc = Components.classes; |
12 | 38 | const Ci = Components.interfaces; |
12 | 39 | const Cr = Components.results; |
12 | 40 | const Cu = Components.utils; |
41 | ||
15 | 42 | Cu.import("resource://weave/constants.js"); |
43 | ||
6 | 44 | let Status = { |
24 | 45 | get login() this._login, |
13 | 46 | set login(code) { |
21 | 47 | this._login = code; |
48 | ||
28 | 49 | if (code == LOGIN_FAILED_NO_USERNAME || |
16 | 50 | code == LOGIN_FAILED_NO_PASSWORD || |
13 | 51 | code == LOGIN_FAILED_NO_PASSPHRASE) |
20 | 52 | this.service = CLIENT_NOT_CONFIGURED; |
6 | 53 | else if (code != LOGIN_SUCCEEDED) |
4 | 54 | this.service = LOGIN_FAILED; |
55 | else |
|
10 | 56 | this.service = STATUS_OK; |
57 | }, |
|
58 | ||
18 | 59 | get sync() this._sync, |
9 | 60 | set sync(code) { |
9 | 61 | this._sync = code; |
22 | 62 | this.service = code == SYNC_SUCCEEDED ? STATUS_OK : SYNC_FAILED; |
63 | }, |
|
64 | ||
30 | 65 | get engines() this._engines, |
39 | 66 | set engines([name, code]) { |
12 | 67 | this._engines[name] = code; |
68 | ||
9 | 69 | if (code != ENGINE_SUCCEEDED) |
6 | 70 | this.service = SYNC_FAILED_PARTIAL; |
71 | }, |
|
72 | ||
10 | 73 | resetBackoff: function resetBackoff() { |
12 | 74 | this.enforceBackoff = false; |
12 | 75 | this.backoffInterval = 0; |
16 | 76 | this.minimumNextSync = 0; |
77 | }, |
|
22 | 78 | resetSync: function resetSync() { |
30 | 79 | this.service = STATUS_OK; |
30 | 80 | this._login = LOGIN_SUCCEEDED; |
30 | 81 | this._sync = SYNC_SUCCEEDED; |
40 | 82 | this._engines = {}; |
40 | 83 | this.partial = false; |
84 | }, |
|
85 | }; |
|
86 | ||
87 | // Initialize various status values |
|
12 | 88 | Status.resetBackoff(); |
15 | 89 | Status.resetSync(); |