summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/spellchecker/spellcheck_custom_dictionary.cc31
-rw-r--r--chrome/browser/spellchecker/spellcheck_custom_dictionary.h9
-rw-r--r--chrome/browser/spellchecker/spellcheck_custom_dictionary_unittest.cc60
-rw-r--r--chrome/browser/sync/test/integration/dictionary_helper.cc66
-rw-r--r--chrome/browser/ui/webui/options/language_dictionary_overlay_handler.cc6
-rw-r--r--chrome/common/spellcheck_common.h2
-rw-r--r--chrome/common/spellcheck_messages.h8
-rw-r--r--chrome/renderer/spellchecker/custom_dictionary_engine.cc5
-rw-r--r--chrome/renderer/spellchecker/custom_dictionary_engine.h2
-rw-r--r--chrome/renderer/spellchecker/custom_dictionary_engine_unittest.cc14
-rw-r--r--chrome/renderer/spellchecker/spellcheck.cc4
-rw-r--r--chrome/renderer/spellchecker/spellcheck.h4
-rw-r--r--chrome/renderer/spellchecker/spellcheck_unittest.cc3
13 files changed, 99 insertions, 115 deletions
diff --git a/chrome/browser/spellchecker/spellcheck_custom_dictionary.cc b/chrome/browser/spellchecker/spellcheck_custom_dictionary.cc
index ec1cdd7..0cd0c7c 100644
--- a/chrome/browser/spellchecker/spellcheck_custom_dictionary.cc
+++ b/chrome/browser/spellchecker/spellcheck_custom_dictionary.cc
@@ -22,6 +22,7 @@
using content::BrowserThread;
using chrome::spellcheck_common::WordList;
+using chrome::spellcheck_common::WordSet;
namespace {
@@ -125,7 +126,7 @@ void SaveDictionaryFileReliably(
// Removes duplicate and invalid words from |to_add| word list and sorts it.
// Looks for duplicates in both |to_add| and |existing| word lists. Returns a
// bitmap of |ChangeSanitationResult| values.
-int SanitizeWordsToAdd(const WordList& existing, WordList& to_add) {
+int SanitizeWordsToAdd(const WordSet& existing, WordList& to_add) {
// Do not add duplicate words.
std::sort(to_add.begin(), to_add.end());
WordList new_words;
@@ -154,7 +155,7 @@ int SanitizeWordsToAdd(const WordList& existing, WordList& to_add) {
// Removes word from |to_remove| that are missing from |existing| word list and
// sorts |to_remove|. Returns a bitmap of |ChangeSanitationResult| values.
-int SanitizeWordsToRemove(const WordList& existing, WordList& to_remove) {
+int SanitizeWordsToRemove(const WordSet& existing, WordList& to_remove) {
// Do not remove words that are missing from the dictionary.
std::sort(to_remove.begin(), to_remove.end());
WordList found_words;
@@ -198,7 +199,7 @@ void SpellcheckCustomDictionary::Change::RemoveWord(const std::string& word) {
to_remove_.push_back(word);
}
-int SpellcheckCustomDictionary::Change::Sanitize(const WordList& words) {
+int SpellcheckCustomDictionary::Change::Sanitize(const WordSet& words) {
int result = VALID_CHANGE;
if (!to_add_.empty())
result |= SanitizeWordsToAdd(words, to_add_);
@@ -231,14 +232,13 @@ SpellcheckCustomDictionary::SpellcheckCustomDictionary(
SpellcheckCustomDictionary::~SpellcheckCustomDictionary() {
}
-const WordList& SpellcheckCustomDictionary::GetWords() const {
+const WordSet& SpellcheckCustomDictionary::GetWords() const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
return words_;
}
bool SpellcheckCustomDictionary::AddWord(const std::string& word) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- std::sort(words_.begin(), words_.end());
Change dictionary_change;
dictionary_change.AddWord(word);
int result = dictionary_change.Sanitize(GetWords());
@@ -251,7 +251,6 @@ bool SpellcheckCustomDictionary::AddWord(const std::string& word) {
bool SpellcheckCustomDictionary::RemoveWord(const std::string& word) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- std::sort(words_.begin(), words_.end());
Change dictionary_change;
dictionary_change.RemoveWord(word);
int result = dictionary_change.Sanitize(GetWords());
@@ -262,6 +261,10 @@ bool SpellcheckCustomDictionary::RemoveWord(const std::string& word) {
return result == VALID_CHANGE;
}
+bool SpellcheckCustomDictionary::HasWord(const std::string& word) {
+ return !!words_.count(word);
+}
+
void SpellcheckCustomDictionary::AddObserver(Observer* observer) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
observers_.AddObserver(observer);
@@ -317,7 +320,6 @@ syncer::SyncMergeResult SpellcheckCustomDictionary::MergeDataAndStartSyncing(
}
// Add remote words locally.
- std::sort(words_.begin(), words_.end());
Change to_change_locally(to_add_locally);
to_change_locally.Sanitize(GetWords());
Apply(to_change_locally);
@@ -325,7 +327,6 @@ syncer::SyncMergeResult SpellcheckCustomDictionary::MergeDataAndStartSyncing(
Save(to_change_locally);
// Add as many as possible local words remotely.
- std::sort(words_.begin(), words_.end());
std::sort(to_add_locally.begin(), to_add_locally.end());
WordList to_add_remotely;
std::set_difference(words_.begin(),
@@ -355,7 +356,7 @@ syncer::SyncDataList SpellcheckCustomDictionary::GetAllSyncData(
syncer::SyncDataList data;
std::string word;
size_t i = 0;
- for (WordList::const_iterator it = words_.begin();
+ for (WordSet::const_iterator it = words_.begin();
it != words_.end() &&
i < chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS;
++it, ++i) {
@@ -392,7 +393,6 @@ syncer::SyncError SpellcheckCustomDictionary::ProcessSyncChanges(
}
}
- std::sort(words_.begin(), words_.end());
dictionary_change.Sanitize(GetWords());
Apply(dictionary_change);
Notify(dictionary_change);
@@ -407,7 +407,7 @@ WordList SpellcheckCustomDictionary::LoadDictionaryFile(
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
WordList words;
LoadDictionaryFileReliably(words, path);
- if (!words.empty() && VALID_CHANGE != SanitizeWordsToAdd(WordList(), words))
+ if (!words.empty() && VALID_CHANGE != SanitizeWordsToAdd(WordSet(), words))
SaveDictionaryFileReliably(words, path);
SpellCheckHostMetrics::RecordCustomWordCountStats(words.size());
return words;
@@ -444,7 +444,6 @@ void SpellcheckCustomDictionary::UpdateDictionaryFile(
void SpellcheckCustomDictionary::OnLoaded(WordList custom_words) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- std::sort(words_.begin(), words_.end());
Change dictionary_change(custom_words);
dictionary_change.Sanitize(GetWords());
Apply(dictionary_change);
@@ -457,18 +456,16 @@ void SpellcheckCustomDictionary::Apply(
const SpellcheckCustomDictionary::Change& dictionary_change) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (!dictionary_change.to_add().empty()) {
- words_.insert(words_.end(),
- dictionary_change.to_add().begin(),
+ words_.insert(dictionary_change.to_add().begin(),
dictionary_change.to_add().end());
}
if (!dictionary_change.to_remove().empty()) {
- std::sort(words_.begin(), words_.end());
- WordList updated_words;
+ WordSet updated_words;
std::set_difference(words_.begin(),
words_.end(),
dictionary_change.to_remove().begin(),
dictionary_change.to_remove().end(),
- std::back_inserter(updated_words));
+ std::inserter(updated_words, updated_words.end()));
std::swap(words_, updated_words);
}
}
diff --git a/chrome/browser/spellchecker/spellcheck_custom_dictionary.h b/chrome/browser/spellchecker/spellcheck_custom_dictionary.h
index 3854156..e54b6fa 100644
--- a/chrome/browser/spellchecker/spellcheck_custom_dictionary.h
+++ b/chrome/browser/spellchecker/spellcheck_custom_dictionary.h
@@ -45,7 +45,7 @@ class SpellcheckCustomDictionary : public SpellcheckDictionary,
// invalid words from words to be added, removing missing words from words
// to be removed, and sorting both lists of words. Assumes that |words| is
// sorted. Returns a bitmap of |ChangeSanitationResult| values.
- int Sanitize(const chrome::spellcheck_common::WordList& words);
+ int Sanitize(const chrome::spellcheck_common::WordSet& words);
// Returns the words to be added in this change.
const chrome::spellcheck_common::WordList& to_add() const;
@@ -78,7 +78,7 @@ class SpellcheckCustomDictionary : public SpellcheckDictionary,
virtual ~SpellcheckCustomDictionary();
// Returns the in-memory cache of words in the custom dictionary.
- const chrome::spellcheck_common::WordList& GetWords() const;
+ const chrome::spellcheck_common::WordSet& GetWords() const;
// Adds |word| to the dictionary, schedules a write to disk, and notifies
// observers of the change. Returns true if |word| is valid and not a
@@ -90,6 +90,9 @@ class SpellcheckCustomDictionary : public SpellcheckDictionary,
// returns false.
bool RemoveWord(const std::string& word);
+ // Returns true if the dictionary contains |word|. Otherwise returns false.
+ bool HasWord(const std::string& word);
+
// Adds |observer| to be notified of dictionary events and changes.
void AddObserver(Observer* observer);
@@ -158,7 +161,7 @@ class SpellcheckCustomDictionary : public SpellcheckDictionary,
void Notify(const Change& dictionary_change);
// In-memory cache of the custom words file.
- chrome::spellcheck_common::WordList words_;
+ chrome::spellcheck_common::WordSet words_;
// A path for custom dictionary.
base::FilePath custom_dictionary_path_;
diff --git a/chrome/browser/spellchecker/spellcheck_custom_dictionary_unittest.cc b/chrome/browser/spellchecker/spellcheck_custom_dictionary_unittest.cc
index 1d5b7cb..d196f65 100644
--- a/chrome/browser/spellchecker/spellcheck_custom_dictionary_unittest.cc
+++ b/chrome/browser/spellchecker/spellcheck_custom_dictionary_unittest.cc
@@ -31,6 +31,7 @@ using base::HistogramSamples;
using base::StatisticsRecorder;
using content::BrowserThread;
using chrome::spellcheck_common::WordList;
+using chrome::spellcheck_common::WordSet;
namespace {
@@ -40,9 +41,8 @@ syncer::SyncDataList GetAllSyncDataNoLimit(
const SpellcheckCustomDictionary* dictionary) {
syncer::SyncDataList data;
std::string word;
- for (WordList::const_iterator it = dictionary->GetWords().begin();
- it != dictionary->GetWords().end();
- ++it) {
+ const WordSet& words = dictionary->GetWords();
+ for (WordSet::const_iterator it = words.begin(); it != words.end(); ++it) {
word = *it;
sync_pb::EntitySpecifics specifics;
specifics.mutable_dictionary()->set_word(word);
@@ -225,27 +225,23 @@ TEST_F(SpellcheckCustomDictionaryTest, MultiProfile) {
SpellcheckCustomDictionary* custom_dictionary2 =
spellcheck_service2->GetCustomDictionary();
- WordList expected1;
- WordList expected2;
+ WordSet expected1;
+ WordSet expected2;
custom_dictionary->AddWord("foo");
custom_dictionary->AddWord("bar");
- expected1.push_back("foo");
- expected1.push_back("bar");
+ expected1.insert("foo");
+ expected1.insert("bar");
custom_dictionary2->AddWord("hoge");
custom_dictionary2->AddWord("fuga");
- expected2.push_back("hoge");
- expected2.push_back("fuga");
+ expected2.insert("hoge");
+ expected2.insert("fuga");
- WordList actual1 = custom_dictionary->GetWords();
- std::sort(actual1.begin(), actual1.end());
- std::sort(expected1.begin(), expected1.end());
+ WordSet actual1 = custom_dictionary->GetWords();
EXPECT_EQ(actual1, expected1);
- WordList actual2 = custom_dictionary2->GetWords();
- std::sort(actual2.begin(), actual2.end());
- std::sort(expected2.begin(), expected2.end());
+ WordSet actual2 = custom_dictionary2->GetWords();
EXPECT_EQ(actual2, expected2);
}
@@ -330,14 +326,14 @@ TEST_F(SpellcheckCustomDictionaryTest,
syncer::SyncDataList data = dictionary->GetAllSyncData(syncer::DICTIONARY);
EXPECT_TRUE(data.empty());
- EXPECT_TRUE(dictionary->AddWord("foo"));
EXPECT_TRUE(dictionary->AddWord("bar"));
+ EXPECT_TRUE(dictionary->AddWord("foo"));
data = dictionary->GetAllSyncData(syncer::DICTIONARY);
EXPECT_EQ(2UL, data.size());
std::vector<std::string> words;
- words.push_back("foo");
words.push_back("bar");
+ words.push_back("foo");
for (size_t i = 0; i < data.size(); i++) {
EXPECT_TRUE(data[i].GetSpecifics().has_dictionary());
EXPECT_EQ(syncer::DICTIONARY, data[i].GetDataType());
@@ -345,8 +341,8 @@ TEST_F(SpellcheckCustomDictionaryTest,
EXPECT_EQ(words[i], data[i].GetSpecifics().dictionary().word());
}
- EXPECT_TRUE(dictionary->RemoveWord("foo"));
EXPECT_TRUE(dictionary->RemoveWord("bar"));
+ EXPECT_TRUE(dictionary->RemoveWord("foo"));
data = dictionary->GetAllSyncData(syncer::DICTIONARY);
EXPECT_TRUE(data.empty());
@@ -452,11 +448,11 @@ TEST_F(SpellcheckCustomDictionaryTest, ProcessSyncChanges) {
EXPECT_FALSE(dictionary->ProcessSyncChanges(FROM_HERE, changes).IsSet());
- const chrome::spellcheck_common::WordList& words = dictionary->GetWords();
+ const WordSet& words = dictionary->GetWords();
EXPECT_EQ(2UL, words.size());
- EXPECT_EQ(words.end(), std::find(words.begin(), words.end(), "bar"));
- EXPECT_NE(words.end(), std::find(words.begin(), words.end(), "foo"));
- EXPECT_NE(words.end(), std::find(words.begin(), words.end(), "baz"));
+ EXPECT_EQ(0UL, words.count("bar"));
+ EXPECT_EQ(1UL, words.count("foo"));
+ EXPECT_EQ(1UL, words.count("baz"));
}
TEST_F(SpellcheckCustomDictionaryTest, MergeDataAndStartSyncing) {
@@ -499,12 +495,9 @@ TEST_F(SpellcheckCustomDictionaryTest, MergeDataAndStartSyncing) {
EXPECT_EQ(0, error_counter);
EXPECT_TRUE(custom_dictionary->IsSyncing());
- WordList words = custom_dictionary->GetWords();
- WordList words2 = custom_dictionary2->GetWords();
+ WordSet words = custom_dictionary->GetWords();
+ WordSet words2 = custom_dictionary2->GetWords();
EXPECT_EQ(words.size(), words2.size());
-
- std::sort(words.begin(), words.end());
- std::sort(words2.begin(), words2.end());
EXPECT_EQ(words, words2);
}
@@ -1126,3 +1119,16 @@ TEST_F(SpellcheckCustomDictionaryTest, RecordSizeStatsCorrectly) {
samples2->Subtract(*baseline);
EXPECT_EQ(2,samples2->sum());
}
+
+TEST_F(SpellcheckCustomDictionaryTest, HasWord) {
+ SpellcheckService* spellcheck_service =
+ SpellcheckServiceFactory::GetForProfile(profile_.get());
+ SpellcheckCustomDictionary* custom_dictionary =
+ spellcheck_service->GetCustomDictionary();
+ OnLoaded(*custom_dictionary, WordList());
+ EXPECT_FALSE(custom_dictionary->HasWord("foo"));
+ EXPECT_FALSE(custom_dictionary->HasWord("bar"));
+ custom_dictionary->AddWord("foo");
+ EXPECT_TRUE(custom_dictionary->HasWord("foo"));
+ EXPECT_FALSE(custom_dictionary->HasWord("bar"));
+}
diff --git a/chrome/browser/sync/test/integration/dictionary_helper.cc b/chrome/browser/sync/test/integration/dictionary_helper.cc
index 5ec83d5..9ef7674 100644
--- a/chrome/browser/sync/test/integration/dictionary_helper.cc
+++ b/chrome/browser/sync/test/integration/dictionary_helper.cc
@@ -4,6 +4,8 @@
#include "chrome/browser/sync/test/integration/dictionary_helper.h"
+#include <algorithm>
+
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/spellchecker/spellcheck_factory.h"
#include "chrome/browser/spellchecker/spellcheck_service.h"
@@ -22,7 +24,6 @@ class DictionarySyncIntegrationTestHelper {
static bool ApplyChange(
SpellcheckCustomDictionary* dictionary,
SpellcheckCustomDictionary::Change& change) {
- std::sort(dictionary->words_.begin(), dictionary->words_.end());
int result = change.Sanitize(dictionary->GetWords());
dictionary->Apply(change);
dictionary->Notify(change);
@@ -37,15 +38,6 @@ class DictionarySyncIntegrationTestHelper {
namespace dictionary_helper {
namespace {
-bool DictionaryHasWord(
- const SpellcheckCustomDictionary* dictionary,
- const std::string& word) {
- return dictionary->GetWords().end() != std::find(
- dictionary->GetWords().begin(),
- dictionary->GetWords().end(),
- word);
-}
-
SpellcheckCustomDictionary* GetDictionary(int index) {
return SpellcheckServiceFactory::GetForProfile(
sync_datatype_helper::test()->GetProfile(index))->GetCustomDictionary();
@@ -56,14 +48,6 @@ SpellcheckCustomDictionary* GetVerifierDictionary() {
sync_datatype_helper::test()->verifier())->GetCustomDictionary();
}
-bool HaveWord(int index, std::string word) {
- return DictionaryHasWord(GetDictionary(index), word);
-}
-
-bool HaveWordInVerifier(std::string word) {
- return DictionaryHasWord(GetVerifierDictionary(), word);
-}
-
void LoadDictionary(SpellcheckCustomDictionary* dictionary) {
if (dictionary->IsLoaded())
return;
@@ -76,17 +60,6 @@ void LoadDictionary(SpellcheckCustomDictionary* dictionary) {
ASSERT_TRUE(dictionary->IsLoaded());
}
-bool HaveWordMatches(const std::string& word) {
- bool reference = sync_datatype_helper::test()->use_verifier() ?
- HaveWordInVerifier(word) : HaveWord(0, word);
- for (int i = 0; i < sync_datatype_helper::test()->num_clients(); ++i) {
- if (reference != HaveWord(i, word)) {
- return false;
- }
- }
- return true;
-}
-
} // namespace
@@ -106,35 +79,28 @@ size_t GetVerifierDictionarySize() {
}
bool DictionariesMatch() {
- chrome::spellcheck_common::WordList reference =
- sync_datatype_helper::test()->use_verifier() ?
- GetVerifierDictionary()->GetWords() : GetDictionary(0)->GetWords();
+ const chrome::spellcheck_common::WordSet& reference =
+ sync_datatype_helper::test()->use_verifier()
+ ? GetVerifierDictionary()->GetWords()
+ : GetDictionary(0)->GetWords();
for (int i = 0; i < sync_datatype_helper::test()->num_clients(); ++i) {
- if (reference.size() != GetDictionary(i)->GetWords().size())
- return false;
- }
- for (chrome::spellcheck_common::WordList::iterator it = reference.begin();
- it != reference.end();
- ++it) {
- if (!HaveWordMatches(*it))
+ const chrome::spellcheck_common::WordSet& dictionary =
+ GetDictionary(i)->GetWords();
+ if (reference.size() != dictionary.size() ||
+ !std::equal(reference.begin(), reference.end(), dictionary.begin())) {
return false;
+ }
}
return true;
}
bool DictionaryMatchesVerifier(int index) {
- chrome::spellcheck_common::WordList expected =
+ const chrome::spellcheck_common::WordSet& expected =
GetVerifierDictionary()->GetWords();
- chrome::spellcheck_common::WordList actual = GetDictionary(index)->GetWords();
- if (expected.size() != actual.size())
- return false;
- for (chrome::spellcheck_common::WordList::iterator it = expected.begin();
- it != expected.end();
- ++it) {
- if (actual.end() == std::find(actual.begin(), actual.end(), *it))
- return false;
- }
- return true;
+ const chrome::spellcheck_common::WordSet& actual =
+ GetDictionary(index)->GetWords();
+ return expected.size() == actual.size() &&
+ std::equal(expected.begin(), expected.end(), actual.begin());
}
bool AddWord(int index, const std::string& word) {
diff --git a/chrome/browser/ui/webui/options/language_dictionary_overlay_handler.cc b/chrome/browser/ui/webui/options/language_dictionary_overlay_handler.cc
index 11f17c1..d6be0e4 100644
--- a/chrome/browser/ui/webui/options/language_dictionary_overlay_handler.cc
+++ b/chrome/browser/ui/webui/options/language_dictionary_overlay_handler.cc
@@ -91,7 +91,11 @@ void LanguageDictionaryOverlayHandler::ResetDictionaryWords() {
}
ListValue list_value;
- list_value.AppendStrings(dictionary_->GetWords());
+ const chrome::spellcheck_common::WordSet& words = dictionary_->GetWords();
+ for (chrome::spellcheck_common::WordSet::const_iterator it = words.begin();
+ it != words.end(); ++it) {
+ list_value.AppendString(*it);
+ }
web_ui()->CallJavascriptFunction("EditDictionaryOverlay.setWordList",
list_value);
}
diff --git a/chrome/common/spellcheck_common.h b/chrome/common/spellcheck_common.h
index a79aa1c..9c3f706 100644
--- a/chrome/common/spellcheck_common.h
+++ b/chrome/common/spellcheck_common.h
@@ -5,6 +5,7 @@
#ifndef CHROME_COMMON_SPELLCHECK_COMMON_H_
#define CHROME_COMMON_SPELLCHECK_COMMON_H_
+#include <set>
#include <string>
#include <vector>
@@ -40,6 +41,7 @@ static const size_t MAX_SYNCABLE_DICTIONARY_WORDS = 1300;
static const size_t MAX_CUSTOM_DICTIONARY_WORD_BYTES = 99;
typedef std::vector<std::string> WordList;
+typedef std::set<std::string> WordSet;
base::FilePath GetVersionedFileName(const std::string& input_language,
const base::FilePath& dict_dir);
diff --git a/chrome/common/spellcheck_messages.h b/chrome/common/spellcheck_messages.h
index d808b80..e1f1639 100644
--- a/chrome/common/spellcheck_messages.h
+++ b/chrome/common/spellcheck_messages.h
@@ -33,12 +33,12 @@ IPC_STRUCT_TRAITS_END()
IPC_MESSAGE_CONTROL1(SpellCheckMsg_EnableSpellCheck,
bool)
-// Passes some initialization params to the renderer's spellchecker. This can
-// be called directly after startup or in (async) response to a
-// RequestDictionary ViewHost message.
+// Passes some initialization params from the browser to the renderer's
+// spellchecker. This can be called directly after startup or in (async)
+// response to a RequestDictionary ViewHost message.
IPC_MESSAGE_CONTROL4(SpellCheckMsg_Init,
IPC::PlatformFileForTransit /* bdict_file */,
- std::vector<std::string> /* custom_dict_words */,
+ std::set<std::string> /* custom_dict_words */,
std::string /* language */,
bool /* auto spell correct */)
diff --git a/chrome/renderer/spellchecker/custom_dictionary_engine.cc b/chrome/renderer/spellchecker/custom_dictionary_engine.cc
index 06c4abd..6612729 100644
--- a/chrome/renderer/spellchecker/custom_dictionary_engine.cc
+++ b/chrome/renderer/spellchecker/custom_dictionary_engine.cc
@@ -13,13 +13,12 @@ CustomDictionaryEngine::CustomDictionaryEngine() {
CustomDictionaryEngine::~CustomDictionaryEngine() {
}
-void CustomDictionaryEngine::Init(
- const std::vector<std::string>& custom_words) {
+void CustomDictionaryEngine::Init(const std::set<std::string>& custom_words) {
// SpellingMenuOberver calls UTF16ToUTF8(word) to convert words for storage,
// synchronization, and use in the custom dictionary engine. Since
// (UTF8ToUTF16(UTF16ToUTF8(word)) == word) holds, the engine does not need to
// normalize the strings.
- for (std::vector<std::string>::const_iterator it = custom_words.begin();
+ for (std::set<std::string>::const_iterator it = custom_words.begin();
it != custom_words.end();
++it) {
dictionary_.insert(UTF8ToUTF16(*it));
diff --git a/chrome/renderer/spellchecker/custom_dictionary_engine.h b/chrome/renderer/spellchecker/custom_dictionary_engine.h
index d2dc8ca..db2650f 100644
--- a/chrome/renderer/spellchecker/custom_dictionary_engine.h
+++ b/chrome/renderer/spellchecker/custom_dictionary_engine.h
@@ -20,7 +20,7 @@ class CustomDictionaryEngine {
~CustomDictionaryEngine();
// Initialize the custom dictionary engine.
- void Init(const std::vector<std::string>& words);
+ void Init(const std::set<std::string>& words);
// Spellcheck |text|. Assumes that another spelling engine has set
// |misspelling_start| and |misspelling_len| to indicate a misspelling.
diff --git a/chrome/renderer/spellchecker/custom_dictionary_engine_unittest.cc b/chrome/renderer/spellchecker/custom_dictionary_engine_unittest.cc
index 440d110..3a6ea8a 100644
--- a/chrome/renderer/spellchecker/custom_dictionary_engine_unittest.cc
+++ b/chrome/renderer/spellchecker/custom_dictionary_engine_unittest.cc
@@ -1,15 +1,23 @@
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/renderer/spellchecker/custom_dictionary_engine.h"
+#include "base/strings/utf_string_conversions.h"
+#include "chrome/renderer/spellchecker/custom_dictionary_engine.h"
#include "testing/gtest/include/gtest/gtest.h"
TEST(CustomDictionaryTest, HandlesEmptyWordWithInvalidSubstring) {
CustomDictionaryEngine engine;
- std::vector<std::string> custom_words;
-
+ std::set<std::string> custom_words;
engine.Init(custom_words);
EXPECT_FALSE(engine.SpellCheckWord(string16().c_str(), 15, 23));
}
+TEST(CustomDictionaryTest, Basic) {
+ CustomDictionaryEngine engine;
+ EXPECT_FALSE(engine.SpellCheckWord(ASCIIToUTF16("helllo").c_str(), 0, 6));
+ std::set<std::string> custom_words;
+ custom_words.insert("helllo");
+ engine.Init(custom_words);
+ EXPECT_TRUE(engine.SpellCheckWord(ASCIIToUTF16("helllo").c_str(), 0, 6));
+}
diff --git a/chrome/renderer/spellchecker/spellcheck.cc b/chrome/renderer/spellchecker/spellcheck.cc
index fe3c678..019d0e0 100644
--- a/chrome/renderer/spellchecker/spellcheck.cc
+++ b/chrome/renderer/spellchecker/spellcheck.cc
@@ -130,7 +130,7 @@ bool SpellCheck::OnControlMessageReceived(const IPC::Message& message) {
}
void SpellCheck::OnInit(IPC::PlatformFileForTransit bdict_file,
- const std::vector<std::string>& custom_words,
+ const std::set<std::string>& custom_words,
const std::string& language,
bool auto_spell_correct) {
Init(IPC::PlatformFileForTransitToPlatformFile(bdict_file),
@@ -167,7 +167,7 @@ void SpellCheck::OnRequestDocumentMarkers() {
// TODO(groby): Make sure we always have a spelling engine, even before Init()
// is called.
void SpellCheck::Init(base::PlatformFile file,
- const std::vector<std::string>& custom_words,
+ const std::set<std::string>& custom_words,
const std::string& language) {
spellcheck_.Init(file, language);
custom_dictionary_.Init(custom_words);
diff --git a/chrome/renderer/spellchecker/spellcheck.h b/chrome/renderer/spellchecker/spellcheck.h
index 58032be..c44c698 100644
--- a/chrome/renderer/spellchecker/spellcheck.h
+++ b/chrome/renderer/spellchecker/spellcheck.h
@@ -45,7 +45,7 @@ class SpellCheck : public content::RenderProcessObserver,
// TODO: Try to move that all to SpellcheckLanguage.
void Init(base::PlatformFile file,
- const std::vector<std::string>& custom_words,
+ const std::set<std::string>& custom_words,
const std::string& language);
// If there is no dictionary file, then this requests one from the browser
@@ -119,7 +119,7 @@ class SpellCheck : public content::RenderProcessObserver,
// Message handlers.
void OnInit(IPC::PlatformFileForTransit bdict_file,
- const std::vector<std::string>& custom_words,
+ const std::set<std::string>& custom_words,
const std::string& language,
bool auto_spell_correct);
void OnCustomDictionaryChanged(
diff --git a/chrome/renderer/spellchecker/spellcheck_unittest.cc b/chrome/renderer/spellchecker/spellcheck_unittest.cc
index 9d9be84..cc5b37e 100644
--- a/chrome/renderer/spellchecker/spellcheck_unittest.cc
+++ b/chrome/renderer/spellchecker/spellcheck_unittest.cc
@@ -67,8 +67,7 @@ class SpellCheckTest : public testing::Test {
spell_check_->spellcheck_.platform_spelling_engine_.reset(
new HunspellEngine);
#endif
- spell_check_->Init(
- file, std::vector<std::string>(), language);
+ spell_check_->Init(file, std::set<std::string>(), language);
}
void EnableAutoCorrect(bool enable_autocorrect) {