Home | History | Annotate | Download | only in browser
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_ACCEPT_LANGUAGES_H_
      6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_ACCEPT_LANGUAGES_H_
      7 
      8 #include <set>
      9 #include <string>
     10 
     11 #include "base/basictypes.h"
     12 #include "base/prefs/pref_change_registrar.h"
     13 
     14 class PrefService;
     15 
     16 namespace translate {
     17 
     18 // TranslateAcceptLanguages tracks the value of the "Accept-Language" HTTP
     19 // header.
     20 class TranslateAcceptLanguages {
     21  public:
     22 
     23   // |accept_languages_pref| is the path to the preference storing the accept
     24   // languages.
     25   TranslateAcceptLanguages(PrefService* prefs,
     26                            const char* accept_languages_pref);
     27   virtual ~TranslateAcceptLanguages();
     28 
     29   // Returns true if |language| is available as Accept-Languages. |language|
     30   // will be converted if it has the synonym of accept language.
     31   static bool CanBeAcceptLanguage(const std::string& language);
     32 
     33   // Returns true if the passed language has been configured by the user as an
     34   // accept language. |language| will be converted if it has the synonym of
     35   // accept languages.
     36   bool IsAcceptLanguage(const std::string& language);
     37 
     38  private:
     39   // Initializes the |accept_languages_| language table based on the associated
     40   // preference in |prefs|.
     41   void InitAcceptLanguages(PrefService* prefs);
     42 
     43   // Set of accept languages.
     44   std::set<std::string> accept_languages_;
     45 
     46   // Listens to accept languages changes.
     47   PrefChangeRegistrar pref_change_registrar_;
     48 
     49   // Path of accept languages preference.
     50   const std::string accept_languages_pref_;
     51 
     52   DISALLOW_COPY_AND_ASSIGN(TranslateAcceptLanguages);
     53 };
     54 
     55 }  // namespace translate
     56 
     57 #endif  // CHROME_BROWSER_TRANSLATE_TRANSLATE_ACCEPT_LANGUAGES_H_
     58