Index: chrome/browser/extensions/api/language_settings_private/language_settings_private_api.cc |
diff --git a/chrome/browser/extensions/api/language_settings_private/language_settings_private_api.cc b/chrome/browser/extensions/api/language_settings_private/language_settings_private_api.cc |
index 1a76caf1caac07a8a271344cc9794216fdc6a3bd..9eba66a7c2c7cd90e15fd9f6cc14c655f63bcc38 100644 |
--- a/chrome/browser/extensions/api/language_settings_private/language_settings_private_api.cc |
+++ b/chrome/browser/extensions/api/language_settings_private/language_settings_private_api.cc |
@@ -183,14 +183,83 @@ LanguageSettingsPrivateGetSpellcheckWordsFunction::Run() { |
SpellcheckServiceFactory::GetForContext(browser_context()); |
SpellcheckCustomDictionary* dictionary = service->GetCustomDictionary(); |
+ if (dictionary->IsLoaded()) |
+ return RespondNow(OneArgument(GetSpellcheckWords().release())); |
+ |
+ dictionary->AddObserver(this); |
+ AddRef(); // Balanced in OnCustomDictionaryLoaded(). |
+ return RespondLater(); |
+} |
+ |
+void |
+LanguageSettingsPrivateGetSpellcheckWordsFunction::OnCustomDictionaryLoaded() { |
+ SpellcheckService* service = |
+ SpellcheckServiceFactory::GetForContext(browser_context()); |
+ service->GetCustomDictionary()->RemoveObserver(this); |
+ Respond(OneArgument(GetSpellcheckWords().release())); |
+ Release(); |
+} |
+ |
+void |
+LanguageSettingsPrivateGetSpellcheckWordsFunction::OnCustomDictionaryChanged( |
+ const SpellcheckCustomDictionary::Change& dictionary_change) { |
stevenjb
2015/09/28 23:58:10
nit: NOTREACHED() << "SpellcheckCustomDictionary C
michaelpg
2015/09/29 00:27:24
Done.
|
+} |
+ |
+scoped_ptr<base::ListValue> |
+LanguageSettingsPrivateGetSpellcheckWordsFunction::GetSpellcheckWords() const { |
+ SpellcheckService* service = |
+ SpellcheckServiceFactory::GetForContext(browser_context()); |
+ SpellcheckCustomDictionary* dictionary = service->GetCustomDictionary(); |
+ DCHECK(dictionary->IsLoaded()); |
+ |
+ // TODO(michaelpg): Sort using app locale. |
scoped_ptr<base::ListValue> word_list(new base::ListValue()); |
- // TODO(michaelpg): observe the dictionary and respond later if not loaded. |
- if (dictionary->IsLoaded()) { |
- const std::set<std::string>& words = dictionary->GetWords(); |
- for (const std::string& word : words) |
- word_list->AppendString(word); |
- } |
- return RespondNow(OneArgument(word_list.release())); |
+ const std::set<std::string>& words = dictionary->GetWords(); |
+ for (const std::string& word : words) |
+ word_list->AppendString(word); |
+ return word_list.Pass(); |
+} |
+ |
+LanguageSettingsPrivateAddSpellcheckWordFunction:: |
+ LanguageSettingsPrivateAddSpellcheckWordFunction() { |
+} |
+ |
+LanguageSettingsPrivateAddSpellcheckWordFunction:: |
+ ~LanguageSettingsPrivateAddSpellcheckWordFunction() { |
+} |
+ |
+ExtensionFunction::ResponseAction |
+LanguageSettingsPrivateAddSpellcheckWordFunction::Run() { |
+ scoped_ptr<language_settings_private::AddSpellcheckWord::Params> params = |
+ language_settings_private::AddSpellcheckWord::Params::Create(*args_); |
+ EXTENSION_FUNCTION_VALIDATE(params.get()); |
+ |
+ SpellcheckService* service = |
+ SpellcheckServiceFactory::GetForContext(browser_context()); |
+ bool success = service->GetCustomDictionary()->AddWord(params->word); |
+ |
+ return RespondNow(OneArgument(new base::FundamentalValue(success))); |
+} |
+ |
+LanguageSettingsPrivateRemoveSpellcheckWordFunction:: |
+ LanguageSettingsPrivateRemoveSpellcheckWordFunction() { |
+} |
+ |
+LanguageSettingsPrivateRemoveSpellcheckWordFunction:: |
+ ~LanguageSettingsPrivateRemoveSpellcheckWordFunction() { |
+} |
+ |
+ExtensionFunction::ResponseAction |
+LanguageSettingsPrivateRemoveSpellcheckWordFunction::Run() { |
+ scoped_ptr<language_settings_private::RemoveSpellcheckWord::Params> params = |
+ language_settings_private::RemoveSpellcheckWord::Params::Create(*args_); |
+ EXTENSION_FUNCTION_VALIDATE(params.get()); |
+ |
+ SpellcheckService* service = |
+ SpellcheckServiceFactory::GetForContext(browser_context()); |
+ bool success = service->GetCustomDictionary()->RemoveWord(params->word); |
+ |
+ return RespondNow(OneArgument(new base::FundamentalValue(success))); |
} |
LanguageSettingsPrivateGetTranslateTargetLanguageFunction:: |