Bug 1325112 - 2. Purge caches in debug geckoview_example; r=rbarker

Preload Gecko with the "-purgecaches" flag in debug builds of
geckoview_example, similar to what we do for Fennec.

MozReview-Commit-ID: dBZgBbDUQ9
This commit is contained in:
Jim Chen 2017-05-15 23:11:17 -04:00
parent cf5d7c70ea
commit e53a5e57a0
2 changed files with 25 additions and 6 deletions

View File

@ -284,16 +284,30 @@ public class GeckoView extends LayerView
init(context, newSettings);
}
public static final void preload(Context context) {
final GeckoProfile profile = GeckoProfile.get(
context.getApplicationContext());
/**
* Preload GeckoView by starting Gecko in the background, if Gecko is not already running.
*
* @param context Activity or Application Context for starting GeckoView.
*/
public static void preload(final Context context) {
preload(context, /* geckoArgs */ null);
}
/**
* Preload GeckoView by starting Gecko with the specified arguments in the background,
* if Geckois not already running.
*
* @param context Activity or Application Context for starting GeckoView.
* @param geckoArgs Arguments to be passed to Gecko, if Gecko is not already running
*/
public static void preload(final Context context, final String geckoArgs) {
final Context appContext = context.getApplicationContext();
if (GeckoAppShell.getApplicationContext() == null) {
GeckoAppShell.setApplicationContext(context.getApplicationContext());
GeckoAppShell.setApplicationContext(appContext);
}
if (GeckoThread.initMainProcess(profile,
/* args */ null,
if (GeckoThread.initMainProcess(GeckoProfile.get(appContext),
geckoArgs,
/* debugging */ false)) {
GeckoThread.launch();
}

View File

@ -31,6 +31,11 @@ public class GeckoViewActivity extends Activity {
Log.i(LOGTAG, "zerdatime " + SystemClock.elapsedRealtime() +
" - application start");
if (BuildConfig.DEBUG) {
// In debug builds, we want to load JavaScript resources fresh with each build.
GeckoView.preload(this, "-purgecaches");
}
setContentView(R.layout.geckoview_activity);
mGeckoView = (GeckoView) findViewById(R.id.gecko_view);