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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_HOST_H_
6 #define CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_HOST_H_
12 #include "base/gtest_prod_util.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/platform_file.h"
15 #include "content/public/browser/browser_thread.h"
22 class RenderProcessHost
;
26 class SpellCheckHostMetrics
;
27 class SpellCheckProfileProvider
;
30 class URLRequestContextGetter
;
33 // An abstract interface that provides operations that controls the spellchecker
34 // attached to the browser. This class provides the operations listed below:
35 // * Adding a word to the user dictionary;
36 // * Retrieving the dictionary file (if it has one);
37 // * Retrieving the list of words in the user dictionary;
38 // * Retrieving the language used by the spellchecker.
39 // * Listing available languages for a Profile object;
40 // * Accepting an observer to reacting the state change of the object.
41 // You can also remove the observer from the SpellCheckHost object.
42 // The object should implement SpellCheckProfileProvider interface.
44 // The following snippet describes how to use this class,
45 // std::vector<std::string> languages;
46 // SpellCheckHost::GetSpellCheckLanguages(profile_, &languages);
47 // spellcheck_host_ = SpellCheckHost::Create(
48 // observer, languages[0], req_getter);
50 // The class is intended to be owned by SpellCheckProfile so users should
51 // retrieve the instance via Profile::GetSpellCheckHost().
52 // Users should not hold the reference over the function scope because
53 // the instance can be invalidated during the browser's lifecycle.
54 class SpellCheckHost
{
56 // Event types used for reporting the status of this class and its derived
57 // classes to browser tests.
63 virtual ~SpellCheckHost() {}
65 // Creates the instance of SpellCheckHost implementation object.
66 static SpellCheckHost
* Create(
67 SpellCheckProfileProvider
* profile
,
68 const std::string
& language
,
69 net::URLRequestContextGetter
* request_context_getter
,
70 SpellCheckHostMetrics
* metrics
);
72 // Clears a profile which is set on creation.
73 // Used to prevent calling back to a deleted object.
74 virtual void UnsetProfile() = 0;
76 // Pass the renderer some basic intialization information. Note that the
77 // renderer will not load Hunspell until it needs to.
78 virtual void InitForRenderer(content::RenderProcessHost
* process
) = 0;
80 // Adds the given word to the custom words list and inform renderer of the
82 virtual void AddWord(const std::string
& word
) = 0;
84 virtual const base::PlatformFile
& GetDictionaryFile() const = 0;
86 virtual const std::string
& GetLanguage() const = 0;
88 virtual bool IsUsingPlatformChecker() const = 0;
90 // Returns a metrics counter associated with this object,
91 // or null when metrics recording is disabled.
92 virtual SpellCheckHostMetrics
* GetMetrics() const = 0;
94 // Returns true if the dictionary is ready to use.
95 virtual bool IsReady() const = 0;
97 // This function computes a vector of strings which are to be displayed in
98 // the context menu over a text area for changing spell check languages. It
99 // returns the index of the current spell check language in the vector.
100 // TODO(port): this should take a vector of string16, but the implementation
101 // has some dependencies in l10n util that need porting first.
102 static int GetSpellCheckLanguages(Profile
* profile
,
103 std::vector
<std::string
>* languages
);
106 // Signals the event attached by AttachTestEvent() to report the specified
107 // event to browser tests. This function is called by this class and its
108 // derived classes to report their status. This function does not do anything
109 // when we do not set an event to |status_event_|.
110 static bool SignalStatusEvent(EventType type
);
113 FRIEND_TEST_ALL_PREFIXES(SpellCheckHostBrowserTest
, DeleteCorruptedBDICT
);
115 // Attaches an event so browser tests can listen the status events.
116 static void AttachStatusEvent(base::WaitableEvent
* status_event
);
118 // Waits until a spellchecker updates its status. This function returns
119 // immediately when we do not set an event to |status_event_|.
120 static EventType
WaitStatusEvent();
123 #endif // CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_HOST_H_