Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(235)

Side by Side Diff: chrome/browser/spellchecker/spellcheck_custom_dictionary.cc

Issue 183853011: Move TrimWhitespace to the base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/file_util.h" 9 #include "base/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
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 TrimWhitespaceASCII(contents, TRIM_ALL, &contents); 71 base::TrimWhitespaceASCII(contents, base::TRIM_ALL, &contents);
72 base::SplitString(contents, '\n', &words); 72 base::SplitString(contents, '\n', &words);
73 return VALID_CHECKSUM; 73 return VALID_CHECKSUM;
74 } 74 }
75 75
76 // Returns true for invalid words and false for valid words. 76 // Returns true for invalid words and false for valid words.
77 bool IsInvalidWord(const std::string& word) { 77 bool IsInvalidWord(const std::string& word) {
78 std::string tmp; 78 std::string tmp;
79 return !IsStringUTF8(word) || 79 return !IsStringUTF8(word) ||
80 word.length() > 80 word.length() >
81 chrome::spellcheck_common::MAX_CUSTOM_DICTIONARY_WORD_BYTES || 81 chrome::spellcheck_common::MAX_CUSTOM_DICTIONARY_WORD_BYTES ||
82 word.empty() || 82 word.empty() ||
83 TRIM_NONE != TrimWhitespaceASCII(word, TRIM_ALL, &tmp); 83 base::TRIM_NONE != base::TrimWhitespaceASCII(word, base::TRIM_ALL, &tmp);
84 } 84 }
85 85
86 // Loads the custom spellcheck dictionary from |path| into |custom_words|. If 86 // Loads the custom spellcheck dictionary from |path| into |custom_words|. If
87 // the dictionary checksum is not valid, but backup checksum is valid, then 87 // the dictionary checksum is not valid, but backup checksum is valid, then
88 // restores the backup and loads that into |custom_words| instead. If the backup 88 // restores the backup and loads that into |custom_words| instead. If the backup
89 // is invalid too, then clears |custom_words|. Must be called on the file 89 // is invalid too, then clears |custom_words|. Must be called on the file
90 // thread. 90 // thread.
91 void LoadDictionaryFileReliably(WordList& custom_words, 91 void LoadDictionaryFileReliably(WordList& custom_words,
92 const base::FilePath& path) { 92 const base::FilePath& path) {
93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 527
528 void SpellcheckCustomDictionary::Notify( 528 void SpellcheckCustomDictionary::Notify(
529 const SpellcheckCustomDictionary::Change& dictionary_change) { 529 const SpellcheckCustomDictionary::Change& dictionary_change) {
530 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 530 DCHECK(BrowserThread::CurrentlyOn(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 }
OLDNEW
« no previous file with comments | « chrome/browser/search_engines/template_url_service.cc ('k') | chrome/browser/ui/app_list/search/search_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698