• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_PREFS_H_
6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_PREFS_H_
7 #pragma once
8 
9 #include <string>
10 
11 #include "googleurl/src/gurl.h"
12 
13 class DictionaryValue;
14 class ListValue;
15 class PrefService;
16 
17 class TranslatePrefs {
18  public:
19   static const char kPrefTranslateLanguageBlacklist[];
20   static const char kPrefTranslateSiteBlacklist[];
21   static const char kPrefTranslateWhitelists[];
22   static const char kPrefTranslateDeniedCount[];
23   static const char kPrefTranslateAcceptedCount[];
24 
25   explicit TranslatePrefs(PrefService* user_prefs);
26 
27   bool IsLanguageBlacklisted(const std::string& original_language);
28   void BlacklistLanguage(const std::string& original_language);
29   void RemoveLanguageFromBlacklist(const std::string& original_language);
30 
31   bool IsSiteBlacklisted(const std::string& site);
32   void BlacklistSite(const std::string& site);
33   void RemoveSiteFromBlacklist(const std::string& site);
34 
35   bool IsLanguagePairWhitelisted(const std::string& original_language,
36       const std::string& target_language);
37   void WhitelistLanguagePair(const std::string& original_language,
38       const std::string& target_language);
39   void RemoveLanguagePairFromWhitelist(const std::string& original_language,
40       const std::string& target_language);
41 
42   // These methods are used to track how many times the user has denied the
43   // translation for a specific language. (So we can present a UI to black-list
44   // that language if the user keeps denying translations).
45   int GetTranslationDeniedCount(const std::string& language);
46   void IncrementTranslationDeniedCount(const std::string& language);
47   void ResetTranslationDeniedCount(const std::string& language);
48 
49   // These methods are used to track how many times the user has accepted the
50   // translation for a specific language. (So we can present a UI to white-list
51   // that langueg if the user keeps accepting translations).
52   int GetTranslationAcceptedCount(const std::string& language);
53   void IncrementTranslationAcceptedCount(const std::string& language);
54   void ResetTranslationAcceptedCount(const std::string& language);
55 
56   static bool CanTranslate(PrefService* user_prefs,
57       const std::string& original_language, const GURL& url);
58   static bool ShouldAutoTranslate(PrefService* user_prefs,
59       const std::string& original_language, std::string* target_language);
60   static void RegisterUserPrefs(PrefService* user_prefs);
61 
62  private:
63   static void MigrateTranslateWhitelists(PrefService* user_prefs);
64   bool IsValueBlacklisted(const char* pref_id, const std::string& value);
65   void BlacklistValue(const char* pref_id, const std::string& value);
66   void RemoveValueFromBlacklist(const char* pref_id, const std::string& value);
67   bool IsValueInList(const ListValue* list, const std::string& value);
68   bool IsLanguageWhitelisted(const std::string& original_language,
69       std::string* target_language);
70 
71   // Retrieves the dictionary mapping the number of times translation has been
72   // denied for a language, creating it if necessary.
73   DictionaryValue* GetTranslationDeniedCountDictionary();
74 
75   // Retrieves the dictionary mapping the number of times translation has been
76   // accepted for a language, creating it if necessary.
77   DictionaryValue* GetTranslationAcceptedCountDictionary();
78 
79   PrefService* prefs_;  // Weak.
80 };
81 
82 #endif  // CHROME_BROWSER_TRANSLATE_TRANSLATE_PREFS_H_
83