OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 CHROME_BROWSER_TRANSLATE_TRANSLATE_PREFS_H_ |
6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_PREFS_H_ | 6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_PREFS_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
11 | 11 |
12 class PrefRegistrySyncable; | 12 class PrefRegistrySyncable; |
13 class PrefService; | 13 class PrefService; |
14 | 14 |
15 namespace base { | 15 namespace base { |
16 class DictionaryValue; | 16 class DictionaryValue; |
17 class ListValue; | 17 class ListValue; |
18 } | 18 } |
19 | 19 |
20 class TranslatePrefs { | 20 class TranslatePrefs { |
21 public: | 21 public: |
22 static const char kPrefTranslateLanguageBlacklist[]; | 22 static const char kPrefTranslateLanguageBlacklist[]; |
23 static const char kPrefTranslateSiteBlacklist[]; | 23 static const char kPrefTranslateSiteBlacklist[]; |
24 static const char kPrefTranslateWhitelists[]; | 24 static const char kPrefTranslateWhitelists[]; |
25 static const char kPrefTranslateDeniedCount[]; | 25 static const char kPrefTranslateDeniedCount[]; |
26 static const char kPrefTranslateAcceptedCount[]; | 26 static const char kPrefTranslateAcceptedCount[]; |
27 | 27 |
28 explicit TranslatePrefs(PrefService* user_prefs); | 28 explicit TranslatePrefs(PrefService* user_prefs); |
29 | 29 |
30 bool IsLanguageBlacklisted(const std::string& original_language); | 30 bool IsLanguageBlacklisted(const std::string& original_language) const; |
31 void BlacklistLanguage(const std::string& original_language); | 31 void BlacklistLanguage(const std::string& original_language); |
32 void RemoveLanguageFromBlacklist(const std::string& original_language); | 32 void RemoveLanguageFromBlacklist(const std::string& original_language); |
33 | 33 |
34 bool IsSiteBlacklisted(const std::string& site); | 34 bool IsSiteBlacklisted(const std::string& site) const; |
35 void BlacklistSite(const std::string& site); | 35 void BlacklistSite(const std::string& site); |
36 void RemoveSiteFromBlacklist(const std::string& site); | 36 void RemoveSiteFromBlacklist(const std::string& site); |
37 | 37 |
38 bool IsLanguagePairWhitelisted(const std::string& original_language, | 38 bool IsLanguagePairWhitelisted(const std::string& original_language, |
39 const std::string& target_language); | 39 const std::string& target_language); |
40 void WhitelistLanguagePair(const std::string& original_language, | 40 void WhitelistLanguagePair(const std::string& original_language, |
41 const std::string& target_language); | 41 const std::string& target_language); |
42 void RemoveLanguagePairFromWhitelist(const std::string& original_language, | 42 void RemoveLanguagePairFromWhitelist(const std::string& original_language, |
43 const std::string& target_language); | 43 const std::string& target_language); |
44 | 44 |
45 // Will return true if at least one language has been blacklisted | |
MAD
2013/02/12 20:42:42
missing '.' at end of sentence...
Miguel Garcia
2013/02/13 09:31:27
Done.
| |
46 bool HasBlacklistedLanguages() const; | |
47 void ClearBlacklistedLanguages(); | |
48 | |
49 // Will return true if at least one site has been blacklisted | |
MAD
2013/02/12 20:42:42
missing '.' at end of sentence...
Miguel Garcia
2013/02/13 09:31:27
Done.
| |
50 bool HasBlacklistedSites(); | |
51 void ClearBlacklistedSites(); | |
52 | |
45 // These methods are used to track how many times the user has denied the | 53 // These methods are used to track how many times the user has denied the |
46 // translation for a specific language. (So we can present a UI to black-list | 54 // translation for a specific language. (So we can present a UI to black-list |
47 // that language if the user keeps denying translations). | 55 // that language if the user keeps denying translations). |
48 int GetTranslationDeniedCount(const std::string& language); | 56 int GetTranslationDeniedCount(const std::string& language) const; |
49 void IncrementTranslationDeniedCount(const std::string& language); | 57 void IncrementTranslationDeniedCount(const std::string& language); |
50 void ResetTranslationDeniedCount(const std::string& language); | 58 void ResetTranslationDeniedCount(const std::string& language); |
51 | 59 |
52 // These methods are used to track how many times the user has accepted the | 60 // These methods are used to track how many times the user has accepted the |
53 // translation for a specific language. (So we can present a UI to white-list | 61 // translation for a specific language. (So we can present a UI to white-list |
54 // that langueg if the user keeps accepting translations). | 62 // that language if the user keeps accepting translations). |
55 int GetTranslationAcceptedCount(const std::string& language); | 63 int GetTranslationAcceptedCount(const std::string& language); |
56 void IncrementTranslationAcceptedCount(const std::string& language); | 64 void IncrementTranslationAcceptedCount(const std::string& language); |
57 void ResetTranslationAcceptedCount(const std::string& language); | 65 void ResetTranslationAcceptedCount(const std::string& language); |
58 | 66 |
59 static bool CanTranslate(PrefService* user_prefs, | 67 static bool CanTranslate(PrefService* user_prefs, |
60 const std::string& original_language, const GURL& url); | 68 const std::string& original_language, const GURL& url); |
61 static bool ShouldAutoTranslate(PrefService* user_prefs, | 69 static bool ShouldAutoTranslate(PrefService* user_prefs, |
62 const std::string& original_language, std::string* target_language); | 70 const std::string& original_language, std::string* target_language); |
63 static void RegisterUserPrefs(PrefService* prefs, | 71 static void RegisterUserPrefs(PrefService* prefs, |
64 PrefRegistrySyncable* registry); | 72 PrefRegistrySyncable* registry); |
65 | 73 |
66 private: | 74 private: |
67 static void MigrateTranslateWhitelists(PrefService* user_prefs); | 75 static void MigrateTranslateWhitelists(PrefService* user_prefs); |
68 bool IsValueBlacklisted(const char* pref_id, const std::string& value); | 76 bool IsValueBlacklisted(const char* pref_id, const std::string& value) const; |
69 void BlacklistValue(const char* pref_id, const std::string& value); | 77 void BlacklistValue(const char* pref_id, const std::string& value); |
70 void RemoveValueFromBlacklist(const char* pref_id, const std::string& value); | 78 void RemoveValueFromBlacklist(const char* pref_id, const std::string& value); |
71 bool IsValueInList(const base::ListValue* list, const std::string& value); | 79 bool IsValueInList( |
80 const base::ListValue* list, const std::string& value) const; | |
72 bool IsLanguageWhitelisted(const std::string& original_language, | 81 bool IsLanguageWhitelisted(const std::string& original_language, |
73 std::string* target_language); | 82 std::string* target_language) const; |
74 | 83 bool IsListEmpty(const char* pref_id) const; |
75 // Retrieves the dictionary mapping the number of times translation has been | 84 // Retrieves the dictionary mapping the number of times translation has been |
76 // denied for a language, creating it if necessary. | 85 // denied for a language, creating it if necessary. |
77 base::DictionaryValue* GetTranslationDeniedCountDictionary(); | 86 base::DictionaryValue* GetTranslationDeniedCountDictionary(); |
78 | 87 |
79 // Retrieves the dictionary mapping the number of times translation has been | 88 // Retrieves the dictionary mapping the number of times translation has been |
80 // accepted for a language, creating it if necessary. | 89 // accepted for a language, creating it if necessary. |
81 base::DictionaryValue* GetTranslationAcceptedCountDictionary(); | 90 base::DictionaryValue* GetTranslationAcceptedCountDictionary() const; |
82 | 91 |
83 PrefService* prefs_; // Weak. | 92 PrefService* prefs_; // Weak. |
84 }; | 93 }; |
85 | 94 |
86 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_PREFS_H_ | 95 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_PREFS_H_ |
OLD | NEW |