make service.js the main entry point from chrome/content; make the service be lazy-loaded; make crypto be lazy-loaded

This commit is contained in:
Dan Mills 2008-03-25 15:14:00 -07:00
Родитель 49d0c55031
Коммит 89a59249b4
6 изменённых файлов: 35 добавлений и 57 удалений

Просмотреть файл

@ -34,7 +34,7 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
const EXPORTED_SYMBOLS = ['WeaveCrypto']; const EXPORTED_SYMBOLS = ['Crypto'];
const Cc = Components.classes; const Cc = Components.classes;
const Ci = Components.interfaces; const Ci = Components.interfaces;
@ -49,10 +49,12 @@ Cu.import("resource://weave/async.js");
Function.prototype.async = Async.sugar; Function.prototype.async = Async.sugar;
function WeaveCrypto() { Utils.lazy(this, 'Crypto', CryptoSvc);
function CryptoSvc() {
this._init(); this._init();
} }
WeaveCrypto.prototype = { CryptoSvc.prototype = {
_logName: "Crypto", _logName: "Crypto",
__os: null, __os: null,

Просмотреть файл

@ -49,6 +49,8 @@ Cu.import("resource://weave/constants.js");
Function.prototype.async = Async.sugar; Function.prototype.async = Async.sugar;
Utils.lazy(this, 'DAV', DAVCollection);
/* /*
* DAV object * DAV object
* Abstracts the raw DAV commands * Abstracts the raw DAV commands

Просмотреть файл

@ -52,7 +52,6 @@ Cu.import("resource://weave/syncCores.js");
Cu.import("resource://weave/async.js"); Cu.import("resource://weave/async.js");
Function.prototype.async = Async.sugar; Function.prototype.async = Async.sugar;
let Crypto = new WeaveCrypto();
function Engine(davCollection, pbeId) { function Engine(davCollection, pbeId) {
//this._init(davCollection, pbeId); //this._init(davCollection, pbeId);

Просмотреть файл

@ -34,7 +34,7 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
const EXPORTED_SYMBOLS = ['WeaveSyncService']; const EXPORTED_SYMBOLS = ['Weave'];
const Cc = Components.classes; const Cc = Components.classes;
const Ci = Components.interfaces; const Ci = Components.interfaces;
@ -52,15 +52,28 @@ Cu.import("resource://weave/identity.js");
Cu.import("resource://weave/async.js"); Cu.import("resource://weave/async.js");
Function.prototype.async = Async.sugar; Function.prototype.async = Async.sugar;
let Crypto = new WeaveCrypto();
// for export
let Weave = {};
Components.utils.import("resource://weave/constants.js", Weave);
Components.utils.import("resource://weave/util.js", Weave);
Components.utils.import("resource://weave/async.js", Weave);
Components.utils.import("resource://weave/crypto.js", Weave);
Components.utils.import("resource://weave/identity.js", Weave);
Components.utils.import("resource://weave/dav.js", Weave);
Components.utils.import("resource://weave/stores.js", Weave);
Components.utils.import("resource://weave/syncCores.js", Weave);
Components.utils.import("resource://weave/engines.js", Weave);
Components.utils.import("resource://weave/service.js", Weave);
Utils.lazy(Weave, 'Service', WeaveSvc);
/* /*
* Service singleton * Service singleton
* Main entry point into Weave's sync framework * Main entry point into Weave's sync framework
*/ */
function WeaveSyncService() { this._init(); } function WeaveSvc() { this._init(); }
WeaveSyncService.prototype = { WeaveSvc.prototype = {
__os: null, __os: null,
get _os() { get _os() {

Просмотреть файл

@ -51,6 +51,17 @@ Cu.import("resource://weave/log4moz.js");
let Utils = { let Utils = {
// lazy load objects from a constructor on first access. It will
// work with the global object ('this' in the global context).
lazy: function Weave_lazy(dest, prop, ctr) {
let getter = function() {
delete dest[prop];
dest[prop] = new ctr();
return dest[prop];
};
dest.__defineGetter__(prop, getter);
},
deepEquals: function Weave_deepEquals(a, b) { deepEquals: function Weave_deepEquals(a, b) {
if (!a && !b) if (!a && !b)
return true; return true;

Просмотреть файл

@ -1,49 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Bookmarks Sync.
*
* The Initial Developer of the Original Code is Mozilla.
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Dan Mills <thunder@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
const EXPORTED_SYMBOLS = ['Weave'];
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cr = Components.results;
const Cu = Components.utils;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://weave/service.js");
let Weave = {};
//Weave.Crypto = new WeaveCrypto();
Weave.Service = new WeaveSyncService();