| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/spellchecker.h" | 5 #include "chrome/browser/spellchecker.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 SpellCheckerPlatform::AddWord(word); | 833 SpellCheckerPlatform::AddWord(word); |
| 834 return; | 834 return; |
| 835 } | 835 } |
| 836 | 836 |
| 837 // Check if the |hunspell_| has been initialized at all. | 837 // Check if the |hunspell_| has been initialized at all. |
| 838 Initialize(); | 838 Initialize(); |
| 839 | 839 |
| 840 // Add the word to hunspell. | 840 // Add the word to hunspell. |
| 841 std::string word_to_add = UTF16ToUTF8(word); | 841 std::string word_to_add = UTF16ToUTF8(word); |
| 842 // Don't attempt to add an empty word, or one larger than Hunspell can handle | 842 // Don't attempt to add an empty word, or one larger than Hunspell can handle |
| 843 if (!word_to_add.empty() && word_to_add.length() < MAXWORDUTF8LEN) { | 843 if (!word_to_add.empty() && word_to_add.length() < MAXWORDLEN) { |
| 844 // Either add the word to |hunspell_|, or, if |hunspell_| is still loading, | 844 // Either add the word to |hunspell_|, or, if |hunspell_| is still loading, |
| 845 // defer it till after the load completes. | 845 // defer it till after the load completes. |
| 846 if (hunspell_.get()) | 846 if (hunspell_.get()) |
| 847 hunspell_->add(word_to_add.c_str()); | 847 hunspell_->add(word_to_add.c_str()); |
| 848 else | 848 else |
| 849 custom_words_.push(word_to_add); | 849 custom_words_.push(word_to_add); |
| 850 } | 850 } |
| 851 | 851 |
| 852 // Now add the word to the custom dictionary file. | 852 // Now add the word to the custom dictionary file. |
| 853 Task* write_word_task = | 853 Task* write_word_task = |
| 854 new AddWordToCustomDictionaryTask(custom_dictionary_file_name_, word); | 854 new AddWordToCustomDictionaryTask(custom_dictionary_file_name_, word); |
| 855 if (file_loop_) { | 855 if (file_loop_) { |
| 856 file_loop_->PostTask(FROM_HERE, write_word_task); | 856 file_loop_->PostTask(FROM_HERE, write_word_task); |
| 857 } else { | 857 } else { |
| 858 write_word_task->Run(); | 858 write_word_task->Run(); |
| 859 delete write_word_task; | 859 delete write_word_task; |
| 860 } | 860 } |
| 861 } | 861 } |
| 862 | 862 |
| 863 bool SpellChecker::CheckSpelling(const string16& word_to_check, int tag) { | 863 bool SpellChecker::CheckSpelling(const string16& word_to_check, int tag) { |
| 864 bool word_correct = false; | 864 bool word_correct = false; |
| 865 | 865 |
| 866 TimeTicks begin_time = TimeTicks::Now(); | 866 TimeTicks begin_time = TimeTicks::Now(); |
| 867 if (is_using_platform_spelling_engine_) { | 867 if (is_using_platform_spelling_engine_) { |
| 868 word_correct = SpellCheckerPlatform::CheckSpelling(word_to_check, tag); | 868 word_correct = SpellCheckerPlatform::CheckSpelling(word_to_check, tag); |
| 869 } else { | 869 } else { |
| 870 std::string word_to_check_utf8(UTF16ToUTF8(word_to_check)); | 870 std::string word_to_check_utf8(UTF16ToUTF8(word_to_check)); |
| 871 // Hunspell shouldn't let us exceed its max, but check just in case | 871 // Hunspell shouldn't let us exceed its max, but check just in case |
| 872 if (word_to_check_utf8.length() < MAXWORDUTF8LEN) { | 872 if (word_to_check_utf8.length() < MAXWORDLEN) { |
| 873 // |hunspell_->spell| returns 0 if the word is spelled correctly and | 873 // |hunspell_->spell| returns 0 if the word is spelled correctly and |
| 874 // non-zero otherwsie. | 874 // non-zero otherwsie. |
| 875 word_correct = (hunspell_->spell(word_to_check_utf8.c_str()) != 0); | 875 word_correct = (hunspell_->spell(word_to_check_utf8.c_str()) != 0); |
| 876 } | 876 } |
| 877 } | 877 } |
| 878 DHISTOGRAM_TIMES("Spellcheck.CheckTime", TimeTicks::Now() - begin_time); | 878 DHISTOGRAM_TIMES("Spellcheck.CheckTime", TimeTicks::Now() - begin_time); |
| 879 | 879 |
| 880 return word_correct; | 880 return word_correct; |
| 881 } | 881 } |
| 882 | 882 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 896 | 896 |
| 897 // Populate the vector of WideStrings. | 897 // Populate the vector of WideStrings. |
| 898 for (int i = 0; i < number_of_suggestions; i++) { | 898 for (int i = 0; i < number_of_suggestions; i++) { |
| 899 if (i < kMaxSuggestions) | 899 if (i < kMaxSuggestions) |
| 900 optional_suggestions->push_back(UTF8ToUTF16(suggestions[i])); | 900 optional_suggestions->push_back(UTF8ToUTF16(suggestions[i])); |
| 901 free(suggestions[i]); | 901 free(suggestions[i]); |
| 902 } | 902 } |
| 903 if (suggestions != NULL) | 903 if (suggestions != NULL) |
| 904 free(suggestions); | 904 free(suggestions); |
| 905 } | 905 } |
| OLD | NEW |