| 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 "components/translate/core/browser/translate_language_list.h" | 5 #include "components/translate/core/browser/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 "components/translate/core/browser/translate_browser_metrics.h" | 16 #include "components/translate/core/browser/translate_browser_metrics.h" |
| 17 #include "components/translate/core/browser/translate_download_manager.h" | 17 #include "components/translate/core/browser/translate_download_manager.h" |
| 18 #include "components/translate/core/browser/translate_event_details.h" | 18 #include "components/translate/core/browser/translate_event_details.h" |
| 19 #include "components/translate/core/browser/translate_url_fetcher.h" | 19 #include "components/translate/core/browser/translate_url_fetcher.h" |
| 20 #include "components/translate/core/browser/translate_url_util.h" | 20 #include "components/translate/core/browser/translate_url_util.h" |
| 21 #include "components/translate/core/common/translate_util.h" | 21 #include "components/translate/core/common/translate_util.h" |
| 22 #include "net/base/url_util.h" | 22 #include "net/base/url_util.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 24 #include "url/gurl.h" | 24 #include "url/gurl.h" |
| 25 | 25 |
| 26 namespace translate { |
| 27 |
| 26 namespace { | 28 namespace { |
| 27 | 29 |
| 28 // The default list of languages the Google translation server supports. | 30 // The default list of languages the Google translation server supports. |
| 29 // We use this list until we receive the list that the server exposes. | 31 // We use this list until we receive the list that the server exposes. |
| 30 // For information, here is the list of languages that Chrome can be run in | 32 // For information, here is the list of languages that Chrome can be run in |
| 31 // but that the translation server does not support: | 33 // but that the translation server does not support: |
| 32 // am Amharic | 34 // am Amharic |
| 33 // bn Bengali | 35 // bn Bengali |
| 34 // gu Gujarati | 36 // gu Gujarati |
| 35 // kn Kannada | 37 // kn Kannada |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 request_pending_ = true; | 180 request_pending_ = true; |
| 179 return; | 181 return; |
| 180 } | 182 } |
| 181 | 183 |
| 182 request_pending_ = false; | 184 request_pending_ = false; |
| 183 | 185 |
| 184 if (language_list_fetcher_.get() && | 186 if (language_list_fetcher_.get() && |
| 185 (language_list_fetcher_->state() == TranslateURLFetcher::IDLE || | 187 (language_list_fetcher_->state() == TranslateURLFetcher::IDLE || |
| 186 language_list_fetcher_->state() == TranslateURLFetcher::FAILED)) { | 188 language_list_fetcher_->state() == TranslateURLFetcher::FAILED)) { |
| 187 GURL url = TranslateLanguageUrl(); | 189 GURL url = TranslateLanguageUrl(); |
| 188 url = TranslateURLUtil::AddHostLocaleToUrl(url); | 190 url = AddHostLocaleToUrl(url); |
| 189 url = TranslateURLUtil::AddApiKeyToUrl(url); | 191 url = AddApiKeyToUrl(url); |
| 190 url = net::AppendQueryParameter( | 192 url = net::AppendQueryParameter( |
| 191 url, kAlphaLanguageQueryName, kAlphaLanguageQueryValue); | 193 url, kAlphaLanguageQueryName, kAlphaLanguageQueryValue); |
| 192 | 194 |
| 193 std::string message = base::StringPrintf( | 195 std::string message = base::StringPrintf( |
| 194 "Language list including alpha languages fetch starts (URL: %s)", | 196 "Language list including alpha languages fetch starts (URL: %s)", |
| 195 url.spec().c_str()); | 197 url.spec().c_str()); |
| 196 NotifyEvent(__LINE__, message); | 198 NotifyEvent(__LINE__, message); |
| 197 | 199 |
| 198 bool result = language_list_fetcher_->Request( | 200 bool result = language_list_fetcher_->Request( |
| 199 url, | 201 url, |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 // languages, and don't use UMA or NotifyEvent. | 332 // languages, and don't use UMA or NotifyEvent. |
| 331 alpha_languages_.clear(); | 333 alpha_languages_.clear(); |
| 332 for (base::DictionaryValue::Iterator iter(*alpha_languages); | 334 for (base::DictionaryValue::Iterator iter(*alpha_languages); |
| 333 !iter.IsAtEnd(); iter.Advance()) { | 335 !iter.IsAtEnd(); iter.Advance()) { |
| 334 const std::string& lang = iter.key(); | 336 const std::string& lang = iter.key(); |
| 335 if (!l10n_util::IsLocaleNameTranslated(lang.c_str(), locale)) | 337 if (!l10n_util::IsLocaleNameTranslated(lang.c_str(), locale)) |
| 336 continue; | 338 continue; |
| 337 alpha_languages_.insert(lang); | 339 alpha_languages_.insert(lang); |
| 338 } | 340 } |
| 339 } | 341 } |
| 342 |
| 343 } // namespace translate |
| OLD | NEW |