Chromium Code Reviews| OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_HOST_IMPL_H_ | 5 #ifndef CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_HOST_IMPL_H_ | 
| 6 #define CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_HOST_IMPL_H_ | 6 #define CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_HOST_IMPL_H_ | 
| 7 #pragma once | 7 #pragma once | 
| 8 | 8 | 
| 9 #include <string> | 9 #include <string> | 
| 10 #include <vector> | 10 #include <vector> | 
| 11 | 11 | 
| 12 #include "base/compiler_specific.h" | |
| 12 #include "base/file_path.h" | 13 #include "base/file_path.h" | 
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" | 
| 15 #include "base/memory/weak_ptr.h" | |
| 14 #include "chrome/browser/spellchecker/spellcheck_host.h" | 16 #include "chrome/browser/spellchecker/spellcheck_host.h" | 
| 15 #include "chrome/browser/spellchecker/spellcheck_profile_provider.h" | 17 #include "chrome/browser/spellchecker/spellcheck_profile_provider.h" | 
| 16 #include "content/public/common/url_fetcher_delegate.h" | 18 #include "content/public/common/url_fetcher_delegate.h" | 
| 17 #include "content/public/browser/notification_observer.h" | 19 #include "content/public/browser/notification_observer.h" | 
| 18 #include "content/public/browser/notification_registrar.h" | 20 #include "content/public/browser/notification_registrar.h" | 
| 19 | 21 | 
| 20 // This class implements the SpellCheckHost interface to provide the | 22 // This class implements the SpellCheckHost interface to provide the | 
| 21 // functionalities listed below: | 23 // functionalities listed below: | 
| 22 // * Adding a word to the custom dictionary; | 24 // * Adding a word to the custom dictionary; | 
| 23 // * Storing the custom dictionary to the file, and read it back | 25 // * Storing the custom dictionary to the file, and read it back | 
| (...skipping 15 matching lines...) Expand all Loading... | |
| 39 // can be listed using SpellCheckHost::GetAvailableLanguages() static method. | 41 // can be listed using SpellCheckHost::GetAvailableLanguages() static method. | 
| 40 class SpellCheckHostImpl : public SpellCheckHost, | 42 class SpellCheckHostImpl : public SpellCheckHost, | 
| 41 public content::URLFetcherDelegate, | 43 public content::URLFetcherDelegate, | 
| 42 public content::NotificationObserver { | 44 public content::NotificationObserver { | 
| 43 public: | 45 public: | 
| 44 SpellCheckHostImpl(SpellCheckProfileProvider* profile, | 46 SpellCheckHostImpl(SpellCheckProfileProvider* profile, | 
| 45 const std::string& language, | 47 const std::string& language, | 
| 46 net::URLRequestContextGetter* request_context_getter, | 48 net::URLRequestContextGetter* request_context_getter, | 
| 47 SpellCheckHostMetrics* metrics); | 49 SpellCheckHostMetrics* metrics); | 
| 48 | 50 | 
| 51 virtual ~SpellCheckHostImpl(); | |
| 52 | |
| 49 void Initialize(); | 53 void Initialize(); | 
| 50 | 54 | 
| 51 // SpellCheckHost implementation | 55 // SpellCheckHost implementation | 
| 52 virtual void UnsetProfile(); | 56 virtual void UnsetProfile() OVERRIDE; | 
| 53 virtual void InitForRenderer(RenderProcessHost* process); | 57 virtual void InitForRenderer(RenderProcessHost* process) OVERRIDE; | 
| 54 virtual void AddWord(const std::string& word); | 58 virtual void AddWord(const std::string& word) OVERRIDE; | 
| 55 virtual const base::PlatformFile& GetDictionaryFile() const; | 59 virtual const base::PlatformFile& GetDictionaryFile() const OVERRIDE; | 
| 56 virtual const std::string& GetLanguage() const; | 60 virtual const std::string& GetLanguage() const OVERRIDE; | 
| 57 virtual bool IsUsingPlatformChecker() const; | 61 virtual bool IsUsingPlatformChecker() const OVERRIDE; | 
| 58 | 62 | 
| 59 private: | 63 private: | 
| 60 typedef SpellCheckProfileProvider::CustomWordList CustomWordList; | 64 typedef SpellCheckProfileProvider::CustomWordList CustomWordList; | 
| 61 | 65 | 
| 62 // These two classes can destruct us. | 66 // These two classes can destruct us. | 
| 63 friend class content::BrowserThread; | 67 friend class content::BrowserThread; | 
| 64 friend class DeleteTask<SpellCheckHostImpl>; | 68 friend class DeleteTask<SpellCheckHostImpl>; | 
| 65 | 69 | 
| 66 virtual ~SpellCheckHostImpl(); | |
| 67 | |
| 68 // Figure out the location for the dictionary. This is only non-trivial for | 70 // Figure out the location for the dictionary. This is only non-trivial for | 
| 69 // Windows: | 71 // Windows: | 
| 70 // The default place whether the spellcheck dictionary can reside is | 72 // The default place whether the spellcheck dictionary can reside is | 
| 71 // chrome::DIR_APP_DICTIONARIES. However, for systemwide installations, | 73 // chrome::DIR_APP_DICTIONARIES. However, for systemwide installations, | 
| 72 // this directory may not have permissions for download. In that case, the | 74 // this directory may not have permissions for download. In that case, the | 
| 73 // alternate directory for download is chrome::DIR_USER_DATA. | 75 // alternate directory for download is chrome::DIR_USER_DATA. | 
| 74 void InitializeDictionaryLocation(); | 76 void InitializeDictionaryLocation(); | 
| 77 void InitializeDictionaryLocationComplete(); | |
| 75 | 78 | 
| 76 // Load and parse the custom words dictionary and open the bdic file. | 79 void AddWordComplete(const std::string& word); | 
| 
 
Hironori Bono
2011/11/08 07:20:25
nit: can you add a comment for this function, such
 
 | |
| 77 // Executed on the file thread. | |
| 78 void InitializeInternal(); | |
| 79 | |
| 80 void InitializeOnFileThread(); | |
| 81 | 80 | 
| 82 // Inform |profile_| that initialization has finished. | 81 // Inform |profile_| that initialization has finished. | 
| 83 // |custom_words| holds the custom word list which was | 82 // |custom_words| holds the custom word list which was | 
| 84 // loaded at the file thread. | 83 // loaded at the file thread. | 
| 85 void InformProfileOfInitializationWithCustomWords( | 84 void InformProfileOfInitializationWithCustomWords( | 
| 86 CustomWordList* custom_words); | 85 CustomWordList* custom_words); | 
| 87 | 86 | 
| 88 // An alternative version of InformProfileOfInitializationWithCustomWords() | 87 // An alternative version of InformProfileOfInitializationWithCustomWords() | 
| 89 // which implies empty |custom_words|. | 88 // which implies empty |custom_words|. | 
| 90 void InformProfileOfInitialization(); | 89 void InformProfileOfInitialization(); | 
| (...skipping 18 matching lines...) Expand all Loading... | |
| 109 // downloading the spellcheck dictionary; saves the dictionary to |data_|. | 108 // downloading the spellcheck dictionary; saves the dictionary to |data_|. | 
| 110 virtual void OnURLFetchComplete(const content::URLFetcher* source); | 109 virtual void OnURLFetchComplete(const content::URLFetcher* source); | 
| 111 | 110 | 
| 112 // NotificationProfile implementation. | 111 // NotificationProfile implementation. | 
| 113 virtual void Observe(int type, | 112 virtual void Observe(int type, | 
| 114 const content::NotificationSource& source, | 113 const content::NotificationSource& source, | 
| 115 const content::NotificationDetails& details); | 114 const content::NotificationDetails& details); | 
| 116 | 115 | 
| 117 // Saves |data_| to disk. Run on the file thread. | 116 // Saves |data_| to disk. Run on the file thread. | 
| 118 void SaveDictionaryData(); | 117 void SaveDictionaryData(); | 
| 118 void SaveDictionaryDataComplete(); | |
| 119 | 119 | 
| 120 // Verifies the specified BDict file exists and it is sane. This function | 120 // Verifies the specified BDict file exists and it is sane. This function | 
| 121 // should be called before opening the file so we can delete it and download a | 121 // should be called before opening the file so we can delete it and download a | 
| 122 // new dictionary if it is corrupted. | 122 // new dictionary if it is corrupted. | 
| 123 bool VerifyBDict(const FilePath& path) const; | 123 bool VerifyBDict(const FilePath& path) const; | 
| 124 | 124 | 
| 125 // May be NULL. | 125 // May be NULL. | 
| 126 SpellCheckProfileProvider* profile_; | 126 SpellCheckProfileProvider* profile_; | 
| 127 | 127 | 
| 128 // The desired location of the dictionary file (whether or not t exists yet). | 128 // The desired location of the dictionary file (whether or not t exists yet). | 
| 129 FilePath bdict_file_path_; | 129 FilePath bdict_file_path_; | 
| 130 | 130 | 
| 131 // The location of the custom words file. | 131 // The location of the custom words file. | 
| 132 FilePath custom_dictionary_file_; | 132 FilePath custom_dictionary_file_; | 
| 133 | 133 | 
| 134 bool dictionary_saved_; | |
| 
 
Hironori Bono
2011/11/08 07:20:25
nit: can you add a comment for this variable, such
 
 | |
| 135 | |
| 134 // The language of the dictionary file. | 136 // The language of the dictionary file. | 
| 135 std::string language_; | 137 std::string language_; | 
| 136 | 138 | 
| 137 // The file descriptor/handle for the dictionary file. | 139 // The file descriptor/handle for the dictionary file. | 
| 138 base::PlatformFile file_; | 140 base::PlatformFile file_; | 
| 139 | 141 | 
| 140 // We don't want to attempt to download a missing dictionary file more than | 142 // We don't want to attempt to download a missing dictionary file more than | 
| 141 // once. | 143 // once. | 
| 142 bool tried_to_download_; | 144 bool tried_to_download_; | 
| 143 | 145 | 
| 144 // Whether we should use the platform spellchecker instead of Hunspell. | 146 // Whether we should use the platform spellchecker instead of Hunspell. | 
| 145 bool use_platform_spellchecker_; | 147 bool use_platform_spellchecker_; | 
| 146 | 148 | 
| 147 // Data received from the dictionary download. | 149 // Data received from the dictionary download. | 
| 148 std::string data_; | 150 std::string data_; | 
| 149 | 151 | 
| 150 // Used for downloading the dictionary file. We don't hold a reference, and | 152 // Used for downloading the dictionary file. We don't hold a reference, and | 
| 151 // it is only valid to use it on the UI thread. | 153 // it is only valid to use it on the UI thread. | 
| 152 net::URLRequestContextGetter* request_context_getter_; | 154 net::URLRequestContextGetter* request_context_getter_; | 
| 153 | 155 | 
| 154 // Used for downloading the dictionary file. | 156 // Used for downloading the dictionary file. | 
| 155 scoped_ptr<content::URLFetcher> fetcher_; | 157 scoped_ptr<content::URLFetcher> fetcher_; | 
| 156 | 158 | 
| 157 content::NotificationRegistrar registrar_; | 159 content::NotificationRegistrar registrar_; | 
| 158 | 160 | 
| 159 // An optional metrics counter given by the constructor. | 161 // An optional metrics counter given by the constructor. | 
| 160 SpellCheckHostMetrics* metrics_; | 162 SpellCheckHostMetrics* metrics_; | 
| 161 | 163 | 
| 164 base::WeakPtrFactory<SpellCheckHostImpl> weak_ptr_factory_; | |
| 165 | |
| 166 scoped_ptr<CustomWordList> custom_words_; | |
| 167 | |
| 162 DISALLOW_COPY_AND_ASSIGN(SpellCheckHostImpl); | 168 DISALLOW_COPY_AND_ASSIGN(SpellCheckHostImpl); | 
| 163 }; | 169 }; | 
| 164 | 170 | 
| 165 #endif // CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_HOST_IMPL_H_ | 171 #endif // CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_HOST_IMPL_H_ | 
| OLD | NEW |