| 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 <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/spellcheck_factory.h" | 14 #include "chrome/browser/spellchecker/spellcheck_factory.h" |
| 15 #include "chrome/browser/spellchecker/spellcheck_hunspell_dictionary.h" | 15 #include "chrome/browser/spellchecker/spellcheck_hunspell_dictionary.h" |
| 16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 17 #include "components/prefs/pref_member.h" | 17 #include "components/prefs/pref_member.h" |
| 18 #include "components/prefs/pref_service.h" | 18 #include "components/prefs/pref_service.h" |
| 19 #include "components/spellcheck/browser/feedback_sender.h" | 19 #include "components/spellcheck/browser/feedback_sender.h" |
| 20 #include "components/spellcheck/browser/pref_names.h" | 20 #include "components/spellcheck/browser/pref_names.h" |
| 21 #include "components/spellcheck/browser/spellcheck_host_metrics.h" | 21 #include "components/spellcheck/browser/spellcheck_host_metrics.h" |
| 22 #include "components/spellcheck/browser/spellcheck_platform.h" | 22 #include "components/spellcheck/browser/spellcheck_platform.h" |
| 23 #include "components/spellcheck/browser/spelling_service_client.h" | 23 #include "components/spellcheck/browser/spelling_service_client.h" |
| 24 #include "components/spellcheck/common/spellcheck_bdict_language.h" | 24 #include "components/spellcheck/common/spellcheck_bdict_language.h" |
| 25 #include "components/spellcheck/common/spellcheck_common.h" | 25 #include "components/spellcheck/common/spellcheck_common.h" |
| 26 #include "components/spellcheck/common/spellcheck_messages.h" | 26 #include "components/spellcheck/common/spellcheck_messages.h" |
| 27 #include "components/spellcheck/spellcheck_build_features.h" |
| 27 #include "components/user_prefs/user_prefs.h" | 28 #include "components/user_prefs/user_prefs.h" |
| 28 #include "content/public/browser/browser_context.h" | 29 #include "content/public/browser/browser_context.h" |
| 29 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
| 30 #include "content/public/browser/notification_service.h" | 31 #include "content/public/browser/notification_service.h" |
| 31 #include "content/public/browser/notification_types.h" | 32 #include "content/public/browser/notification_types.h" |
| 32 #include "content/public/browser/render_process_host.h" | 33 #include "content/public/browser/render_process_host.h" |
| 33 #include "content/public/browser/storage_partition.h" | 34 #include "content/public/browser/storage_partition.h" |
| 34 #include "ipc/ipc_platform_file.h" | 35 #include "ipc/ipc_platform_file.h" |
| 35 | 36 |
| 36 using content::BrowserThread; | 37 using content::BrowserThread; |
| 37 | 38 |
| 38 // TODO(rlp): I do not like globals, but keeping these for now during | 39 // TODO(rlp): I do not like globals, but keeping these for now during |
| 39 // transition. | 40 // transition. |
| 40 // An event used by browser tests to receive status events from this class and | 41 // An event used by browser tests to receive status events from this class and |
| 41 // its derived classes. | 42 // its derived classes. |
| 42 base::WaitableEvent* g_status_event = NULL; | 43 base::WaitableEvent* g_status_event = NULL; |
| 43 SpellcheckService::EventType g_status_type = | 44 SpellcheckService::EventType g_status_type = |
| 44 SpellcheckService::BDICT_NOTINITIALIZED; | 45 SpellcheckService::BDICT_NOTINITIALIZED; |
| 45 | 46 |
| 46 SpellcheckService::SpellcheckService(content::BrowserContext* context) | 47 SpellcheckService::SpellcheckService(content::BrowserContext* context) |
| 47 : context_(context), | 48 : context_(context), |
| 48 weak_ptr_factory_(this) { | 49 weak_ptr_factory_(this) { |
| 49 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 50 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 50 PrefService* prefs = user_prefs::UserPrefs::Get(context); | 51 PrefService* prefs = user_prefs::UserPrefs::Get(context); |
| 51 pref_change_registrar_.Init(prefs); | 52 pref_change_registrar_.Init(prefs); |
| 52 StringListPrefMember dictionaries_pref; | 53 StringListPrefMember dictionaries_pref; |
| 53 dictionaries_pref.Init(spellcheck::prefs::kSpellCheckDictionaries, prefs); | 54 dictionaries_pref.Init(spellcheck::prefs::kSpellCheckDictionaries, prefs); |
| 54 std::string first_of_dictionaries; | 55 std::string first_of_dictionaries; |
| 55 | 56 |
| 56 #if defined(USE_BROWSER_SPELLCHECKER) | 57 #if BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
| 57 // Ensure that the renderer always knows the platform spellchecking language. | 58 // Ensure that the renderer always knows the platform spellchecking language. |
| 58 // This language is used for initialization of the text iterator. If the | 59 // This language is used for initialization of the text iterator. If the |
| 59 // iterator is not initialized, then the context menu does not show spellcheck | 60 // iterator is not initialized, then the context menu does not show spellcheck |
| 60 // suggestions. | 61 // suggestions. |
| 61 // | 62 // |
| 62 // No migration is necessary, because the spellcheck language preference is | 63 // No migration is necessary, because the spellcheck language preference is |
| 63 // not user visible or modifiable in Chrome on Mac. | 64 // not user visible or modifiable in Chrome on Mac. |
| 64 dictionaries_pref.SetValue(std::vector<std::string>( | 65 dictionaries_pref.SetValue(std::vector<std::string>( |
| 65 1, spellcheck_platform::GetSpellCheckerLanguage())); | 66 1, spellcheck_platform::GetSpellCheckerLanguage())); |
| 66 first_of_dictionaries = dictionaries_pref.GetValue().front(); | 67 first_of_dictionaries = dictionaries_pref.GetValue().front(); |
| 67 #else | 68 #else |
| 68 // Migrate preferences from single-language to multi-language schema. | 69 // Migrate preferences from single-language to multi-language schema. |
| 69 StringPrefMember single_dictionary_pref; | 70 StringPrefMember single_dictionary_pref; |
| 70 single_dictionary_pref.Init(spellcheck::prefs::kSpellCheckDictionary, prefs); | 71 single_dictionary_pref.Init(spellcheck::prefs::kSpellCheckDictionary, prefs); |
| 71 std::string single_dictionary = single_dictionary_pref.GetValue(); | 72 std::string single_dictionary = single_dictionary_pref.GetValue(); |
| 72 | 73 |
| 73 if (!dictionaries_pref.GetValue().empty()) | 74 if (!dictionaries_pref.GetValue().empty()) |
| 74 first_of_dictionaries = dictionaries_pref.GetValue().front(); | 75 first_of_dictionaries = dictionaries_pref.GetValue().front(); |
| 75 | 76 |
| 76 if (first_of_dictionaries.empty() && !single_dictionary.empty()) { | 77 if (first_of_dictionaries.empty() && !single_dictionary.empty()) { |
| 77 first_of_dictionaries = single_dictionary; | 78 first_of_dictionaries = single_dictionary; |
| 78 dictionaries_pref.SetValue( | 79 dictionaries_pref.SetValue( |
| 79 std::vector<std::string>(1, first_of_dictionaries)); | 80 std::vector<std::string>(1, first_of_dictionaries)); |
| 80 } | 81 } |
| 81 | 82 |
| 82 single_dictionary_pref.SetValue(""); | 83 single_dictionary_pref.SetValue(""); |
| 83 #endif // defined(USE_BROWSER_SPELLCHECKER) | 84 #endif // BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
| 84 | 85 |
| 85 std::string language_code; | 86 std::string language_code; |
| 86 std::string country_code; | 87 std::string country_code; |
| 87 spellcheck::GetISOLanguageCountryCodeFromLocale( | 88 spellcheck::GetISOLanguageCountryCodeFromLocale( |
| 88 first_of_dictionaries, &language_code, &country_code); | 89 first_of_dictionaries, &language_code, &country_code); |
| 89 feedback_sender_.reset(new spellcheck::FeedbackSender( | 90 feedback_sender_.reset(new spellcheck::FeedbackSender( |
| 90 content::BrowserContext::GetDefaultStoragePartition(context)-> | 91 content::BrowserContext::GetDefaultStoragePartition(context)-> |
| 91 GetURLRequestContext(), | 92 GetURLRequestContext(), |
| 92 language_code, country_code)); | 93 language_code, country_code)); |
| 93 | 94 |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 spellcheck::GetISOLanguageCountryCodeFromLocale( | 375 spellcheck::GetISOLanguageCountryCodeFromLocale( |
| 375 feedback_language, &language_code, &country_code); | 376 feedback_language, &language_code, &country_code); |
| 376 feedback_sender_->OnLanguageCountryChange(language_code, country_code); | 377 feedback_sender_->OnLanguageCountryChange(language_code, country_code); |
| 377 if (SpellingServiceClient::IsAvailable( | 378 if (SpellingServiceClient::IsAvailable( |
| 378 context_, SpellingServiceClient::SPELLCHECK)) { | 379 context_, SpellingServiceClient::SPELLCHECK)) { |
| 379 feedback_sender_->StartFeedbackCollection(); | 380 feedback_sender_->StartFeedbackCollection(); |
| 380 } else { | 381 } else { |
| 381 feedback_sender_->StopFeedbackCollection(); | 382 feedback_sender_->StopFeedbackCollection(); |
| 382 } | 383 } |
| 383 } | 384 } |
| OLD | NEW |