OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 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 CHROME_BROWSER_TRANSLATE_TRANSLATE_PREFS_H_ | 5 #ifndef COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_PREFS_H_ |
6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_PREFS_H_ | 6 #define COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_PREFS_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
12 #include "url/gurl.h" | 12 #include "url/gurl.h" |
13 | 13 |
14 class PrefService; | 14 class PrefService; |
15 class Profile; | 15 class Profile; |
16 | 16 |
(...skipping 11 matching lines...) Expand all Loading... | |
28 // It is assumed that |prefs_| is alive while this instance is alive. | 28 // It is assumed that |prefs_| is alive while this instance is alive. |
29 class TranslatePrefs { | 29 class TranslatePrefs { |
30 public: | 30 public: |
31 static const char kPrefTranslateLanguageBlacklist[]; | 31 static const char kPrefTranslateLanguageBlacklist[]; |
32 static const char kPrefTranslateSiteBlacklist[]; | 32 static const char kPrefTranslateSiteBlacklist[]; |
33 static const char kPrefTranslateWhitelists[]; | 33 static const char kPrefTranslateWhitelists[]; |
34 static const char kPrefTranslateDeniedCount[]; | 34 static const char kPrefTranslateDeniedCount[]; |
35 static const char kPrefTranslateAcceptedCount[]; | 35 static const char kPrefTranslateAcceptedCount[]; |
36 static const char kPrefTranslateBlockedLanguages[]; | 36 static const char kPrefTranslateBlockedLanguages[]; |
37 | 37 |
38 explicit TranslatePrefs(PrefService* user_prefs); | 38 TranslatePrefs(PrefService* user_prefs, |
39 #if defined(OS_CHROMEOS) | |
40 const char* preferred_languages_pref, | |
41 #endif | |
42 const char* accept_languages_pref); | |
39 | 43 |
40 // Resets the blocked languages list, the sites blacklist, the languages | 44 // Resets the blocked languages list, the sites blacklist, the languages |
41 // whitelist, and the accepted/denied counts. | 45 // whitelist, and the accepted/denied counts. |
42 void ResetToDefaults(); | 46 void ResetToDefaults(); |
43 | 47 |
44 bool IsBlockedLanguage(const std::string& original_language) const; | 48 bool IsBlockedLanguage(const std::string& original_language) const; |
45 void BlockLanguage(const std::string& original_language); | 49 void BlockLanguage(const std::string& original_language); |
46 void UnblockLanguage(const std::string& original_language); | 50 void UnblockLanguage(const std::string& original_language); |
47 | 51 |
48 // Removes a language from the old blacklist. This method is for | 52 // Removes a language from the old blacklist. Only used internally for |
49 // chrome://translate-internals/. Don't use this if there is no special | 53 // diagnostics. Don't use this if there is no special reason. |
50 // reason. | |
51 void RemoveLanguageFromLegacyBlacklist(const std::string& original_language); | 54 void RemoveLanguageFromLegacyBlacklist(const std::string& original_language); |
52 | 55 |
53 bool IsSiteBlacklisted(const std::string& site) const; | 56 bool IsSiteBlacklisted(const std::string& site) const; |
54 void BlacklistSite(const std::string& site); | 57 void BlacklistSite(const std::string& site); |
55 void RemoveSiteFromBlacklist(const std::string& site); | 58 void RemoveSiteFromBlacklist(const std::string& site); |
56 | 59 |
57 bool HasWhitelistedLanguagePairs() const; | 60 bool HasWhitelistedLanguagePairs() const; |
58 | 61 |
59 bool IsLanguagePairWhitelisted(const std::string& original_language, | 62 bool IsLanguagePairWhitelisted(const std::string& original_language, |
60 const std::string& target_language); | 63 const std::string& target_language); |
61 void WhitelistLanguagePair(const std::string& original_language, | 64 void WhitelistLanguagePair(const std::string& original_language, |
62 const std::string& target_language); | 65 const std::string& target_language); |
63 void RemoveLanguagePairFromWhitelist(const std::string& original_language, | 66 void RemoveLanguagePairFromWhitelist(const std::string& original_language, |
64 const std::string& target_language); | 67 const std::string& target_language); |
65 | 68 |
66 // Will return true if at least one language has been blacklisted. | 69 // Will return true if at least one language has been blacklisted. |
67 bool HasBlockedLanguages() const; | 70 bool HasBlockedLanguages() const; |
68 | 71 |
69 // Will return true if at least one site has been blacklisted. | 72 // Will return true if at least one site has been blacklisted. |
70 bool HasBlacklistedSites() const; | 73 bool HasBlacklistedSites() const; |
71 | 74 |
72 // These methods are used to track how many times the user has denied the | 75 // These methods are used to track how many times the user has denied the |
73 // translation for a specific language. (So we can present a UI to black-list | 76 // translation for a specific language. (So we can present a UI to black-list |
74 // that language if the user keeps denying translations). | 77 // that language if the user keeps denying translations). |
75 int GetTranslationDeniedCount(const std::string& language) const; | 78 int GetTranslationDeniedCount(const std::string& language) const; |
76 void IncrementTranslationDeniedCount(const std::string& language); | 79 void IncrementTranslationDeniedCount(const std::string& language); |
77 void ResetTranslationDeniedCount(const std::string& language); | 80 void ResetTranslationDeniedCount(const std::string& language); |
78 | 81 |
79 // These methods are used to track how many times the user has accepted the | 82 // These methods are used to track how many times the user has accepted the |
80 // translation for a specific language. (So we can present a UI to white-list | 83 // translation for a specific language. (So we can present a UI to white-list |
81 // that language if the user keeps accepting translations). | 84 // that language if the user keeps accepting translations). |
82 int GetTranslationAcceptedCount(const std::string& language); | 85 int GetTranslationAcceptedCount(const std::string& language); |
83 void IncrementTranslationAcceptedCount(const std::string& language); | 86 void IncrementTranslationAcceptedCount(const std::string& language); |
84 void ResetTranslationAcceptedCount(const std::string& language); | 87 void ResetTranslationAcceptedCount(const std::string& language); |
85 | 88 |
86 // Sets the language list of chrome://settings/languages. | 89 // Sets the language list of the language settings. |
blundell
2014/02/12 14:01:43
This comment reads oddly now: The method is called
| |
87 void GetLanguageList(std::vector<std::string>* languages); | 90 void GetLanguageList(std::vector<std::string>* languages); |
88 | 91 |
89 // Updates the language list of chrome://settings/languages. | 92 // Updates the language list of the language settings. |
90 void UpdateLanguageList(const std::vector<std::string>& languages); | 93 void UpdateLanguageList(const std::vector<std::string>& languages); |
91 | 94 |
92 static bool CanTranslateLanguage( | 95 bool CanTranslateLanguage(bool is_accept_language, |
93 Profile* profile, const std::string& language); | 96 const std::string& language); |
94 static bool ShouldAutoTranslate(PrefService* user_prefs, | 97 bool ShouldAutoTranslate(const std::string& original_language, |
95 const std::string& original_language, std::string* target_language); | 98 std::string* target_language); |
96 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 99 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
97 static void MigrateUserPrefs(PrefService* user_prefs); | 100 static void MigrateUserPrefs(PrefService* user_prefs, |
101 const char* accept_languages_pref); | |
98 | 102 |
99 // Converts the language code for Translate. This removes the sub code (like | 103 // Converts the language code for Translate. This removes the sub code (like |
100 // -US) except for Chinese, and converts the synonyms. | 104 // -US) except for Chinese, and converts the synonyms. |
101 // The same logic exists at language_options.js, and please keep consistency | 105 // The same logic exists at language_options.js, and please keep consistency |
102 // with the JavaScript file. | 106 // with the JavaScript file. |
103 static std::string ConvertLangCodeForTranslation(const std::string &lang); | 107 static std::string ConvertLangCodeForTranslation(const std::string& lang); |
104 | 108 |
105 private: | 109 private: |
106 friend class TranslatePrefsTest; | 110 friend class TranslatePrefsTest; |
107 FRIEND_TEST_ALL_PREFIXES(TranslatePrefsTest, CreateBlockedLanguages); | 111 FRIEND_TEST_ALL_PREFIXES(TranslatePrefsTest, CreateBlockedLanguages); |
108 FRIEND_TEST_ALL_PREFIXES(TranslatePrefsTest, | 112 FRIEND_TEST_ALL_PREFIXES(TranslatePrefsTest, |
109 CreateBlockedLanguagesNonEnglishUI); | 113 CreateBlockedLanguagesNonEnglishUI); |
110 | 114 |
111 // Merges two language sets to migrate to the language setting UI. | 115 // Merges two language sets to migrate to the language setting UI. |
112 static void CreateBlockedLanguages( | 116 static void CreateBlockedLanguages( |
113 std::vector<std::string>* blocked_languages, | 117 std::vector<std::string>* blocked_languages, |
114 const std::vector<std::string>& blacklisted_languages, | 118 const std::vector<std::string>& blacklisted_languages, |
115 const std::vector<std::string>& accept_languages); | 119 const std::vector<std::string>& accept_languages); |
116 | 120 |
117 void ClearBlockedLanguages(); | 121 void ClearBlockedLanguages(); |
118 void ClearBlacklistedSites(); | 122 void ClearBlacklistedSites(); |
119 void ClearWhitelistedLanguagePairs(); | 123 void ClearWhitelistedLanguagePairs(); |
120 bool IsValueBlacklisted(const char* pref_id, const std::string& value) const; | 124 bool IsValueBlacklisted(const char* pref_id, const std::string& value) const; |
121 void BlacklistValue(const char* pref_id, const std::string& value); | 125 void BlacklistValue(const char* pref_id, const std::string& value); |
122 void RemoveValueFromBlacklist(const char* pref_id, const std::string& value); | 126 void RemoveValueFromBlacklist(const char* pref_id, const std::string& value); |
123 bool IsValueInList( | 127 bool IsValueInList(const base::ListValue* list, |
124 const base::ListValue* list, const std::string& value) const; | 128 const std::string& value) const; |
125 bool IsLanguageWhitelisted(const std::string& original_language, | |
126 std::string* target_language) const; | |
127 bool IsListEmpty(const char* pref_id) const; | 129 bool IsListEmpty(const char* pref_id) const; |
128 bool IsDictionaryEmpty(const char* pref_id) const; | 130 bool IsDictionaryEmpty(const char* pref_id) const; |
129 | 131 |
132 // Path to the preference storing the accept languages. | |
133 const std::string accept_languages_pref_; | |
134 #if defined(OS_CHROMEOS) | |
135 // Path to the preference storing the preferred languages. | |
136 // Only used on ChromeOS. | |
137 const std::string preferred_languages_pref_; | |
138 #endif | |
139 | |
130 // Retrieves the dictionary mapping the number of times translation has been | 140 // Retrieves the dictionary mapping the number of times translation has been |
131 // denied for a language, creating it if necessary. | 141 // denied for a language, creating it if necessary. |
132 base::DictionaryValue* GetTranslationDeniedCountDictionary(); | 142 base::DictionaryValue* GetTranslationDeniedCountDictionary(); |
133 | 143 |
134 // Retrieves the dictionary mapping the number of times translation has been | 144 // Retrieves the dictionary mapping the number of times translation has been |
135 // accepted for a language, creating it if necessary. | 145 // accepted for a language, creating it if necessary. |
136 base::DictionaryValue* GetTranslationAcceptedCountDictionary() const; | 146 base::DictionaryValue* GetTranslationAcceptedCountDictionary() const; |
137 | 147 |
138 PrefService* prefs_; // Weak. | 148 PrefService* prefs_; // Weak. |
139 | 149 |
140 DISALLOW_COPY_AND_ASSIGN(TranslatePrefs); | 150 DISALLOW_COPY_AND_ASSIGN(TranslatePrefs); |
141 }; | 151 }; |
142 | 152 |
143 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_PREFS_H_ | 153 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_PREFS_H_ |
OLD | NEW |