Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(282)

Side by Side Diff: chrome/browser/spellchecker/spellcheck_host.cc

Issue 11416297: [Spellcheck] remove dead file (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/spellchecker/spellcheck_host.h"
6
7 #include "base/string_split.h"
8 #include "base/synchronization/waitable_event.h"
9 #include "chrome/browser/api/prefs/pref_member.h"
10 #include "chrome/browser/prefs/pref_service.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/spellchecker/spellcheck_host_impl.h"
13 #include "chrome/browser/spellchecker/spellcheck_platform_mac.h"
14 #include "chrome/common/pref_names.h"
15 #include "chrome/common/spellcheck_common.h"
16
17 using content::BrowserThread;
18
19 namespace {
20
21 // An event used by browser tests to receive status events from this class and
22 // its derived classes.
23 base::WaitableEvent* g_status_event = NULL;
24 SpellCheckHost::EventType g_status_type = SpellCheckHost::BDICT_NOTINITIALIZED;
25
26 } // namespace
27
28 // static
29 SpellCheckHost* SpellCheckHost::Create(
30 SpellCheckProfileProvider* profile,
31 const std::string& language,
32 net::URLRequestContextGetter* request_context_getter,
33 SpellCheckHostMetrics* metrics) {
34 SpellCheckHostImpl* host =
35 new SpellCheckHostImpl(profile, language, request_context_getter,
36 metrics);
37 if (!host)
38 return NULL;
39
40 host->Initialize();
41 return host;
42 }
43
44 // static
45 int SpellCheckHost::GetSpellCheckLanguages(
46 Profile* profile,
47 std::vector<std::string>* languages) {
48 StringPrefMember accept_languages_pref;
49 StringPrefMember dictionary_language_pref;
50 accept_languages_pref.Init(prefs::kAcceptLanguages, profile->GetPrefs(),
51 NULL);
52 dictionary_language_pref.Init(prefs::kSpellCheckDictionary,
53 profile->GetPrefs(), NULL);
54 std::string dictionary_language = dictionary_language_pref.GetValue();
55
56 // Now scan through the list of accept languages, and find possible mappings
57 // from this list to the existing list of spell check languages.
58 std::vector<std::string> accept_languages;
59
60 #if defined(OS_MACOSX)
61 if (spellcheck_mac::SpellCheckerAvailable())
62 spellcheck_mac::GetAvailableLanguages(&accept_languages);
63 else
64 base::SplitString(accept_languages_pref.GetValue(), ',', &accept_languages);
65 #else
66 base::SplitString(accept_languages_pref.GetValue(), ',', &accept_languages);
67 #endif // !OS_MACOSX
68
69 GetSpellCheckLanguagesFromAcceptLanguages(
70 accept_languages, dictionary_language, languages);
71
72 for (size_t i = 0; i < languages->size(); ++i) {
73 if ((*languages)[i] == dictionary_language)
74 return i;
75 }
76 return -1;
77 }
78
79 // static
80 void SpellCheckHost::GetSpellCheckLanguagesFromAcceptLanguages(
81 const std::vector<std::string>& accept_languages,
82 const std::string& dictionary_language,
83 std::vector<std::string>* languages) {
84 // The current dictionary language should be there.
85 languages->push_back(dictionary_language);
86
87 for (std::vector<std::string>::const_iterator i = accept_languages.begin();
88 i != accept_languages.end(); ++i) {
89 std::string language =
90 chrome::spellcheck_common::GetCorrespondingSpellCheckLanguage(*i);
91 if (!language.empty() &&
92 std::find(languages->begin(), languages->end(), language) ==
93 languages->end()) {
94 languages->push_back(language);
95 }
96 }
97 }
98
99 // static
100 bool SpellCheckHost::SignalStatusEvent(SpellCheckHost::EventType status_type) {
101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
102
103 if (!g_status_event)
104 return false;
105 g_status_type = status_type;
106 g_status_event->Signal();
107 return true;
108 }
109
110 // static
111 void SpellCheckHost::AttachStatusEvent(base::WaitableEvent* status_event) {
112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
113
114 g_status_event = status_event;
115 }
116
117 // static
118 SpellCheckHost::EventType SpellCheckHost::WaitStatusEvent() {
119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
120
121 if (g_status_event)
122 g_status_event->Wait();
123 return g_status_type;
124 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698