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_accept_languages.h" | 5 #include "chrome/browser/translate/translate_accept_languages.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/prefs/pref_change_registrar.h" | 8 #include "base/prefs/pref_change_registrar.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/translate/translate_manager.h" | 15 #include "chrome/browser/translate/translate_manager.h" |
16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
17 #include "chrome/common/translate/translate_util.h" | 17 #include "components/translate/common/translate_util.h" |
18 #include "content/public/browser/notification_source.h" | 18 #include "content/public/browser/notification_source.h" |
19 #include "net/url_request/url_fetcher.h" | 19 #include "net/url_request/url_fetcher.h" |
20 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
21 | 21 |
22 TranslateAcceptLanguages::TranslateAcceptLanguages() { | 22 TranslateAcceptLanguages::TranslateAcceptLanguages() { |
23 } | 23 } |
24 | 24 |
25 TranslateAcceptLanguages::~TranslateAcceptLanguages() { | 25 TranslateAcceptLanguages::~TranslateAcceptLanguages() { |
26 } | 26 } |
27 | 27 |
28 // static | 28 // static |
29 bool TranslateAcceptLanguages::CanBeAcceptLanguage( | 29 bool TranslateAcceptLanguages::CanBeAcceptLanguage( |
30 const std::string& language) { | 30 const std::string& language) { |
31 std::string accept_language = language; | 31 std::string accept_language = language; |
32 TranslateUtil::ToChromeLanguageSynonym(&accept_language); | 32 translate::ToChromeLanguageSynonym(&accept_language); |
33 | 33 |
34 const std::string locale = g_browser_process->GetApplicationLocale(); | 34 const std::string locale = g_browser_process->GetApplicationLocale(); |
35 std::vector<std::string> accept_language_codes; | 35 std::vector<std::string> accept_language_codes; |
36 l10n_util::GetAcceptLanguagesForLocale(locale, &accept_language_codes); | 36 l10n_util::GetAcceptLanguagesForLocale(locale, &accept_language_codes); |
37 | 37 |
38 if (std::find(accept_language_codes.begin(), | 38 if (std::find(accept_language_codes.begin(), |
39 accept_language_codes.end(), | 39 accept_language_codes.end(), |
40 accept_language) != accept_language_codes.end()) { | 40 accept_language) != accept_language_codes.end()) { |
41 return true; | 41 return true; |
42 } | 42 } |
(...skipping 23 matching lines...) Expand all Loading... |
66 prefs::kAcceptLanguages, | 66 prefs::kAcceptLanguages, |
67 base::Bind(&TranslateAcceptLanguages::InitAcceptLanguages, | 67 base::Bind(&TranslateAcceptLanguages::InitAcceptLanguages, |
68 base::Unretained(this), | 68 base::Unretained(this), |
69 pref_service)); | 69 pref_service)); |
70 pref_change_registrars_[pref_service] = pref_change_registrar; | 70 pref_change_registrars_[pref_service] = pref_change_registrar; |
71 | 71 |
72 iter = accept_languages_.find(pref_service); | 72 iter = accept_languages_.find(pref_service); |
73 } | 73 } |
74 | 74 |
75 std::string accept_language = language; | 75 std::string accept_language = language; |
76 TranslateUtil::ToChromeLanguageSynonym(&accept_language); | 76 translate::ToChromeLanguageSynonym(&accept_language); |
77 return iter->second.count(accept_language) != 0; | 77 return iter->second.count(accept_language) != 0; |
78 } | 78 } |
79 | 79 |
80 void TranslateAcceptLanguages::InitAcceptLanguages(PrefService* prefs) { | 80 void TranslateAcceptLanguages::InitAcceptLanguages(PrefService* prefs) { |
81 DCHECK(prefs); | 81 DCHECK(prefs); |
82 | 82 |
83 // We have been asked for this profile, build the languages. | 83 // We have been asked for this profile, build the languages. |
84 std::string accept_langs_str = prefs->GetString(prefs::kAcceptLanguages); | 84 std::string accept_langs_str = prefs->GetString(prefs::kAcceptLanguages); |
85 std::vector<std::string> accept_langs_list; | 85 std::vector<std::string> accept_langs_list; |
86 LanguageSet accept_langs_set; | 86 LanguageSet accept_langs_set; |
(...skipping 27 matching lines...) Expand all Loading... |
114 size_t count = accept_languages_.erase(pref_service); | 114 size_t count = accept_languages_.erase(pref_service); |
115 // We should know about this profile since we are listening for | 115 // We should know about this profile since we are listening for |
116 // notifications on it. | 116 // notifications on it. |
117 DCHECK_EQ(1u, count); | 117 DCHECK_EQ(1u, count); |
118 PrefChangeRegistrar* pref_change_registrar = | 118 PrefChangeRegistrar* pref_change_registrar = |
119 pref_change_registrars_[pref_service]; | 119 pref_change_registrars_[pref_service]; |
120 count = pref_change_registrars_.erase(pref_service); | 120 count = pref_change_registrars_.erase(pref_service); |
121 DCHECK_EQ(1u, count); | 121 DCHECK_EQ(1u, count); |
122 delete pref_change_registrar; | 122 delete pref_change_registrar; |
123 } | 123 } |
OLD | NEW |