Bug 850219 - Mark nsIContentPrefService as deprecated in favor of nsIContentPrefService2. r=mak
authorDrew Willcoxon <adw@mozilla.com>
Thu, 08 Aug 2013 20:38:49 -0700
changeset 141981 914bf3adc1ed28584a92f7bc63dfe8da39d0c595
parent 141980 cb05c6b8ae8e59e5ebc585c0ec9534ab23c9ac04
child 141982 b582bf2f4929133959aebbd378e1b9c7bc779de7
push id25076
push userryanvm@gmail.com
push dateFri, 09 Aug 2013 23:09:21 +0000
treeherdermozilla-central@cead6eb63964 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs850219
milestone26.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 850219 - Mark nsIContentPrefService as deprecated in favor of nsIContentPrefService2. r=mak
dom/interfaces/base/nsIContentPrefService.idl
toolkit/components/contentprefs/ContentPrefService2.jsm
toolkit/components/contentprefs/nsContentPrefService.js
toolkit/mozapps/downloads/DownloadLastDir.jsm
--- a/dom/interfaces/base/nsIContentPrefService.idl
+++ b/dom/interfaces/base/nsIContentPrefService.idl
@@ -34,16 +34,19 @@ interface nsIContentPrefObserver : nsISu
 };
 
 [scriptable, function, uuid(c1b3d6df-5373-4606-8494-8bcf14a7fc62)]
 interface nsIContentPrefCallback : nsISupports
 {
   void onResult(in nsIVariant aResult);
 };
 
+/**
+ * @deprecated Please use nsIContentPrefService2 instead.
+ */
 [scriptable, uuid(e3f772f3-023f-4b32-b074-36cf0fd5d414)]
 interface nsIContentPrefService : nsISupports
 {
   /**
    * Get a pref.
    *
    * Besides the regular string, integer, boolean, etc. values, this method
    * may return null (nsIDataType::VTYPE_EMPTY), which means the pref is set
--- a/toolkit/components/contentprefs/ContentPrefService2.jsm
+++ b/toolkit/components/contentprefs/ContentPrefService2.jsm
@@ -691,30 +691,30 @@ ContentPrefService2.prototype = {
     if (!groupStr)
       return null;
     try {
       var groupURI = Services.io.newURI(groupStr, null, null);
     }
     catch (err) {
       return groupStr;
     }
-    return this._cps.grouper.group(groupURI);
+    return this._cps._grouper.group(groupURI);
   },
 
   _schedule: function CPS2__schedule(fn) {
     Services.tm.mainThread.dispatch(fn.bind(this),
                                     Ci.nsIThread.DISPATCH_NORMAL);
   },
 
   addObserverForName: function CPS2_addObserverForName(name, observer) {
-    this._cps.addObserver(name, observer);
+    this._cps._addObserver(name, observer);
   },
 
   removeObserverForName: function CPS2_removeObserverForName(name, observer) {
-    this._cps.removeObserver(name, observer);
+    this._cps._removeObserver(name, observer);
   },
 
   extractDomain: function CPS2_extractDomain(str) {
     return this._parseGroup(str);
   },
 
   /**
    * Tests use this as a backchannel by calling it directly.
--- a/toolkit/components/contentprefs/nsContentPrefService.js
+++ b/toolkit/components/contentprefs/nsContentPrefService.js
@@ -226,16 +226,18 @@ ContentPrefService.prototype = {
 
   _cache: cache,
   _privModeStorage: privModeStorage,
 
   //**************************************************************************//
   // nsIContentPrefService
 
   getPref: function ContentPrefService_getPref(aGroup, aName, aContext, aCallback) {
+    warnDeprecated();
+
     if (!aName)
       throw Components.Exception("aName cannot be null or an empty string",
                                  Cr.NS_ERROR_ILLEGAL_VALUE);
 
     var group = this._parseGroupParam(aGroup);
 
     if (aContext && aContext.usePrivateBrowsing) {
       if (this._privModeStorage.has(group, aName)) {
@@ -251,16 +253,18 @@ ContentPrefService.prototype = {
     }
 
     if (group == null)
       return this._selectGlobalPref(aName, aCallback);
     return this._selectPref(group, aName, aCallback);
   },
 
   setPref: function ContentPrefService_setPref(aGroup, aName, aValue, aContext) {
+    warnDeprecated();
+
     // If the pref is already set to the value, there's nothing more to do.
     var currentValue = this.getPref(aGroup, aName, aContext);
     if (typeof currentValue != "undefined") {
       if (currentValue == aValue)
         return;
     }
 
     var group = this._parseGroupParam(aGroup);
@@ -288,32 +292,38 @@ ContentPrefService.prototype = {
     else
       this._insertPref(groupID, settingID, aValue);
 
     this._cache.setWithCast(group, aName, aValue);
     this._notifyPrefSet(group, aName, aValue);
   },
 
   hasPref: function ContentPrefService_hasPref(aGroup, aName, aContext) {
+    warnDeprecated();
+
     // XXX If consumers end up calling this method regularly, then we should
     // optimize this to query the database directly.
     return (typeof this.getPref(aGroup, aName, aContext) != "undefined");
   },
 
   hasCachedPref: function ContentPrefService_hasCachedPref(aGroup, aName, aContext) {
+    warnDeprecated();
+
     if (!aName)
       throw Components.Exception("aName cannot be null or an empty string",
                                  Cr.NS_ERROR_ILLEGAL_VALUE);
 
     let group = this._parseGroupParam(aGroup);
     let storage = aContext && aContext.usePrivateBrowsing ? this._privModeStorage: this._cache;
     return storage.has(group, aName);
   },
 
   removePref: function ContentPrefService_removePref(aGroup, aName, aContext) {
+    warnDeprecated();
+
     // If there's no old value, then there's nothing to remove.
     if (!this.hasPref(aGroup, aName, aContext))
       return;
 
     var group = this._parseGroupParam(aGroup);
 
     if (aContext && aContext.usePrivateBrowsing) {
       this._privModeStorage.remove(group, aName);
@@ -339,16 +349,18 @@ ContentPrefService.prototype = {
     if (groupID)
       this._deleteGroupIfUnused(groupID);
 
     this._cache.remove(group, aName);
     this._notifyPrefRemoved(group, aName);
   },
 
   removeGroupedPrefs: function ContentPrefService_removeGroupedPrefs(aContext) {
+    warnDeprecated();
+
     // will not delete global preferences
     if (aContext && aContext.usePrivateBrowsing) {
         // keep only global prefs
         this._privModeStorage.removeAllGroups();
     }
     this._cache.removeAllGroups();
     this._dbConnection.beginTransaction();
     try {
@@ -362,16 +374,18 @@ ContentPrefService.prototype = {
     }
     catch(ex) {
       this._dbConnection.rollbackTransaction();
       throw ex;
     }
   },
 
   removePrefsByName: function ContentPrefService_removePrefsByName(aName, aContext) {
+    warnDeprecated();
+
     if (!aName)
       throw Components.Exception("aName cannot be null or an empty string",
                                  Cr.NS_ERROR_ILLEGAL_VALUE);
 
     if (aContext && aContext.usePrivateBrowsing) {
       for (let [group, name, ] in this._privModeStorage) {
         if (name === aName) {
           this._privModeStorage.remove(group, aName);
@@ -418,16 +432,18 @@ ContentPrefService.prototype = {
         this._deleteGroupIfUnused(groupIDs[i]);
       if (!aContext || !aContext.usePrivateBrowsing) {
         this._notifyPrefRemoved(groupNames[i], aName);
       }
     }
   },
 
   getPrefs: function ContentPrefService_getPrefs(aGroup, aContext) {
+    warnDeprecated();
+
     var group = this._parseGroupParam(aGroup);
     if (aContext && aContext.usePrivateBrowsing) {
         let prefs = Cc["@mozilla.org/hash-property-bag;1"].
                     createInstance(Ci.nsIWritablePropertyBag);
         for (let [sgroup, sname, sval] in this._privModeStorage) {
           if (sgroup === group)
             prefs.setProperty(sname, sval);
         }
@@ -435,16 +451,18 @@ ContentPrefService.prototype = {
     }
 
     if (group == null)
       return this._selectGlobalPrefs();
     return this._selectPrefs(group);
   },
 
   getPrefsByName: function ContentPrefService_getPrefsByName(aName, aContext) {
+    warnDeprecated();
+
     if (!aName)
       throw Components.Exception("aName cannot be null or an empty string",
                                  Cr.NS_ERROR_ILLEGAL_VALUE);
 
     if (aContext && aContext.usePrivateBrowsing) {
       let prefs = Cc["@mozilla.org/hash-property-bag;1"].
                   createInstance(Ci.nsIWritablePropertyBag);
       for (let [sgroup, sname, sval] in this._privModeStorage) {
@@ -459,30 +477,40 @@ ContentPrefService.prototype = {
 
   // A hash of arrays of observers, indexed by setting name.
   _observers: {},
 
   // An array of generic observers, which observe all settings.
   _genericObservers: [],
 
   addObserver: function ContentPrefService_addObserver(aName, aObserver) {
+    warnDeprecated();
+    this._addObserver.apply(this, arguments);
+  },
+
+  _addObserver: function ContentPrefService__addObserver(aName, aObserver) {
     var observers;
     if (aName) {
       if (!this._observers[aName])
         this._observers[aName] = [];
       observers = this._observers[aName];
     }
     else
       observers = this._genericObservers;
 
     if (observers.indexOf(aObserver) == -1)
       observers.push(aObserver);
   },
 
   removeObserver: function ContentPrefService_removeObserver(aName, aObserver) {
+    warnDeprecated();
+    this._removeObserver.apply(this, arguments);
+  },
+
+  _removeObserver: function ContentPrefService__removeObserver(aName, aObserver) {
     var observers;
     if (aName) {
       if (!this._observers[aName])
         return;
       observers = this._observers[aName];
     }
     else
       observers = this._genericObservers;
@@ -531,25 +559,30 @@ ContentPrefService.prototype = {
         observer.onContentPrefSet(aGroup, aName, aValue);
       }
       catch(ex) {
         Cu.reportError(ex);
       }
     }
   },
 
-  _grouper: null,
   get grouper() {
-    if (!this._grouper)
-      this._grouper = Cc["@mozilla.org/content-pref/hostname-grouper;1"].
-                      getService(Ci.nsIContentURIGrouper);
+    warnDeprecated();
     return this._grouper;
   },
+  __grouper: null,
+  get _grouper() {
+    if (!this.__grouper)
+      this.__grouper = Cc["@mozilla.org/content-pref/hostname-grouper;1"].
+                       getService(Ci.nsIContentURIGrouper);
+    return this.__grouper;
+  },
 
   get DBConnection() {
+    warnDeprecated();
     return this._dbConnection;
   },
 
 
   //**************************************************************************//
   // Data Retrieval & Modification
 
   __stmtSelectPref: null,
@@ -1200,16 +1233,23 @@ ContentPrefService.prototype = {
     if (aGroup instanceof Ci.nsIURI)
       return this.grouper.group(aGroup);
 
     throw Components.Exception("aGroup is not a string, nsIURI or null",
                                Cr.NS_ERROR_ILLEGAL_VALUE);
   },
 };
 
+function warnDeprecated() {
+  Cu.import("resource://gre/modules/Deprecated.jsm");
+  Deprecated.warning("nsIContentPrefService is deprecated. Please use nsIContentPrefService2 instead.",
+                     "https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIContentPrefService2",
+                     Components.stack.caller);
+}
+
 
 function HostnameGrouper() {}
 
 HostnameGrouper.prototype = {
   //**************************************************************************//
   // XPCOM Plumbing
   
   classID:          Components.ID("{8df290ae-dcaa-4c11-98a5-2429a4dc97bb}"),
--- a/toolkit/mozapps/downloads/DownloadLastDir.jsm
+++ b/toolkit/mozapps/downloads/DownloadLastDir.jsm
@@ -91,51 +91,59 @@ this.DownloadLastDir = function Download
   this.window = aWindow;
 }
 
 DownloadLastDir.prototype = {
   isPrivate: function DownloadLastDir_isPrivate() {
     return PrivateBrowsingUtils.isWindowPrivate(this.window);
   },
   // compat shims
-  get file() { return this.getFile(); },
+  get file() this._getLastFile(),
   set file(val) { this.setFile(null, val); },
   cleanupPrivateFile: function () {
     gDownloadLastDirFile = null;
   },
   // This function is now deprecated as it uses the sync nsIContentPrefService
   // interface. New consumers should use the getFileAsync function.
   getFile: function (aURI) {
+    Components.utils.import("resource://gre/modules/Deprecated.jsm");
+    Deprecated.warning("DownloadLastDir.getFile is deprecated. Please use getFileAsync instead.",
+                       "https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/DownloadLastDir.jsm",
+                       Components.stack.caller);
+
     if (aURI && isContentPrefEnabled()) {
       let loadContext = this.window
                             .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                             .getInterface(Components.interfaces.nsIWebNavigation)
                             .QueryInterface(Components.interfaces.nsILoadContext);
       let lastDir = Services.contentPrefs.getPref(aURI, LAST_DIR_PREF, loadContext);
       if (lastDir) {
         var lastDirFile = Components.classes["@mozilla.org/file/local;1"]
                                     .createInstance(Components.interfaces.nsIFile);
         lastDirFile.initWithPath(lastDir);
         return lastDirFile;
       }
     }
+    return this._getLastFile();
+  },
+
+  _getLastFile: function () {
     if (gDownloadLastDirFile && !gDownloadLastDirFile.exists())
       gDownloadLastDirFile = null;
 
     if (this.isPrivate()) {
       if (!gDownloadLastDirFile)
         gDownloadLastDirFile = readLastDirPref();
       return gDownloadLastDirFile;
     }
-    else
-      return readLastDirPref();
+    return readLastDirPref();
   },
 
   getFileAsync: function(aURI, aCallback) {
-    let plainPrefFile = this.getFile();
+    let plainPrefFile = this._getLastFile();
     if (!aURI || !isContentPrefEnabled()) {
       Services.tm.mainThread.dispatch(function() aCallback(plainPrefFile),
                                       Components.interfaces.nsIThread.DISPATCH_NORMAL);
       return;
     }
 
     let uri = aURI instanceof Components.interfaces.nsIURI ? aURI.spec : aURI;
     let cps2 = Components.classes["@mozilla.org/content-pref/service;1"]