| 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 a metrics counter associated with this object, | 82 // Returns a metrics counter associated with this object, |
| 81 // or null when metrics recording is disabled. | 83 // or null when metrics recording is disabled. |
| 82 SpellCheckHostMetrics* GetMetrics() const; | 84 SpellCheckHostMetrics* GetMetrics() const; |
| 83 | 85 |
| 84 // Returns the instance of the custom dictionary. Custom dictionary | 86 // Returns the instance of the custom dictionary. |
| 85 // will be lazily initialized. | |
| 86 SpellcheckCustomDictionary* GetCustomDictionary(); | 87 SpellcheckCustomDictionary* GetCustomDictionary(); |
| 87 | 88 |
| 88 // Inform |profile_| that initialization has finished. | |
| 89 // |custom_words| holds the custom word list which was | |
| 90 // loaded at the file thread. | |
| 91 void InformProfileOfInitializationWithCustomWords( | |
| 92 chrome::spellcheck_common::WordList* custom_words); | |
| 93 | |
| 94 // NotificationProfile implementation. | 89 // NotificationProfile implementation. |
| 95 virtual void Observe(int type, | 90 virtual void Observe(int type, |
| 96 const content::NotificationSource& source, | 91 const content::NotificationSource& source, |
| 97 const content::NotificationDetails& details) OVERRIDE; | 92 const content::NotificationDetails& details) OVERRIDE; |
| 98 | 93 |
| 99 // PrefObserver implementation. | 94 // PrefObserver implementation. |
| 100 virtual void OnPreferenceChanged(PrefServiceBase* service, | 95 virtual void OnPreferenceChanged(PrefServiceBase* service, |
| 101 const std::string& pref_name) OVERRIDE; | 96 const std::string& pref_name) OVERRIDE; |
| 97 |
| 98 // SpellcheckCustomDictionary::Observer implementation. |
| 99 virtual void OnCustomDictionaryLoaded() OVERRIDE; |
| 100 virtual void OnCustomDictionaryWordAdded(const std::string& word) OVERRIDE; |
| 101 virtual void OnCustomDictionaryWordRemoved(const std::string& word) OVERRIDE; |
| 102 |
| 102 private: | 103 private: |
| 103 FRIEND_TEST_ALL_PREFIXES(SpellcheckServiceBrowserTest, DeleteCorruptedBDICT); | 104 FRIEND_TEST_ALL_PREFIXES(SpellcheckServiceBrowserTest, DeleteCorruptedBDICT); |
| 104 | 105 |
| 105 // Attaches an event so browser tests can listen the status events. | 106 // Attaches an event so browser tests can listen the status events. |
| 106 static void AttachStatusEvent(base::WaitableEvent* status_event); | 107 static void AttachStatusEvent(base::WaitableEvent* status_event); |
| 107 | 108 |
| 108 // Waits until a spellchecker updates its status. This function returns | 109 // Waits until a spellchecker updates its status. This function returns |
| 109 // immediately when we do not set an event to |status_event_|. | 110 // immediately when we do not set an event to |status_event_|. |
| 110 static EventType WaitStatusEvent(); | 111 static EventType WaitStatusEvent(); |
| 111 | 112 |
| 112 PrefChangeRegistrar pref_change_registrar_; | 113 PrefChangeRegistrar pref_change_registrar_; |
| 113 content::NotificationRegistrar registrar_; | 114 content::NotificationRegistrar registrar_; |
| 114 | 115 |
| 115 // A pointer to the profile which this service refers to. | 116 // A pointer to the profile which this service refers to. |
| 116 Profile* profile_; | 117 Profile* profile_; |
| 117 | 118 |
| 118 scoped_ptr<SpellCheckHostMetrics> metrics_; | 119 scoped_ptr<SpellCheckHostMetrics> metrics_; |
| 119 | 120 |
| 120 scoped_ptr<SpellcheckCustomDictionary> custom_dictionary_; | 121 scoped_ptr<SpellcheckCustomDictionary> custom_dictionary_; |
| 121 | 122 |
| 122 scoped_ptr<SpellcheckHunspellDictionary> hunspell_dictionary_; | 123 scoped_ptr<SpellcheckHunspellDictionary> hunspell_dictionary_; |
| 123 | 124 |
| 124 base::WeakPtrFactory<SpellcheckService> weak_ptr_factory_; | 125 base::WeakPtrFactory<SpellcheckService> weak_ptr_factory_; |
| 125 | 126 |
| 126 DISALLOW_COPY_AND_ASSIGN(SpellcheckService); | 127 DISALLOW_COPY_AND_ASSIGN(SpellcheckService); |
| 127 }; | 128 }; |
| 128 | 129 |
| 129 #endif // CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_SERVICE_H_ | 130 #endif // CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_SERVICE_H_ |
| OLD | NEW |