| OLD | NEW |
| 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_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_SERVICE_H_ |
| 6 #define CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_SERVICE_H_ | 6 #define CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_SERVICE_H_ |
| 7 | 7 |
| 8 #include "base/gtest_prod_util.h" | 8 #include "base/gtest_prod_util.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 namespace content { | 28 namespace content { |
| 29 class RenderProcessHost; | 29 class RenderProcessHost; |
| 30 } | 30 } |
| 31 | 31 |
| 32 // Encapsulates the browser side spellcheck service. There is one of these per | 32 // Encapsulates the browser side spellcheck service. There is one of these per |
| 33 // profile and each is created by the SpellCheckServiceFactory. The | 33 // profile and each is created by the SpellCheckServiceFactory. The |
| 34 // SpellCheckService maintains any per-profile information about spellcheck. | 34 // SpellCheckService maintains any per-profile information about spellcheck. |
| 35 class SpellcheckService : public ProfileKeyedService, | 35 class SpellcheckService : public ProfileKeyedService, |
| 36 public PrefObserver, | 36 public PrefObserver, |
| 37 public content::NotificationObserver { | 37 public content::NotificationObserver, |
| 38 public SpellcheckCustomDictionary::Observer { |
| 38 public: | 39 public: |
| 39 // Event types used for reporting the status of this class and its derived | 40 // Event types used for reporting the status of this class and its derived |
| 40 // classes to browser tests. | 41 // classes to browser tests. |
| 41 enum EventType { | 42 enum EventType { |
| 42 BDICT_NOTINITIALIZED, | 43 BDICT_NOTINITIALIZED, |
| 43 BDICT_CORRUPTED, | 44 BDICT_CORRUPTED, |
| 44 }; | 45 }; |
| 45 | 46 |
| 46 explicit SpellcheckService(Profile* profile); | 47 explicit SpellcheckService(Profile* profile); |
| 47 virtual ~SpellcheckService(); | 48 virtual ~SpellcheckService(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 60 const std::vector<std::string>& accept_languages, | 61 const std::vector<std::string>& accept_languages, |
| 61 const std::string& dictionary_language, | 62 const std::string& dictionary_language, |
| 62 std::vector<std::string>* languages); | 63 std::vector<std::string>* languages); |
| 63 | 64 |
| 64 // Signals the event attached by AttachTestEvent() to report the specified | 65 // Signals the event attached by AttachTestEvent() to report the specified |
| 65 // event to browser tests. This function is called by this class and its | 66 // event to browser tests. This function is called by this class and its |
| 66 // derived classes to report their status. This function does not do anything | 67 // derived classes to report their status. This function does not do anything |
| 67 // when we do not set an event to |status_event_|. | 68 // when we do not set an event to |status_event_|. |
| 68 static bool SignalStatusEvent(EventType type); | 69 static bool SignalStatusEvent(EventType type); |
| 69 | 70 |
| 70 void Initialize(); | |
| 71 | |
| 72 // Instantiates SpellCheckHostMetrics object and makes it ready for recording | 71 // Instantiates SpellCheckHostMetrics object and makes it ready for recording |
| 73 // metrics. This should be called only if the metrics recording is active. | 72 // metrics. This should be called only if the metrics recording is active. |
| 74 void StartRecordingMetrics(bool spellcheck_enabled); | 73 void StartRecordingMetrics(bool spellcheck_enabled); |
| 75 | 74 |
| 75 // Pass all renderers some basic initialization infomration. |
| 76 void InitForAllRenderers(); |
| 77 |
| 76 // Pass the renderer some basic intialization information. Note that the | 78 // Pass the renderer some basic intialization information. Note that the |
| 77 // renderer will not load Hunspell until it needs to. | 79 // renderer will not load Hunspell until it needs to. |
| 78 void InitForRenderer(content::RenderProcessHost* process); | 80 void InitForRenderer(content::RenderProcessHost* process); |
| 79 | 81 |
| 80 // Returns true if the dictionary is ready to use. | 82 // Returns true if the dictionary is ready to use. |
| 81 bool IsReady() const; | 83 bool IsReady() const; |
| 82 | 84 |
| 83 // Hunspell dictionary functions. | 85 // Hunspell dictionary functions. |
| 84 virtual const base::PlatformFile& GetDictionaryFile() const; | 86 virtual const base::PlatformFile& GetDictionaryFile() const; |
| 85 virtual const std::string& GetLanguage() const; | 87 virtual const std::string& GetLanguage() const; |
| 86 virtual bool IsUsingPlatformChecker() const; | 88 virtual bool IsUsingPlatformChecker() const; |
| 87 | 89 |
| 88 // Returns a metrics counter associated with this object, | 90 // Returns a metrics counter associated with this object, |
| 89 // or null when metrics recording is disabled. | 91 // or null when metrics recording is disabled. |
| 90 SpellCheckHostMetrics* GetMetrics() const; | 92 SpellCheckHostMetrics* GetMetrics() const; |
| 91 | 93 |
| 92 // Returns the instance of the custom dictionary. Custom dictionary | 94 // Returns the instance of the custom dictionary. |
| 93 // will be lazily initialized. | |
| 94 SpellcheckCustomDictionary* GetCustomDictionary(); | 95 SpellcheckCustomDictionary* GetCustomDictionary(); |
| 95 | 96 |
| 96 // Inform |profile_| that initialization has finished. | |
| 97 // |custom_words| holds the custom word list which was | |
| 98 // loaded at the file thread. | |
| 99 void InformProfileOfInitializationWithCustomWords( | |
| 100 chrome::spellcheck_common::WordList* custom_words); | |
| 101 | |
| 102 // NotificationProfile implementation. | 97 // NotificationProfile implementation. |
| 103 virtual void Observe(int type, | 98 virtual void Observe(int type, |
| 104 const content::NotificationSource& source, | 99 const content::NotificationSource& source, |
| 105 const content::NotificationDetails& details) OVERRIDE; | 100 const content::NotificationDetails& details) OVERRIDE; |
| 106 | 101 |
| 107 // PrefObserver implementation. | 102 // PrefObserver implementation. |
| 108 virtual void OnPreferenceChanged(PrefServiceBase* service, | 103 virtual void OnPreferenceChanged(PrefServiceBase* service, |
| 109 const std::string& pref_name) OVERRIDE; | 104 const std::string& pref_name) OVERRIDE; |
| 105 |
| 106 // SpellcheckCustomDictionary::Observer implementation. |
| 107 virtual void OnCustomDictionaryLoaded() OVERRIDE; |
| 108 virtual void OnCustomDictionaryWordAdded(const std::string& word) OVERRIDE; |
| 109 virtual void OnCustomDictionaryWordRemoved(const std::string& word) OVERRIDE; |
| 110 |
| 110 private: | 111 private: |
| 111 FRIEND_TEST_ALL_PREFIXES(SpellcheckServiceBrowserTest, DeleteCorruptedBDICT); | 112 FRIEND_TEST_ALL_PREFIXES(SpellcheckServiceBrowserTest, DeleteCorruptedBDICT); |
| 112 | 113 |
| 113 // Attaches an event so browser tests can listen the status events. | 114 // Attaches an event so browser tests can listen the status events. |
| 114 static void AttachStatusEvent(base::WaitableEvent* status_event); | 115 static void AttachStatusEvent(base::WaitableEvent* status_event); |
| 115 | 116 |
| 116 // Waits until a spellchecker updates its status. This function returns | 117 // Waits until a spellchecker updates its status. This function returns |
| 117 // immediately when we do not set an event to |status_event_|. | 118 // immediately when we do not set an event to |status_event_|. |
| 118 static EventType WaitStatusEvent(); | 119 static EventType WaitStatusEvent(); |
| 119 | 120 |
| 120 PrefChangeRegistrar pref_change_registrar_; | 121 PrefChangeRegistrar pref_change_registrar_; |
| 121 content::NotificationRegistrar registrar_; | 122 content::NotificationRegistrar registrar_; |
| 122 | 123 |
| 123 // A pointer to the profile which this service refers to. | 124 // A pointer to the profile which this service refers to. |
| 124 Profile* profile_; | 125 Profile* profile_; |
| 125 | 126 |
| 126 scoped_ptr<SpellCheckHostMetrics> metrics_; | 127 scoped_ptr<SpellCheckHostMetrics> metrics_; |
| 127 | 128 |
| 128 scoped_ptr<SpellcheckCustomDictionary> custom_dictionary_; | 129 scoped_ptr<SpellcheckCustomDictionary> custom_dictionary_; |
| 129 | 130 |
| 130 scoped_ptr<SpellcheckHunspellDictionary> hunspell_dictionary_; | 131 scoped_ptr<SpellcheckHunspellDictionary> hunspell_dictionary_; |
| 131 | 132 |
| 132 base::WeakPtrFactory<SpellcheckService> weak_ptr_factory_; | 133 base::WeakPtrFactory<SpellcheckService> weak_ptr_factory_; |
| 133 | 134 |
| 134 DISALLOW_COPY_AND_ASSIGN(SpellcheckService); | 135 DISALLOW_COPY_AND_ASSIGN(SpellcheckService); |
| 135 }; | 136 }; |
| 136 | 137 |
| 137 #endif // CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_SERVICE_H_ | 138 #endif // CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_SERVICE_H_ |
| OLD | NEW |