diff options
author | John Reck <jreck@google.com> | 2011-08-26 15:37:29 -0700 |
---|---|---|
committer | John Reck <jreck@google.com> | 2011-08-29 15:39:05 -0700 |
commit | 52be4785a258687055515117775d5bcb8bec1c12 (patch) | |
tree | 1a08d2c2981d49329936ca177d40f093a37c3c42 /src/com/android/browser/TabControl.java | |
parent | 88956b9456a6c8396dc966e6bfb61e45287569a5 (diff) | |
download | android_packages_apps_Gello-52be4785a258687055515117775d5bcb8bec1c12.tar.gz android_packages_apps_Gello-52be4785a258687055515117775d5bcb8bec1c12.tar.bz2 android_packages_apps_Gello-52be4785a258687055515117775d5bcb8bec1c12.zip |
Fix issues with state save/restore
Bug: 5144214
Tracked down the issue with messed up state to a bug where
tab ids were not unique, and would actually get messed up in restore.
Switched it to the tab's responsibility to assign an id to itself
in the ctor to make sure all possible paths where a tab is created
are fixed as well as the tab being the best informed about whether
or not it has an ID to restore from. Added some checks to watch for
a similar problem in the future as well.
Change-Id: Icd8333232a0baca7a3639323538886ea595de05a
Diffstat (limited to 'src/com/android/browser/TabControl.java')
-rw-r--r-- | src/com/android/browser/TabControl.java | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/com/android/browser/TabControl.java b/src/com/android/browser/TabControl.java index e99071a6..932a8116 100644 --- a/src/com/android/browser/TabControl.java +++ b/src/com/android/browser/TabControl.java @@ -62,7 +62,7 @@ class TabControl { mTabQueue = new ArrayList<Tab>(mMaxTabs); } - static long getNextId() { + synchronized static long getNextId() { return sNextId++; } @@ -170,7 +170,6 @@ class TabControl { } void addPreloadedTab(Tab tab) { - tab.setId(getNextId()); mTabs.add(tab); tab.setController(mController); mController.onSetWebView(tab, tab.getWebView()); @@ -197,7 +196,6 @@ class TabControl { // Create a new tab and add it to the tab list Tab t = new Tab(mController, w, state); - t.setId(getNextId()); mTabs.add(t); // Initially put the tab in the background. t.putInBackground(); @@ -214,7 +212,6 @@ class TabControl { SnapshotTab createSnapshotTab(long snapshotId) { SnapshotTab t = new SnapshotTab(mController, snapshotId); - t.setId(getNextId()); mTabs.add(t); return t; } @@ -302,9 +299,20 @@ class TabControl { Bundle tabState = tab.saveState(); if (tabState != null) { ids[i++] = tab.getId(); - outState.putBundle(Long.toString(tab.getId()), tabState); + String key = Long.toString(tab.getId()); + if (outState.containsKey(key)) { + // Dump the tab state for debugging purposes + for (Tab dt : mTabs) { + Log.e(LOGTAG, dt.toString()); + } + throw new IllegalStateException( + "Error saving state, duplicate tab ids!"); + } + outState.putBundle(key, tabState); } else { ids[i++] = -1; + // Since we won't be restoring the thumbnail, delete it + tab.deleteThumbnail(); } } if (!outState.isEmpty()) { @@ -404,7 +412,6 @@ class TabControl { // Create a new tab and don't restore the state yet, add it // to the tab list Tab t = new Tab(mController, state); - t.setId(id); tabMap.put(id, t); mTabs.add(t); // added the tab to the front as they are not current @@ -419,11 +426,6 @@ class TabControl { if (mCurrentTab == -1) { if (getTabCount() > 0) { setCurrentTab(getTab(0)); - } else { - Tab t = createNewTab(); - setCurrentTab(t); - t.getWebView().loadUrl(BrowserSettings.getInstance() - .getHomePage()); } } // restore parent/child relationships |