OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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 bool three_finger_swipe = |
| 49 prefs->GetBoolean(prefs::kEnableTouchpadThreeFingerSwipe); |
| 50 system::touchpad_settings::SetThreeFingerSwipe(three_finger_swipe); |
| 51 |
| 52 const int sensitivity = prefs->GetInteger(prefs::kTouchpadSensitivity); |
| 53 system::touchpad_settings::SetSensitivity(sensitivity); |
| 54 |
| 55 // If we are not logged in, use owner preferences. |
| 56 PrefService* local_prefs = g_browser_process->local_state(); |
| 57 const bool tap_to_click = |
| 58 g_browser_process->profile_manager()->IsLoggedIn() ? |
| 59 prefs->GetBoolean(prefs::kTapToClickEnabled) : |
| 60 local_prefs->GetBoolean(prefs::kOwnerTapToClickEnabled); |
| 61 system::touchpad_settings::SetTapToClick(tap_to_click); |
| 62 } |
| 63 |
| 64 // When we detect a mouse is attached, apply mouse settings of the last |
| 65 // used profile. |
| 66 void DeviceChangeHandler::MouseExists(bool exists) { |
| 67 if (!exists) |
| 68 return; |
| 69 |
| 70 // Using GetDefaultProfile here because GetLastUsedProfile returns the |
| 71 // LoginManager profile in browser tests. |
| 72 PrefService* prefs = |
| 73 g_browser_process->profile_manager()->GetDefaultProfile()->GetPrefs(); |
| 74 |
| 75 const int sensitivity = prefs->GetInteger(prefs::kMouseSensitivity); |
| 76 system::mouse_settings::SetSensitivity(sensitivity); |
| 77 |
| 78 // If we are not logged in, use owner preferences. |
| 79 PrefService* local_prefs = g_browser_process->local_state(); |
| 80 const bool primary_button_right = |
| 81 g_browser_process->profile_manager()->IsLoggedIn() ? |
| 82 prefs->GetBoolean(prefs::kPrimaryMouseButtonRight) : |
| 83 local_prefs->GetBoolean(prefs::kOwnerPrimaryMouseButtonRight); |
| 84 system::mouse_settings::SetPrimaryButtonRight(primary_button_right); |
| 85 } |
| 86 |
| 87 } // namespace system |
| 88 } // namespace chromeos |
| 89 |
OLD | NEW |