| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/translate/translate_language_list.h" | 5 #include "chrome/browser/translate/translate_language_list.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| 11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/browser_process.h" | |
| 17 #include "chrome/browser/translate/chrome_translate_delegate.h" | |
| 18 #include "chrome/browser/translate/translate_manager.h" | 16 #include "chrome/browser/translate/translate_manager.h" |
| 19 #include "chrome/browser/translate/translate_url_util.h" | 17 #include "chrome/browser/translate/translate_url_util.h" |
| 20 #include "components/translate/core/browser/translate_browser_metrics.h" | 18 #include "components/translate/core/browser/translate_browser_metrics.h" |
| 19 #include "components/translate/core/browser/translate_download_manager.h" |
| 21 #include "components/translate/core/browser/translate_event_details.h" | 20 #include "components/translate/core/browser/translate_event_details.h" |
| 22 #include "components/translate/core/browser/translate_url_fetcher.h" | 21 #include "components/translate/core/browser/translate_url_fetcher.h" |
| 23 #include "net/base/url_util.h" | 22 #include "net/base/url_util.h" |
| 24 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 25 #include "url/gurl.h" | 24 #include "url/gurl.h" |
| 26 | 25 |
| 27 namespace { | 26 namespace { |
| 28 | 27 |
| 29 // The default list of languages the Google translation server supports. | 28 // The default list of languages the Google translation server supports. |
| 30 // We use this list until we receive the list that the server exposes. | 29 // We use this list until we receive the list that the server exposes. |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 base::DictionaryValue* language_dict = | 160 base::DictionaryValue* language_dict = |
| 162 static_cast<base::DictionaryValue*>(json_value.get()); | 161 static_cast<base::DictionaryValue*>(json_value.get()); |
| 163 base::DictionaryValue* target_languages = NULL; | 162 base::DictionaryValue* target_languages = NULL; |
| 164 if (!language_dict->GetDictionary(TranslateLanguageList::kTargetLanguagesKey, | 163 if (!language_dict->GetDictionary(TranslateLanguageList::kTargetLanguagesKey, |
| 165 &target_languages) || | 164 &target_languages) || |
| 166 target_languages == NULL) { | 165 target_languages == NULL) { |
| 167 NOTREACHED(); | 166 NOTREACHED(); |
| 168 return; | 167 return; |
| 169 } | 168 } |
| 170 | 169 |
| 171 const std::string& locale = g_browser_process->GetApplicationLocale(); | 170 const std::string& locale = |
| 171 TranslateDownloadManager::GetInstance()->application_locale(); |
| 172 | 172 |
| 173 // Now we can clear language list. | 173 // Now we can clear language list. |
| 174 target_language_set->clear(); | 174 target_language_set->clear(); |
| 175 std::string message; | 175 std::string message; |
| 176 // ... and replace it with the values we just fetched from the server. | 176 // ... and replace it with the values we just fetched from the server. |
| 177 for (base::DictionaryValue::Iterator iter(*target_languages); | 177 for (base::DictionaryValue::Iterator iter(*target_languages); |
| 178 !iter.IsAtEnd(); | 178 !iter.IsAtEnd(); |
| 179 iter.Advance()) { | 179 iter.Advance()) { |
| 180 const std::string& lang = iter.key(); | 180 const std::string& lang = iter.key(); |
| 181 if (!l10n_util::IsLocaleNameTranslated(lang.c_str(), locale)) { | 181 if (!l10n_util::IsLocaleNameTranslated(lang.c_str(), locale)) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 TranslateLanguageList::TranslateLanguageList() { | 220 TranslateLanguageList::TranslateLanguageList() { |
| 221 // We default to our hard coded list of languages in | 221 // We default to our hard coded list of languages in |
| 222 // |kDefaultSupportedLanguages|. This list will be overriden by a server | 222 // |kDefaultSupportedLanguages|. This list will be overriden by a server |
| 223 // providing supported langauges list. | 223 // providing supported langauges list. |
| 224 for (size_t i = 0; i < arraysize(kDefaultSupportedLanguages); ++i) | 224 for (size_t i = 0; i < arraysize(kDefaultSupportedLanguages); ++i) |
| 225 all_supported_languages_.insert(kDefaultSupportedLanguages[i]); | 225 all_supported_languages_.insert(kDefaultSupportedLanguages[i]); |
| 226 | 226 |
| 227 if (update_is_disabled) | 227 if (update_is_disabled) |
| 228 return; | 228 return; |
| 229 | 229 |
| 230 language_list_fetcher_.reset(new TranslateURLFetcher( | 230 language_list_fetcher_.reset(new TranslateURLFetcher(kFetcherId)); |
| 231 kFetcherId, ChromeTranslateDelegate::GetInstance())); | |
| 232 language_list_fetcher_->set_max_retry_on_5xx(kMaxRetryOn5xx); | 231 language_list_fetcher_->set_max_retry_on_5xx(kMaxRetryOn5xx); |
| 233 } | 232 } |
| 234 | 233 |
| 235 TranslateLanguageList::~TranslateLanguageList() { | 234 TranslateLanguageList::~TranslateLanguageList() { |
| 236 } | 235 } |
| 237 | 236 |
| 238 void TranslateLanguageList::GetSupportedLanguages( | 237 void TranslateLanguageList::GetSupportedLanguages( |
| 239 std::vector<std::string>* languages) { | 238 std::vector<std::string>* languages) { |
| 240 DCHECK(languages && languages->empty()); | 239 DCHECK(languages && languages->empty()); |
| 241 std::set<std::string>::const_iterator iter = all_supported_languages_.begin(); | 240 std::set<std::string>::const_iterator iter = all_supported_languages_.begin(); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 | 321 |
| 323 NotifyEvent(__LINE__, "Language list is updated"); | 322 NotifyEvent(__LINE__, "Language list is updated"); |
| 324 | 323 |
| 325 DCHECK_EQ(kFetcherId, id); | 324 DCHECK_EQ(kFetcherId, id); |
| 326 | 325 |
| 327 SetSupportedLanguages(data, &all_supported_languages_, &alpha_languages_); | 326 SetSupportedLanguages(data, &all_supported_languages_, &alpha_languages_); |
| 328 language_list_fetcher_.reset(); | 327 language_list_fetcher_.reset(); |
| 329 | 328 |
| 330 last_updated_ = base::Time::Now(); | 329 last_updated_ = base::Time::Now(); |
| 331 } | 330 } |
| OLD | NEW |