Remove Instant histograms.
[chromium-blink-merge.git] / chrome / browser / spellchecker / spellcheck_host.h
blobb4b6b091ada79190e63e0f3c3cf6f5bf1464aa06
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_
8 #include <string>
9 #include <vector>
11 #include "base/gtest_prod_util.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/platform_file.h"
14 #include "content/public/browser/browser_thread.h"
16 namespace base {
17 class WaitableEvent;
20 namespace content {
21 class RenderProcessHost;
24 class Profile;
25 class SpellCheckHostMetrics;
26 class SpellCheckProfileProvider;
28 namespace net {
29 class URLRequestContextGetter;
32 // An abstract interface that provides operations that controls the spellchecker
33 // attached to the browser. This class provides the operations listed below:
34 // * Adding a word to the user dictionary;
35 // * Retrieving the dictionary file (if it has one);
36 // * Retrieving the list of words in the user dictionary;
37 // * Retrieving the language used by the spellchecker.
38 // * Listing available languages for a Profile object;
39 // * Accepting an observer to reacting the state change of the object.
40 // You can also remove the observer from the SpellCheckHost object.
41 // The object should implement SpellCheckProfileProvider interface.
43 // The following snippet describes how to use this class,
44 // std::vector<std::string> languages;
45 // SpellCheckHost::GetSpellCheckLanguages(profile_, &languages);
46 // spellcheck_host_ = SpellCheckHost::Create(
47 // observer, languages[0], req_getter);
49 // The class is intended to be owned by SpellCheckProfile so users should
50 // retrieve the instance via Profile::GetSpellCheckHost().
51 // Users should not hold the reference over the function scope because
52 // the instance can be invalidated during the browser's lifecycle.
53 class SpellCheckHost {
54 public:
55 // Event types used for reporting the status of this class and its derived
56 // classes to browser tests.
57 enum EventType {
58 BDICT_NOTINITIALIZED,
59 BDICT_CORRUPTED,
62 virtual ~SpellCheckHost() {}
64 // Creates the instance of SpellCheckHost implementation object.
65 static SpellCheckHost* Create(
66 SpellCheckProfileProvider* profile,
67 const std::string& language,
68 net::URLRequestContextGetter* request_context_getter,
69 SpellCheckHostMetrics* metrics);
71 // Clears a profile which is set on creation.
72 // Used to prevent calling back to a deleted object.
73 virtual void UnsetProfile() = 0;
75 // Pass the renderer some basic intialization information. Note that the
76 // renderer will not load Hunspell until it needs to.
77 virtual void InitForRenderer(content::RenderProcessHost* process) = 0;
79 // Adds the given word to the custom words list and inform renderer of the
80 // update.
81 virtual void AddWord(const std::string& word) = 0;
83 virtual const base::PlatformFile& GetDictionaryFile() const = 0;
85 virtual const std::string& GetLanguage() const = 0;
87 virtual bool IsUsingPlatformChecker() const = 0;
89 // Returns a metrics counter associated with this object,
90 // or null when metrics recording is disabled.
91 virtual SpellCheckHostMetrics* GetMetrics() const = 0;
93 // Returns true if the dictionary is ready to use.
94 virtual bool IsReady() const = 0;
96 // This function computes a vector of strings which are to be displayed in
97 // the context menu over a text area for changing spell check languages. It
98 // returns the index of the current spell check language in the vector.
99 // TODO(port): this should take a vector of string16, but the implementation
100 // has some dependencies in l10n util that need porting first.
101 static int GetSpellCheckLanguages(Profile* profile,
102 std::vector<std::string>* languages);
104 // Computes a vector of strings which are to be displayed in the context
105 // menu from |accept_languages| and |dictionary_language|.
106 static void GetSpellCheckLanguagesFromAcceptLanguages(
107 const std::vector<std::string>& accept_languages,
108 const std::string& dictionary_language,
109 std::vector<std::string>* languages);
111 // Signals the event attached by AttachTestEvent() to report the specified
112 // event to browser tests. This function is called by this class and its
113 // derived classes to report their status. This function does not do anything
114 // when we do not set an event to |status_event_|.
115 static bool SignalStatusEvent(EventType type);
117 private:
118 FRIEND_TEST_ALL_PREFIXES(SpellCheckHostBrowserTest, DeleteCorruptedBDICT);
120 // Attaches an event so browser tests can listen the status events.
121 static void AttachStatusEvent(base::WaitableEvent* status_event);
123 // Waits until a spellchecker updates its status. This function returns
124 // immediately when we do not set an event to |status_event_|.
125 static EventType WaitStatusEvent();
128 #endif // CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_HOST_H_