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

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

Issue 11414282: Improve reliability of custom spelling dictionary file. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years 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
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 #ifndef CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_CUSTOM_DICTIONARY_H_ 5 #ifndef CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_CUSTOM_DICTIONARY_H_
6 #define CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_CUSTOM_DICTIONARY_H_ 6 #define CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_CUSTOM_DICTIONARY_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/observer_list.h"
14 #include "chrome/browser/spellchecker/spellcheck_dictionary.h" 15 #include "chrome/browser/spellchecker/spellcheck_dictionary.h"
15 #include "chrome/common/spellcheck_common.h" 16 #include "chrome/common/spellcheck_common.h"
16 17
17 // Defines a custom dictionary which users can add their own words to. 18 // Defines a custom dictionary which users can add their own words to.
18 class SpellcheckCustomDictionary : public SpellcheckDictionary { 19 class SpellcheckCustomDictionary : public SpellcheckDictionary {
19 public: 20 public:
20 class Observer { 21 class Observer {
21 public: 22 public:
22 virtual void OnCustomDictionaryLoaded() = 0; 23 virtual void OnCustomDictionaryLoaded() = 0;
23 virtual void OnCustomDictionaryWordAdded(const std::string& word) = 0; 24 virtual void OnCustomDictionaryWordAdded(const std::string& word) = 0;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 // The caller owns this new list. 69 // The caller owns this new list.
69 chrome::spellcheck_common::WordList* LoadDictionary(); 70 chrome::spellcheck_common::WordList* LoadDictionary();
70 71
71 // The reply point for PostTaskAndReplyWithResult. Called when LoadDictionary 72 // The reply point for PostTaskAndReplyWithResult. Called when LoadDictionary
72 // is finished reading words from custom dictionary file. Moves the strings 73 // is finished reading words from custom dictionary file. Moves the strings
73 // from the |custom_words| argument into the private member variable |words_| 74 // from the |custom_words| argument into the private member variable |words_|
74 // and deletes the memory at |custom_words|. 75 // and deletes the memory at |custom_words|.
75 void SetCustomWordListAndDelete( 76 void SetCustomWordListAndDelete(
76 chrome::spellcheck_common::WordList* custom_words); 77 chrome::spellcheck_common::WordList* custom_words);
77 78
79 // Loads the dictionary file into |custom_words|. If the dictionary checksum
80 // is not valid, but backup checksum is valid, then restores the backup and
81 // loads that into |custom_words| instead.
groby-ooo-7-16 2012/12/05 00:56:19 "If the backup is invalid too, |custom_words| will
please use gerrit instead 2012/12/05 16:51:26 Done.
82 void LoadDictionaryFileReliably(
83 chrome::spellcheck_common::WordList* custom_words);
84
85 // Backs up the original dictionary and checksum files, saves |custom_words|
groby-ooo-7-16 2012/12/05 00:56:19 - "and checksum files"
please use gerrit instead 2012/12/05 16:51:26 Done.
86 // and its checksum into the dictionary file.
87 void SaveDictionaryFileReliably(
88 const chrome::spellcheck_common::WordList& custom_words);
89
90 // Extracts the checksum out of |contents| and truncates |contents| to exclude
91 // the checksum line. Returns an empty string if |contents| do not contain a
92 // checksum.
93 std::string GetChecksum(std::string* contents);
94
78 // In-memory cache of the custom words file. 95 // In-memory cache of the custom words file.
79 chrome::spellcheck_common::WordList words_; 96 chrome::spellcheck_common::WordList words_;
80 97
81 // A path for custom dictionary per profile. 98 // A path for custom dictionary per profile.
82 FilePath custom_dictionary_path_; 99 FilePath custom_dictionary_path_;
83 100
84 base::WeakPtrFactory<SpellcheckCustomDictionary> weak_ptr_factory_; 101 base::WeakPtrFactory<SpellcheckCustomDictionary> weak_ptr_factory_;
85 102
86 std::vector<Observer*> observers_; 103 ObserverList<Observer> observers_;
104
105 const FilePath::StringType backup_extension_;
106 const std::string checksum_prefix_;
groby-ooo-7-16 2012/12/05 00:56:19 Why a member? It never changes its value, and it's
please use gerrit instead 2012/12/05 16:51:26 Done.
87 107
88 DISALLOW_COPY_AND_ASSIGN(SpellcheckCustomDictionary); 108 DISALLOW_COPY_AND_ASSIGN(SpellcheckCustomDictionary);
89 }; 109 };
90 110
91 #endif // CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_CUSTOM_DICTIONARY_H_ 111 #endif // CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_CUSTOM_DICTIONARY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698