summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2012-04-23 14:50:09 -0700
committerJohn Reck <jreck@google.com>2012-04-23 17:57:54 -0700
commit3ad8d5cf0911ba015e019bc75e8fb13c091efe0e (patch)
treed5effce7657453109ca3ec4b9be83bc4bf4441e9 /src
parentd6207eee8f87bbbfbc57bb4674b29e80c92e9d3b (diff)
downloadpackages_apps_browser-3ad8d5cf0911ba015e019bc75e8fb13c091efe0e.zip
packages_apps_browser-3ad8d5cf0911ba015e019bc75e8fb13c091efe0e.tar.gz
packages_apps_browser-3ad8d5cf0911ba015e019bc75e8fb13c091efe0e.tar.bz2
Bookmark page changes
Bug: 6372933 Fix a race condition between update & destroy Fix update path Add some extra debug support Change-Id: I66a450e175b22d992de97d5bc24200961144412a
Diffstat (limited to 'src')
-rw-r--r--src/com/android/browser/BrowserBookmarksAdapterItem.java1
-rw-r--r--src/com/android/browser/BrowserBookmarksPage.java4
-rw-r--r--src/com/android/browser/PreferenceKeys.java1
-rw-r--r--src/com/android/browser/preferences/DebugPreferencesFragment.java8
-rw-r--r--src/com/android/browser/provider/BrowserProvider2.java12
-rw-r--r--src/com/android/browser/util/ThreadedCursorAdapter.java47
6 files changed, 62 insertions, 11 deletions
diff --git a/src/com/android/browser/BrowserBookmarksAdapterItem.java b/src/com/android/browser/BrowserBookmarksAdapterItem.java
index 913b0fd..ee2ed70 100644
--- a/src/com/android/browser/BrowserBookmarksAdapterItem.java
+++ b/src/com/android/browser/BrowserBookmarksAdapterItem.java
@@ -15,7 +15,6 @@
*/
package com.android.browser;
-import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
public class BrowserBookmarksAdapterItem {
diff --git a/src/com/android/browser/BrowserBookmarksPage.java b/src/com/android/browser/BrowserBookmarksPage.java
index 5a609b1..a038a2d 100644
--- a/src/com/android/browser/BrowserBookmarksPage.java
+++ b/src/com/android/browser/BrowserBookmarksPage.java
@@ -161,6 +161,10 @@ public class BrowserBookmarksPage extends Fragment implements View.OnCreateConte
@Override
public void onLoaderReset(Loader<Cursor> loader) {
+ if (loader.getId() >= LOADER_BOOKMARKS) {
+ BrowserBookmarksAdapter adapter = mBookmarkAdapters.get(loader.getId());
+ adapter.changeCursor(null);
+ }
}
@Override
diff --git a/src/com/android/browser/PreferenceKeys.java b/src/com/android/browser/PreferenceKeys.java
index ff42aaf..f7dc0e0 100644
--- a/src/com/android/browser/PreferenceKeys.java
+++ b/src/com/android/browser/PreferenceKeys.java
@@ -76,6 +76,7 @@ public interface PreferenceKeys {
static final String PREF_SMALL_SCREEN = "small_screen";
static final String PREF_WIDE_VIEWPORT = "wide_viewport";
static final String PREF_RESET_PRELOGIN = "reset_prelogin";
+ static final String PREF_ADD_BOOKMARKS = "add_bookmarks";
// ----------------------
// Keys for lab_preferences.xml
diff --git a/src/com/android/browser/preferences/DebugPreferencesFragment.java b/src/com/android/browser/preferences/DebugPreferencesFragment.java
index 24821d1..80347bd 100644
--- a/src/com/android/browser/preferences/DebugPreferencesFragment.java
+++ b/src/com/android/browser/preferences/DebugPreferencesFragment.java
@@ -25,6 +25,7 @@ import com.android.browser.BrowserSettings;
import com.android.browser.GoogleAccountLogin;
import com.android.browser.PreferenceKeys;
import com.android.browser.R;
+import com.android.browser.provider.BrowserProvider2;
public class DebugPreferencesFragment extends PreferenceFragment
implements OnPreferenceClickListener {
@@ -37,6 +38,8 @@ public class DebugPreferencesFragment extends PreferenceFragment
Preference e = findPreference(PreferenceKeys.PREF_RESET_PRELOGIN);
e.setOnPreferenceClickListener(this);
+ e = findPreference(PreferenceKeys.PREF_ADD_BOOKMARKS);
+ e.setOnPreferenceClickListener(this);
}
@Override
@@ -47,6 +50,11 @@ public class DebugPreferencesFragment extends PreferenceFragment
.apply();
return true;
}
+ if (PreferenceKeys.PREF_ADD_BOOKMARKS.equals(preference.getKey())) {
+ getActivity().getContentResolver().insert(
+ BrowserProvider2.DEBUG_ADD_BOOKMARKS_URI, null);
+ return true;
+ }
return false;
}
}
diff --git a/src/com/android/browser/provider/BrowserProvider2.java b/src/com/android/browser/provider/BrowserProvider2.java
index a66c333..34a153e 100644
--- a/src/com/android/browser/provider/BrowserProvider2.java
+++ b/src/com/android/browser/provider/BrowserProvider2.java
@@ -75,6 +75,9 @@ public class BrowserProvider2 extends SQLiteContentProvider {
static final Uri LEGACY_AUTHORITY_URI = new Uri.Builder()
.authority(LEGACY_AUTHORITY).scheme("content").build();
+ public static final Uri DEBUG_ADD_BOOKMARKS_URI = Uri.withAppendedPath(
+ BrowserContract.AUTHORITY_URI, "debug-add-bookmarks");
+
public static interface Thumbnails {
public static final Uri CONTENT_URI = Uri.withAppendedPath(
BrowserContract.AUTHORITY_URI, "thumbnails");
@@ -149,6 +152,7 @@ public class BrowserProvider2 extends SQLiteContentProvider {
static final int THUMBNAILS = 10;
static final int THUMBNAILS_ID = 11;
static final int OMNIBOX_SUGGESTIONS = 20;
+ static final int DEBUG_ADD_BOOKMARKS = 30;
static final int BOOKMARKS = 1000;
static final int BOOKMARKS_ID = 1001;
@@ -230,6 +234,9 @@ public class BrowserProvider2 extends SQLiteContentProvider {
matcher.addURI(authority, "thumbnails/#", THUMBNAILS_ID);
matcher.addURI(authority, "omnibox_suggestions", OMNIBOX_SUGGESTIONS);
+ // Debug
+ matcher.addURI(authority, "debug-add-bookmarks", DEBUG_ADD_BOOKMARKS);
+
// Legacy
matcher.addURI(LEGACY_AUTHORITY, "searches", SEARCHES);
matcher.addURI(LEGACY_AUTHORITY, "searches/#", SEARCHES_ID);
@@ -1482,6 +1489,11 @@ public class BrowserProvider2 extends SQLiteContentProvider {
break;
}
+ case DEBUG_ADD_BOOKMARKS: {
+ mOpenHelper.addDefaultBookmarks(db, FIXED_ID_ROOT);
+ break;
+ }
+
default: {
throw new UnsupportedOperationException("Unknown insert URI " + uri);
}
diff --git a/src/com/android/browser/util/ThreadedCursorAdapter.java b/src/com/android/browser/util/ThreadedCursorAdapter.java
index fe59ad1..d0bf715 100644
--- a/src/com/android/browser/util/ThreadedCursorAdapter.java
+++ b/src/com/android/browser/util/ThreadedCursorAdapter.java
@@ -21,8 +21,8 @@ import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.os.Process;
+import android.os.SystemProperties;
import android.util.Log;
-import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
@@ -32,12 +32,12 @@ import android.widget.CursorAdapter;
import com.android.browser.R;
import java.lang.ref.WeakReference;
-import java.util.HashMap;
public abstract class ThreadedCursorAdapter<T> extends BaseAdapter {
- private static final String LOGTAG = "tca";
+ private static final String LOGTAG = "BookmarksThreadedAdapter";
private static final boolean DEBUG = false;
+ private static boolean sEnableBitmapRecycling = true;
private Context mContext;
private Object mCursorLock = new Object();
@@ -46,6 +46,15 @@ public abstract class ThreadedCursorAdapter<T> extends BaseAdapter {
private Handler mLoadHandler;
private Handler mHandler;
private int mSize;
+ private boolean mHasCursor;
+ private long mGeneration;
+
+ static {
+ // TODO: Remove this once recycling is either stabilized or scrapped
+ sEnableBitmapRecycling = SystemProperties
+ .getBoolean("com.android.browser.recycling", sEnableBitmapRecycling);
+ Log.d(LOGTAG, "Bitmap recycling enabled: " + sEnableBitmapRecycling);
+ }
private class LoadContainer {
WeakReference<View> view;
@@ -53,10 +62,12 @@ public abstract class ThreadedCursorAdapter<T> extends BaseAdapter {
T bind_object;
Adapter owner;
boolean loaded;
+ long generation;
}
public ThreadedCursorAdapter(Context context, Cursor c) {
mContext = context;
+ mHasCursor = (c != null);
mCursorAdapter = new CursorAdapter(context, c, 0) {
@Override
@@ -73,6 +84,7 @@ public abstract class ThreadedCursorAdapter<T> extends BaseAdapter {
public void notifyDataSetChanged() {
super.notifyDataSetChanged();
mSize = getCount();
+ mGeneration++;
ThreadedCursorAdapter.this.notifyDataSetChanged();
}
@@ -80,6 +92,7 @@ public abstract class ThreadedCursorAdapter<T> extends BaseAdapter {
public void notifyDataSetInvalidated() {
super.notifyDataSetInvalidated();
mSize = getCount();
+ mGeneration++;
ThreadedCursorAdapter.this.notifyDataSetInvalidated();
}
@@ -109,7 +122,9 @@ public abstract class ThreadedCursorAdapter<T> extends BaseAdapter {
View view = container.view.get();
if (view == null
|| container.owner != ThreadedCursorAdapter.this
- || container.position != msg.what) {
+ || container.position != msg.what
+ || view.getWindowToken() == null
+ || container.generation != mGeneration) {
return;
}
container.loaded = true;
@@ -142,7 +157,12 @@ public abstract class ThreadedCursorAdapter<T> extends BaseAdapter {
}
synchronized (mCursorLock) {
Cursor c = (Cursor) mCursorAdapter.getItem(position);
- container.bind_object = getRowObject(c, container.bind_object);
+ if (c == null || c.isClosed()) {
+ return;
+ }
+ final T recycleObject = sEnableBitmapRecycling
+ ? container.bind_object : null;
+ container.bind_object = getRowObject(c, recycleObject);
}
mHandler.obtainMessage(position, container).sendToTarget();
}
@@ -161,14 +181,18 @@ public abstract class ThreadedCursorAdapter<T> extends BaseAdapter {
}
if (container.position == position
&& container.owner == this
- && container.loaded) {
+ && container.loaded
+ && container.generation == mGeneration) {
bindView(convertView, container.bind_object);
} else {
bindView(convertView, cachedLoadObject());
- container.position = position;
- container.loaded = false;
- container.owner = this;
- mLoadHandler.obtainMessage(position, container).sendToTarget();
+ if (mHasCursor) {
+ container.position = position;
+ container.loaded = false;
+ container.owner = this;
+ container.generation = mGeneration;
+ mLoadHandler.obtainMessage(position, container).sendToTarget();
+ }
}
return convertView;
}
@@ -181,7 +205,10 @@ public abstract class ThreadedCursorAdapter<T> extends BaseAdapter {
}
public void changeCursor(Cursor cursor) {
+ mLoadHandler.removeCallbacksAndMessages(null);
+ mHandler.removeCallbacksAndMessages(null);
synchronized (mCursorLock) {
+ mHasCursor = (cursor != null);
mCursorAdapter.changeCursor(cursor);
}
}