Bug 895709 - Kill guest mode profile when we start in non-guest mode. r=blassey

This commit is contained in:
Wes Johnston 2013-07-30 09:05:25 -07:00
Родитель 02dad2cff6
Коммит ed478e2678
2 изменённых файлов: 42 добавлений и 2 удалений

Просмотреть файл

@ -400,6 +400,13 @@ abstract public class BrowserApp extends GeckoApp
String args = getIntent().getStringExtra("args");
if (args != null && args.contains("--guest-mode")) {
mProfile = GeckoProfile.createGuestProfile(this);
} else {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
GeckoProfile.removeGuestProfile(BrowserApp.this);
}
});
}
super.onCreate(savedInstanceState);

Просмотреть файл

@ -116,10 +116,11 @@ public final class GeckoProfile {
throw new IllegalArgumentException("context must be non-null");
}
try {
removeGuestProfile(context);
File guestDir = context.getDir("guest", Context.MODE_PRIVATE);
if (guestDir.exists())
guestDir.delete();
guestDir.mkdir();
GeckoProfile profile = get(context, "guest", guestDir);
profile.mInGuestMode = true;
return profile;
@ -129,6 +130,38 @@ public final class GeckoProfile {
return null;
}
public static void removeGuestProfile(Context context) {
if (context == null) {
throw new IllegalArgumentException("context must be non-null");
}
try {
File guestDir = context.getDir("guest", Context.MODE_PRIVATE);
if (guestDir.exists()) {
delete(guestDir);
}
} catch (Exception ex) {
Log.e(LOGTAG, "Error removing guest profile", ex);
}
}
public static boolean delete(File file) throws IOException {
// Try to do a quick initial delete
if (file.delete())
return true;
if (file.isDirectory()) {
// If the quick delete failed and this is a dir, recursively delete the contents of the dir
String files[] = file.list();
for (String temp : files) {
File fileDelete = new File(file, temp);
delete(fileDelete);
}
}
// Even if this is a dir, it should now be empty and delete should work
return file.delete();
}
private GeckoProfile(Context context, String profileName) {
mContext = context;
mName = profileName;