Closed Bug 735333 Opened 13 years ago Closed 12 years ago

Use Services.prefs instead of preferences-service / gPrefService, in SeaMonkey code

Categories

(SeaMonkey :: General, defect)

defect
Not set
trivial

Tracking

(Not tracked)

RESOLVED FIXED
seamonkey2.20

People

(Reporter: sgautherie, Assigned: aryx)

References

Details

(Whiteboard: [good first bug][mentor=mcsmurf][lang=js] [meta])

Attachments

(14 files, 30 obsolete files)

9.51 KB, patch
Details | Diff | Splinter Review
10.99 KB, patch
Details | Diff | Splinter Review
14.80 KB, patch
Details | Diff | Splinter Review
1.52 KB, patch
Details | Diff | Splinter Review
9.90 KB, patch
Details | Diff | Splinter Review
3.62 KB, patch
Details | Diff | Splinter Review
4.98 KB, patch
Details | Diff | Splinter Review
1.22 KB, patch
Details | Diff | Splinter Review
13.02 KB, patch
Details | Diff | Splinter Review
10.66 KB, patch
Details | Diff | Splinter Review
4.11 KB, patch
Details | Diff | Splinter Review
52.35 KB, patch
Details | Diff | Splinter Review
7.75 KB, patch
Details | Diff | Splinter Review
28.72 KB, patch
Details | Diff | Splinter Review
+++ This bug was initially created as a clone of Bug #707786 +++ http://mxr.mozilla.org/comm-central/search?string=gPrefService&case=1&find=%2Fsuite%2F "Found 10 matching lines in 3 files" http://mxr.mozilla.org/comm-central/search?string=preferences-service&case=1&find=%2Fsuite%2F "Found 75 matching lines in 42 files"
Comment on attachment 606181 [details] [diff] [review] replace preferences-service / gPrefService with Services.prefs in SeaMonkey code Review of attachment 606181 [details] [diff] [review]: ----------------------------------------------------------------- I suggest to do gPrefService in a first patch, then preferences-service in a second. ::: suite/browser/nsBrowserContentHandler.js @@ +151,5 @@ > } > > function getURLToLoad() > { > + var prefs = Services.prefs.getService(nsIPrefBranch); This is wrong: 1) Services.prefs already includes getService(nsIPrefBranch). 2) prefs var can be removed (= inlined) too.
Attachment #606181 - Flags: review?(sgautherie.bz) → review-
> +++ b/suite/browser/nsBrowserContentHandler.js > +++ b/suite/browser/nsTypeAheadFind.js These are components running in their own global context so you'll need to import Services.jsm somewhere near the top of the file: Components.utils.import("resource://gre/modules/Services.jsm"); I think for components unless the preference service is used repeatedly, importing Services.jsm for one or two users is not necessary. > +++ b/suite/browser/tabbrowser.xml > +++ b/suite/browser/urlbarBindings.xml > - Components.classes["@mozilla.org/preferences-service;1"] > - .getService(Components.interfaces.nsIPrefBranch2); > + Services.prefs.getService(Components.interfaces.nsIPrefBranch2); Ah Services.prefs already does a QueryInterface(Ci.nsIPrefBranch) so just |Services.prefs| will do here. I don't think this is necessary since Services.pref is a lazy getter but you're forcing it to instantiate here thus defeating the whole purpose of using Services. I gave up half way. But please make sure that Services is in the current scope before trying to use it. It also helps if you build SeaMonkey with your patch to see how many things break ;) So please attach an updated patch once you've done this.
Comment on attachment 606181 [details] [diff] [review] replace preferences-service / gPrefService with Services.prefs in SeaMonkey code Don't feel you have to do everything in one giant patch. You might want to start with simple cases where prefs are only used in two or three places in the file, and save the harder files for separate patches. >diff --git a/suite/browser/nsBrowserContentHandler.js b/suite/browser/nsBrowserContentHandler.js >index 64c04b1..48a8fe9 100644 >--- a/suite/browser/nsBrowserContentHandler.js >+++ b/suite/browser/nsBrowserContentHandler.js >@@ -147,18 +147,17 @@ function needHomePageOverride(prefs) > > prefs.setCharPref("browser.startup.homepage_override.mstone", mstone); > > return true; > } > > function getURLToLoad() > { >- var prefs = Components.classes["@mozilla.org/preferences-service;1"] >- .getService(nsIPrefBranch); >+ var prefs = Services.prefs.getService(nsIPrefBranch); > var formatter = Components.classes["@mozilla.org/toolkit/URLFormatterService;1"] > .getService(Components.interfaces.nsIURLFormatter); > > if (needHomePageOverride(prefs)) { nsBrowserContentHandler originally predated Services which is why it gets prefs once here and then hands it out when it's needed. If you want to switch this to use Services.prefs then you would get rid of all the prefs arguments. (This is in addition to removing all the other prefs variables that people have probably already mentioned.) > <field name="mPrefs" readonly="true"> >- Components.classes["@mozilla.org/preferences-service;1"] >- .getService(Components.interfaces.nsIPrefBranch2); >+ Services.prefs.getService(Components.interfaces.nsIPrefBranch2); > </field> Please don't change tabbrowser.xml, I don't want it to use Services. (I know it does but I didn't notice KaiRo/Callek adding them. Oops.) In fact, that goes for all the .xml files for now, I need to decide on a case-by-case basis. > var pref = null; >- pref = Components.classes["@mozilla.org/preferences-service;1"] >- .getService(Components.interfaces.nsIPrefBranch); >+ pref = Services.prefs.getService(Components.interfaces.nsIPrefBranch); Wow, I wonder whether we still have people using pref. (I know it's hard to tell with such a generic variable name; even something like sPrefs would be easier to find.) Ideally they would use Services.prefs instead and then we could just get rid of pref.
Blocks: 737061
Attachment #606181 - Attachment is obsolete: true
Attachment #611849 - Flags: review?(sgautherie.bz)
get _prefs() { delete this._prefs; - return this._prefs = Components.classes["@mozilla.org/preferences-service;1"] - .getService(Components.interfaces.nsIPrefService) - .getBranch("privacy.sanitize."); + return this._prefs = Services.prefs.getBranch("privacy.sanitize."); }, Is "delete this._prefs;" still necessary since Services.prefs is lazily loaded?
Attachment #611870 - Flags: review?(sgautherie.bz)
(In reply to Alan Yeo from comment #7) > get _prefs() { > delete this._prefs; > - return this._prefs = > Components.classes["@mozilla.org/preferences-service;1"] > - > .getService(Components.interfaces.nsIPrefService) > - .getBranch("privacy.sanitize."); > + return this._prefs = Services.prefs.getBranch("privacy.sanitize."); > }, > > Is "delete this._prefs;" still necessary since Services.prefs is lazily > loaded? This is a lazy caching branch getter, so it needs to do that to work properly.
Attached patch suite/mailnews/ (obsolete) — Splinter Review
Attachment #611967 - Flags: review?(sgautherie.bz)
Comment on attachment 611870 [details] [diff] [review] replace preferences-service with Services.prefs in suite/modules/Sanitizer.jsm Review of attachment 611870 [details] [diff] [review]: ----------------------------------------------------------------- ::: suite/modules/Sanitizer.jsm @@ +45,1 @@ > var EXPORTED_SYMBOLS = ["Sanitizer"]; Maybe better to keep EXPORTED_SYMBOLS on top. @@ +45,4 @@ > var EXPORTED_SYMBOLS = ["Sanitizer"]; > > var Sanitizer = { > get _prefs() { It looks like Services.prefs could be used directly at the 3 call lines... @@ +67,5 @@ > this.items[itemName].willClear = false; > }, > > readSettings: function(aParentWindow) { > + var itemPrefs = Services.prefs.getBranch("privacy.item."); (I have a doubt.) Did you confirm that this works? As getBranch() is part of nsIPrefService, not nsIPrefBranch. @@ +196,1 @@ > branch.deleteBranch(""); While here, merge 'branch' var too. Wouldn't Services.prefs.deleteBranch("geo.wifi.access_token.") even do the same job? @@ +227,2 @@ > try { > + Services.prefs.clearUserPref("general.open_location.last_url"); While here, "general.open_location.last_url" should be a property of 'urlbar' (if not a const in the file).
Attachment #611870 - Flags: review?(sgautherie.bz)
(In reply to Serge Gautherie (:sgautherie) from comment #10) > (I have a doubt.) > Did you confirm that this works? > As getBranch() is part of nsIPrefService, not nsIPrefBranch. This is wildly used, so no more doubt ;-> http://mxr.mozilla.org/comm-central/search?string=Services.prefs.getBranch&case=on
Comment on attachment 611849 [details] [diff] [review] replace gPrefService with Services.prefs Let's deal with one patch at a time, ftb...
Attachment #611849 - Flags: review?(sgautherie.bz)
Attachment #611866 - Flags: review?(sgautherie.bz)
Attachment #611967 - Flags: review?(sgautherie.bz)
Assignee: nobody → yeojw10
Status: NEW → ASSIGNED
Hello Alan, are you still working on this?
Nope, I haven't been able to find time to continue working on this. I'll go ahead and unassign myself.
Assignee: yeojw10 → nobody
Status: ASSIGNED → NEW
Assignee: nobody → archaeopteryx
This patch addresses the former review comments except it also switches to Services.jsm in .xml files. Is there any reason why you want the old code there?
Attachment #611849 - Attachment is obsolete: true
Attachment #611866 - Attachment is obsolete: true
Attachment #611870 - Attachment is obsolete: true
Attachment #611967 - Attachment is obsolete: true
Attachment #664179 - Flags: review?(sgautherie.bz)
Comment on attachment 664179 [details] [diff] [review] switchung preference calls to Services.jsm in all of /suite/ > except it also switches to Services.jsm > in .xml files. Is there any reason why you want the old code there? The SeaMonkey module owner doesn't want any dependency on Services in our XBL. Besides that's not the way to import a JSM into a XBL binding. Also separate patches for each SeaMonkey module in order to make reviewing easier. Please. Thank you very much.
Attachment #664179 - Flags: review?(sgautherie.bz)
Attachment #664179 - Attachment is obsolete: true
Attachment #665011 - Flags: review?(iann_bugzilla)
Comment on attachment 665025 [details] [diff] [review] Switch to Services.jsm: suite session restore Review of attachment 665025 [details] [diff] [review]: ----------------------------------------------------------------- ::: suite/common/aboutSessionRestore.js @@ +1,5 @@ > /* 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/. */ > > +Components.utils.import("resource://gre/modules/Services.jsm"); This is already done at line 91, where all import performed.
Attachment #665025 - Flags: review?(misak.bugzilla) → review-
Comment on attachment 665022 [details] [diff] [review] Switch to Services.jsm: suite preferences >+Components.utils.import("resource://gre/modules/Services.jsm"); As it happens, Services is already available from this file... > Services.obs.notifyObservers(window, "app-handler-pane-loaded", null); ... so you don't need to load it yourself. r=me with that fixed.
Attachment #665022 - Flags: review?(neil) → review+
Comment on attachment 665024 [details] [diff] [review] Switch to Services.jsm: suite sanitizer.jsm r=me assuming the tests still pass.
Attachment #665024 - Flags: review?(neil) → review+
Comment on attachment 665015 [details] [diff] [review] Switch to Services.jsm: suite common >- var pref = null; >- pref = Components.classes["@mozilla.org/preferences-service;1"] >- .getService(Components.interfaces.nsIPrefBranch); Careful here because some other file may be accidentally relying on this copy of pref, so you should probably check this patch in last. >+ Components.utils.import("resource://gre/modules/Services.jsm"); [I think any file including contentAreaClick or nsContextMenu will include utilityOverlay.js which will give it Services anyway.]
Comment on attachment 665014 [details] [diff] [review] Switch to Services.jsm: suite browser nsBrowserContentListener and nsBrowserStatusHandler already have access to Services. nsBrowserContentHandler and nsTypeAheadFind don't. Confused yet?
Comment on attachment 665025 [details] [diff] [review] Switch to Services.jsm: suite session restore Review of attachment 665025 [details] [diff] [review]: ----------------------------------------------------------------- Hmm, ignore my previous comment, I was looking to other file.
Attachment #665025 - Flags: review- → review+
Comment on attachment 665026 [details] [diff] [review] Switch to Services.jsm: suite sidebar >+Components.utils.import("resource://gre/modules/Services.jsm"); >+ As usual, don't need this.
Attachment #665026 - Flags: review?(mnyromyr) → review+
Attachment #665023 - Flags: review?(bugspam.Callek) → review+
Attachment #665019 - Flags: review?(bugzilla) → review+
Comment on attachment 665018 [details] [diff] [review] Switch to Services.jsm: suite downloads You seem to have forgotten prefs.getIntPref(PREF_DM_BEHAVIOR)...
Attachment #665018 - Attachment is obsolete: true
Attachment #665018 - Flags: review?(db48x)
Attachment #665647 - Flags: review?(db48x)
Comment on attachment 665011 [details] [diff] [review] Switch to Services.jsm: suite backend >+++ b/suite/mailnews/mail-offline.js >+Components.utils.import("resource://gre/modules/Services.jsm"); This isn't needed as Services.jsm is already imported by other scripts that the callers of mail-offline.js use. >+ switch(Services.prefs.getIntPref("offline.send.unsent_messages")) { Nit: trailing space. >+ switch(Services.prefs.getIntPref("offline.download.download_messages")) { Nit: trailing space. >+++ b/suite/mailnews/phishingDetector.js >+Components.utils.import("resource://gre/modules/Services.jsm"); This isn't needed as Services.jsm is already imported by other scripts that the callers of phishingDetector.js use. r=me with those fixed.
Attachment #665011 - Flags: review?(iann_bugzilla) → review+
Comment on attachment 665012 [details] [diff] [review] Switch to Services.jsm: suite bookmarks and history >+++ b/suite/common/bookmarks/bm-props.js >@@ -53,16 +53,18 @@ > * - "siteLocation" > * - "folderPicker" - hides both the tree and the menu. > * @ readOnly (Boolean) - optional, states if the panel should be read-only > * > * window.arguments[0].performed is set to true if any transaction has > * been performed by the dialog. > */ > >+Components.utils.import("resource://gre/modules/Services.jsm"); This shouldn't be needed as you are importing in editBookmarkOverlay.js so will available to this file. >- prefs.setBoolPref("browser.bookmarks.editDialog.expandTags", >+ Services.prefs.setBoolPref("browser.bookmarks.editDialog.expandTags", > !this._element("tagsSelectorRow").collapsed); You need to indent this so it lines up the " above. > if (!this._element("folderRow").collapsed) >- prefs.setBoolPref("browser.bookmarks.editDialog.expandFolders", >+ Services.prefs.setBoolPref("browser.bookmarks.editDialog.expandFolders", > !this._element("folderTreeRow").collapsed); You need to indent this so it lines up the " above. >+++ b/suite/common/history/controller.js >+Components.utils.import("resource://gre/modules/Services.jsm"); >+ This isn't needed as placesOverlay.xul's caller already imports Services.jsm (other scripts called by placesOverlay.xul already make use of Services). >+++ b/suite/common/history/utils.js >+Components.utils.import("resource://gre/modules/Services.jsm"); This isn't needed as placesOverlay.xul's caller already imports Services.jsm (other scripts called by placesOverlay.xul already make use of Services). >+ return this.ellipsis = Services.prefs.getComplexValue("intl.ellipsis", > Components.interfaces.nsIPrefLocalizedString).data; You need to indent this so it lines up the " above, alternatively write something like: return this.ellipsis = Services.prefs.getComplexValue("intl.ellipsis", Components.interfaces.nsIPrefLocalizedString).data; r=me with those fixed.
Attachment #665012 - Flags: review?(iann_bugzilla) → review+
Comment on attachment 665014 [details] [diff] [review] Switch to Services.jsm: suite browser >+++ b/suite/browser/nsBrowserContentListener.js >+Components.utils.import("resource://gre/modules/Services.jsm"); This import isn't required. >+++ b/suite/browser/nsBrowserStatusHandler.js >+Components.utils.import("resource://gre/modules/Services.jsm"); This import isn't required. r=me with that fixed.
Attachment #665014 - Flags: review?(iann_bugzilla) → review+
Comment on attachment 665015 [details] [diff] [review] Switch to Services.jsm: suite common >+++ b/suite/common/about.xhtml >+ Components.utils.import("resource://gre/modules/Services.jsm"); You don't need to import this. >+++ b/suite/common/contentAreaClick.js >+ Components.utils.import("resource://gre/modules/Services.jsm"); You don't need to import this. >+++ b/suite/common/nsContextMenu.js >+Components.utils.import("resource://gre/modules/Services.jsm"); You don't need to import this. r=me with those fixed. As Neil mentioned this patch probably needs to be checked in last.
Attachment #665015 - Flags: review?(iann_bugzilla) → review+
Comment on attachment 665647 [details] [diff] [review] Switch to Services.jsm: suite downloads, v2 >+++ b/suite/common/downloads/downloadmanager.js >+Components.utils.import("resource://gre/modules/Services.jsm"); This import is not required. >+++ b/suite/common/downloads/progressDialog.js >+Components.utils.import("resource://gre/modules/Services.jsm"); This import is not required. r=me with those fixed.
Attachment #665647 - Flags: review?(db48x) → review+
Comment on attachment 665020 [details] [diff] [review] Switch to Services.jsm: suite mailnews preferences >+++ b/suite/mailnews/prefs/pref-tags.js >+Components.utils.import("resource://gre/modules/Services.jsm"); This import is not needed. r=me with that fixed.
Attachment #665020 - Flags: review?(mnyromyr) → review+
Comment on attachment 665021 [details] [diff] [review] Switch to Services.jsm: suite message display (mailnews) >+++ b/suite/mailnews/mail3PaneWindowCommands.js >+Components.utils.import("resource://gre/modules/Services.jsm"); This import is not needed. >+++ b/suite/mailnews/mailContextMenus.js >+Components.utils.import("resource://gre/modules/Services.jsm"); This import is not needed. >+++ b/suite/mailnews/mailTasksOverlay.js >+Components.utils.import("resource://gre/modules/Services.jsm"); This import is not needed. >+++ b/suite/mailnews/mailWindow.js >+Components.utils.import("resource://gre/modules/Services.jsm"); This import is probably not needed. >+++ b/suite/mailnews/messageWindow.js >+Components.utils.import("resource://gre/modules/Services.jsm"); This import is not needed. >+++ b/suite/mailnews/msgHdrViewOverlay.js >+Components.utils.import("resource://gre/modules/Services.jsm"); This import is not needed. >+++ b/suite/mailnews/msgMail3PaneWindow.js >+Components.utils.import("resource://gre/modules/Services.jsm"); This import is not needed. >+++ b/suite/mailnews/msgViewNavigation.js >+Components.utils.import("resource://gre/modules/Services.jsm"); This import is not needed. >+++ b/suite/mailnews/tabmail.js >+Components.utils.import("resource://gre/modules/Services.jsm"); This import is not needed. >+++ b/suite/mailnews/threadPane.js >+Components.utils.import("resource://gre/modules/Services.jsm"); This import is not needed. r=me with that fixed.
Attachment #665021 - Flags: review?(mnyromyr) → review+
Status: NEW → ASSIGNED
Comment on attachment 665017 [details] [diff] [review] Switch to Services.jsm: suite compose (mailnews) >+Components.utils.import("resource://gre/modules/Services.jsm"); >+ You don't need that here, it's already imported elsewhere.
Attachment #665017 - Flags: review?(mnyromyr) → review+
Oh, and you can assume moa+ for suite/mailnews for this if either Neil, IanN or I have seen it.
Attached file updated SeaMonkey Services.jsm patches (obsolete) —
Hi, these are the updated versions of the patches. It would be nice if someone can build SeaMonkey with these and run the tests. This fails on Thunderbird-Try, see https://bugzilla.mozilla.org/show_bug.cgi?id=798789#c10
Attachment #669495 - Attachment is patch: true
Attachment #669495 - Attachment mime type: application/octet-stream → text/plain
Comment on attachment 669495 [details] updated SeaMonkey Services.jsm patches Not sure what the attachment is, but doesn't appear to be a patch. Could you try again?
Attachment #669495 - Attachment is obsolete: true
Attachment #669495 - Attachment is patch: false
It's a ZIP file containing several patches. Archaeopteryx, aside from unpacking them and attaching them individually, could you make them changeset patches with the normal Hg metadata?
Attachment #665014 - Attachment is obsolete: true
Attachment #665015 - Attachment is obsolete: true
(In reply to Philip Chee from comment #51) > It's a ZIP file containing several patches. Archaeopteryx, aside from > unpacking them and attaching them individually, could you make them > changeset patches with the normal Hg metadata? Done. To advance, we need a compile-and-test run sponsored by someone with a performing machine (Windows would be optimal for debugging). mcsmurf and I didn't manage to use Thunderbird-Try for this (directory issues with the extensions).
Flags: needinfo?
(In reply to Philip Chee from comment #51) > It's a ZIP file containing several patches. Archaeopteryx, aside from > unpacking them and attaching them individually, could you make them > changeset patches with the normal Hg metadata? Done. To advance, we need a compile-and-test run sponsored by someone with a performing machine (Windows would be optimal for debugging). mcsmurf and I didn't manage to use Thunderbird-Try for this (directory issues with the extensions).
I wonder what to actually look for in the mochitest log. Failing tests only or also JavaScript errors in the log? The latter is more difficult to find out as JS errors are not "tagged" (like TEST-UNEXPECTED-FAIL) in the output log. I wonder as I saw this error in mochitest-browser-chrome log: [Exception... "Component returned failure code: 0x8000ffff (NS_ERROR_UNEXPECTED) [nsIPrefBranch.getBoolPref]" nsresult: "0x8000ffff (NS_ERROR_UNEXPECTED)" loc ation: "JS frame :: file:///c:/mozilla/tree-hg/objdirs/seamonkey-objdir-debug-te sts/mozilla/dist/bin/components/nsSessionStartup.js :: sss_init :: line 64" dat a: no] line 64 is the "Services.prefs.getBoolPref("sessionstore.resume_session_once")" call.
Flags: needinfo?
Replaces Attachment 683229 [details] [diff], old patch did not apply anymore.
Attachment #683229 - Attachment is obsolete: true
Replaces Attachment 683236 [details] [diff], old patch did not apply anymore.
Attachment #683236 - Attachment is obsolete: true
Replaces Attachment 683242 [details] [diff], old patch did not apply anymore.
Attachment #683242 - Attachment is obsolete: true
Oh, I see :) the pref name is brower.sessionstore.resume_session_once, not sessionstore.resume_session_once.
Sorry for this. Please also update that line below by adding "browser.": + var resumeFromCrash = Services.prefs.getBoolPref("sessionstore.resume_from_crash");
Replaces Attachment 683249 [details] [diff], fixes the pref issue.
Attachment #683249 - Attachment is obsolete: true
Comment on attachment 696569 [details] [diff] [review] Switch to Services.jsm: suite message display (mailnews), v4 Need to remove the GetPrefService() call from mailWindow.js (as the function went away with this patch).
In addition to the previous patch this one removes the GetPrefService() call from "function CreateMailWindowGlobals()".
Attachment #696569 - Attachment is obsolete: true
Fix bitrot from Bug 833015
Attachment #683238 - Attachment is obsolete: true
Updated patch for checkin (yes, it's happening really soon now)
Attachment #706916 - Attachment is obsolete: true
Patch updated for checkin.
Attachment #683239 - Attachment is obsolete: true
Target Milestone: --- → seamonkey2.20
Status: ASSIGNED → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Whiteboard: [good first bug][mentor=sgautherie][lang=js] [meta] → [good first bug][mentor=mcsmurf][lang=js] [meta]
Depends on: 893547
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: