Home | History | Annotate | Download | only in chromeos
      1 // Copyright (c) 2012 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_CHROMEOS_PREFERENCES_H_
      6 #define CHROME_BROWSER_CHROMEOS_PREFERENCES_H_
      7 
      8 #include <string>
      9 #include <vector>
     10 
     11 #include "ash/shell_observer.h"
     12 #include "base/compiler_specific.h"
     13 #include "base/prefs/pref_member.h"
     14 #include "chrome/browser/chromeos/language_preferences.h"
     15 #include "chrome/browser/chromeos/login/users/user_manager.h"
     16 #include "chrome/browser/prefs/pref_service_syncable_observer.h"
     17 
     18 class PrefRegistrySimple;
     19 class PrefService;
     20 class PrefServiceSyncable;
     21 
     22 class TracingManager;
     23 
     24 namespace user_prefs {
     25 class PrefRegistrySyncable;
     26 }
     27 
     28 namespace chromeos {
     29 
     30 class User;
     31 
     32 namespace input_method {
     33 class InputMethodManager;
     34 }
     35 
     36 // The Preferences class handles Chrome OS preferences. When the class
     37 // is first initialized, it will initialize the OS settings to what's stored in
     38 // the preferences. These include touchpad settings, etc.
     39 // When the preferences change, we change the settings to reflect the new value.
     40 class Preferences : public PrefServiceSyncableObserver,
     41                     public ash::ShellObserver,
     42                     public UserManager::UserSessionStateObserver {
     43  public:
     44   Preferences();
     45   explicit Preferences(
     46       input_method::InputMethodManager* input_method_manager);  // for testing
     47   virtual ~Preferences();
     48 
     49   // These method will register the prefs associated with Chrome OS settings.
     50   static void RegisterPrefs(PrefRegistrySimple* registry);
     51   static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
     52 
     53   // This method will initialize Chrome OS settings to values in user prefs.
     54   // |user| is the user owning this preferences.
     55   void Init(PrefServiceSyncable* prefs, const User* user);
     56 
     57   void InitUserPrefsForTesting(PrefServiceSyncable* prefs, const User* user);
     58   void SetInputMethodListForTesting();
     59 
     60  private:
     61   enum ApplyReason {
     62     REASON_INITIALIZATION,
     63     REASON_ACTIVE_USER_CHANGED,
     64     REASON_PREF_CHANGED
     65   };
     66 
     67   // Initializes all member prefs.
     68   void InitUserPrefs(PrefServiceSyncable* prefs);
     69 
     70   // Callback method for preference changes.
     71   void OnPreferenceChanged(const std::string& pref_name);
     72 
     73   // This will set the OS settings when the preference changed or user owning
     74   // these preferences became active. Also this method is called on
     75   // initialization. The reason of call is stored in |reason| parameter.
     76   // |pref_name| keeps name of changed preference in |reason| is
     77   // |REASON_PREF_CHANGED|, otherwise it is empty.
     78   void ApplyPreferences(ApplyReason reason,
     79                         const std::string& pref_name);
     80 
     81   // A variant of SetLanguageConfigStringList. You can pass comma-separated
     82   // values. Examples of |value|: "", "Control+space,Hiragana"
     83   void SetLanguageConfigStringListAsCSV(const char* section,
     84                                         const char* name,
     85                                         const std::string& value);
     86 
     87   // Restores the user's preferred input method / keyboard layout on signing in.
     88   void SetInputMethodList();
     89 
     90   // Updates the initial key repeat delay and key repeat interval following
     91   // current prefs values. We set the delay and interval at once since an
     92   // underlying XKB API requires it.
     93   void UpdateAutoRepeatRate();
     94 
     95   // Force natural scroll to on if --enable-natural-scroll-default is specified
     96   // on the cmd line.
     97   void ForceNaturalScrollDefault();
     98 
     99   // PrefServiceSyncableObserver implementation.
    100   virtual void OnIsSyncingChanged() OVERRIDE;
    101 
    102   // Overriden from ash::ShellObserver.
    103   virtual void OnTouchHudProjectionToggled(bool enabled) OVERRIDE;
    104 
    105   // Overriden form UserManager::UserSessionStateObserver.
    106   virtual void ActiveUserChanged(const User* active_user) OVERRIDE;
    107 
    108   PrefServiceSyncable* prefs_;
    109 
    110   input_method::InputMethodManager* input_method_manager_;
    111   scoped_ptr<TracingManager> tracing_manager_;
    112 
    113   BooleanPrefMember performance_tracing_enabled_;
    114   BooleanPrefMember tap_to_click_enabled_;
    115   BooleanPrefMember tap_dragging_enabled_;
    116   BooleanPrefMember three_finger_click_enabled_;
    117   BooleanPrefMember natural_scroll_;
    118   BooleanPrefMember vert_edge_scroll_enabled_;
    119   IntegerPrefMember speed_factor_;
    120   IntegerPrefMember mouse_sensitivity_;
    121   IntegerPrefMember touchpad_sensitivity_;
    122   BooleanPrefMember primary_mouse_button_right_;
    123   FilePathPrefMember download_default_directory_;
    124   BooleanPrefMember touch_hud_projection_enabled_;
    125 
    126   // Input method preferences.
    127   StringPrefMember preload_engines_;
    128   StringPrefMember current_input_method_;
    129   StringPrefMember previous_input_method_;
    130   StringPrefMember enabled_extension_imes_;
    131 
    132   BooleanPrefMember xkb_auto_repeat_enabled_;
    133   IntegerPrefMember xkb_auto_repeat_delay_pref_;
    134   IntegerPrefMember xkb_auto_repeat_interval_pref_;
    135 
    136   // User owning these preferences.
    137   const User* user_;
    138 
    139   // Whether user is a primary user.
    140   bool user_is_primary_;
    141 
    142   DISALLOW_COPY_AND_ASSIGN(Preferences);
    143 };
    144 
    145 }  // namespace chromeos
    146 
    147 #endif  // CHROME_BROWSER_CHROMEOS_PREFERENCES_H_
    148