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 23 matching lines...) Expand all Loading... |
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(BrowserThread::CurrentlyOn(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; |
| 45 std::string country_code; |
| 46 chrome::spellcheck_common::GetISOLanguageCountryCodeFromLocale( |
| 47 prefs->GetString(prefs::kSpellCheckDictionary), |
| 48 &language_code, |
| 49 &country_code); |
| 50 feedback_sender_.reset(new spellcheck::FeedbackSender( |
| 51 context->GetRequestContext(), language_code, country_code)); |
| 52 |
44 pref_change_registrar_.Add( | 53 pref_change_registrar_.Add( |
45 prefs::kEnableAutoSpellCorrect, | 54 prefs::kEnableAutoSpellCorrect, |
46 base::Bind(&SpellcheckService::OnEnableAutoSpellCorrectChanged, | 55 base::Bind(&SpellcheckService::OnEnableAutoSpellCorrectChanged, |
47 base::Unretained(this))); | 56 base::Unretained(this))); |
48 pref_change_registrar_.Add( | 57 pref_change_registrar_.Add( |
49 prefs::kSpellCheckDictionary, | 58 prefs::kSpellCheckDictionary, |
50 base::Bind(&SpellcheckService::OnSpellCheckDictionaryChanged, | 59 base::Bind(&SpellcheckService::OnSpellCheckDictionaryChanged, |
51 base::Unretained(this))); | 60 base::Unretained(this))); |
52 pref_change_registrar_.Add( | 61 pref_change_registrar_.Add( |
53 prefs::kSpellCheckUseSpellingService, | 62 prefs::kSpellCheckUseSpellingService, |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 } | 185 } |
177 | 186 |
178 SpellcheckCustomDictionary* SpellcheckService::GetCustomDictionary() { | 187 SpellcheckCustomDictionary* SpellcheckService::GetCustomDictionary() { |
179 return custom_dictionary_.get(); | 188 return custom_dictionary_.get(); |
180 } | 189 } |
181 | 190 |
182 SpellcheckHunspellDictionary* SpellcheckService::GetHunspellDictionary() { | 191 SpellcheckHunspellDictionary* SpellcheckService::GetHunspellDictionary() { |
183 return hunspell_dictionary_.get(); | 192 return hunspell_dictionary_.get(); |
184 } | 193 } |
185 | 194 |
| 195 spellcheck::FeedbackSender* SpellcheckService::GetFeedbackSender() { |
| 196 return feedback_sender_.get(); |
| 197 } |
| 198 |
186 bool SpellcheckService::LoadExternalDictionary(std::string language, | 199 bool SpellcheckService::LoadExternalDictionary(std::string language, |
187 std::string locale, | 200 std::string locale, |
188 std::string path, | 201 std::string path, |
189 DictionaryFormat format) { | 202 DictionaryFormat format) { |
190 return false; | 203 return false; |
191 } | 204 } |
192 | 205 |
193 bool SpellcheckService::UnloadExternalDictionary(std::string path) { | 206 bool SpellcheckService::UnloadExternalDictionary(std::string path) { |
194 return false; | 207 return false; |
195 } | 208 } |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 hunspell_dictionary_->RemoveObserver(this); | 284 hunspell_dictionary_->RemoveObserver(this); |
272 PrefService* prefs = user_prefs::UserPrefs::Get(context_); | 285 PrefService* prefs = user_prefs::UserPrefs::Get(context_); |
273 DCHECK(prefs); | 286 DCHECK(prefs); |
274 | 287 |
275 std::string dictionary = | 288 std::string dictionary = |
276 prefs->GetString(prefs::kSpellCheckDictionary); | 289 prefs->GetString(prefs::kSpellCheckDictionary); |
277 hunspell_dictionary_.reset(new SpellcheckHunspellDictionary( | 290 hunspell_dictionary_.reset(new SpellcheckHunspellDictionary( |
278 dictionary, context_->GetRequestContext(), this)); | 291 dictionary, context_->GetRequestContext(), this)); |
279 hunspell_dictionary_->AddObserver(this); | 292 hunspell_dictionary_->AddObserver(this); |
280 hunspell_dictionary_->Load(); | 293 hunspell_dictionary_->Load(); |
| 294 std::string language_code; |
| 295 std::string country_code; |
| 296 chrome::spellcheck_common::GetISOLanguageCountryCodeFromLocale( |
| 297 dictionary, &language_code, &country_code); |
| 298 feedback_sender_->OnLanguageCountryChange(language_code, country_code); |
| 299 UpdateFeedbackSenderState(); |
281 } | 300 } |
282 | 301 |
283 void SpellcheckService::OnUseSpellingServiceChanged() { | 302 void SpellcheckService::OnUseSpellingServiceChanged() { |
284 bool enabled = pref_change_registrar_.prefs()->GetBoolean( | 303 bool enabled = pref_change_registrar_.prefs()->GetBoolean( |
285 prefs::kSpellCheckUseSpellingService); | 304 prefs::kSpellCheckUseSpellingService); |
286 if (metrics_) | 305 if (metrics_) |
287 metrics_->RecordSpellingServiceStats(enabled); | 306 metrics_->RecordSpellingServiceStats(enabled); |
| 307 UpdateFeedbackSenderState(); |
288 } | 308 } |
| 309 |
| 310 void SpellcheckService::UpdateFeedbackSenderState() { |
| 311 if (SpellingServiceClient::IsAvailable( |
| 312 context_, SpellingServiceClient::SPELLCHECK)) { |
| 313 feedback_sender_->StartFeedbackCollection(); |
| 314 } else { |
| 315 feedback_sender_->StopFeedbackCollection(); |
| 316 } |
| 317 } |
OLD | NEW |