Bug 1258470 - Part 9: Move some of GuestSession into GuestProfile.
Again, this needs a dependency-injection hook of some kind to let the
App handle guest sessions.
MozReview-Commit-ID: AZXSRby2pjH
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -3645,19 +3645,19 @@ public class BrowserApp extends GeckoApp
final Prompt ps = new Prompt(this, new Prompt.PromptCallback() {
@Override
public void onPromptFinished(String result) {
try {
int itemId = new JSONObject(result).getInt("button");
if (itemId == 0) {
final Context context = GeckoAppShell.getApplicationContext();
if (type == GuestModeDialog.ENTERING) {
- GuestSession.enter(context);
+ GeckoProfile.enter(context);
} else {
- GuestSession.leave(context);
+ GeckoProfile.leave(context);
// Now's a good time to make sure we're not displaying the
// Guest Browsing notification.
GuestSession.hideNotification(context);
}
doRestart();
}
} catch (JSONException ex) {
Log.e(LOGTAG, "Exception reading guest mode prompt result", ex);
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoProfile.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoProfile.java
@@ -66,16 +66,17 @@ public final class GeckoProfile {
Log.w(LOGTAG, "Directory changes should only be enabled for tests. And even then it's a bad idea.");
sAcceptDirectoryChanges = true;
}
public static final String DEFAULT_PROFILE = "default";
// Profile is using a custom directory outside of the Mozilla directory.
public static final String CUSTOM_PROFILE = "";
public static final String GUEST_PROFILE_DIR = "guest";
+ public static final String GUEST_MODE_PREF = "guestMode";
// Session store
private static final String SESSION_FILE = "sessionstore.js";
private static final String SESSION_FILE_BACKUP = "sessionstore.bak";
private static final long MAX_BACKUP_FILE_AGE = 1000 * 3600 * 24; // 24 hours
private boolean mOldSessionDataProcessed = false;
@@ -96,23 +97,23 @@ public final class GeckoProfile {
*
* Not final because this is lazily computed.
*/
private File mProfileDir;
private Boolean mInGuestMode;
public static GeckoProfile initFromArgs(final Context context, final String args) {
- if (GuestSession.shouldUse(context)) {
+ if (shouldUse(context)) {
final GeckoProfile guestProfile = getGuestProfile(context);
if (guestProfile != null) {
return guestProfile;
}
// Failed to create guest profile; leave guest mode.
- GuestSession.leave(context);
+ leave(context);
}
// We never want to use the guest mode profile concurrently with a normal profile
// -- no syncing to it, no dual-profile usage, nothing. GeckoThread startup with
// a conventional GeckoProfile will cause the guest profile to be deleted and
// guest mode to reset.
if (getGuestDir(context).isDirectory()) {
final GeckoProfile guestProfile = getGuestProfile(context);
@@ -348,16 +349,28 @@ public final class GeckoProfile {
if (profileDir != null && !profileDir.isDirectory()) {
throw new IllegalArgumentException("Profile directory must exist if specified.");
}
// N.B., mProfileDir can be null at this point.
mDB = dbFactory.get(profileName, mProfileDir);
}
+ public static boolean shouldUse(final Context context) {
+ return GeckoSharedPrefs.forApp(context).getBoolean(GUEST_MODE_PREF, false);
+ }
+
+ public static void enter(final Context context) {
+ GeckoSharedPrefs.forApp(context).edit().putBoolean(GUEST_MODE_PREF, true).commit();
+ }
+
+ public static void leave(final Context context) {
+ GeckoSharedPrefs.forApp(context).edit().putBoolean(GUEST_MODE_PREF, false).commit();
+ }
+
@RobocopTarget
public BrowserDB getDB() {
return mDB;
}
private void setDir(File dir) {
if (dir != null && dir.exists() && dir.isDirectory()) {
synchronized (this) {
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoThread.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoThread.java
@@ -142,17 +142,17 @@ public class GeckoThread extends Thread
private static boolean canUseProfile(final Context context, final GeckoProfile profile,
final String profileName, final File profileDir) {
if (profileDir != null && !profileDir.isDirectory()) {
return false;
}
if (profile == null) {
// We haven't initialized; any profile is okay as long as we follow the guest mode setting.
- return GuestSession.shouldUse(context) ==
+ return GeckoProfile.shouldUse(context) ==
GeckoProfile.isGuestProfile(context, profileName, profileDir);
}
// We already initialized and have a profile; see if it matches ours.
try {
return profileDir == null ? profileName.equals(profile.getName()) :
profile.getDir().getCanonicalPath().equals(profileDir.getCanonicalPath());
} catch (final IOException e) {
--- a/mobile/android/base/java/org/mozilla/gecko/GuestSession.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GuestSession.java
@@ -14,29 +14,16 @@ import android.support.v4.app.Notificati
import android.view.Window;
import android.view.WindowManager;
// Utility methods for entering/exiting guest mode.
public final class GuestSession {
private static final String LOGTAG = "GeckoGuestSession";
public static final String NOTIFICATION_INTENT = "org.mozilla.gecko.GUEST_SESSION_INPROGRESS";
- public static final String GUEST_MODE_PREF = "guestMode";
-
- public static boolean shouldUse(final Context context) {
- return GeckoSharedPrefs.forApp(context).getBoolean(GUEST_MODE_PREF, false);
- }
-
- public static void enter(final Context context) {
- GeckoSharedPrefs.forApp(context).edit().putBoolean(GUEST_MODE_PREF, true).commit();
- }
-
- public static void leave(final Context context) {
- GeckoSharedPrefs.forApp(context).edit().putBoolean(GUEST_MODE_PREF, false).commit();
- }
private static PendingIntent getNotificationIntent(Context context) {
Intent intent = new Intent(NOTIFICATION_INTENT);
intent.setClassName(context, AppConstants.MOZ_ANDROID_BROWSER_INTENT_CLASS);
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
public static void showNotification(Context context) {