| 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 <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 DCHECK(!listening_spellcheck_); | 63 DCHECK(!listening_spellcheck_); |
| 64 pref_change_registrar_.RemoveAll(); | 64 pref_change_registrar_.RemoveAll(); |
| 65 notification_registrar_.RemoveAll(); | 65 notification_registrar_.RemoveAll(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 LanguageSettingsPrivateDelegate* LanguageSettingsPrivateDelegate::Create( | 68 LanguageSettingsPrivateDelegate* LanguageSettingsPrivateDelegate::Create( |
| 69 content::BrowserContext* context) { | 69 content::BrowserContext* context) { |
| 70 return new LanguageSettingsPrivateDelegate(context); | 70 return new LanguageSettingsPrivateDelegate(context); |
| 71 } | 71 } |
| 72 | 72 |
| 73 ScopedVector<language_settings_private::SpellcheckDictionaryStatus> | 73 std::vector<language_settings_private::SpellcheckDictionaryStatus> |
| 74 LanguageSettingsPrivateDelegate::GetHunspellDictionaryStatuses() { | 74 LanguageSettingsPrivateDelegate::GetHunspellDictionaryStatuses() { |
| 75 ScopedVector<language_settings_private::SpellcheckDictionaryStatus> statuses; | 75 std::vector<language_settings_private::SpellcheckDictionaryStatus> statuses; |
| 76 for (const auto& dictionary : GetHunspellDictionaries()) { | 76 for (const auto& dictionary : GetHunspellDictionaries()) { |
| 77 if (!dictionary) | 77 if (!dictionary) |
| 78 continue; | 78 continue; |
| 79 scoped_ptr<language_settings_private::SpellcheckDictionaryStatus> status( | 79 language_settings_private::SpellcheckDictionaryStatus status; |
| 80 new language_settings_private::SpellcheckDictionaryStatus()); | 80 status.language_code = dictionary->GetLanguage(); |
| 81 status->language_code = dictionary->GetLanguage(); | 81 status.is_ready = dictionary->IsReady(); |
| 82 status->is_ready = dictionary->IsReady(); | 82 if (!status.is_ready) { |
| 83 if (!status->is_ready) { | |
| 84 if (dictionary->IsDownloadInProgress()) | 83 if (dictionary->IsDownloadInProgress()) |
| 85 status->is_downloading.reset(new bool(true)); | 84 status.is_downloading.reset(new bool(true)); |
| 86 if (dictionary->IsDownloadFailure()) | 85 if (dictionary->IsDownloadFailure()) |
| 87 status->download_failed.reset(new bool(true)); | 86 status.download_failed.reset(new bool(true)); |
| 88 } | 87 } |
| 89 statuses.push_back(std::move(status)); | 88 statuses.push_back(std::move(status)); |
| 90 } | 89 } |
| 91 return statuses; | 90 return statuses; |
| 92 } | 91 } |
| 93 | 92 |
| 94 void LanguageSettingsPrivateDelegate::Shutdown() { | 93 void LanguageSettingsPrivateDelegate::Shutdown() { |
| 95 // Unregister with the event router. We first check and see if there *is* an | 94 // Unregister with the event router. We first check and see if there *is* an |
| 96 // event router, because some unit tests try to shutdown all context services, | 95 // event router, because some unit tests try to shutdown all context services, |
| 97 // but didn't initialize the event router first. | 96 // but didn't initialize the event router first. |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 | 227 |
| 229 listening_spellcheck_ = should_listen; | 228 listening_spellcheck_ = should_listen; |
| 230 } | 229 } |
| 231 | 230 |
| 232 void LanguageSettingsPrivateDelegate::OnSpellcheckDictionariesChanged() { | 231 void LanguageSettingsPrivateDelegate::OnSpellcheckDictionariesChanged() { |
| 233 RefreshDictionaries(listening_spellcheck_, listening_spellcheck_); | 232 RefreshDictionaries(listening_spellcheck_, listening_spellcheck_); |
| 234 BroadcastDictionariesChangedEvent(); | 233 BroadcastDictionariesChangedEvent(); |
| 235 } | 234 } |
| 236 | 235 |
| 237 void LanguageSettingsPrivateDelegate::BroadcastDictionariesChangedEvent() { | 236 void LanguageSettingsPrivateDelegate::BroadcastDictionariesChangedEvent() { |
| 238 std::vector<linked_ptr<language_settings_private::SpellcheckDictionaryStatus>> | 237 std::vector<language_settings_private::SpellcheckDictionaryStatus> statuses = |
| 239 broadcast_statuses; | |
| 240 ScopedVector<language_settings_private::SpellcheckDictionaryStatus> statuses = | |
| 241 GetHunspellDictionaryStatuses(); | 238 GetHunspellDictionaryStatuses(); |
| 242 | 239 |
| 243 for (language_settings_private::SpellcheckDictionaryStatus* status : statuses) | |
| 244 broadcast_statuses.push_back(make_linked_ptr(status)); | |
| 245 statuses.weak_clear(); | |
| 246 | |
| 247 scoped_ptr<base::ListValue> args( | 240 scoped_ptr<base::ListValue> args( |
| 248 language_settings_private::OnSpellcheckDictionariesChanged::Create( | 241 language_settings_private::OnSpellcheckDictionariesChanged::Create( |
| 249 broadcast_statuses)); | 242 statuses)); |
| 250 scoped_ptr<extensions::Event> extension_event(new extensions::Event( | 243 scoped_ptr<extensions::Event> extension_event(new extensions::Event( |
| 251 events::LANGUAGE_SETTINGS_PRIVATE_ON_SPELLCHECK_DICTIONARIES_CHANGED, | 244 events::LANGUAGE_SETTINGS_PRIVATE_ON_SPELLCHECK_DICTIONARIES_CHANGED, |
| 252 language_settings_private::OnSpellcheckDictionariesChanged::kEventName, | 245 language_settings_private::OnSpellcheckDictionariesChanged::kEventName, |
| 253 std::move(args))); | 246 std::move(args))); |
| 254 EventRouter::Get(context_)->BroadcastEvent(std::move(extension_event)); | 247 EventRouter::Get(context_)->BroadcastEvent(std::move(extension_event)); |
| 255 } | 248 } |
| 256 | 249 |
| 257 void LanguageSettingsPrivateDelegate::RemoveDictionaryObservers() { | 250 void LanguageSettingsPrivateDelegate::RemoveDictionaryObservers() { |
| 258 for (const auto& dictionary : hunspell_dictionaries_) { | 251 for (const auto& dictionary : hunspell_dictionaries_) { |
| 259 if (dictionary) | 252 if (dictionary) |
| 260 dictionary->RemoveObserver(this); | 253 dictionary->RemoveObserver(this); |
| 261 } | 254 } |
| 262 } | 255 } |
| 263 | 256 |
| 264 } // namespace extensions | 257 } // namespace extensions |
| OLD | NEW |