Home | History | Annotate | Download | only in system
      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 #include "chrome/browser/chromeos/system/device_change_handler.h"
      6 
      7 #include "base/prefs/pref_service.h"
      8 #include "chrome/browser/browser_process.h"
      9 #include "chrome/browser/chromeos/system/input_device_settings.h"
     10 #include "chrome/browser/profiles/profile_manager.h"
     11 #include "chrome/common/pref_names.h"
     12 
     13 namespace chromeos {
     14 namespace system {
     15 
     16 DeviceChangeHandler::DeviceChangeHandler()
     17     : pointer_device_observer_(new PointerDeviceObserver) {
     18   pointer_device_observer_->AddObserver(this);
     19   pointer_device_observer_->Init();
     20 
     21   // Apply settings on startup.
     22   TouchpadExists(true);
     23   MouseExists(true);
     24 }
     25 
     26 DeviceChangeHandler::~DeviceChangeHandler() {
     27   pointer_device_observer_->RemoveObserver(this);
     28 }
     29 
     30 // When we detect a touchpad is attached, apply touchpad settings of the last
     31 // used profile.
     32 void DeviceChangeHandler::TouchpadExists(bool exists) {
     33   if (!exists)
     34     return;
     35 
     36   // Using GetDefaultProfile here because GetLastUsedProfile returns the
     37   // LoginManager profile in browser tests.
     38   PrefService* prefs =
     39       g_browser_process->profile_manager()->GetDefaultProfile()->GetPrefs();
     40 
     41   const bool tap_dragging = prefs->GetBoolean(prefs::kTapDraggingEnabled);
     42   system::touchpad_settings::SetTapDragging(tap_dragging);
     43 
     44   const bool three_finger_click =
     45       prefs->GetBoolean(prefs::kEnableTouchpadThreeFingerClick);
     46   system::touchpad_settings::SetThreeFingerClick(three_finger_click);
     47 
     48   const int sensitivity = prefs->GetInteger(prefs::kTouchpadSensitivity);
     49   system::touchpad_settings::SetSensitivity(sensitivity);
     50 
     51   // If we are not logged in, use owner preferences.
     52   PrefService* local_prefs = g_browser_process->local_state();
     53   const bool tap_to_click =
     54       g_browser_process->profile_manager()->IsLoggedIn() ?
     55           prefs->GetBoolean(prefs::kTapToClickEnabled) :
     56           local_prefs->GetBoolean(prefs::kOwnerTapToClickEnabled);
     57   system::touchpad_settings::SetTapToClick(tap_to_click);
     58 }
     59 
     60 // When we detect a mouse is attached, apply mouse settings of the last
     61 // used profile.
     62 void DeviceChangeHandler::MouseExists(bool exists) {
     63   if (!exists)
     64     return;
     65 
     66   // Using GetDefaultProfile here because GetLastUsedProfile returns the
     67   // LoginManager profile in browser tests.
     68   PrefService* prefs =
     69       g_browser_process->profile_manager()->GetDefaultProfile()->GetPrefs();
     70 
     71   const int sensitivity = prefs->GetInteger(prefs::kMouseSensitivity);
     72   system::mouse_settings::SetSensitivity(sensitivity);
     73 
     74   // If we are not logged in, use owner preferences.
     75   PrefService* local_prefs = g_browser_process->local_state();
     76   const bool primary_button_right =
     77       g_browser_process->profile_manager()->IsLoggedIn() ?
     78           prefs->GetBoolean(prefs::kPrimaryMouseButtonRight) :
     79           local_prefs->GetBoolean(prefs::kOwnerPrimaryMouseButtonRight);
     80   system::mouse_settings::SetPrimaryButtonRight(primary_button_right);
     81 }
     82 
     83 }  // namespace system
     84 }  // namespace chromeos
     85 
     86