summaryrefslogtreecommitdiffstats
path: root/src/com/android/browser/Tab.java
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2012-04-19 15:27:12 -0700
committerJohn Reck <jreck@google.com>2012-04-19 15:50:52 -0700
commit68234a9351dfca2e68769de46e60d22ec2f03818 (patch)
tree2aa5fb13c406e11b8d2bfbebb12df13088af111d /src/com/android/browser/Tab.java
parent2b71d6dad1cbdc84da3eed140429a102971a1106 (diff)
downloadpackages_apps_Browser-68234a9351dfca2e68769de46e60d22ec2f03818.tar.gz
packages_apps_Browser-68234a9351dfca2e68769de46e60d22ec2f03818.tar.bz2
packages_apps_Browser-68234a9351dfca2e68769de46e60d22ec2f03818.zip
Save and load snapshots async
Bug: 5416822 Change-Id: I213c3507af61e7ca0354dad7e72ece7a2547f54e
Diffstat (limited to 'src/com/android/browser/Tab.java')
-rw-r--r--src/com/android/browser/Tab.java77
1 files changed, 61 insertions, 16 deletions
diff --git a/src/com/android/browser/Tab.java b/src/com/android/browser/Tab.java
index 04bee08dd..c73bdf6b3 100644
--- a/src/com/android/browser/Tab.java
+++ b/src/com/android/browser/Tab.java
@@ -77,6 +77,7 @@ import com.android.common.speech.LoggingEvents;
import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.util.ArrayList;
@@ -2060,36 +2061,80 @@ class Tab implements PictureListener {
return false;
}
+ private static class SaveCallback implements ValueCallback<Boolean> {
+ boolean mResult;
+
+ @Override
+ public void onReceiveValue(Boolean value) {
+ mResult = value;
+ synchronized (this) {
+ notifyAll();
+ }
+ }
+
+ }
+
+ /**
+ * Must be called on the UI thread
+ */
public ContentValues createSnapshotValues() {
- if (mMainView == null) return null;
+ WebViewClassic web = getWebViewClassic();
+ if (web == null) return null;
+ ContentValues values = new ContentValues();
+ values.put(Snapshots.TITLE, mCurrentState.mTitle);
+ values.put(Snapshots.URL, mCurrentState.mUrl);
+ values.put(Snapshots.BACKGROUND, web.getPageBackgroundColor());
+ values.put(Snapshots.DATE_CREATED, System.currentTimeMillis());
+ values.put(Snapshots.FAVICON, compressBitmap(getFavicon()));
+ Bitmap screenshot = Controller.createScreenshot(mMainView,
+ Controller.getDesiredThumbnailWidth(mContext),
+ Controller.getDesiredThumbnailHeight(mContext));
+ values.put(Snapshots.THUMBNAIL, compressBitmap(screenshot));
+ return values;
+ }
+
+ /**
+ * Probably want to call this on a background thread
+ */
+ public boolean saveViewState(ContentValues values) {
+ WebViewClassic web = getWebViewClassic();
+ if (web == null) return false;
String path = UUID.randomUUID().toString();
+ SaveCallback callback = new SaveCallback();
+ OutputStream outs = null;
try {
- OutputStream outs = mContext.openFileOutput(path, Context.MODE_PRIVATE);
+ outs = mContext.openFileOutput(path, Context.MODE_PRIVATE);
GZIPOutputStream stream = new GZIPOutputStream(outs);
- if (!getWebViewClassic().saveViewState(stream)) {
- return null;
+ synchronized (callback) {
+ web.saveViewState(stream, callback);
+ callback.wait();
}
stream.flush();
stream.close();
} catch (Exception e) {
Log.w(LOGTAG, "Failed to save view state", e);
- return null;
+ if (outs != null) {
+ try {
+ outs.close();
+ } catch (IOException ignore) {}
+ }
+ File file = mContext.getFileStreamPath(path);
+ if (file.exists() && !file.delete()) {
+ file.deleteOnExit();
+ }
+ return false;
}
File savedFile = mContext.getFileStreamPath(path);
+ if (!callback.mResult) {
+ if (!savedFile.delete()) {
+ savedFile.deleteOnExit();
+ }
+ return false;
+ }
long size = savedFile.length();
- ContentValues values = new ContentValues();
- values.put(Snapshots.TITLE, mCurrentState.mTitle);
- values.put(Snapshots.URL, mCurrentState.mUrl);
values.put(Snapshots.VIEWSTATE_PATH, path);
values.put(Snapshots.VIEWSTATE_SIZE, size);
- values.put(Snapshots.BACKGROUND, getWebViewClassic().getPageBackgroundColor());
- values.put(Snapshots.DATE_CREATED, System.currentTimeMillis());
- values.put(Snapshots.FAVICON, compressBitmap(getFavicon()));
- Bitmap screenshot = Controller.createScreenshot(mMainView,
- Controller.getDesiredThumbnailWidth(mContext),
- Controller.getDesiredThumbnailHeight(mContext));
- values.put(Snapshots.THUMBNAIL, compressBitmap(screenshot));
- return values;
+ return true;
}
public byte[] compressBitmap(Bitmap bitmap) {