Index: chrome/browser/spellchecker/spellcheck_service.cc |
diff --git a/chrome/browser/spellchecker/spellcheck_service.cc b/chrome/browser/spellchecker/spellcheck_service.cc |
index f40924e8c18e3ff48c2c981a1514e2ff5b7ce827..4dda3274a78a03534847c1c29b52ab6b560e2eb1 100644 |
--- a/chrome/browser/spellchecker/spellcheck_service.cc |
+++ b/chrome/browser/spellchecker/spellcheck_service.cc |
@@ -4,6 +4,8 @@ |
#include "chrome/browser/spellchecker/spellcheck_service.h" |
+#include <algorithm> |
+ |
#include "base/prefs/pref_member.h" |
#include "base/prefs/pref_service.h" |
#include "base/strings/string_split.h" |
@@ -75,19 +77,16 @@ SpellcheckService::~SpellcheckService() { |
} |
// static |
-int SpellcheckService::GetSpellCheckLanguages( |
- content::BrowserContext* context, |
- std::vector<std::string>* languages) { |
+std::set<int> SpellcheckService::GetSpellCheckLanguages( |
+ content::BrowserContext* context, |
+ std::vector<std::string>* languages) { |
PrefService* prefs = user_prefs::UserPrefs::Get(context); |
- StringPrefMember accept_languages_pref; |
- StringPrefMember dictionary_language_pref; |
- accept_languages_pref.Init(prefs::kAcceptLanguages, prefs); |
- dictionary_language_pref.Init(prefs::kSpellCheckDictionary, prefs); |
- std::string dictionary_language = dictionary_language_pref.GetValue(); |
+ std::vector<std::string> dictionary_languages = |
+ chrome::spellcheck_common::GetDictionaryLanguagesPref(prefs); |
- // 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; |
+ StringPrefMember accept_languages_pref; |
+ accept_languages_pref.Init(prefs::kAcceptLanguages, prefs); |
#if defined(OS_MACOSX) |
if (spellcheck_mac::SpellCheckerAvailable()) |
@@ -98,23 +97,22 @@ int SpellcheckService::GetSpellCheckLanguages( |
base::SplitString(accept_languages_pref.GetValue(), ',', &accept_languages); |
#endif // !OS_MACOSX |
- GetSpellCheckLanguagesFromAcceptLanguages( |
- accept_languages, dictionary_language, languages); |
+ *languages = dictionary_languages; |
groby-ooo-7-16
2015/03/03 17:54:34
Can you please leave a short comment somewhere how
|
+ GetSpellCheckLanguagesFromAcceptLanguages(accept_languages, languages); |
- for (size_t i = 0; i < languages->size(); ++i) { |
- if ((*languages)[i] == dictionary_language) |
- return i; |
- } |
- return -1; |
+ // |languages| vector begins with the entries from |dictionary_languages|, |
+ // therefore these indices are correct. |
+ std::set<int> selected_language_indices; |
groby-ooo-7-16
2015/03/03 17:54:34
If it's always the first <n> elements, why not ret
|
+ for (size_t i = 0; i < dictionary_languages.size(); ++i) |
+ selected_language_indices.insert(i); |
+ |
+ return selected_language_indices; |
} |
// static |
void SpellcheckService::GetSpellCheckLanguagesFromAcceptLanguages( |
const std::vector<std::string>& accept_languages, |
- const std::string& dictionary_language, |
std::vector<std::string>* languages) { |
- // The current dictionary language should be there. |
- languages->push_back(dictionary_language); |
for (std::vector<std::string>::const_iterator i = accept_languages.begin(); |
i != accept_languages.end(); ++i) { |