From e17db4221f15a19fa636602ae317263cdde1a325 Mon Sep 17 00:00:00 2001 From: John Reck Date: Fri, 29 Jul 2011 14:58:10 -0700 Subject: Fix race condition Bug: 5042778 There was a chance that the widget refresh would happen before the SQL transaction was committed. Meaning the widget would correctly be notified, but it would refresh before the delete actually occured Change-Id: Ie7ae3104077c9ebeba4928d3fe7b6a6793f31ca1 --- src/com/android/browser/provider/BrowserProvider2.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/com/android/browser/provider/BrowserProvider2.java b/src/com/android/browser/provider/BrowserProvider2.java index 1821b50..0c1fd42 100644 --- a/src/com/android/browser/provider/BrowserProvider2.java +++ b/src/com/android/browser/provider/BrowserProvider2.java @@ -355,6 +355,7 @@ public class BrowserProvider2 extends SQLiteContentProvider { SyncStateContentProviderHelper mSyncHelper = new SyncStateContentProviderHelper(); // This is so provider tests can intercept widget updating ContentObserver mWidgetObserver = null; + boolean mUpdateWidgets = false; final class DatabaseHelper extends SQLiteOpenHelper { static final String DATABASE_NAME = "browser2.db"; @@ -766,10 +767,19 @@ public class BrowserProvider2 extends SQLiteContentProvider { } void refreshWidgets() { - if (mWidgetObserver == null) { - BookmarkThumbnailWidgetProvider.refreshWidgets(getContext()); - } else { - mWidgetObserver.dispatchChange(false); + mUpdateWidgets = true; + } + + @Override + protected void onEndTransaction(boolean callerIsSyncAdapter) { + super.onEndTransaction(callerIsSyncAdapter); + if (mUpdateWidgets) { + if (mWidgetObserver == null) { + BookmarkThumbnailWidgetProvider.refreshWidgets(getContext()); + } else { + mWidgetObserver.dispatchChange(false); + } + mUpdateWidgets = false; } } -- cgit v1.1