From 9aa25b46ec5354b7ecf7ffdfe1941de6fedaa014 Mon Sep 17 00:00:00 2001 From: Brian Nicholson Date: Thu, 7 Jun 2012 17:18:32 -0700 Subject: [PATCH] Bug 756735 - Synchronize accesses to mLoadTasks in Favicons. r=blassey --- mobile/android/base/Favicons.java | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/mobile/android/base/Favicons.java b/mobile/android/base/Favicons.java index 206de231734..ed163fb23ec 100644 --- a/mobile/android/base/Favicons.java +++ b/mobile/android/base/Favicons.java @@ -21,6 +21,7 @@ import java.io.InputStream; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; +import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -136,7 +137,7 @@ public class Favicons { mContext = context; mDbHelper = new DatabaseHelper(context); - mLoadTasks = new HashMap(); + mLoadTasks = Collections.synchronizedMap(new HashMap()); mNextFaviconLoadId = 0; } @@ -166,13 +167,17 @@ public class Favicons { public boolean cancelFaviconLoad(long taskId) { Log.d(LOGTAG, "Requesting cancelation of favicon load (" + taskId + ")"); - if (!mLoadTasks.containsKey(taskId)) - return false; + boolean cancelled = false; + synchronized (mLoadTasks) { + if (!mLoadTasks.containsKey(taskId)) + return false; - Log.d(LOGTAG, "Cancelling favicon load (" + taskId + ")"); + Log.d(LOGTAG, "Cancelling favicon load (" + taskId + ")"); - LoadFaviconTask task = mLoadTasks.get(taskId); - return task.cancel(false); + LoadFaviconTask task = mLoadTasks.get(taskId); + cancelled = task.cancel(false); + } + return cancelled; } public void clearFavicons() { @@ -184,11 +189,13 @@ public class Favicons { mDbHelper.close(); // Cancel any pending tasks - Set taskIds = mLoadTasks.keySet(); - Iterator iter = taskIds.iterator(); - while (iter.hasNext()) { - long taskId = iter.next(); - cancelFaviconLoad(taskId); + synchronized (mLoadTasks) { + Set taskIds = mLoadTasks.keySet(); + Iterator iter = taskIds.iterator(); + while (iter.hasNext()) { + long taskId = iter.next(); + cancelFaviconLoad(taskId); + } } }