| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/extensions/api/language_settings_private/language_setti
ngs_private_delegate.h" | 5 #include "chrome/browser/extensions/api/language_settings_private/language_setti
ngs_private_delegate.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/memory/linked_ptr.h" | 14 #include "base/memory/linked_ptr.h" |
| 15 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/chrome_notification_types.h" | 18 #include "chrome/browser/chrome_notification_types.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/spellchecker/spellcheck_factory.h" | 20 #include "chrome/browser/spellchecker/spellcheck_factory.h" |
| 21 #include "chrome/browser/spellchecker/spellcheck_service.h" | 21 #include "chrome/browser/spellchecker/spellcheck_service.h" |
| 22 #include "chrome/common/pref_names.h" | |
| 23 #include "components/prefs/pref_service.h" | 22 #include "components/prefs/pref_service.h" |
| 23 #include "components/spellcheck/browser/pref_names.h" |
| 24 #include "content/public/browser/browser_context.h" | 24 #include "content/public/browser/browser_context.h" |
| 25 #include "content/public/browser/notification_source.h" | 25 #include "content/public/browser/notification_source.h" |
| 26 | 26 |
| 27 namespace extensions { | 27 namespace extensions { |
| 28 | 28 |
| 29 namespace language_settings_private = api::language_settings_private; | 29 namespace language_settings_private = api::language_settings_private; |
| 30 | 30 |
| 31 LanguageSettingsPrivateDelegate::LanguageSettingsPrivateDelegate( | 31 LanguageSettingsPrivateDelegate::LanguageSettingsPrivateDelegate( |
| 32 content::BrowserContext* context) | 32 content::BrowserContext* context) |
| 33 : custom_dictionary_(nullptr), | 33 : custom_dictionary_(nullptr), |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 bool should_listen = | 203 bool should_listen = |
| 204 event_router->HasEventListener(language_settings_private:: | 204 event_router->HasEventListener(language_settings_private:: |
| 205 OnSpellcheckDictionariesChanged::kEventName) || | 205 OnSpellcheckDictionariesChanged::kEventName) || |
| 206 event_router->HasEventListener(language_settings_private:: | 206 event_router->HasEventListener(language_settings_private:: |
| 207 OnCustomDictionaryChanged::kEventName); | 207 OnCustomDictionaryChanged::kEventName); |
| 208 | 208 |
| 209 if (should_listen && !listening_spellcheck_) { | 209 if (should_listen && !listening_spellcheck_) { |
| 210 // Update and observe the hunspell dictionaries. | 210 // Update and observe the hunspell dictionaries. |
| 211 RefreshDictionaries(listening_spellcheck_, should_listen); | 211 RefreshDictionaries(listening_spellcheck_, should_listen); |
| 212 // Observe the dictionaries preference. | 212 // Observe the dictionaries preference. |
| 213 pref_change_registrar_.Add(prefs::kSpellCheckDictionaries, base::Bind( | 213 pref_change_registrar_.Add( |
| 214 &LanguageSettingsPrivateDelegate::OnSpellcheckDictionariesChanged, | 214 spellcheck::prefs::kSpellCheckDictionaries, |
| 215 base::Unretained(this))); | 215 base::Bind( |
| 216 &LanguageSettingsPrivateDelegate::OnSpellcheckDictionariesChanged, |
| 217 base::Unretained(this))); |
| 216 // Observe the dictionary of custom words. | 218 // Observe the dictionary of custom words. |
| 217 if (custom_dictionary_) | 219 if (custom_dictionary_) |
| 218 custom_dictionary_->AddObserver(this); | 220 custom_dictionary_->AddObserver(this); |
| 219 } else if (!should_listen && listening_spellcheck_) { | 221 } else if (!should_listen && listening_spellcheck_) { |
| 220 // Stop observing any dictionaries that still exist. | 222 // Stop observing any dictionaries that still exist. |
| 221 RemoveDictionaryObservers(); | 223 RemoveDictionaryObservers(); |
| 222 hunspell_dictionaries_.clear(); | 224 hunspell_dictionaries_.clear(); |
| 223 pref_change_registrar_.Remove(prefs::kSpellCheckDictionaries); | 225 pref_change_registrar_.Remove(spellcheck::prefs::kSpellCheckDictionaries); |
| 224 if (custom_dictionary_) | 226 if (custom_dictionary_) |
| 225 custom_dictionary_->RemoveObserver(this); | 227 custom_dictionary_->RemoveObserver(this); |
| 226 } | 228 } |
| 227 | 229 |
| 228 listening_spellcheck_ = should_listen; | 230 listening_spellcheck_ = should_listen; |
| 229 } | 231 } |
| 230 | 232 |
| 231 void LanguageSettingsPrivateDelegate::OnSpellcheckDictionariesChanged() { | 233 void LanguageSettingsPrivateDelegate::OnSpellcheckDictionariesChanged() { |
| 232 RefreshDictionaries(listening_spellcheck_, listening_spellcheck_); | 234 RefreshDictionaries(listening_spellcheck_, listening_spellcheck_); |
| 233 BroadcastDictionariesChangedEvent(); | 235 BroadcastDictionariesChangedEvent(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 248 } | 250 } |
| 249 | 251 |
| 250 void LanguageSettingsPrivateDelegate::RemoveDictionaryObservers() { | 252 void LanguageSettingsPrivateDelegate::RemoveDictionaryObservers() { |
| 251 for (const auto& dictionary : hunspell_dictionaries_) { | 253 for (const auto& dictionary : hunspell_dictionaries_) { |
| 252 if (dictionary) | 254 if (dictionary) |
| 253 dictionary->RemoveObserver(this); | 255 dictionary->RemoveObserver(this); |
| 254 } | 256 } |
| 255 } | 257 } |
| 256 | 258 |
| 257 } // namespace extensions | 259 } // namespace extensions |
| OLD | NEW |