Home | History | Annotate | Download | only in translate
      1 // Copyright 2013 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 <map>
      9 #include <set>
     10 #include <string>
     11 
     12 #include "base/basictypes.h"
     13 #include "content/public/browser/notification_observer.h"
     14 #include "content/public/browser/notification_registrar.h"
     15 
     16 class PrefChangeRegistrar;
     17 class PrefService;
     18 class Profile;
     19 
     20 class TranslateAcceptLanguages : public content::NotificationObserver {
     21  public:
     22   TranslateAcceptLanguages();
     23   virtual ~TranslateAcceptLanguages();
     24 
     25   // Returns true if |language| is available as Accept-Languages. |language|
     26   // will be cnverted if it has the synonym of accept language.
     27   static bool CanBeAcceptLanguage(const std::string& language);
     28 
     29   // Returns true if the passed language has been configured by the user as an
     30   // accept language. |language| will be converted if it has the synonym of
     31   // accept languages.
     32   bool IsAcceptLanguage(Profile* profile,
     33                         const std::string& language);
     34 
     35  private:
     36   // content::NotificationObserver implementation:
     37   virtual void Observe(int type,
     38                        const content::NotificationSource& source,
     39                        const content::NotificationDetails& details) OVERRIDE;
     40 
     41   // Initializes the |accept_languages_| language table based on the associated
     42   // preference in |prefs|.
     43   void InitAcceptLanguages(PrefService* prefs);
     44 
     45   // A map that associates a profile with its parsed "accept languages".
     46   typedef std::set<std::string> LanguageSet;
     47   typedef std::map<PrefService*, LanguageSet> PrefServiceLanguagesMap;
     48   PrefServiceLanguagesMap accept_languages_;
     49 
     50   // Each PrefChangeRegistrar only tracks a single PrefService, so a map from
     51   // each PrefService used to its registrar is needed.
     52   typedef std::map<PrefService*, PrefChangeRegistrar*> PrefServiceRegistrarMap;
     53   PrefServiceRegistrarMap pref_change_registrars_;
     54 
     55   content::NotificationRegistrar notification_registrar_;
     56 
     57   DISALLOW_COPY_AND_ASSIGN(TranslateAcceptLanguages);
     58 };
     59 
     60 #endif  // CHROME_BROWSER_TRANSLATE_TRANSLATE_ACCEPT_LANGUAGES_H_
     61