| 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/ui/webui/options/language_options_handler_common.h" | 5 #include "chrome/browser/ui/webui/options/language_options_handler_common.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 } | 124 } |
| 125 | 125 |
| 126 localized_strings->Set("translateSupportedLanguages", languages_list); | 126 localized_strings->Set("translateSupportedLanguages", languages_list); |
| 127 } | 127 } |
| 128 | 128 |
| 129 void LanguageOptionsHandlerCommon::Uninitialize() { | 129 void LanguageOptionsHandlerCommon::Uninitialize() { |
| 130 SpellcheckService* service = GetSpellcheckService(); | 130 SpellcheckService* service = GetSpellcheckService(); |
| 131 if (!service) | 131 if (!service) |
| 132 return; | 132 return; |
| 133 | 133 |
| 134 for (auto* dict : service->GetHunspellDictionaries()) | 134 for (const auto& dict : service->GetHunspellDictionaries()) |
| 135 dict->RemoveObserver(this); | 135 dict->RemoveObserver(this); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void LanguageOptionsHandlerCommon::RegisterMessages() { | 138 void LanguageOptionsHandlerCommon::RegisterMessages() { |
| 139 web_ui()->RegisterMessageCallback("languageOptionsOpen", | 139 web_ui()->RegisterMessageCallback("languageOptionsOpen", |
| 140 base::Bind( | 140 base::Bind( |
| 141 &LanguageOptionsHandlerCommon::LanguageOptionsOpenCallback, | 141 &LanguageOptionsHandlerCommon::LanguageOptionsOpenCallback, |
| 142 base::Unretained(this))); | 142 base::Unretained(this))); |
| 143 web_ui()->RegisterMessageCallback("spellCheckLanguageChange", | 143 web_ui()->RegisterMessageCallback("spellCheckLanguageChange", |
| 144 base::Bind( | 144 base::Bind( |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 return dictionary; | 203 return dictionary; |
| 204 } | 204 } |
| 205 | 205 |
| 206 void LanguageOptionsHandlerCommon::LanguageOptionsOpenCallback( | 206 void LanguageOptionsHandlerCommon::LanguageOptionsOpenCallback( |
| 207 const base::ListValue* args) { | 207 const base::ListValue* args) { |
| 208 content::RecordAction(UserMetricsAction("LanguageOptions_Open")); | 208 content::RecordAction(UserMetricsAction("LanguageOptions_Open")); |
| 209 SpellcheckService* service = GetSpellcheckService(); | 209 SpellcheckService* service = GetSpellcheckService(); |
| 210 if (!service) | 210 if (!service) |
| 211 return; | 211 return; |
| 212 | 212 |
| 213 for (auto* dictionary : service->GetHunspellDictionaries()) { | 213 for (const auto& dictionary : service->GetHunspellDictionaries()) { |
| 214 dictionary->RemoveObserver(this); | 214 dictionary->RemoveObserver(this); |
| 215 dictionary->AddObserver(this); | 215 dictionary->AddObserver(this); |
| 216 | 216 |
| 217 if (dictionary->IsDownloadInProgress()) | 217 if (dictionary->IsDownloadInProgress()) |
| 218 OnHunspellDictionaryDownloadBegin(dictionary->GetLanguage()); | 218 OnHunspellDictionaryDownloadBegin(dictionary->GetLanguage()); |
| 219 else if (dictionary->IsDownloadFailure()) | 219 else if (dictionary->IsDownloadFailure()) |
| 220 OnHunspellDictionaryDownloadFailure(dictionary->GetLanguage()); | 220 OnHunspellDictionaryDownloadFailure(dictionary->GetLanguage()); |
| 221 else | 221 else |
| 222 OnHunspellDictionaryDownloadSuccess(dictionary->GetLanguage()); | 222 OnHunspellDictionaryDownloadSuccess(dictionary->GetLanguage()); |
| 223 } | 223 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 242 const std::string language_code = | 242 const std::string language_code = |
| 243 base::UTF16ToASCII(ExtractStringValue(args)); | 243 base::UTF16ToASCII(ExtractStringValue(args)); |
| 244 const std::string action = base::StringPrintf( | 244 const std::string action = base::StringPrintf( |
| 245 "LanguageOptions_SpellCheckLanguageChange_%s", language_code.c_str()); | 245 "LanguageOptions_SpellCheckLanguageChange_%s", language_code.c_str()); |
| 246 content::RecordComputedAction(action); | 246 content::RecordComputedAction(action); |
| 247 | 247 |
| 248 SpellcheckService* service = GetSpellcheckService(); | 248 SpellcheckService* service = GetSpellcheckService(); |
| 249 if (!service) | 249 if (!service) |
| 250 return; | 250 return; |
| 251 | 251 |
| 252 for (auto* dictionary : service->GetHunspellDictionaries()) { | 252 for (const auto& dictionary : service->GetHunspellDictionaries()) { |
| 253 dictionary->RemoveObserver(this); | 253 dictionary->RemoveObserver(this); |
| 254 dictionary->AddObserver(this); | 254 dictionary->AddObserver(this); |
| 255 } | 255 } |
| 256 } | 256 } |
| 257 | 257 |
| 258 void LanguageOptionsHandlerCommon::UpdateLanguageListCallback( | 258 void LanguageOptionsHandlerCommon::UpdateLanguageListCallback( |
| 259 const base::ListValue* args) { | 259 const base::ListValue* args) { |
| 260 CHECK_EQ(args->GetSize(), 1u); | 260 CHECK_EQ(args->GetSize(), 1u); |
| 261 const base::ListValue* language_list; | 261 const base::ListValue* language_list; |
| 262 args->GetList(0, &language_list); | 262 args->GetList(0, &language_list); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 276 translate_prefs->UpdateLanguageList(languages); | 276 translate_prefs->UpdateLanguageList(languages); |
| 277 } | 277 } |
| 278 | 278 |
| 279 void LanguageOptionsHandlerCommon::RetrySpellcheckDictionaryDownload( | 279 void LanguageOptionsHandlerCommon::RetrySpellcheckDictionaryDownload( |
| 280 const base::ListValue* args) { | 280 const base::ListValue* args) { |
| 281 std::string language = base::UTF16ToUTF8(ExtractStringValue(args)); | 281 std::string language = base::UTF16ToUTF8(ExtractStringValue(args)); |
| 282 SpellcheckService* service = GetSpellcheckService(); | 282 SpellcheckService* service = GetSpellcheckService(); |
| 283 if (!service) | 283 if (!service) |
| 284 return; | 284 return; |
| 285 | 285 |
| 286 for (auto* dictionary : service->GetHunspellDictionaries()) { | 286 for (const auto& dictionary : service->GetHunspellDictionaries()) { |
| 287 if (dictionary->GetLanguage() == language) { | 287 if (dictionary->GetLanguage() == language) { |
| 288 dictionary->RetryDownloadDictionary( | 288 dictionary->RetryDownloadDictionary( |
| 289 Profile::FromWebUI(web_ui())->GetRequestContext()); | 289 Profile::FromWebUI(web_ui())->GetRequestContext()); |
| 290 return; | 290 return; |
| 291 } | 291 } |
| 292 } | 292 } |
| 293 } | 293 } |
| 294 | 294 |
| 295 SpellcheckService* LanguageOptionsHandlerCommon::GetSpellcheckService() { | 295 SpellcheckService* LanguageOptionsHandlerCommon::GetSpellcheckService() { |
| 296 return SpellcheckServiceFactory::GetForContext(Profile::FromWebUI(web_ui())); | 296 return SpellcheckServiceFactory::GetForContext(Profile::FromWebUI(web_ui())); |
| 297 } | 297 } |
| 298 | 298 |
| 299 } // namespace options | 299 } // namespace options |
| OLD | NEW |