Implement proper HomeConfigBackend to load and save HomePager configuration

RESOLVED FIXED in Firefox 29

Status

()

Firefox for Android
Awesomescreen
RESOLVED FIXED
4 years ago
4 years ago

People

(Reporter: lucasr, Assigned: lucasr)

Tracking

(Blocks: 1 bug)

unspecified
Firefox 29
All
Android
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: shovel-ready)

Attachments

(1 attachment)

(Assignee)

Description

4 years ago
Right now, we're just using a temporary static backend.

A few things to keep in mind:
- We shouldn't rely on the backend being a singleton
- External changes to the configuration source (be it a JSON file, a SharedPref, or whatever) should always trigger the attached OnChangeListener.
- Performance is really important. HomePager can't take too long to show up on startup.  Let's save as little as possible so that loading the data is as fast as possible. This also includes the time to parse the configuration in whatever format we choose.
- Whatever format we choose, the HomePager configuration should be stored per profile, not globally.
(Assignee)

Updated

4 years ago
Blocks: 949174
(Assignee)

Updated

4 years ago
No longer blocks: 949174
(Assignee)

Updated

4 years ago
Whiteboard: shovel-ready

Updated

4 years ago
Blocks: 948527

Updated

4 years ago
Blocks: 942875
(Assignee)

Updated

4 years ago
Assignee: nobody → lucasr.at.mozilla
I was looking at the product page, and I just wanted to mention that we also want to support "disabled" panels, which is not in the visual mocks.
(Assignee)

Comment 2

4 years ago
Created attachment 8357897 [details] [diff] [review]
Implement backend to load and save HomePager configuration (r=margaret)
(Assignee)

Updated

4 years ago
Blocks: 958171
(Assignee)

Comment 3

4 years ago
Comment on attachment 8357897 [details] [diff] [review]
Implement backend to load and save HomePager configuration (r=margaret)

Tested this with local hacks (as there's no settings UI yet). Works fine.

Went with a JSON string stored in SharedPreferences. I considered storing it in a json file in the profile directory but using SharedPreferences gives all the thread-safety from the SharedPreferences API as well as key monitoring for free. We still need to implement proper per-profile shared preferences though (bug 940575).

I noticed that HomePager is not handling live config changes properly while testing this patch. This is a separate issue that I'll investigate in bug 958171.

The backend simply falls back to our current built-in configuration (history, top sites, bookmarks, reading list) if the configuration is undefined. This way we can simply hide the settings UI before the merge if we decide to skip this feature in 29.
Attachment #8357897 - Flags: review?(margaret.leibovic)

Comment 4

4 years ago
Comment on attachment 8357897 [details] [diff] [review]
Implement backend to load and save HomePager configuration (r=margaret)

Review of attachment 8357897 [details] [diff] [review]:
-----------------------------------------------------------------

Nice, this is more straightforward than I thought it would be.

Just to make sure we're all on the same page, my understanding here is that we'll always load a default config until the user goes into the settings UI to change their preferences. And when that happens, the settings UI code will call save with that new list of page entries. And HomeConfig can register a change listener to update appropriately when these changes happen (I imagine that's what you'll do in bug 958171). Is that right?

For simplicity, I feel like it would be nice if we could just have a default shared preference with the default config, but I also like the solution here because it means we won't need to do any I/O unless the user changes the default preference, which is nice for first-run performance (we will need to deal with this for distributions that include some config file or whatever, but that's not something to worry about right now).

Also, I like that this removes the dependency on ListManager/PanelManager. As we discussed earlier today, the settings code can just ask PanelManager for the available panels and then change the set of panels in the config if the user chooses to do that.

::: mobile/android/base/home/HomeConfigPrefsBackend.java
@@ +180,5 @@
> +        editor.putString(PREFS_KEY, jsonString);
> +        editor.commit();
> +    }
> +
> +    public void setOnChangeListener(OnChangeListener listener) {

Nit: @Override, since this is implementing the interface.
Attachment #8357897 - Flags: review?(margaret.leibovic) → review+
Comment on attachment 8357897 [details] [diff] [review]
Implement backend to load and save HomePager configuration (r=margaret)

Review of attachment 8357897 [details] [diff] [review]:
-----------------------------------------------------------------

This looks good to me too! I'll apply this under my patches for bug 942875 so I can use these changes.

::: mobile/android/base/home/HomeConfigPrefsBackend.java
@@ +30,5 @@
> +import java.util.EnumSet;
> +import java.util.List;
> +
> +class HomeConfigPrefsBackend implements HomeConfigBackend {
> +    private static final String LOGTAG = "GeckoHomeConfigPrefsBackend";

I think this is too long for the Android logger - tag length is limited to 23 characters.

http://developer.android.com/reference/android/util/Log.html#isLoggable%28java.lang.String,%20int%29

Updated

4 years ago
Blocks: 958189
(Assignee)

Comment 6

4 years ago
(In reply to :Margaret Leibovic from comment #4)
> Comment on attachment 8357897 [details] [diff] [review]
> Implement backend to load and save HomePager configuration (r=margaret)
> 
> Review of attachment 8357897 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> Nice, this is more straightforward than I thought it would be.
> 
> Just to make sure we're all on the same page, my understanding here is that
> we'll always load a default config until the user goes into the settings UI
> to change their preferences. And when that happens, the settings UI code
> will call save with that new list of page entries.

Exactly.

> And HomeConfig can register a change listener to update appropriately when
> these changes happen (I imagine that's what you'll do in bug 958171). Is that right?

HomePager and HomeConfigLoader are already hooked up to live-update when the config changes. See:

http://mxr.mozilla.org/mozilla-central/source/mobile/android/base/home/HomeConfigLoader.java#38

When the config changes (i.e. the backend's OnChangeListener is triggered), HomeConfigLoader is automatically reloaded to fetch the latest list of panel entries (from a SharedPrefences key in this case).

Bug 958171 is more about live config changes leading to broken UI state.

> For simplicity, I feel like it would be nice if we could just have a default
> shared preference with the default config, but I also like the solution here
> because it means we won't need to do any I/O unless the user changes the
> default preference, which is nice for first-run performance (we will need to
> deal with this for distributions that include some config file or whatever,
> but that's not something to worry about right now).

Yeah, that's the intent: avoiding any unnecessary I/0 until the user changes the configuration. And it's also a clean way to keep the feature disabled if we decide to skip 29. 

> Also, I like that this removes the dependency on ListManager/PanelManager.
> As we discussed earlier today, the settings code can just ask PanelManager
> for the available panels and then change the set of panels in the config if
> the user chooses to do that.

Precisely ;-)

> ::: mobile/android/base/home/HomeConfigPrefsBackend.java
> @@ +180,5 @@
> > +        editor.putString(PREFS_KEY, jsonString);
> > +        editor.commit();
> > +    }
> > +
> > +    public void setOnChangeListener(OnChangeListener listener) {
> 
> Nit: @Override, since this is implementing the interface.

Nice catch, done.
(Assignee)

Comment 7

4 years ago
(In reply to Chenxia Liu [:liuche] from comment #5)
> Comment on attachment 8357897 [details] [diff] [review]
> Implement backend to load and save HomePager configuration (r=margaret)
> 
> Review of attachment 8357897 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> This looks good to me too! I'll apply this under my patches for bug 942875
> so I can use these changes.
> 
> ::: mobile/android/base/home/HomeConfigPrefsBackend.java
> @@ +30,5 @@
> > +import java.util.EnumSet;
> > +import java.util.List;
> > +
> > +class HomeConfigPrefsBackend implements HomeConfigBackend {
> > +    private static final String LOGTAG = "GeckoHomeConfigPrefsBackend";
> 
> I think this is too long for the Android logger - tag length is limited to
> 23 characters.
> 
> http://developer.android.com/reference/android/util/Log.
> html#isLoggable%28java.lang.String,%20int%29

Renamed to GeckoHomeConfigBackend, thanks.
(Assignee)

Comment 8

4 years ago
https://hg.mozilla.org/integration/fx-team/rev/fec4987cbee9
https://hg.mozilla.org/mozilla-central/rev/fec4987cbee9
Status: NEW → RESOLVED
Last Resolved: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 29
You need to log in before you can comment on or make changes to this bug.