Closed Bug 785298 Opened 12 years ago Closed 12 years ago

Settings API: set() can carry a customized message to notify "mozsettings-changed" observers

Categories

(Core :: DOM: Core & HTML, defect)

ARM
Gonk (Firefox OS)
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla18
blocking-basecamp +

People

(Reporter: airpingu, Assigned: airpingu)

References

Details

Attachments

(2 files, 5 obsolete files)

We hope to support Settings API to be able to carry a customized message to notify "mozsettings-changed" observers in addition to key and value. This would be helpful when we want to distinquish who is calling the set(). For example, if we can know it is set from an internal service, we can check the message (containing the caller's identification) to avoid processing it again after receiving "mozsettings-changed" event.
I should be able to upload a patch later. ;)
Assignee: nobody → clian
Blocks: 729877
Attached patch Patch (obsolete) — Splinter Review
Hi :gwagner,

May I invite you to have a review on this one? Please see the Description for the motivation. These changes should be compatible with the current JS codes but not for C++ codes, so we need to add |JSVAL_NULL| to explicitly specify the new |aMessage| field. Please let me know if I can do anything better. :)
Attachment #654911 - Flags: review?(anygregor)
Oops... try server Win64 build is red when using |JSVAL_NULL| (https://tbpl.mozilla.org/?tree=Try&rev=b0999a0faaf8). I'll upload a new patch with |JS::NullValue()|.
Attached patch Patch, V2 (obsolete) — Splinter Review
Upload a new patch using |JS::NullValue()| instead of |JSVAL_NULL| which fails to build for Win64.
Attachment #654911 - Attachment is obsolete: true
Attachment #654911 - Flags: review?(anygregor)
Attachment #655900 - Flags: review?(anygregor)
(In reply to Gene Lian [:gene] from comment #4)
> Created attachment 655900 [details] [diff] [review]
> Patch, V2
> 
> Upload a new patch using |JS::NullValue()| instead of |JSVAL_NULL| which
> fails to build for Win64.

Looks good to me but please add some tests for messages.
(In reply to Gregor Wagner [:gwagner] from comment #5)
> (In reply to Gene Lian [:gene] from comment #4)
> > Created attachment 655900 [details] [diff] [review]
> > Patch, V2
> > 
> > Upload a new patch using |JS::NullValue()| instead of |JSVAL_NULL| which
> > fails to build for Win64.
> 
> Looks good to me but please add some tests for messages.

Thanks Gregor! :) I was trying to write some xpcshell testing for this. However, I cannot get the service of @mozilla.org/observer-service;1.

EST-UNEXPECTED-FAIL | xpcshell/head.js | [Exception... "Component returned failure code: 0x80570016 (NS_ERROR_XPC_GS_RETURNED_FAILURE) [nsIJSCID.getService]"  nsresult: "0x80570016 (NS_ERROR_XPC_GS_RETURNED_FAILURE)"  location: "JS frame :: file:///home/gene/build/dist/bin/components/SettingsService.js :: SettingsService :: line 152"  data: no]

Can't we get that service by a desktop build? What do you think where is the right place to test if message is successfully carried when receiving "mozsettings-changed" event? Any quick suggestion is highly appreciated! :)
(In reply to Gene Lian [:gene] from comment #6)
> (In reply to Gregor Wagner [:gwagner] from comment #5)
> > (In reply to Gene Lian [:gene] from comment #4)
> > > Created attachment 655900 [details] [diff] [review]
> > > Patch, V2
> > > 
> > > Upload a new patch using |JS::NullValue()| instead of |JSVAL_NULL| which
> > > fails to build for Win64.
> > 
> > Looks good to me but please add some tests for messages.
> 
> Thanks Gregor! :) I was trying to write some xpcshell testing for this.
> However, I cannot get the service of @mozilla.org/observer-service;1.
> 
> EST-UNEXPECTED-FAIL | xpcshell/head.js | [Exception... "Component returned
> failure code: 0x80570016 (NS_ERROR_XPC_GS_RETURNED_FAILURE)
> [nsIJSCID.getService]"  nsresult: "0x80570016
> (NS_ERROR_XPC_GS_RETURNED_FAILURE)"  location: "JS frame ::
> file:///home/gene/build/dist/bin/components/SettingsService.js ::
> SettingsService :: line 152"  data: no]
> 
> Can't we get that service by a desktop build? What do you think where is the
> right place to test if message is successfully carried when receiving
> "mozsettings-changed" event? Any quick suggestion is highly appreciated! :)

Did you write new tests or did you extend the current tests in 
https://mxr.mozilla.org/mozilla-central/source/xpcom/tests/TestSettingsAPI.cpp
(In reply to Gregor Wagner [:gwagner] from comment #7)
> Did you write new tests or did you extend the current tests in 
> https://mxr.mozilla.org/mozilla-central/source/xpcom/tests/TestSettingsAPI.
> cpp

Thanks for the suggestions. I think I can directly extend the TestSettingsAPI.cpp. Should be able to upload a patch for this today.
Attached patch Part1, SettingsService (obsolete) — Splinter Review
Attachment #655900 - Attachment is obsolete: true
Attachment #655900 - Flags: review?(anygregor)
Attachment #656793 - Flags: review?(anygregor)
Attached patch Part2, Test Cases (obsolete) — Splinter Review
Hi Gregor :)

I tried to extend the TestSettingsAPI.cpp by adding an observer to listen to the "mozsettings-changed" event. The test cases not only test if the new messages are successfully passed but also test the existing key and value. The following shows the testing log, where you can see 2 cases for observers are added.

TEST-PASS | Start TestSettingsAPI
Running TestSettingsAPI tests...
TEST-PASS | boolean
TEST-PASS | Lock order
TEST-PASS | integer
TEST-PASS | double
TEST-PASS | Lock order
TEST-PASS | null
TEST-PASS | observer
TEST-PASS | observer
TEST-PASS | END!
Finished running TestSettingsAPI tests.

Please feel free to let me know if I can do anything better. :)
Attachment #656796 - Flags: review?(anygregor)
(In reply to Gene Lian [:gene] from comment #10)
> Created attachment 656796 [details] [diff] [review]
> Part2, Test Cases
> 
> Hi Gregor :)
> 
> I tried to extend the TestSettingsAPI.cpp by adding an observer to listen to
> the "mozsettings-changed" event. The test cases not only test if the new
> messages are successfully passed but also test the existing key and value.
> The following shows the testing log, where you can see 2 cases for observers
> are added.
> 
> TEST-PASS | Start TestSettingsAPI
> Running TestSettingsAPI tests...
> TEST-PASS | boolean
> TEST-PASS | Lock order
> TEST-PASS | integer
> TEST-PASS | double
> TEST-PASS | Lock order
> TEST-PASS | null
> TEST-PASS | observer
> TEST-PASS | observer
> TEST-PASS | END!
> Finished running TestSettingsAPI tests.
> 
> Please feel free to let me know if I can do anything better. :)

Oops.. try server build doesn't pass () :(

Hi Gregor,

May I ask what is the root cause of the following line when trying to use nsObserverService? I'll also try to figure it out at the same time but would appreciate if you could please give any quick hints.

###!!! ASSERTION: Using observer service after XPCOM shutdown!: 'Error', file ../../../xpcom/ds/nsObserverService.cpp, line 110

You can find the full log at: https://tbpl.mozilla.org/?tree=Try&rev=1c111923081b
(In reply to Gene Lian [:gene] from comment #11)
> ###!!! ASSERTION: Using observer service after XPCOM shutdown!: 'Error',
> file ../../../xpcom/ds/nsObserverService.cpp, line 110

Hmm... it seems it happens when it tries to call RemoveObserver() where the XPCOM has already been shut down. I'll try to call sTestSettingsObserver = nullptr; to explicitly do it before the end of main().

https://tbpl.mozilla.org/?tree=Try&rev=1935ff88abb2

Rush to home! Hope to get good news tomorrow!
Comment on attachment 656793 [details] [diff] [review]
Part1, SettingsService

> 
>-[scriptable, uuid(3ab3cbc0-8513-11e1-b0c4-0800200c9a66)]
>+[scriptable, uuid(d7a395a0-e292-11e1-834e-1761d57f5f99)]
> interface nsISettingsServiceLock : nsISupports
> {
>-  void set(in string aName, in jsval aValue, in nsISettingsServiceCallback aCallback);
>+  void set(in string aName,
>+           in jsval aValue,
>+           in nsISettingsServiceCallback aCallback,
>+           [optional] in jsval aMessage);


Why is aMessage a jsval and not a string? Isn't the common use-case that you
want to pass a string-message? I don't think a boolean or numeric message is very useful.
Hi Gregor,

Change the message from jsval to a string type, which should already cover common use cases. Thanks for the suggestions! :)
Attachment #656793 - Attachment is obsolete: true
Attachment #656793 - Flags: review?(anygregor)
Attachment #657180 - Flags: review?(anygregor)
Attached patch Part2, Test Cases, V2 (obsolete) — Splinter Review
Objectives:

1. Test if the observer can receive "mozsettings-changed" event when calling .set().
2. If yes, check if we can get the right 'key'.
3. If yes, check if we can get the right 'value'.
4. If yes, check if we can get the right 'message', which should be null for case #1 and "test.observer.message" for case #2.

The remaining parts are some minor code clean-ups. Also, please find try server result (green!) at https://tbpl.mozilla.org/?tree=Try&rev=1a4df439af55 and let me know if I can do anything better. :)
Attachment #656796 - Attachment is obsolete: true
Attachment #656796 - Flags: review?(anygregor)
Attachment #657181 - Flags: review?(anygregor)
This one should also be a basecamp-blocker because it blocks bug 729877 which is basecamp+.
blocking-basecamp: --- → ?
Comment on attachment 657180 [details] [diff] [review]
Part1, SettingsService, V2


>-[scriptable, uuid(3ab3cbc0-8513-11e1-b0c4-0800200c9a66)]
>+[scriptable, uuid(d7a395a0-e292-11e1-834e-1761d57f5f99)]
> interface nsISettingsServiceLock : nsISupports
> {
>-  void set(in string aName, in jsval aValue, in nsISettingsServiceCallback aCallback);
>+  void set(in string aName,
>+           in jsval aValue,
>+           in nsISettingsServiceCallback aCallback,
>+           [optional] in string aMessage);
>+

We will have to change string to astring but that's a followup.
Attachment #657180 - Flags: review?(anygregor) → review+
Comment on attachment 657181 [details] [diff] [review]
Part2, Test Cases, V2


> 
>+static bool VerifyJSValue(
>+  JSContext *cx, const JS::Value &value, const char *string) {
>+  JSBool match;
>+  if (!value.isString() ||
>+      !JS_StringEqualsAscii(cx, value.toString(), string, &match) ||
>+      (match != JS_TRUE)) {
>+    return false;
>+  }
>+  return true;
>+}

You only check for string values so please rename to
VerifyJSValueIsSting or similar.



>   while (callbackCount > 0)
>     NS_ProcessNextEvent(current);
> 
>+  while (observerCount > 0 && !errors)
>+    NS_ProcessNextEvent(current);
>+

Combine the two whiles.
Attachment #657181 - Flags: review?(anygregor) → review+
:gwagner already has review+ at comment 18.
Attachment #657181 - Attachment is obsolete: true
Attachment #657274 - Flags: review+
blocking-basecamp: ? → +
Flags: in-testsuite+
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/dff1055c2f50
https://hg.mozilla.org/mozilla-central/rev/304f86e12b60
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla18
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: