OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_prefs.h" | 5 #include "chrome/browser/translate/translate_prefs.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "chrome/browser/prefs/pref_service.h" | 8 #include "chrome/browser/prefs/pref_service.h" |
9 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 9 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
10 | 10 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 return false; | 141 return false; |
142 return (!prefs.IsLanguageBlacklisted(original_language)); | 142 return (!prefs.IsLanguageBlacklisted(original_language)); |
143 } | 143 } |
144 | 144 |
145 bool TranslatePrefs::ShouldAutoTranslate(PrefService* user_prefs, | 145 bool TranslatePrefs::ShouldAutoTranslate(PrefService* user_prefs, |
146 const std::string& original_language, std::string* target_language) { | 146 const std::string& original_language, std::string* target_language) { |
147 TranslatePrefs prefs(user_prefs); | 147 TranslatePrefs prefs(user_prefs); |
148 return prefs.IsLanguageWhitelisted(original_language, target_language); | 148 return prefs.IsLanguageWhitelisted(original_language, target_language); |
149 } | 149 } |
150 | 150 |
151 void TranslatePrefs::RegisterUserPrefs(PrefService* user_prefs) { | 151 void TranslatePrefs::RegisterUserPrefs(PrefServiceSyncable* user_prefs) { |
152 if (!user_prefs->FindPreference(kPrefTranslateLanguageBlacklist)) | 152 if (!user_prefs->FindPreference(kPrefTranslateLanguageBlacklist)) |
153 user_prefs->RegisterListPref(kPrefTranslateLanguageBlacklist, | 153 user_prefs->RegisterListPref(kPrefTranslateLanguageBlacklist, |
154 PrefService::SYNCABLE_PREF); | 154 PrefServiceSyncable::SYNCABLE_PREF); |
155 if (!user_prefs->FindPreference(kPrefTranslateSiteBlacklist)) | 155 if (!user_prefs->FindPreference(kPrefTranslateSiteBlacklist)) |
156 user_prefs->RegisterListPref(kPrefTranslateSiteBlacklist, | 156 user_prefs->RegisterListPref(kPrefTranslateSiteBlacklist, |
157 PrefService::SYNCABLE_PREF); | 157 PrefServiceSyncable::SYNCABLE_PREF); |
158 if (!user_prefs->FindPreference(kPrefTranslateWhitelists)) { | 158 if (!user_prefs->FindPreference(kPrefTranslateWhitelists)) { |
159 user_prefs->RegisterDictionaryPref(kPrefTranslateWhitelists, | 159 user_prefs->RegisterDictionaryPref(kPrefTranslateWhitelists, |
160 PrefService::SYNCABLE_PREF); | 160 PrefServiceSyncable::SYNCABLE_PREF); |
161 MigrateTranslateWhitelists(user_prefs); | 161 MigrateTranslateWhitelists(user_prefs); |
162 } | 162 } |
163 if (!user_prefs->FindPreference(kPrefTranslateDeniedCount)) | 163 if (!user_prefs->FindPreference(kPrefTranslateDeniedCount)) |
164 user_prefs->RegisterDictionaryPref(kPrefTranslateDeniedCount, | 164 user_prefs->RegisterDictionaryPref(kPrefTranslateDeniedCount, |
165 PrefService::SYNCABLE_PREF); | 165 PrefServiceSyncable::SYNCABLE_PREF); |
166 if (!user_prefs->FindPreference(kPrefTranslateAcceptedCount)) | 166 if (!user_prefs->FindPreference(kPrefTranslateAcceptedCount)) |
167 user_prefs->RegisterDictionaryPref(kPrefTranslateAcceptedCount, | 167 user_prefs->RegisterDictionaryPref(kPrefTranslateAcceptedCount, |
168 PrefService::SYNCABLE_PREF); | 168 PrefServiceSyncable::SYNCABLE_PREF); |
169 } | 169 } |
170 | 170 |
171 // TranslatePrefs: private, static: -------------------------------------------- | 171 // TranslatePrefs: private, static: -------------------------------------------- |
172 | 172 |
173 void TranslatePrefs::MigrateTranslateWhitelists(PrefService* user_prefs) { | 173 void TranslatePrefs::MigrateTranslateWhitelists(PrefService* user_prefs) { |
174 // Old format of kPrefTranslateWhitelists | 174 // Old format of kPrefTranslateWhitelists |
175 // - original language -> list of target langs to auto-translate | 175 // - original language -> list of target langs to auto-translate |
176 // - list of langs is in order of being enabled i.e. last in list is the | 176 // - list of langs is in order of being enabled i.e. last in list is the |
177 // most recent language that user enabled via | 177 // most recent language that user enabled via |
178 // Always translate |source_lang| to |target_lang|" | 178 // Always translate |source_lang| to |target_lang|" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 | 250 |
251 bool TranslatePrefs::IsLanguageWhitelisted( | 251 bool TranslatePrefs::IsLanguageWhitelisted( |
252 const std::string& original_language, std::string* target_language) { | 252 const std::string& original_language, std::string* target_language) { |
253 const DictionaryValue* dict = prefs_->GetDictionary(kPrefTranslateWhitelists); | 253 const DictionaryValue* dict = prefs_->GetDictionary(kPrefTranslateWhitelists); |
254 if (dict && dict->GetString(original_language, target_language)) { | 254 if (dict && dict->GetString(original_language, target_language)) { |
255 DCHECK(!target_language->empty()); | 255 DCHECK(!target_language->empty()); |
256 return !target_language->empty(); | 256 return !target_language->empty(); |
257 } | 257 } |
258 return false; | 258 return false; |
259 } | 259 } |
OLD | NEW |