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

Side by Side Diff: components/translate/core/browser/translate_prefs.h

Issue 2200493002: using ulp to improve TranslateManager GetTargetLanguage() and InitiateTranslation() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add unit tests Created 4 years, 4 months 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #ifndef COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_PREFS_H_ 5 #ifndef COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_PREFS_H_
6 #define COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_PREFS_H_ 6 #define COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_PREFS_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <string> 10 #include <string>
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 std::string language_; 71 std::string language_;
72 size_t max_denial_count_; 72 size_t max_denial_count_;
73 base::ListValue* time_list_; // Weak, owned by the containing prefs service. 73 base::ListValue* time_list_; // Weak, owned by the containing prefs service.
74 }; 74 };
75 75
76 // The wrapper of PrefService object for Translate. 76 // The wrapper of PrefService object for Translate.
77 // 77 //
78 // It is assumed that |prefs_| is alive while this instance is alive. 78 // It is assumed that |prefs_| is alive while this instance is alive.
79 class TranslatePrefs { 79 class TranslatePrefs {
80 public: 80 public:
81 static const char kPrefLanguageProfile[];
81 static const char kPrefTranslateSiteBlacklist[]; 82 static const char kPrefTranslateSiteBlacklist[];
82 static const char kPrefTranslateWhitelists[]; 83 static const char kPrefTranslateWhitelists[];
83 static const char kPrefTranslateDeniedCount[]; 84 static const char kPrefTranslateDeniedCount[];
84 static const char kPrefTranslateIgnoredCount[]; 85 static const char kPrefTranslateIgnoredCount[];
85 static const char kPrefTranslateAcceptedCount[]; 86 static const char kPrefTranslateAcceptedCount[];
86 static const char kPrefTranslateBlockedLanguages[]; 87 static const char kPrefTranslateBlockedLanguages[];
87 static const char kPrefTranslateLastDeniedTimeForLanguage[]; 88 static const char kPrefTranslateLastDeniedTimeForLanguage[];
88 static const char kPrefTranslateTooOftenDeniedForLanguage[]; 89 static const char kPrefTranslateTooOftenDeniedForLanguage[];
89 90
90 // |preferred_languages_pref| is only used on Chrome OS, other platforms must 91 // |preferred_languages_pref| is only used on Chrome OS, other platforms must
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 void GetLanguageList(std::vector<std::string>* languages) const; 159 void GetLanguageList(std::vector<std::string>* languages) const;
159 160
160 // Updates the language list of the language settings. 161 // Updates the language list of the language settings.
161 void UpdateLanguageList(const std::vector<std::string>& languages); 162 void UpdateLanguageList(const std::vector<std::string>& languages);
162 163
163 bool CanTranslateLanguage(TranslateAcceptLanguages* accept_languages, 164 bool CanTranslateLanguage(TranslateAcceptLanguages* accept_languages,
164 const std::string& language); 165 const std::string& language);
165 bool ShouldAutoTranslate(const std::string& original_language, 166 bool ShouldAutoTranslate(const std::string& original_language,
166 std::string* target_language); 167 std::string* target_language);
167 168
169 // Language and probability pair.
170 typedef std::pair<std::string, double> LanguageProbability;
groby-ooo-7-16 2016/08/02 00:38:21 LanguageAndProbability, please (so it's obvious th
ftang 2016/08/03 02:01:18 Done.
171 typedef std::vector<LanguageProbability> LanguageProbabilityList;
172
173 // Output the User Profile Profile's (ULP) "reading" list into |list| as
174 // order list of <string, double> pair. Return the confidence of the list
175 // or 0.0 if there no ULP "reading" list.
176 virtual double GetReadingFromUserLanguageProfile(
177 LanguageProbabilityList* list) const;
178
179 // Output the User Profile Profile's (ULP) "writing" list into |list| as
180 // order list of <string, double> pair. Return the confidence of the list
181 // or 0.0 if there no ULP "writing" list.
182 virtual double GetWritingFromUserLanguageProfile(
183 LanguageProbabilityList* list) const;
184
185 // Output the order list of Universal Language Settings (ULS) to |list|
groby-ooo-7-16 2016/08/02 00:38:21 What is the order list?
ftang 2016/08/03 02:01:18 function removed.
186 // and return the number of item on the list or 0 if there are no ULS list.
groby-ooo-7-16 2016/08/02 00:38:21 The number of items should be available via |list-
ftang 2016/08/03 02:01:18 function removed.
187 virtual int GetUniversialLanguageSettings(
188 std::vector<std::string>* list) const;
189
168 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 190 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
169 static void MigrateUserPrefs(PrefService* user_prefs, 191 static void MigrateUserPrefs(PrefService* user_prefs,
170 const char* accept_languages_pref); 192 const char* accept_languages_pref);
171 193
172 private: 194 private:
173 friend class TranslatePrefsTest; 195 friend class TranslatePrefsTest;
174 196
175 // Merges two language sets to migrate to the language setting UI. 197 // Merges two language sets to migrate to the language setting UI.
176 static void CreateBlockedLanguages( 198 static void CreateBlockedLanguages(
177 std::vector<std::string>* blocked_languages, 199 std::vector<std::string>* blocked_languages,
178 const std::vector<std::string>& blacklisted_languages, 200 const std::vector<std::string>& blacklisted_languages,
179 const std::vector<std::string>& accept_languages); 201 const std::vector<std::string>& accept_languages);
180 202
181 void ClearBlockedLanguages(); 203 void ClearBlockedLanguages();
182 void ClearBlacklistedSites(); 204 void ClearBlacklistedSites();
183 void ClearWhitelistedLanguagePairs(); 205 void ClearWhitelistedLanguagePairs();
184 bool IsValueBlacklisted(const char* pref_id, const std::string& value) const; 206 bool IsValueBlacklisted(const char* pref_id, const std::string& value) const;
185 void BlacklistValue(const char* pref_id, const std::string& value); 207 void BlacklistValue(const char* pref_id, const std::string& value);
186 void RemoveValueFromBlacklist(const char* pref_id, const std::string& value); 208 void RemoveValueFromBlacklist(const char* pref_id, const std::string& value);
187 bool IsValueInList(const base::ListValue* list, 209 bool IsValueInList(const base::ListValue* list,
188 const std::string& value) const; 210 const std::string& value) const;
189 bool IsListEmpty(const char* pref_id) const; 211 bool IsListEmpty(const char* pref_id) const;
190 bool IsDictionaryEmpty(const char* pref_id) const; 212 bool IsDictionaryEmpty(const char* pref_id) const;
191 213
214 double GetFromUserLanguageProfile(base::StringPiece path,
215 LanguageProbabilityList* list) const;
216
192 // Path to the preference storing the accept languages. 217 // Path to the preference storing the accept languages.
193 const std::string accept_languages_pref_; 218 const std::string accept_languages_pref_;
194 #if defined(OS_CHROMEOS) 219 #if defined(OS_CHROMEOS)
195 // Path to the preference storing the preferred languages. 220 // Path to the preference storing the preferred languages.
196 // Only used on ChromeOS. 221 // Only used on ChromeOS.
197 std::string preferred_languages_pref_; 222 std::string preferred_languages_pref_;
198 #endif 223 #endif
199 224
200 // Retrieves the dictionary mapping the number of times translation has been 225 // Retrieves the dictionary mapping the number of times translation has been
201 // denied for a language, creating it if necessary. 226 // denied for a language, creating it if necessary.
202 base::DictionaryValue* GetTranslationDeniedCountDictionary(); 227 base::DictionaryValue* GetTranslationDeniedCountDictionary();
203 228
204 // Retrieves the dictionary mapping the number of times translation has been 229 // Retrieves the dictionary mapping the number of times translation has been
205 // accepted for a language, creating it if necessary. 230 // accepted for a language, creating it if necessary.
206 base::DictionaryValue* GetTranslationAcceptedCountDictionary() const; 231 base::DictionaryValue* GetTranslationAcceptedCountDictionary() const;
207 232
208 PrefService* prefs_; // Weak. 233 PrefService* prefs_; // Weak.
209 234
210 std::string country_; // The country the app runs in. 235 std::string country_; // The country the app runs in.
211 236
212 DISALLOW_COPY_AND_ASSIGN(TranslatePrefs); 237 DISALLOW_COPY_AND_ASSIGN(TranslatePrefs);
213 }; 238 };
214 239
215 } // namespace translate 240 } // namespace translate
216 241
217 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_PREFS_H_ 242 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_PREFS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698