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

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 |contents|. If the dictionary checksum is
80 // not valid, but backup checksum is valid, then restores the backup and loads
81 // that into |contents| instead.
82 void LoadDictionaryContentsReliably(std::string* contents);
groby-ooo-7-16 2012/12/04 00:16:30 We should probably document somewhere that we expe
please use gerrit instead 2012/12/04 05:46:40 Where is the best place to document this? Class co
83
84 // Backs up the original dictionary and checksum files, saves |contents| into
85 // the dictionary file, and saves the checksum of |contents| into the checksum
86 // file.
groby-ooo-7-16 2012/12/04 00:16:30 I'd feel more comfortable having the checksum in t
please use gerrit instead 2012/12/04 05:46:40 Done.
87 void SaveDictionryContentsReliably(const std::string& contents);
groby-ooo-7-16 2012/12/04 00:16:30 Spelling: Diction_a_ry (Hey, y u no spellcheck! ;)
please use gerrit instead 2012/12/04 05:46:40 Done.
88
89 // Extract the |checksum| out of |contents|.
90 std::string GetChecksum(std::string* contents);
groby-ooo-7-16 2012/12/04 00:16:30 const std::string& contents - it's not an out para
please use gerrit instead 2012/12/04 05:46:40 Added a comment to clarify: "If this method return
91
78 // In-memory cache of the custom words file. 92 // In-memory cache of the custom words file.
79 chrome::spellcheck_common::WordList words_; 93 chrome::spellcheck_common::WordList words_;
80 94
81 // A path for custom dictionary per profile. 95 // A path for custom dictionary per profile.
82 FilePath custom_dictionary_path_; 96 FilePath custom_dictionary_path_;
83 97
84 base::WeakPtrFactory<SpellcheckCustomDictionary> weak_ptr_factory_; 98 base::WeakPtrFactory<SpellcheckCustomDictionary> weak_ptr_factory_;
85 99
86 std::vector<Observer*> observers_; 100 ObserverList<Observer> observers_;
101
102 const FilePath::StringType backup_extension_;
103 const std::string checksum_prefix_;
87 104
88 DISALLOW_COPY_AND_ASSIGN(SpellcheckCustomDictionary); 105 DISALLOW_COPY_AND_ASSIGN(SpellcheckCustomDictionary);
89 }; 106 };
90 107
91 #endif // CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_CUSTOM_DICTIONARY_H_ 108 #endif // CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_CUSTOM_DICTIONARY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698