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 // TranslateAcceptLanguages tracks the value of the "Accept-Language" HTTP 17 // header. 18 class TranslateAcceptLanguages { 19 public: 20 21 // |accept_languages_pref| is the path to the preference storing the accept 22 // languages. 23 TranslateAcceptLanguages(PrefService* prefs, 24 const char* accept_languages_pref); 25 virtual ~TranslateAcceptLanguages(); 26 27 // Returns true if |language| is available as Accept-Languages. |language| 28 // will be converted if it has the synonym of accept language. 29 static bool CanBeAcceptLanguage(const std::string& language); 30 31 // Returns true if the passed language has been configured by the user as an 32 // accept language. |language| will be converted if it has the synonym of 33 // accept languages. 34 bool IsAcceptLanguage(const std::string& language); 35 36 private: 37 // Initializes the |accept_languages_| language table based on the associated 38 // preference in |prefs|. 39 void InitAcceptLanguages(PrefService* prefs); 40 41 // Set of accept languages. 42 std::set<std::string> accept_languages_; 43 44 // Listens to accept languages changes. 45 PrefChangeRegistrar pref_change_registrar_; 46 47 // Path of accept languages preference. 48 const std::string accept_languages_pref_; 49 50 DISALLOW_COPY_AND_ASSIGN(TranslateAcceptLanguages); 51 }; 52 53 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_ACCEPT_LANGUAGES_H_ 54