Index: chrome/browser/spellchecker/spellcheck_service.cc |
diff --git a/chrome/browser/spellchecker/spellcheck_service.cc b/chrome/browser/spellchecker/spellcheck_service.cc |
index e03289626ee2cb238d3b7094d3ba4d55b9218e6f..093ce73de5beed540d963ab374660392bfa7c541 100644 |
--- a/chrome/browser/spellchecker/spellcheck_service.cc |
+++ b/chrome/browser/spellchecker/spellcheck_service.cc |
@@ -8,6 +8,7 @@ |
#include "base/prefs/pref_member.h" |
#include "base/prefs/pref_service.h" |
#include "base/strings/string_split.h" |
+#include "base/supports_user_data.h" |
#include "base/synchronization/waitable_event.h" |
#include "chrome/browser/spellchecker/feedback_sender.h" |
#include "chrome/browser/spellchecker/spellcheck_factory.h" |
@@ -43,11 +44,11 @@ SpellcheckService::SpellcheckService(content::BrowserContext* context) |
PrefService* prefs = user_prefs::UserPrefs::Get(context); |
pref_change_registrar_.Init(prefs); |
- StringListPrefMember dictionaries_pref; |
- dictionaries_pref.Init(prefs::kSpellCheckDictionaries, prefs); |
std::string first_of_dictionaries; |
- if (!dictionaries_pref.GetValue().empty()) |
- first_of_dictionaries = dictionaries_pref.GetValue().front(); |
+ if (!chrome::spellcheck_common::GetDictionaryLanguagesPref(prefs).empty()) { |
+ first_of_dictionaries = |
+ chrome::spellcheck_common::GetDictionaryLanguagesPref(prefs).front(); |
+ } |
// For preference migration, set the new preference kSpellCheckDictionaries |
// to be the same as the old kSpellCheckDictionary. |
@@ -57,6 +58,8 @@ SpellcheckService::SpellcheckService(content::BrowserContext* context) |
if (first_of_dictionaries.empty() && !single_dictionary.empty()) { |
first_of_dictionaries = single_dictionary; |
+ StringListPrefMember dictionaries_pref; |
+ dictionaries_pref.Init(prefs::kSpellCheckDictionaries, prefs); |
dictionaries_pref.SetValue( |
std::vector<std::string>(1, first_of_dictionaries)); |
} |
@@ -78,7 +81,7 @@ SpellcheckService::SpellcheckService(content::BrowserContext* context) |
base::Unretained(this))); |
pref_change_registrar_.Add( |
prefs::kSpellCheckDictionaries, |
- base::Bind(&SpellcheckService::OnSpellCheckDictionaryChanged, |
+ base::Bind(&SpellcheckService::OnSpellCheckDictionariesChanged, |
base::Unretained(this))); |
if (!chrome::spellcheck_common::IsMultilingualSpellcheckEnabled()) { |
pref_change_registrar_.Add( |
@@ -86,12 +89,13 @@ SpellcheckService::SpellcheckService(content::BrowserContext* context) |
base::Bind(&SpellcheckService::OnUseSpellingServiceChanged, |
base::Unretained(this))); |
} |
+ |
pref_change_registrar_.Add( |
prefs::kEnableContinuousSpellcheck, |
base::Bind(&SpellcheckService::InitForAllRenderers, |
base::Unretained(this))); |
- OnSpellCheckDictionaryChanged(); |
+ OnSpellCheckDictionariesChanged(); |
custom_dictionary_.reset(new SpellcheckCustomDictionary(context_->GetPath())); |
custom_dictionary_->AddObserver(this); |
@@ -112,31 +116,18 @@ base::WeakPtr<SpellcheckService> SpellcheckService::GetWeakPtr() { |
} |
// static |
-int SpellcheckService::GetSpellCheckLanguages( |
+size_t SpellcheckService::GetSpellCheckLanguages( |
base::SupportsUserData* context, |
std::vector<std::string>* languages) { |
PrefService* prefs = user_prefs::UserPrefs::Get(context); |
StringPrefMember accept_languages_pref; |
accept_languages_pref.Init(prefs::kAcceptLanguages, prefs); |
- std::string dictionary_language; |
- prefs->GetList(prefs::kSpellCheckDictionaries) |
- ->GetString(0, &dictionary_language); |
- |
- // Now scan through the list of accept languages, and find possible mappings |
- // from this list to the existing list of spell check languages. |
std::vector<std::string> accept_languages; |
- |
-#if defined(OS_MACOSX) |
please use gerrit instead
2015/07/06 23:28:15
If you're removing Mac specific code because this
Julius
2015/07/07 01:14:21
Done.
|
- if (spellcheck_mac::SpellCheckerAvailable()) |
- spellcheck_mac::GetAvailableLanguages(&accept_languages); |
- else |
- base::SplitString(accept_languages_pref.GetValue(), ',', &accept_languages); |
-#else |
base::SplitString(accept_languages_pref.GetValue(), ',', &accept_languages); |
-#endif // !OS_MACOSX |
- languages->push_back(dictionary_language); |
+ *languages = chrome::spellcheck_common::GetDictionaryLanguagesPref(prefs); |
+ size_t enabled_spellcheck_languages = languages->size(); |
for (std::vector<std::string>::const_iterator i = accept_languages.begin(); |
i != accept_languages.end(); ++i) { |
@@ -149,12 +140,7 @@ int SpellcheckService::GetSpellCheckLanguages( |
} |
} |
- for (size_t i = 0; i < languages->size(); ++i) { |
- if ((*languages)[i] == dictionary_language) |
- return i; |
- } |
- |
- return -1; |
+ return enabled_spellcheck_languages; |
} |
// static |
@@ -299,14 +285,17 @@ void SpellcheckService::OnEnableAutoSpellCorrectChanged() { |
} |
} |
-void SpellcheckService::OnSpellCheckDictionaryChanged() { |
+void SpellcheckService::OnSpellCheckDictionariesChanged() { |
if (hunspell_dictionary_.get()) |
hunspell_dictionary_->RemoveObserver(this); |
- PrefService* prefs = user_prefs::UserPrefs::Get(context_); |
- DCHECK(prefs); |
std::string dictionary; |
- prefs->GetList(prefs::kSpellCheckDictionaries)->GetString(0, &dictionary); |
please use gerrit instead
2015/07/06 23:28:15
The current implementation is fine as is. Why chan
Julius
2015/07/07 01:14:21
Probably the better way.
|
+ std::vector<std::string> languages; |
+ size_t dictionary_languages = GetSpellCheckLanguages(context_, &languages); |
+ if (dictionary_languages > 0) { |
+ DCHECK(!languages.empty()); |
+ dictionary = languages.front(); |
+ } |
hunspell_dictionary_.reset(new SpellcheckHunspellDictionary( |
dictionary, context_->GetRequestContext(), this)); |