Open
Bug 800690
Opened 12 years ago
Updated 2 years ago
Create a template class to cache and subscribe preferences
Categories
(Core :: Graphics, defect)
Core
Graphics
Tracking
()
NEW
People
(Reporter: ajones, Unassigned)
References
Details
Attachments
(3 files, 6 obsolete files)
5.41 KB,
patch
|
Details | Diff | Splinter Review | |
4.60 KB,
patch
|
benjamin
:
review+
|
Details | Diff | Splinter Review |
6.54 KB,
patch
|
Details | Diff | Splinter Review |
Create something to cache preferences so we don't end up with bespoke code all over the place repeating the pattern of checking the preference if we haven't already done so all over the place.
Reporter | ||
Comment 1•12 years ago
|
||
Reporter | ||
Comment 2•12 years ago
|
||
Attachment #670687 -
Flags: review?(roc)
Reporter | ||
Comment 3•12 years ago
|
||
Comment on attachment 670687 [details] [diff] [review] Part 2: Create a container that caches and subscribes preference values Review of attachment 670687 [details] [diff] [review]: ----------------------------------------------------------------- Make the string be a template parameter? Then it doesn't have to be stored in the object. bsmedberg will need to review this.
Attachment #670687 -
Flags: review?(roc)
Attachment #670687 -
Flags: review?
Attachment #670687 -
Flags: feedback+
Reporter | ||
Updated•12 years ago
|
Attachment #670687 -
Flags: review? → review?(benjamin)
Reporter | ||
Updated•12 years ago
|
Attachment #670687 -
Flags: review?(benjamin) → review?
Comment 5•12 years ago
|
||
Try run for 21322ebec200 is complete. Detailed breakdown of the results available here: https://tbpl.mozilla.org/?tree=Try&rev=21322ebec200 Results (out of 13 total builds): success: 13 Builds (or logs if builds failed) available at: http://ftp.mozilla.org/pub/mozilla.org/firefox/try-builds/ajones@mozilla.com-21322ebec200
Attachment #670687 -
Flags: review? → review?(benjamin)
Reporter | ||
Comment 6•12 years ago
|
||
Attachment #670686 -
Attachment is obsolete: true
Reporter | ||
Comment 7•12 years ago
|
||
Attachment #670687 -
Attachment is obsolete: true
Attachment #670687 -
Flags: review?(benjamin)
Attachment #671592 -
Flags: review?(benjamin)
Reporter | ||
Comment 8•12 years ago
|
||
Attachment #670688 -
Attachment is obsolete: true
Comment 9•12 years ago
|
||
Comment on attachment 671592 [details] [diff] [review] Part 2: Create a container that caches and subscribes preference values v2 Thank you for the patch. I don't think that the API is quite right yet, but I do think that something like this would help make pref usage simpler and avoid code duplication. Catch me on irc `bsmedberg` if you'd like to talk about this in realtime. 1) Does this compile? I'm having trouble understading how template <const nsDependentCString& tPref, typename T> could work, since tPref can't be a compile-time constant. I also don't think we want to paramaterize it that way since you'd be generating a new copy of the methods for each pref name. 2) The code here is very similar to Preferences::Add*VarCache. Can we unify the callback mechanism some? 3) I don't think that the Preferences::Get specialization is very intuitive (specializing on return values gets ambiguous quickly). I think it would be better to do all this by specializing PrefContainer instead. 4) PrefContainer.cpp is an empty file and shouldn't exist.
Attachment #671592 -
Flags: review?(benjamin) → review-
Reporter | ||
Comment 10•12 years ago
|
||
(In reply to Benjamin Smedberg [:bsmedberg] from comment #9) > Comment on attachment 671592 [details] [diff] [review] > Part 2: Create a container that caches and subscribes preference values v2 > > Thank you for the patch. I don't think that the API is quite right yet, but > I do think that something like this would help make pref usage simpler and > avoid code duplication. Catch me on irc `bsmedberg` if you'd like to talk > about this in realtime. > > 1) Does this compile? I'm having trouble understading how > > template <const nsDependentCString& tPref, typename T> See some usage examples in Part 3. > could work, since tPref can't be a compile-time constant. I also don't think > we want to paramaterize it that way since you'd be generating a new copy of > the methods for each pref name. The size issue can be eliminated by creating helper methods but that would seem premature at this stage. > 2) The code here is very similar to Preferences::Add*VarCache. Can we unify > the callback mechanism some? I had considered that but neither contain complicated logic and the complexity of implementing one in terms of the other seemed to be greater than the waste involved in the overlap. I hope that PrefContainer to be simpler and safer alternative to Add*VarCache on the basis that it protects against observer leakage. You may have preferred the previous incarnation of the patch, however I followed roc's advice and this lead me to what I consider to be an simpler and better implementation.
Reporter | ||
Updated•12 years ago
|
Attachment #670686 -
Attachment is obsolete: false
Reporter | ||
Updated•12 years ago
|
Attachment #670687 -
Attachment is patch: false
Reporter | ||
Updated•12 years ago
|
Attachment #670687 -
Attachment is obsolete: false
Attachment #670687 -
Attachment is patch: true
Reporter | ||
Updated•12 years ago
|
Attachment #670688 -
Attachment is obsolete: false
Reporter | ||
Updated•12 years ago
|
Attachment #671590 -
Attachment is obsolete: true
Reporter | ||
Updated•12 years ago
|
Attachment #671592 -
Attachment is obsolete: true
Reporter | ||
Updated•12 years ago
|
Attachment #671598 -
Attachment is obsolete: true
Reporter | ||
Comment 11•12 years ago
|
||
Comment on attachment 670687 [details] [diff] [review] Part 2: Create a container that caches and subscribes preference values Let's consider the v2 patches a blind alley and consider the original patches instead.
Attachment #670687 -
Flags: review?(benjamin)
Reporter | ||
Comment 12•12 years ago
|
||
Rebased for strongly typed nsresult.
Reporter | ||
Updated•12 years ago
|
Attachment #670687 -
Attachment is obsolete: true
Attachment #670687 -
Flags: review?(benjamin)
Reporter | ||
Updated•12 years ago
|
Attachment #672154 -
Flags: review?(benjamin)
Comment 13•12 years ago
|
||
Try run for 75d167396c28 is complete. Detailed breakdown of the results available here: https://tbpl.mozilla.org/?tree=Try&rev=75d167396c28 Results (out of 2 total builds): exception: 2 Builds (or logs if builds failed) available at: http://ftp.mozilla.org/pub/mozilla.org/firefox/try-builds/ajones@mozilla.com-75d167396c28
Reporter | ||
Comment 14•12 years ago
|
||
Attachment #672154 -
Attachment is obsolete: true
Attachment #672154 -
Flags: review?(benjamin)
Attachment #672173 -
Flags: review?(benjamin)
Reporter | ||
Comment 15•12 years ago
|
||
Attachment #670688 -
Attachment is obsolete: true
Comment 16•12 years ago
|
||
Try run for ba26192dafe0 is complete. Detailed breakdown of the results available here: https://tbpl.mozilla.org/?tree=Try&rev=ba26192dafe0 Results (out of 38 total builds): success: 31 warnings: 7 Builds (or logs if builds failed) available at: http://ftp.mozilla.org/pub/mozilla.org/firefox/try-builds/ajones@mozilla.com-ba26192dafe0
Comment 17•12 years ago
|
||
Comment on attachment 672173 [details] [diff] [review] Part 2: Create a container that caches and subscribes preference values v4 >diff --git a/modules/libpref/public/PrefContainer.h b/modules/libpref/public/PrefContainer.h >+/** >+ * PrefContainer is cached and self updating preference container. It removes >+ * the need for special code to cache a preference. Rather the preference is >+ * read and subscribed when the object is created and it is unsubscribed when >+ * the object is destroyed. >+ * >+ * The usage is something like this: >+ * >+ * PrefContainer<boolean> mSelfDestructEnabled; >+ * >+ * And in the constructor >+ * >+ * : mSelfDestructEnabled("self.destruct.enabled", true); >+ * >+ * It defines a default conversion so you can write: >+ * >+ * if (mSelfDestructEnabled.Get()) Please list the types that PrefContainer is currently specialized on. >diff --git a/modules/libpref/src/Makefile.in b/modules/libpref/src/Makefile.in >--- a/modules/libpref/src/Makefile.in >+++ b/modules/libpref/src/Makefile.in >@@ -19,16 +19,17 @@ GRE_MODULE = 1 > LIBXUL_LIBRARY = 1 > > CPPSRCS = \ > nsPrefBranch.cpp \ > nsPrefsFactory.cpp \ > prefapi.cpp \ > prefread.cpp \ > Preferences.cpp \ >+ PrefContainer.cpp \ > $(NULL) nit, either match the tabtabtabspacespace or convert the entire block to spaces >+template<> >+void >+PrefContainerBase<nsCString>::Update() >+{ >+ if (NS_SUCCEEDED(Preferences::GetCString(mPref, &mValue))) { >+ mValue = mDefault; I'm pretty sure you mean NS_FAILED here, no? Too bad that writing internal-linkage compiled code tests is so hard. r=me with those changes
Attachment #672173 -
Flags: review?(benjamin) → review+
Updated•2 years ago
|
Severity: normal → S3
You need to log in
before you can comment on or make changes to this bug.
Description
•