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 #include "chrome/browser/spellchecker/spellcheck_service.h" | 5 #include "chrome/browser/spellchecker/spellcheck_service.h" |
6 | 6 |
7 #include "base/prefs/pref_member.h" | 7 #include "base/prefs/pref_member.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 // transition. | 30 // transition. |
31 // An event used by browser tests to receive status events from this class and | 31 // An event used by browser tests to receive status events from this class and |
32 // its derived classes. | 32 // its derived classes. |
33 base::WaitableEvent* g_status_event = NULL; | 33 base::WaitableEvent* g_status_event = NULL; |
34 SpellcheckService::EventType g_status_type = | 34 SpellcheckService::EventType g_status_type = |
35 SpellcheckService::BDICT_NOTINITIALIZED; | 35 SpellcheckService::BDICT_NOTINITIALIZED; |
36 | 36 |
37 SpellcheckService::SpellcheckService(content::BrowserContext* context) | 37 SpellcheckService::SpellcheckService(content::BrowserContext* context) |
38 : context_(context), | 38 : context_(context), |
39 weak_ptr_factory_(this) { | 39 weak_ptr_factory_(this) { |
40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 40 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
41 PrefService* prefs = user_prefs::UserPrefs::Get(context); | 41 PrefService* prefs = user_prefs::UserPrefs::Get(context); |
42 pref_change_registrar_.Init(prefs); | 42 pref_change_registrar_.Init(prefs); |
43 | 43 |
44 std::string language_code; | 44 std::string language_code; |
45 std::string country_code; | 45 std::string country_code; |
46 chrome::spellcheck_common::GetISOLanguageCountryCodeFromLocale( | 46 chrome::spellcheck_common::GetISOLanguageCountryCodeFromLocale( |
47 prefs->GetString(prefs::kSpellCheckDictionary), | 47 prefs->GetString(prefs::kSpellCheckDictionary), |
48 &language_code, | 48 &language_code, |
49 &country_code); | 49 &country_code); |
50 feedback_sender_.reset(new spellcheck::FeedbackSender( | 50 feedback_sender_.reset(new spellcheck::FeedbackSender( |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 std::find(languages->begin(), languages->end(), language) == | 137 std::find(languages->begin(), languages->end(), language) == |
138 languages->end()) { | 138 languages->end()) { |
139 languages->push_back(language); | 139 languages->push_back(language); |
140 } | 140 } |
141 } | 141 } |
142 } | 142 } |
143 | 143 |
144 // static | 144 // static |
145 bool SpellcheckService::SignalStatusEvent( | 145 bool SpellcheckService::SignalStatusEvent( |
146 SpellcheckService::EventType status_type) { | 146 SpellcheckService::EventType status_type) { |
147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 147 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
148 | 148 |
149 if (!g_status_event) | 149 if (!g_status_event) |
150 return false; | 150 return false; |
151 g_status_type = status_type; | 151 g_status_type = status_type; |
152 g_status_event->Signal(); | 152 g_status_event->Signal(); |
153 return true; | 153 return true; |
154 } | 154 } |
155 | 155 |
156 void SpellcheckService::StartRecordingMetrics(bool spellcheck_enabled) { | 156 void SpellcheckService::StartRecordingMetrics(bool spellcheck_enabled) { |
157 metrics_.reset(new SpellCheckHostMetrics()); | 157 metrics_.reset(new SpellCheckHostMetrics()); |
158 metrics_->RecordEnabledStats(spellcheck_enabled); | 158 metrics_->RecordEnabledStats(spellcheck_enabled); |
159 OnUseSpellingServiceChanged(); | 159 OnUseSpellingServiceChanged(); |
160 } | 160 } |
161 | 161 |
162 void SpellcheckService::InitForRenderer(content::RenderProcessHost* process) { | 162 void SpellcheckService::InitForRenderer(content::RenderProcessHost* process) { |
163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 163 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
164 | 164 |
165 content::BrowserContext* context = process->GetBrowserContext(); | 165 content::BrowserContext* context = process->GetBrowserContext(); |
166 if (SpellcheckServiceFactory::GetForContext(context) != this) | 166 if (SpellcheckServiceFactory::GetForContext(context) != this) |
167 return; | 167 return; |
168 | 168 |
169 PrefService* prefs = user_prefs::UserPrefs::Get(context); | 169 PrefService* prefs = user_prefs::UserPrefs::Get(context); |
170 IPC::PlatformFileForTransit file = IPC::InvalidPlatformFileForTransit(); | 170 IPC::PlatformFileForTransit file = IPC::InvalidPlatformFileForTransit(); |
171 | 171 |
172 if (hunspell_dictionary_->GetDictionaryFile().IsValid()) { | 172 if (hunspell_dictionary_->GetDictionaryFile().IsValid()) { |
173 file = IPC::GetFileHandleForProcess( | 173 file = IPC::GetFileHandleForProcess( |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 } | 243 } |
244 | 244 |
245 void SpellcheckService::OnHunspellDictionaryDownloadSuccess() { | 245 void SpellcheckService::OnHunspellDictionaryDownloadSuccess() { |
246 } | 246 } |
247 | 247 |
248 void SpellcheckService::OnHunspellDictionaryDownloadFailure() { | 248 void SpellcheckService::OnHunspellDictionaryDownloadFailure() { |
249 } | 249 } |
250 | 250 |
251 // static | 251 // static |
252 void SpellcheckService::AttachStatusEvent(base::WaitableEvent* status_event) { | 252 void SpellcheckService::AttachStatusEvent(base::WaitableEvent* status_event) { |
253 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 253 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
254 | 254 |
255 g_status_event = status_event; | 255 g_status_event = status_event; |
256 } | 256 } |
257 | 257 |
258 // static | 258 // static |
259 SpellcheckService::EventType SpellcheckService::GetStatusEvent() { | 259 SpellcheckService::EventType SpellcheckService::GetStatusEvent() { |
260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 260 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
261 return g_status_type; | 261 return g_status_type; |
262 } | 262 } |
263 | 263 |
264 void SpellcheckService::InitForAllRenderers() { | 264 void SpellcheckService::InitForAllRenderers() { |
265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 265 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
266 for (content::RenderProcessHost::iterator i( | 266 for (content::RenderProcessHost::iterator i( |
267 content::RenderProcessHost::AllHostsIterator()); | 267 content::RenderProcessHost::AllHostsIterator()); |
268 !i.IsAtEnd(); i.Advance()) { | 268 !i.IsAtEnd(); i.Advance()) { |
269 content::RenderProcessHost* process = i.GetCurrentValue(); | 269 content::RenderProcessHost* process = i.GetCurrentValue(); |
270 if (process && process->GetHandle()) | 270 if (process && process->GetHandle()) |
271 InitForRenderer(process); | 271 InitForRenderer(process); |
272 } | 272 } |
273 } | 273 } |
274 | 274 |
275 void SpellcheckService::OnEnableAutoSpellCorrectChanged() { | 275 void SpellcheckService::OnEnableAutoSpellCorrectChanged() { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 } | 312 } |
313 | 313 |
314 void SpellcheckService::UpdateFeedbackSenderState() { | 314 void SpellcheckService::UpdateFeedbackSenderState() { |
315 if (SpellingServiceClient::IsAvailable( | 315 if (SpellingServiceClient::IsAvailable( |
316 context_, SpellingServiceClient::SPELLCHECK)) { | 316 context_, SpellingServiceClient::SPELLCHECK)) { |
317 feedback_sender_->StartFeedbackCollection(); | 317 feedback_sender_->StartFeedbackCollection(); |
318 } else { | 318 } else { |
319 feedback_sender_->StopFeedbackCollection(); | 319 feedback_sender_->StopFeedbackCollection(); |
320 } | 320 } |
321 } | 321 } |
OLD | NEW |