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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 words->clear(); | 61 words->clear(); |
62 std::string contents; | 62 std::string contents; |
63 base::ReadFileToString(file_path, &contents); | 63 base::ReadFileToString(file_path, &contents); |
64 size_t pos = contents.rfind(CHECKSUM_PREFIX); | 64 size_t pos = contents.rfind(CHECKSUM_PREFIX); |
65 if (pos != std::string::npos) { | 65 if (pos != std::string::npos) { |
66 std::string checksum = contents.substr(pos + strlen(CHECKSUM_PREFIX)); | 66 std::string checksum = contents.substr(pos + strlen(CHECKSUM_PREFIX)); |
67 contents = contents.substr(0, pos); | 67 contents = contents.substr(0, pos); |
68 if (checksum != base::MD5String(contents)) | 68 if (checksum != base::MD5String(contents)) |
69 return INVALID_CHECKSUM; | 69 return INVALID_CHECKSUM; |
70 } | 70 } |
71 base::TrimWhitespaceASCII(contents, base::TRIM_ALL, &contents); | 71 |
72 std::vector<std::string> word_list; | 72 std::vector<std::string> word_list = base::SplitString( |
73 base::SplitString(contents, '\n', &word_list); | 73 base::TrimWhitespaceASCII(contents, base::TRIM_ALL), "\n", |
| 74 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
74 words->insert(word_list.begin(), word_list.end()); | 75 words->insert(word_list.begin(), word_list.end()); |
75 return VALID_CHECKSUM; | 76 return VALID_CHECKSUM; |
76 } | 77 } |
77 | 78 |
78 // Returns true for valid custom dictionary words. | 79 // Returns true for valid custom dictionary words. |
79 bool IsValidWord(const std::string& word) { | 80 bool IsValidWord(const std::string& word) { |
80 std::string tmp; | 81 std::string tmp; |
81 return !word.empty() && | 82 return !word.empty() && |
82 word.size() <= | 83 word.size() <= |
83 chrome::spellcheck_common::MAX_CUSTOM_DICTIONARY_WORD_BYTES && | 84 chrome::spellcheck_common::MAX_CUSTOM_DICTIONARY_WORD_BYTES && |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 } | 500 } |
500 | 501 |
501 void SpellcheckCustomDictionary::Notify(const Change& dictionary_change) { | 502 void SpellcheckCustomDictionary::Notify(const Change& dictionary_change) { |
502 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 503 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
503 if (!IsLoaded() || dictionary_change.empty()) | 504 if (!IsLoaded() || dictionary_change.empty()) |
504 return; | 505 return; |
505 FOR_EACH_OBSERVER(Observer, | 506 FOR_EACH_OBSERVER(Observer, |
506 observers_, | 507 observers_, |
507 OnCustomDictionaryChanged(dictionary_change)); | 508 OnCustomDictionaryChanged(dictionary_change)); |
508 } | 509 } |
OLD | NEW |