Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Side by Side Diff: chrome/browser/translate/translate_prefs.cc

Issue 11570009: Split PrefService into PrefService, PrefServiceSimple and PrefServiceSyncable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to head again, previous had unrelated broken win_rel test. Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « chrome/browser/translate/translate_prefs.h ('k') | chrome/browser/ui/alternate_error_tab_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698