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_PROFILE_H_ | 5 #ifndef CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_PROFILE_H_ |
| 6 #define CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_PROFILE_H_ | 6 #define CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_PROFILE_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/file_path.h" | |
| 12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 14 #include "chrome/browser/spellchecker/spellcheck_profile_provider.h" | 15 #include "chrome/browser/spellchecker/spellcheck_profile_provider.h" |
| 16 #include "chrome/common/chrome_constants.h" | |
| 17 #include "chrome/common/chrome_paths.h" | |
| 18 #include "content/browser/browser_thread.h" | |
|
gmorrita
2011/10/12 03:41:11
Isn't it possible to have this in .cc file?
shinyak (Google)
2011/10/12 10:46:54
Done.
| |
| 15 | 19 |
| 16 class Profile; | 20 class Profile; |
| 17 class SpellCheckHost; | 21 class SpellCheckHost; |
| 18 class SpellCheckHostMetrics; | 22 class SpellCheckHostMetrics; |
| 19 | 23 |
| 20 namespace net { | 24 namespace net { |
| 21 class URLRequestContextGetter; | 25 class URLRequestContextGetter; |
| 22 } | 26 } |
| 23 | 27 |
| 24 // A facade of spell-check related objects in the browser process. | 28 // A facade of spell-check related objects in the browser process. |
| 25 // This class is responsible for managing a life-cycle of: | 29 // This class is responsible for managing a life-cycle of: |
| 26 // * SpellCheckHost object (instantiation, deletion, reset) | 30 // * SpellCheckHost object (instantiation, deletion, reset) |
| 27 // * SpellCheckHostMetrics object (only initiate when metrics is enabled) | 31 // * SpellCheckHostMetrics object (only initiate when metrics is enabled) |
| 28 // | 32 // |
| 29 // The following snippet describes how to use this class: | 33 // The following snippet describes how to use this class: |
| 30 // | 34 // |
| 31 // PrefService* pref = ....; | 35 // PrefService* pref = ....; |
| 32 // net::URLRequestContextGetter* context = ...; | 36 // net::URLRequestContextGetter* context = ...; |
| 33 // SpellCheckProfile* profile = new SpellCheckProfile(); | 37 // SpellCheckProfile* profile = new SpellCheckProfile(); |
| 34 // profile->StartRecordingMetrics(true); // to enable recording | 38 // profile->StartRecordingMetrics(true); // to enable recording |
| 35 // profile->ReinitializeResult(true, true, pref->GetLanguage(), context); | 39 // profile->ReinitializeResult(true, true, pref->GetLanguage(), context); |
| 36 // ... | 40 // ... |
| 37 // SpellCheckHost* host = profile->GetHost(); | 41 // SpellCheckHost* host = profile->GetHost(); |
| 38 // | 42 // |
| 39 // The class is intended to be owned and managed by ProfileImpl internally. | 43 // The class is intended to be owned and managed by ProfileImpl internally. |
| 40 // Any usable APIs are provided by SpellCheckHost interface, | 44 // Any usable APIs are provided by SpellCheckHost interface, |
| 41 // which can be retrieved from Profile::GetSpellCheckHost(). | 45 // which can be retrieved from Profile::GetSpellCheckHost(). |
| 42 class SpellCheckProfile : public SpellCheckProfileProvider { | 46 class SpellCheckProfile |
| 47 : public SpellCheckProfileProvider, | |
|
Hironori Bono
2011/10/12 02:56:56
nit: need four spaces before ':'.
shinyak (Google)
2011/10/12 10:46:54
Done.
| |
| 48 public base::RefCountedThreadSafe<SpellCheckProfile> | |
| 49 { | |
|
Hironori Bono
2011/10/12 02:56:56
nit: this '{' should be placed at the end of the p
shinyak (Google)
2011/10/12 10:46:54
Done.
| |
| 43 public: | 50 public: |
| 44 // Return value of ReinitializeHost() | 51 // Return value of ReinitializeHost() |
| 45 enum ReinitializeResult { | 52 enum ReinitializeResult { |
| 46 // SpellCheckProfile created new SpellCheckHost object. We can | 53 // SpellCheckProfile created new SpellCheckHost object. We can |
| 47 // retrieve it once the asynchronous initialization task is | 54 // retrieve it once the asynchronous initialization task is |
| 48 // finished. | 55 // finished. |
| 49 REINITIALIZE_CREATED_HOST, | 56 REINITIALIZE_CREATED_HOST, |
| 50 // An existing SpellCheckHost insntace is deleted, that means | 57 // An existing SpellCheckHost insntace is deleted, that means |
| 51 // the spell-check feature just tunred from enabled to disabled. | 58 // the spell-check feature just tunred from enabled to disabled. |
| 52 // The state should be synced to renderer processes | 59 // The state should be synced to renderer processes |
| 53 REINITIALIZE_REMOVED_HOST, | 60 REINITIALIZE_REMOVED_HOST, |
| 54 // The API did nothing. SpellCheckHost instance isn't created nor | 61 // The API did nothing. SpellCheckHost instance isn't created nor |
| 55 // deleted. | 62 // deleted. |
| 56 REINITIALIZE_DID_NOTHING | 63 REINITIALIZE_DID_NOTHING |
| 57 }; | 64 }; |
| 58 | 65 |
| 59 SpellCheckProfile(); | 66 SpellCheckProfile(); |
| 60 virtual ~SpellCheckProfile(); | |
| 61 | 67 |
| 62 // Retrieves SpellCheckHost object. | 68 // Retrieves SpellCheckHost object. |
| 63 // This can return NULL when the spell-checking is disabled | 69 // This can return NULL when the spell-checking is disabled |
| 64 // or the host object is not ready yet. | 70 // or the host object is not ready yet. |
| 65 SpellCheckHost* GetHost(); | 71 SpellCheckHost* GetHost(); |
| 66 | 72 |
| 67 // Initializes or deletes SpellCheckHost object if necessary. | 73 // Initializes or deletes SpellCheckHost object if necessary. |
| 68 // The caller should provide URLRequestContextGetter for | 74 // The caller should provide URLRequestContextGetter for |
| 69 // possible dictionary download. | 75 // possible dictionary download. |
| 70 // | 76 // |
| 71 // If |force| is true, the host instance is newly created | 77 // If |force| is true, the host instance is newly created |
| 72 // regardless there is existing instance. | 78 // regardless there is existing instance. |
| 73 ReinitializeResult ReinitializeHost( | 79 ReinitializeResult ReinitializeHost( |
| 74 bool force, | 80 bool force, |
| 75 bool enable, | 81 bool enable, |
| 76 const std::string& language, | 82 const std::string& language, |
| 77 net::URLRequestContextGetter* request_context); | 83 net::URLRequestContextGetter* request_context); |
| 78 | 84 |
| 79 // Instantiates SpellCheckHostMetrics object and | 85 // Instantiates SpellCheckHostMetrics object and |
| 80 // makes it ready for recording metrics. | 86 // makes it ready for recording metrics. |
| 81 // This should be called only if the metrics recording is active. | 87 // This should be called only if the metrics recording is active. |
| 82 void StartRecordingMetrics(bool spellcheck_enabled); | 88 void StartRecordingMetrics(bool spellcheck_enabled); |
| 83 | 89 |
| 84 // SpellCheckProfileProvider implementation. | 90 // SpellCheckProfileProvider implementation. |
| 85 virtual void SpellCheckHostInitialized(CustomWordList* custom_words); | 91 virtual void LoadCustomDictionary(); |
| 92 virtual void SpellCheckHostInitialized(); | |
| 86 virtual const CustomWordList& GetCustomWords() const; | 93 virtual const CustomWordList& GetCustomWords() const; |
| 87 virtual void CustomWordAddedLocally(const std::string& word); | 94 virtual void CustomWordAddedLocally(const std::string& word); |
| 88 | 95 |
| 89 protected: | 96 protected: |
| 97 friend class base::RefCountedThreadSafe<SpellCheckProfile>; | |
| 98 virtual ~SpellCheckProfile(); | |
| 99 | |
| 90 // Only tests should override this. | 100 // Only tests should override this. |
| 91 virtual SpellCheckHost* CreateHost( | 101 virtual SpellCheckHost* CreateHost( |
| 92 SpellCheckProfileProvider* provider, | 102 SpellCheckProfileProvider* provider, |
| 93 const std::string& language, | 103 const std::string& language, |
| 94 net::URLRequestContextGetter* request_context, | 104 net::URLRequestContextGetter* request_context, |
| 95 SpellCheckHostMetrics* metrics); | 105 SpellCheckHostMetrics* metrics); |
| 96 | 106 |
| 97 virtual bool IsTesting() const; | 107 virtual bool IsTesting() const; |
| 98 | 108 |
| 109 // Tests should override this. | |
| 110 virtual void WriteWordToCustomDictionary(const std::string& word); | |
| 99 private: | 111 private: |
| 112 // Load a custom dictionary on file thread. | |
| 113 void LoadCustomDictionaryOnFileThread(); | |
| 114 | |
| 115 // Write a custom dictionary addition to disk. | |
| 116 void WriteWordToCustomDictionaryOnFileThread(const std::string& word); | |
| 117 | |
| 100 scoped_refptr<SpellCheckHost> host_; | 118 scoped_refptr<SpellCheckHost> host_; |
| 101 scoped_ptr<SpellCheckHostMetrics> metrics_; | 119 scoped_ptr<SpellCheckHostMetrics> metrics_; |
| 102 | 120 |
| 103 // Indicates whether |host_| has told us initialization is | 121 // Indicates whether |host_| has told us initialization is |
| 104 // finished. | 122 // finished. |
| 105 bool host_ready_; | 123 bool host_ready_; |
| 106 | 124 |
| 125 // The location of the custom words file. | |
| 126 FilePath custom_dictionary_file_; | |
| 127 | |
| 107 // In-memory cache of the custom words file. | 128 // In-memory cache of the custom words file. |
| 108 scoped_ptr<CustomWordList> custom_words_; | 129 scoped_ptr<CustomWordList> custom_words_; |
| 109 | 130 |
| 110 DISALLOW_COPY_AND_ASSIGN(SpellCheckProfile); | 131 DISALLOW_COPY_AND_ASSIGN(SpellCheckProfile); |
| 111 }; | 132 }; |
| 112 | 133 |
| 113 #endif // CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_PROFILE_H_ | 134 #endif // CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_PROFILE_H_ |
| OLD | NEW |