| 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 <vector> | 9 #include <vector> |
| 9 | 10 |
| 10 #include "base/bind.h" | 11 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 12 #include "base/memory/linked_ptr.h" | 13 #include "base/memory/linked_ptr.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
| 15 #include "base/prefs/pref_service.h" | 16 #include "base/prefs/pref_service.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 17 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 scoped_ptr<language_settings_private::SpellcheckDictionaryStatus> status( | 79 scoped_ptr<language_settings_private::SpellcheckDictionaryStatus> status( |
| 79 new language_settings_private::SpellcheckDictionaryStatus()); | 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) { |
| 83 if (dictionary->IsDownloadInProgress()) | 84 if (dictionary->IsDownloadInProgress()) |
| 84 status->is_downloading.reset(new bool(true)); | 85 status->is_downloading.reset(new bool(true)); |
| 85 if (dictionary->IsDownloadFailure()) | 86 if (dictionary->IsDownloadFailure()) |
| 86 status->download_failed.reset(new bool(true)); | 87 status->download_failed.reset(new bool(true)); |
| 87 } | 88 } |
| 88 statuses.push_back(status.Pass()); | 89 statuses.push_back(std::move(status)); |
| 89 } | 90 } |
| 90 return statuses.Pass(); | 91 return statuses; |
| 91 } | 92 } |
| 92 | 93 |
| 93 void LanguageSettingsPrivateDelegate::Shutdown() { | 94 void LanguageSettingsPrivateDelegate::Shutdown() { |
| 94 // Unregister with the event router. We first check and see if there *is* an | 95 // Unregister with the event router. We first check and see if there *is* an |
| 95 // event router, because some unit tests try to shutdown all context services, | 96 // event router, because some unit tests try to shutdown all context services, |
| 96 // but didn't initialize the event router first. | 97 // but didn't initialize the event router first. |
| 97 EventRouter* event_router = EventRouter::Get(context_); | 98 EventRouter* event_router = EventRouter::Get(context_); |
| 98 if (event_router) | 99 if (event_router) |
| 99 event_router->UnregisterObserver(this); | 100 event_router->UnregisterObserver(this); |
| 100 | 101 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 std::vector<std::string> to_add(change.to_add().begin(), | 158 std::vector<std::string> to_add(change.to_add().begin(), |
| 158 change.to_add().end()); | 159 change.to_add().end()); |
| 159 std::vector<std::string> to_remove(change.to_remove().begin(), | 160 std::vector<std::string> to_remove(change.to_remove().begin(), |
| 160 change.to_remove().end()); | 161 change.to_remove().end()); |
| 161 scoped_ptr<base::ListValue> args( | 162 scoped_ptr<base::ListValue> args( |
| 162 language_settings_private::OnCustomDictionaryChanged::Create( | 163 language_settings_private::OnCustomDictionaryChanged::Create( |
| 163 to_add, to_remove)); | 164 to_add, to_remove)); |
| 164 scoped_ptr<Event> extension_event(new Event( | 165 scoped_ptr<Event> extension_event(new Event( |
| 165 events::LANGUAGE_SETTINGS_PRIVATE_ON_CUSTOM_DICTIONARY_CHANGED, | 166 events::LANGUAGE_SETTINGS_PRIVATE_ON_CUSTOM_DICTIONARY_CHANGED, |
| 166 language_settings_private::OnCustomDictionaryChanged::kEventName, | 167 language_settings_private::OnCustomDictionaryChanged::kEventName, |
| 167 args.Pass())); | 168 std::move(args))); |
| 168 EventRouter::Get(context_)->BroadcastEvent(extension_event.Pass()); | 169 EventRouter::Get(context_)->BroadcastEvent(std::move(extension_event)); |
| 169 } | 170 } |
| 170 | 171 |
| 171 void LanguageSettingsPrivateDelegate::RefreshDictionaries( | 172 void LanguageSettingsPrivateDelegate::RefreshDictionaries( |
| 172 bool was_listening, bool should_listen) { | 173 bool was_listening, bool should_listen) { |
| 173 if (!profile_added_) | 174 if (!profile_added_) |
| 174 return; | 175 return; |
| 175 if (was_listening) | 176 if (was_listening) |
| 176 RemoveDictionaryObservers(); | 177 RemoveDictionaryObservers(); |
| 177 hunspell_dictionaries_.clear(); | 178 hunspell_dictionaries_.clear(); |
| 178 SpellcheckService* service = SpellcheckServiceFactory::GetForContext( | 179 SpellcheckService* service = SpellcheckServiceFactory::GetForContext( |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 for (language_settings_private::SpellcheckDictionaryStatus* status : statuses) | 243 for (language_settings_private::SpellcheckDictionaryStatus* status : statuses) |
| 243 broadcast_statuses.push_back(make_linked_ptr(status)); | 244 broadcast_statuses.push_back(make_linked_ptr(status)); |
| 244 statuses.weak_clear(); | 245 statuses.weak_clear(); |
| 245 | 246 |
| 246 scoped_ptr<base::ListValue> args( | 247 scoped_ptr<base::ListValue> args( |
| 247 language_settings_private::OnSpellcheckDictionariesChanged::Create( | 248 language_settings_private::OnSpellcheckDictionariesChanged::Create( |
| 248 broadcast_statuses)); | 249 broadcast_statuses)); |
| 249 scoped_ptr<extensions::Event> extension_event(new extensions::Event( | 250 scoped_ptr<extensions::Event> extension_event(new extensions::Event( |
| 250 events::LANGUAGE_SETTINGS_PRIVATE_ON_SPELLCHECK_DICTIONARIES_CHANGED, | 251 events::LANGUAGE_SETTINGS_PRIVATE_ON_SPELLCHECK_DICTIONARIES_CHANGED, |
| 251 language_settings_private::OnSpellcheckDictionariesChanged::kEventName, | 252 language_settings_private::OnSpellcheckDictionariesChanged::kEventName, |
| 252 args.Pass())); | 253 std::move(args))); |
| 253 EventRouter::Get(context_)->BroadcastEvent(extension_event.Pass()); | 254 EventRouter::Get(context_)->BroadcastEvent(std::move(extension_event)); |
| 254 } | 255 } |
| 255 | 256 |
| 256 void LanguageSettingsPrivateDelegate::RemoveDictionaryObservers() { | 257 void LanguageSettingsPrivateDelegate::RemoveDictionaryObservers() { |
| 257 for (const auto& dictionary : hunspell_dictionaries_) { | 258 for (const auto& dictionary : hunspell_dictionaries_) { |
| 258 if (dictionary) | 259 if (dictionary) |
| 259 dictionary->RemoveObserver(this); | 260 dictionary->RemoveObserver(this); |
| 260 } | 261 } |
| 261 } | 262 } |
| 262 | 263 |
| 263 } // namespace extensions | 264 } // namespace extensions |
| OLD | NEW |