We just eliminated the BrowserDB singleton in Bug 1077590.
Historically, BrowserDB has been the way you got access to bookmarks and
history from inside Fennec. It wrapped a single LocalBrowserDB instance,
which delegated to our ContentProvider.
(The history of this convoluted arrangement is down to the very early days,
where we supported using the Android system browser DB as well as our own,
and needed to be able to switch between them.)
That's now been cleaned up. LocalBrowserDB now inherits from a BrowserDB
interface. GeckoProfile is responsible for handing over the right instance
for the profile. If you know the current profile — and we now always do,
even in Robocop tests — you can get the right DB.
This not only eliminates a wrapper, and some odd init timing, but it also
eliminates a whole class of bugs wherein some calling code tries to access
BrowserDB before it has been initialized, getting a NPE as a result, and
another class of bugs where operations occur on the wrong DB during profile
switches during test startup.
Webapps, and GeckoView consumers, get a StubBrowserDB instead of a
LocalBrowserDB. Apps can decide which kind of BrowserDB to use by
specifying a factory, either early in startup by poking GeckoProfile, or
explicitly the first time they access a specific profile instance.
What does this mean for your bitrotted patches?
Essentially, this pattern:
@Override
public void onSomeMainThreadCall() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
BrowserDB.doSomething();
}
}
}
becomes this:
@Override
public void onSomeMainThreadCall() {
final BrowserDB db = GeckoProfile.get(mContext).getDB();
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
db.doSomething();
}
}
}
Inside BrowserApp, that line simplifies to:
final BrowserDB db = getProfile().getDB();
Note that we grab the DB immediately, to avoid operations being performed
on the wrong DB thanks to background thread delays. This is cheap, so don't
worry about doing this on the main thread.
Any questions, please come find me on IRC, or reply to this email, or
needinfo me on your bug.
Thanks!
-R
_______________________________________________
mobile-firefox-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/mobile-firefox-dev