diff options
| author | John Reck <jreck@google.com> | 2011-07-26 10:22:22 -0700 |
|---|---|---|
| committer | John Reck <jreck@google.com> | 2011-07-27 14:11:44 -0700 |
| commit | 1cf4b79a0020bc18c83ca8bde0e318ecd5252bc2 (patch) | |
| tree | ee1b1ce7a7c86f9a6226e62badf61e6e1bed3b4c /src/com/android/browser/Controller.java | |
| parent | ff6a748ae78165cc2298f5120a4374b4ed6f836b (diff) | |
Restore overhaul
Bug: 5069192
Store thumbnails in a database restored async for each tab
Fix restoring a tab not restoring its current state
Change-Id: I2c14e352638aac0ef766fb3bf4036ff220c53ecd
Diffstat (limited to 'src/com/android/browser/Controller.java')
| -rw-r--r-- | src/com/android/browser/Controller.java | 59 |
1 files changed, 49 insertions, 10 deletions
diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java index b3be6187..92f448c9 100644 --- a/src/com/android/browser/Controller.java +++ b/src/com/android/browser/Controller.java @@ -80,6 +80,7 @@ import com.android.browser.IntentHandler.UrlData; import com.android.browser.UI.ComboViews; import com.android.browser.UI.DropdownChangeListener; import com.android.browser.provider.BrowserProvider; +import com.android.browser.provider.BrowserProvider2.Thumbnails; import com.android.browser.provider.SnapshotProvider.Snapshots; import com.android.browser.search.SearchEngine; import com.android.common.Search; @@ -87,6 +88,7 @@ import com.android.common.Search; import java.io.ByteArrayOutputStream; import java.io.File; import java.net.URLEncoder; +import java.util.ArrayList; import java.util.Calendar; import java.util.HashMap; import java.util.List; @@ -309,6 +311,7 @@ public class Controller private void onPreloginFinished(Bundle icicle, Intent intent, long currentTabId, boolean restoreIncognitoTabs) { if (currentTabId == -1) { + BackgroundHandler.execute(new PruneThumbnails(mActivity, null)); final Bundle extra = intent.getExtras(); // Create an initial tab. // If the intent is ACTION_VIEW and data is not null, the Browser is @@ -335,7 +338,13 @@ public class Controller } else { mTabControl.restoreState(icicle, currentTabId, restoreIncognitoTabs, mUi.needsRestoreAllTabs()); - mUi.updateTabs(mTabControl.getTabs()); + List<Tab> tabs = mTabControl.getTabs(); + ArrayList<Long> restoredTabs = new ArrayList<Long>(tabs.size()); + for (Tab t : tabs) { + restoredTabs.add(t.getId()); + } + BackgroundHandler.execute(new PruneThumbnails(mActivity, restoredTabs)); + mUi.updateTabs(tabs); // TabControl.restoreState() will create a new tab even if // restoring the state fails. setActiveTab(mTabControl.getCurrentTab()); @@ -357,6 +366,38 @@ public class Controller } } + private static class PruneThumbnails implements Runnable { + private Context mContext; + private List<Long> mIds; + + PruneThumbnails(Context context, List<Long> preserveIds) { + mContext = context.getApplicationContext(); + mIds = preserveIds; + } + + @Override + public void run() { + ContentResolver cr = mContext.getContentResolver(); + if (mIds == null || mIds.size() == 0) { + cr.delete(Thumbnails.CONTENT_URI, null, null); + } else { + int length = mIds.size(); + StringBuilder where = new StringBuilder(); + where.append(Thumbnails._ID); + where.append(" not in ("); + for (int i = 0; i < length; i++) { + where.append(mIds.get(i)); + if (i < (length - 1)) { + where.append(","); + } + } + where.append(")"); + cr.delete(Thumbnails.CONTENT_URI, where.toString(), null); + } + } + + } + @Override public WebViewFactory getWebViewFactory() { return mFactory; @@ -612,7 +653,7 @@ public class Controller } - void onSaveInstanceState(Bundle outState, boolean saveImages) { + void onSaveInstanceState(Bundle outState) { // the default implementation requires each view to have an id. As the // browser handles the state itself and it doesn't use id for the views, // don't call the default implementation. Otherwise it will trigger the @@ -620,7 +661,7 @@ public class Controller // focused view XXX has no id". // Save all the tabs - mTabControl.saveState(outState, false); + mTabControl.saveState(outState); if (!outState.isEmpty()) { // Save time so that we know how old incognito tabs (if any) are. outState.putSerializable("lastActiveDate", Calendar.getInstance()); @@ -1902,13 +1943,6 @@ public class Controller R.dimen.bookmarkThumbnailHeight); } - static Bitmap createScreenshot(Tab tab, int width, int height) { - if ((tab != null) && (tab.getWebView() != null)) { - return createScreenshot(tab.getWebView(), width, height); - } - return null; - } - static Bitmap createScreenshot(WebView view, int width, int height) { // We render to a bitmap 2x the desired size so that we can then // re-scale it with filtering since canvas.scale doesn't filter @@ -2646,4 +2680,9 @@ public class Controller return true; } + @Override + public boolean shouldCaptureThumbnails() { + return mUi.shouldCaptureThumbnails(); + } + } |
