diff options
author | John Reck <jreck@google.com> | 2011-04-26 13:48:09 -0700 |
---|---|---|
committer | John Reck <jreck@google.com> | 2011-04-26 13:50:11 -0700 |
commit | 7b06c907aa31c38069ec2718bd4a388f1f801e6f (patch) | |
tree | 76a485017a76047896202701e97735221c4d21e0 /src/com/android/browser/AutofillHandler.java | |
parent | 35e9dd6283a2d65687104eb0b3a459c02dcb150b (diff) | |
download | android_packages_apps_Gello-7b06c907aa31c38069ec2718bd4a388f1f801e6f.tar.gz android_packages_apps_Gello-7b06c907aa31c38069ec2718bd4a388f1f801e6f.tar.bz2 android_packages_apps_Gello-7b06c907aa31c38069ec2718bd4a388f1f801e6f.zip |
Fix race condition
Change-Id: I567e9d987dbd85551d51b34612b542e9694b83e1
Diffstat (limited to 'src/com/android/browser/AutofillHandler.java')
-rw-r--r-- | src/com/android/browser/AutofillHandler.java | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/src/com/android/browser/AutofillHandler.java b/src/com/android/browser/AutofillHandler.java index b0d5dac6..d91c7ff7 100644 --- a/src/com/android/browser/AutofillHandler.java +++ b/src/com/android/browser/AutofillHandler.java @@ -26,6 +26,8 @@ import android.os.Message; import android.preference.PreferenceManager; import android.webkit.WebSettings.AutoFillProfile; +import java.util.concurrent.CountDownLatch; + public class AutofillHandler { private AutoFillProfile mAutoFillProfile; @@ -36,7 +38,7 @@ public class AutofillHandler { private int mAutoFillActiveProfileId; private static final int NO_AUTOFILL_PROFILE_SET = 0; - private boolean mLoadFromDbComplete; + private CountDownLatch mLoaded = new CountDownLatch(1); private Context mContext; public AutofillHandler(Context context) { @@ -50,31 +52,24 @@ public class AutofillHandler { * in the various preference XML files. */ public void asyncLoadFromDb() { - synchronized (this) { - mLoadFromDbComplete = false; - } // Run the initial settings load in an AsyncTask as it hits the // disk multiple times through SharedPreferences and SQLite. We // need to be certain though that this has completed before we start // to load pages though, so in the worst case we will block waiting // for it to finish in BrowserActivity.onCreate(). - new LoadFromDbTask().execute(); + new LoadFromDb().start(); } public void waitForLoad() { - synchronized (this) { - while (!mLoadFromDbComplete) { - try { - wait(); - } catch (InterruptedException e) {} - } - } + try { + mLoaded.await(); + } catch (InterruptedException e) {} } - private class LoadFromDbTask extends AsyncTask<Void, Void, Void> { + private class LoadFromDb extends Thread { @Override - protected Void doInBackground(Void... unused) { + public void run() { SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(mContext); @@ -119,11 +114,7 @@ public class AutofillHandler { c.close(); autoFillDb.close(); - synchronized (this) { - mLoadFromDbComplete = true; - notifyAll(); - } - return null; + mLoaded.countDown(); } } |