am eead5492: am 769cecf7: Close spell-checking dictionaries in a background thread

* commit 'eead5492615f0b05ef85ca1f88d3a41ce3f8d496':
  Close spell-checking dictionaries in a background thread
This commit is contained in:
Jean Chalard 2012-06-06 21:52:46 -07:00 committed by Android Git Automerger
commit c8a120f970

View file

@ -372,27 +372,32 @@ public class AndroidSpellCheckerService extends SpellCheckerService
mUserDictionaries = Collections.synchronizedMap(new TreeMap<String, Dictionary>()); mUserDictionaries = Collections.synchronizedMap(new TreeMap<String, Dictionary>());
final Map<String, Dictionary> oldWhitelistDictionaries = mWhitelistDictionaries; final Map<String, Dictionary> oldWhitelistDictionaries = mWhitelistDictionaries;
mWhitelistDictionaries = Collections.synchronizedMap(new TreeMap<String, Dictionary>()); mWhitelistDictionaries = Collections.synchronizedMap(new TreeMap<String, Dictionary>());
for (DictionaryPool pool : oldPools.values()) { new Thread("spellchecker_close_dicts") {
pool.close(); @Override
} public void run() {
for (Dictionary dict : oldUserDictionaries.values()) { for (DictionaryPool pool : oldPools.values()) {
dict.close(); pool.close();
} }
for (Dictionary dict : oldWhitelistDictionaries.values()) { for (Dictionary dict : oldUserDictionaries.values()) {
dict.close(); dict.close();
} }
synchronized (mUseContactsLock) { for (Dictionary dict : oldWhitelistDictionaries.values()) {
if (null != mContactsDictionary) { dict.close();
// The synchronously loaded contacts dictionary should have been in one }
// or several pools, but it is shielded against multiple closing and it's synchronized (mUseContactsLock) {
// safe to call it several times. if (null != mContactsDictionary) {
final Dictionary dictToClose = mContactsDictionary; // The synchronously loaded contacts dictionary should have been in one
// TODO: revert to the concrete type when USE_BINARY_CONTACTS_DICTIONARY is no // or several pools, but it is shielded against multiple closing and it's
// longer needed // safe to call it several times.
mContactsDictionary = null; final Dictionary dictToClose = mContactsDictionary;
dictToClose.close(); // TODO: revert to the concrete type when USE_BINARY_CONTACTS_DICTIONARY
// is no longer needed
mContactsDictionary = null;
dictToClose.close();
}
}
} }
} }.start();
} }
private DictionaryPool getDictionaryPool(final String locale) { private DictionaryPool getDictionaryPool(final String locale) {