From 22f01a42fcd91dae2a4e723e2477a480a11daa8e Mon Sep 17 00:00:00 2001 From: Satoshi Kataoka Date: Tue, 20 Aug 2013 12:07:17 +0900 Subject: [PATCH] Add a functionality to clear and flush prediction dictionary Bug: 9429906 Change-Id: I84ec444e9d46a0080dc3450b8ab32bfb99407cfe --- .../DynamicPredictionDictionaryBase.java | 14 ++++++++++++++ .../PersonalizationDictionaryUpdateSession.java | 7 +++++++ 2 files changed, 21 insertions(+) diff --git a/java/src/com/android/inputmethod/latin/personalization/DynamicPredictionDictionaryBase.java b/java/src/com/android/inputmethod/latin/personalization/DynamicPredictionDictionaryBase.java index 916be4481..8160501a9 100644 --- a/java/src/com/android/inputmethod/latin/personalization/DynamicPredictionDictionaryBase.java +++ b/java/src/com/android/inputmethod/latin/personalization/DynamicPredictionDictionaryBase.java @@ -411,4 +411,18 @@ public abstract class DynamicPredictionDictionaryBase extends ExpandableDictiona public void unRegisterUpdateSession(PersonalizationDictionaryUpdateSession session) { mSessions.remove(session); } + + public void clearAndFlushDictionary() { + // Clear the node structure on memory + clearDictionary(); + mBigramListLock.lock(); + try { + // Clear the bigram list on memory + mBigramList.evictAll(); + } finally { + mBigramListLock.unlock(); + } + // Then flush the cleared state of the dictionary on disk. + flushPendingWrites(); + } } diff --git a/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionaryUpdateSession.java b/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionaryUpdateSession.java index 433c69c1c..77f0cdbfa 100644 --- a/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionaryUpdateSession.java +++ b/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionaryUpdateSession.java @@ -69,6 +69,13 @@ public abstract class PersonalizationDictionaryUpdateSession { dictionary.unRegisterUpdateSession(this); } + public void clearAndFlushPredictionDictionary(Context context) { + final DynamicPredictionDictionaryBase dictionary = getPredictionDictionary(); + if (dictionary == null) { + return; + } + dictionary.clearAndFlushDictionary(); + } public void closeSession(Context context) { unsetPredictionDictionary();