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

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

Issue 2177343002: Componentize spellcheck [2]: move common/ files to component. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move message generator to component Created 4 years, 4 months 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
OLDNEW
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 <set> 7 #include <set>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
11 #include "base/supports_user_data.h" 11 #include "base/supports_user_data.h"
12 #include "base/synchronization/waitable_event.h" 12 #include "base/synchronization/waitable_event.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "chrome/browser/spellchecker/feedback_sender.h" 14 #include "chrome/browser/spellchecker/feedback_sender.h"
15 #include "chrome/browser/spellchecker/spellcheck_factory.h" 15 #include "chrome/browser/spellchecker/spellcheck_factory.h"
16 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" 16 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h"
17 #include "chrome/browser/spellchecker/spellcheck_hunspell_dictionary.h" 17 #include "chrome/browser/spellchecker/spellcheck_hunspell_dictionary.h"
18 #include "chrome/browser/spellchecker/spellcheck_platform.h" 18 #include "chrome/browser/spellchecker/spellcheck_platform.h"
19 #include "chrome/browser/spellchecker/spelling_service_client.h" 19 #include "chrome/browser/spellchecker/spelling_service_client.h"
20 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
21 #include "chrome/common/spellcheck_bdict_language.h"
22 #include "chrome/common/spellcheck_common.h"
23 #include "chrome/common/spellcheck_messages.h"
24 #include "components/prefs/pref_member.h" 21 #include "components/prefs/pref_member.h"
25 #include "components/prefs/pref_service.h" 22 #include "components/prefs/pref_service.h"
23 #include "components/spellcheck/common/spellcheck_bdict_language.h"
24 #include "components/spellcheck/common/spellcheck_common.h"
25 #include "components/spellcheck/common/spellcheck_messages.h"
26 #include "components/user_prefs/user_prefs.h" 26 #include "components/user_prefs/user_prefs.h"
27 #include "content/public/browser/browser_context.h" 27 #include "content/public/browser/browser_context.h"
28 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
29 #include "content/public/browser/notification_service.h" 29 #include "content/public/browser/notification_service.h"
30 #include "content/public/browser/notification_types.h" 30 #include "content/public/browser/notification_types.h"
31 #include "content/public/browser/render_process_host.h" 31 #include "content/public/browser/render_process_host.h"
32 #include "content/public/browser/storage_partition.h" 32 #include "content/public/browser/storage_partition.h"
33 #include "ipc/ipc_platform_file.h" 33 #include "ipc/ipc_platform_file.h"
34 34
35 using content::BrowserThread; 35 using content::BrowserThread;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 first_of_dictionaries = single_dictionary; 76 first_of_dictionaries = single_dictionary;
77 dictionaries_pref.SetValue( 77 dictionaries_pref.SetValue(
78 std::vector<std::string>(1, first_of_dictionaries)); 78 std::vector<std::string>(1, first_of_dictionaries));
79 } 79 }
80 80
81 single_dictionary_pref.SetValue(""); 81 single_dictionary_pref.SetValue("");
82 #endif // defined(USE_BROWSER_SPELLCHECKER) 82 #endif // defined(USE_BROWSER_SPELLCHECKER)
83 83
84 std::string language_code; 84 std::string language_code;
85 std::string country_code; 85 std::string country_code;
86 chrome::spellcheck_common::GetISOLanguageCountryCodeFromLocale( 86 spellcheck::GetISOLanguageCountryCodeFromLocale(
87 first_of_dictionaries, 87 first_of_dictionaries, &language_code, &country_code);
88 &language_code,
89 &country_code);
90 feedback_sender_.reset(new spellcheck::FeedbackSender( 88 feedback_sender_.reset(new spellcheck::FeedbackSender(
91 content::BrowserContext::GetDefaultStoragePartition(context)-> 89 content::BrowserContext::GetDefaultStoragePartition(context)->
92 GetURLRequestContext(), 90 GetURLRequestContext(),
93 language_code, country_code)); 91 language_code, country_code));
94 92
95 pref_change_registrar_.Add( 93 pref_change_registrar_.Add(
96 prefs::kSpellCheckDictionaries, 94 prefs::kSpellCheckDictionaries,
97 base::Bind(&SpellcheckService::OnSpellCheckDictionariesChanged, 95 base::Bind(&SpellcheckService::OnSpellCheckDictionariesChanged,
98 base::Unretained(this))); 96 base::Unretained(this)));
99 pref_change_registrar_.Add( 97 pref_change_registrar_.Add(
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 spellcheck_dictionaries.insert(dictionary); 140 spellcheck_dictionaries.insert(dictionary);
143 } 141 }
144 142
145 dictionaries->clear(); 143 dictionaries->clear();
146 std::vector<std::string> accept_languages = 144 std::vector<std::string> accept_languages =
147 base::SplitString(prefs->GetString(prefs::kAcceptLanguages), ",", 145 base::SplitString(prefs->GetString(prefs::kAcceptLanguages), ",",
148 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 146 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
149 for (const auto& accept_language : accept_languages) { 147 for (const auto& accept_language : accept_languages) {
150 Dictionary dictionary; 148 Dictionary dictionary;
151 dictionary.language = 149 dictionary.language =
152 chrome::spellcheck_common::GetCorrespondingSpellCheckLanguage( 150 spellcheck::GetCorrespondingSpellCheckLanguage(accept_language);
153 accept_language);
154 if (dictionary.language.empty()) 151 if (dictionary.language.empty())
155 continue; 152 continue;
156 153
157 dictionary.used_for_spellcheck = 154 dictionary.used_for_spellcheck =
158 spellcheck_dictionaries.count(dictionary.language) > 0; 155 spellcheck_dictionaries.count(dictionary.language) > 0;
159 dictionaries->push_back(dictionary); 156 dictionaries->push_back(dictionary);
160 } 157 }
161 } 158 }
162 #endif // !OS_MACOSX 159 #endif // !OS_MACOSX
163 160
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 if (metrics_) 337 if (metrics_)
341 metrics_->RecordSpellingServiceStats(enabled); 338 metrics_->RecordSpellingServiceStats(enabled);
342 UpdateFeedbackSenderState(); 339 UpdateFeedbackSenderState();
343 } 340 }
344 341
345 void SpellcheckService::OnAcceptLanguagesChanged() { 342 void SpellcheckService::OnAcceptLanguagesChanged() {
346 PrefService* prefs = user_prefs::UserPrefs::Get(context_); 343 PrefService* prefs = user_prefs::UserPrefs::Get(context_);
347 std::vector<std::string> accept_languages = 344 std::vector<std::string> accept_languages =
348 base::SplitString(prefs->GetString(prefs::kAcceptLanguages), ",", 345 base::SplitString(prefs->GetString(prefs::kAcceptLanguages), ",",
349 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 346 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
350 std::transform( 347 std::transform(accept_languages.begin(), accept_languages.end(),
351 accept_languages.begin(), accept_languages.end(), 348 accept_languages.begin(),
352 accept_languages.begin(), 349 &spellcheck::GetCorrespondingSpellCheckLanguage);
353 &chrome::spellcheck_common::GetCorrespondingSpellCheckLanguage);
354 350
355 StringListPrefMember dictionaries_pref; 351 StringListPrefMember dictionaries_pref;
356 dictionaries_pref.Init(prefs::kSpellCheckDictionaries, prefs); 352 dictionaries_pref.Init(prefs::kSpellCheckDictionaries, prefs);
357 std::vector<std::string> dictionaries = dictionaries_pref.GetValue(); 353 std::vector<std::string> dictionaries = dictionaries_pref.GetValue();
358 std::vector<std::string> filtered_dictionaries; 354 std::vector<std::string> filtered_dictionaries;
359 355
360 for (const auto& dictionary : dictionaries) { 356 for (const auto& dictionary : dictionaries) {
361 if (std::find(accept_languages.begin(), accept_languages.end(), 357 if (std::find(accept_languages.begin(), accept_languages.end(),
362 dictionary) != accept_languages.end()) { 358 dictionary) != accept_languages.end()) {
363 filtered_dictionaries.push_back(dictionary); 359 filtered_dictionaries.push_back(dictionary);
364 } 360 }
365 } 361 }
366 362
367 dictionaries_pref.SetValue(filtered_dictionaries); 363 dictionaries_pref.SetValue(filtered_dictionaries);
368 } 364 }
369 365
370 void SpellcheckService::UpdateFeedbackSenderState() { 366 void SpellcheckService::UpdateFeedbackSenderState() {
371 std::string feedback_language; 367 std::string feedback_language;
372 if (!hunspell_dictionaries_.empty()) 368 if (!hunspell_dictionaries_.empty())
373 feedback_language = hunspell_dictionaries_.front()->GetLanguage(); 369 feedback_language = hunspell_dictionaries_.front()->GetLanguage();
374 std::string language_code; 370 std::string language_code;
375 std::string country_code; 371 std::string country_code;
376 chrome::spellcheck_common::GetISOLanguageCountryCodeFromLocale( 372 spellcheck::GetISOLanguageCountryCodeFromLocale(
377 feedback_language, &language_code, &country_code); 373 feedback_language, &language_code, &country_code);
378 feedback_sender_->OnLanguageCountryChange(language_code, country_code); 374 feedback_sender_->OnLanguageCountryChange(language_code, country_code);
379 if (SpellingServiceClient::IsAvailable( 375 if (SpellingServiceClient::IsAvailable(
380 context_, SpellingServiceClient::SPELLCHECK)) { 376 context_, SpellingServiceClient::SPELLCHECK)) {
381 feedback_sender_->StartFeedbackCollection(); 377 feedback_sender_->StartFeedbackCollection();
382 } else { 378 } else {
383 feedback_sender_->StopFeedbackCollection(); 379 feedback_sender_->StopFeedbackCollection();
384 } 380 }
385 } 381 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698