| 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   // The reply point for PostTaskAndReply. Called when AddWord is finished | 
|   77   // Executed on the file thread. |   80   // adding a word in the background. | 
|   78   void InitializeInternal(); |   81   void AddWordComplete(const std::string& word); | 
|   79  |  | 
|   80   void InitializeOnFileThread(); |  | 
|   81  |   82  | 
|   82   // Inform |profile_| that initialization has finished. |   83   // Inform |profile_| that initialization has finished. | 
|   83   // |custom_words| holds the custom word list which was |   84   // |custom_words| holds the custom word list which was | 
|   84   // loaded at the file thread. |   85   // loaded at the file thread. | 
|   85   void InformProfileOfInitializationWithCustomWords( |   86   void InformProfileOfInitializationWithCustomWords( | 
|   86       CustomWordList* custom_words); |   87       CustomWordList* custom_words); | 
|   87  |   88  | 
|   88   // An alternative version of InformProfileOfInitializationWithCustomWords() |   89   // An alternative version of InformProfileOfInitializationWithCustomWords() | 
|   89   // which implies empty |custom_words|. |   90   // which implies empty |custom_words|. | 
|   90   void InformProfileOfInitialization(); |   91   void InformProfileOfInitialization(); | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
|  109   // downloading the spellcheck dictionary; saves the dictionary to |data_|. |  110   // downloading the spellcheck dictionary; saves the dictionary to |data_|. | 
|  110   virtual void OnURLFetchComplete(const content::URLFetcher* source); |  111   virtual void OnURLFetchComplete(const content::URLFetcher* source); | 
|  111  |  112  | 
|  112   // NotificationProfile implementation. |  113   // NotificationProfile implementation. | 
|  113   virtual void Observe(int type, |  114   virtual void Observe(int type, | 
|  114                        const content::NotificationSource& source, |  115                        const content::NotificationSource& source, | 
|  115                        const content::NotificationDetails& details); |  116                        const content::NotificationDetails& details); | 
|  116  |  117  | 
|  117   // Saves |data_| to disk. Run on the file thread. |  118   // Saves |data_| to disk. Run on the file thread. | 
|  118   void SaveDictionaryData(); |  119   void SaveDictionaryData(); | 
 |  120   void SaveDictionaryDataComplete(); | 
|  119  |  121  | 
|  120   // Verifies the specified BDict file exists and it is sane. This function |  122   // 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 |  123   // should be called before opening the file so we can delete it and download a | 
|  122   // new dictionary if it is corrupted. |  124   // new dictionary if it is corrupted. | 
|  123   bool VerifyBDict(const FilePath& path) const; |  125   bool VerifyBDict(const FilePath& path) const; | 
|  124  |  126  | 
|  125   // May be NULL. |  127   // May be NULL. | 
|  126   SpellCheckProfileProvider* profile_; |  128   SpellCheckProfileProvider* profile_; | 
|  127  |  129  | 
|  128   // The desired location of the dictionary file (whether or not t exists yet). |  130   // The desired location of the dictionary file (whether or not t exists yet). | 
|  129   FilePath bdict_file_path_; |  131   FilePath bdict_file_path_; | 
|  130  |  132  | 
|  131   // The location of the custom words file. |  133   // The location of the custom words file. | 
|  132   FilePath custom_dictionary_file_; |  134   FilePath custom_dictionary_file_; | 
|  133  |  135  | 
 |  136   // State whether a dictionary has been partially, or fully saved. If the | 
 |  137   // former, shortcut Initialize. | 
 |  138   bool dictionary_saved_; | 
 |  139  | 
|  134   // The language of the dictionary file. |  140   // The language of the dictionary file. | 
|  135   std::string language_; |  141   std::string language_; | 
|  136  |  142  | 
|  137   // The file descriptor/handle for the dictionary file. |  143   // The file descriptor/handle for the dictionary file. | 
|  138   base::PlatformFile file_; |  144   base::PlatformFile file_; | 
|  139  |  145  | 
|  140   // We don't want to attempt to download a missing dictionary file more than |  146   // We don't want to attempt to download a missing dictionary file more than | 
|  141   // once. |  147   // once. | 
|  142   bool tried_to_download_; |  148   bool tried_to_download_; | 
|  143  |  149  | 
|  144   // Whether we should use the platform spellchecker instead of Hunspell. |  150   // Whether we should use the platform spellchecker instead of Hunspell. | 
|  145   bool use_platform_spellchecker_; |  151   bool use_platform_spellchecker_; | 
|  146  |  152  | 
|  147   // Data received from the dictionary download. |  153   // Data received from the dictionary download. | 
|  148   std::string data_; |  154   std::string data_; | 
|  149  |  155  | 
|  150   // Used for downloading the dictionary file. We don't hold a reference, and |  156   // 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. |  157   // it is only valid to use it on the UI thread. | 
|  152   net::URLRequestContextGetter* request_context_getter_; |  158   net::URLRequestContextGetter* request_context_getter_; | 
|  153  |  159  | 
|  154   // Used for downloading the dictionary file. |  160   // Used for downloading the dictionary file. | 
|  155   scoped_ptr<content::URLFetcher> fetcher_; |  161   scoped_ptr<content::URLFetcher> fetcher_; | 
|  156  |  162  | 
|  157   content::NotificationRegistrar registrar_; |  163   content::NotificationRegistrar registrar_; | 
|  158  |  164  | 
|  159   // An optional metrics counter given by the constructor. |  165   // An optional metrics counter given by the constructor. | 
|  160   SpellCheckHostMetrics* metrics_; |  166   SpellCheckHostMetrics* metrics_; | 
|  161  |  167  | 
 |  168   base::WeakPtrFactory<SpellCheckHostImpl> weak_ptr_factory_; | 
 |  169  | 
 |  170   scoped_ptr<CustomWordList> custom_words_; | 
 |  171  | 
|  162   DISALLOW_COPY_AND_ASSIGN(SpellCheckHostImpl); |  172   DISALLOW_COPY_AND_ASSIGN(SpellCheckHostImpl); | 
|  163 }; |  173 }; | 
|  164  |  174  | 
|  165 #endif  // CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_HOST_IMPL_H_ |  175 #endif  // CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_HOST_IMPL_H_ | 
| OLD | NEW |