| 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 <functional> | 7 #include <functional> |
| 8 | 8 |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/files/important_file_writer.h" | 10 #include "base/files/important_file_writer.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 113 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 114 std::stringstream content; | 114 std::stringstream content; |
| 115 for (WordList::const_iterator it = custom_words.begin(); | 115 for (WordList::const_iterator it = custom_words.begin(); |
| 116 it != custom_words.end(); | 116 it != custom_words.end(); |
| 117 ++it) { | 117 ++it) { |
| 118 content << *it << '\n'; | 118 content << *it << '\n'; |
| 119 } | 119 } |
| 120 std::string checksum = base::MD5String(content.str()); | 120 std::string checksum = base::MD5String(content.str()); |
| 121 content << CHECKSUM_PREFIX << checksum; | 121 content << CHECKSUM_PREFIX << checksum; |
| 122 base::CopyFile(path, path.AddExtension(BACKUP_EXTENSION)); | 122 base::CopyFile(path, path.AddExtension(BACKUP_EXTENSION)); |
| 123 base::ImportantFileWriter::WriteFileAtomically(path, content.str()); | 123 base::ImportantFileWriterImpl::WriteFileAtomically(path, content.str()); |
| 124 } | 124 } |
| 125 | 125 |
| 126 // Removes duplicate and invalid words from |to_add| word list and sorts it. | 126 // Removes duplicate and invalid words from |to_add| word list and sorts it. |
| 127 // Looks for duplicates in both |to_add| and |existing| word lists. Returns a | 127 // Looks for duplicates in both |to_add| and |existing| word lists. Returns a |
| 128 // bitmap of |ChangeSanitationResult| values. | 128 // bitmap of |ChangeSanitationResult| values. |
| 129 int SanitizeWordsToAdd(const WordSet& existing, WordList& to_add) { | 129 int SanitizeWordsToAdd(const WordSet& existing, WordList& to_add) { |
| 130 // Do not add duplicate words. | 130 // Do not add duplicate words. |
| 131 std::sort(to_add.begin(), to_add.end()); | 131 std::sort(to_add.begin(), to_add.end()); |
| 132 WordList new_words = base::STLSetDifference<WordList>(to_add, existing); | 132 WordList new_words = base::STLSetDifference<WordList>(to_add, existing); |
| 133 new_words.erase(std::unique(new_words.begin(), new_words.end()), | 133 new_words.erase(std::unique(new_words.begin(), new_words.end()), |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 | 527 |
| 528 void SpellcheckCustomDictionary::Notify( | 528 void SpellcheckCustomDictionary::Notify( |
| 529 const SpellcheckCustomDictionary::Change& dictionary_change) { | 529 const SpellcheckCustomDictionary::Change& dictionary_change) { |
| 530 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 530 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 531 if (!IsLoaded() || dictionary_change.empty()) | 531 if (!IsLoaded() || dictionary_change.empty()) |
| 532 return; | 532 return; |
| 533 FOR_EACH_OBSERVER(Observer, | 533 FOR_EACH_OBSERVER(Observer, |
| 534 observers_, | 534 observers_, |
| 535 OnCustomDictionaryChanged(dictionary_change)); | 535 OnCustomDictionaryChanged(dictionary_change)); |
| 536 } | 536 } |
| OLD | NEW |