| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/spellcheck_custom_dictionary.h" | 5 #include "chrome/browser/spellchecker/spellcheck_custom_dictionary.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/string_split.h" | 8 #include "base/string_split.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/common/chrome_constants.h" | 10 #include "chrome/common/chrome_constants.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 const WordList& SpellcheckCustomDictionary::GetWords() const { | 42 const WordList& SpellcheckCustomDictionary::GetWords() const { |
| 43 return words_; | 43 return words_; |
| 44 } | 44 } |
| 45 | 45 |
| 46 void SpellcheckCustomDictionary::LoadDictionaryIntoCustomWordList( | 46 void SpellcheckCustomDictionary::LoadDictionaryIntoCustomWordList( |
| 47 WordList* custom_words) { | 47 WordList* custom_words) { |
| 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 49 | 49 |
| 50 std::string contents; | 50 std::string contents; |
| 51 file_util::ReadFileToString(custom_dictionary_path_, &contents); | 51 file_util::ReadFileToString(custom_dictionary_path_, &contents); |
| 52 if (contents.empty()) | 52 if (contents.empty()) { |
| 53 custom_words->clear(); |
| 53 return; | 54 return; |
| 55 } |
| 54 | 56 |
| 55 base::SplitString(contents, '\n', custom_words); | 57 base::SplitString(contents, '\n', custom_words); |
| 56 // Clear out empty words. | 58 // Clear out empty words. |
| 57 custom_words->erase(remove_if(custom_words->begin(), custom_words->end(), | 59 custom_words->erase(remove_if(custom_words->begin(), custom_words->end(), |
| 58 mem_fun_ref(&std::string::empty)), custom_words->end()); | 60 mem_fun_ref(&std::string::empty)), custom_words->end()); |
| 59 } | 61 } |
| 60 | 62 |
| 61 void SpellcheckCustomDictionary::SetCustomWordList(WordList* custom_words) { | 63 void SpellcheckCustomDictionary::SetCustomWordList(WordList* custom_words) { |
| 62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 63 | 65 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 return custom_words; | 207 return custom_words; |
| 206 } | 208 } |
| 207 | 209 |
| 208 void SpellcheckCustomDictionary::SetCustomWordListAndDelete( | 210 void SpellcheckCustomDictionary::SetCustomWordListAndDelete( |
| 209 WordList* custom_words) { | 211 WordList* custom_words) { |
| 210 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 212 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 211 | 213 |
| 212 SetCustomWordList(custom_words); | 214 SetCustomWordList(custom_words); |
| 213 delete custom_words; | 215 delete custom_words; |
| 214 } | 216 } |
| OLD | NEW |