Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/system/input_device_settings.h" | 5 #include "chrome/browser/chromeos/system/input_device_settings.h" |
| 6 | 6 |
| 7 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
| 8 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 8 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 9 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" | 9 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" |
| 10 #include "chrome/browser/profiles/profile_manager.h" | 10 #include "chrome/browser/profiles/profile_manager.h" |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 bool keyboard_driven = false; | 227 bool keyboard_driven = false; |
| 228 if (chromeos::system::StatisticsProvider::GetInstance()->GetMachineFlag( | 228 if (chromeos::system::StatisticsProvider::GetInstance()->GetMachineFlag( |
| 229 kOemKeyboardDrivenOobeKey, &keyboard_driven)) { | 229 kOemKeyboardDrivenOobeKey, &keyboard_driven)) { |
| 230 return keyboard_driven; | 230 return keyboard_driven; |
| 231 } | 231 } |
| 232 | 232 |
| 233 return false; | 233 return false; |
| 234 } | 234 } |
| 235 | 235 |
| 236 // static | 236 // static |
| 237 void InputDeviceSettings::RegisterPrefs(PrefRegistrySimple* registry) { | |
| 238 registry->RegisterBooleanPref(::prefs::kLocalTouchScreenEnabled, true); | |
| 239 } | |
| 240 | |
| 241 // static | |
| 237 void InputDeviceSettings::RegisterProfilePrefs(PrefRegistrySimple* registry) { | 242 void InputDeviceSettings::RegisterProfilePrefs(PrefRegistrySimple* registry) { |
| 238 registry->RegisterBooleanPref(::prefs::kTouchScreenEnabled, true); | 243 registry->RegisterBooleanPref(::prefs::kTouchScreenEnabled, true); |
| 239 registry->RegisterBooleanPref(::prefs::kTouchPadEnabled, true); | 244 registry->RegisterBooleanPref(::prefs::kTouchPadEnabled, true); |
| 240 } | 245 } |
| 241 | 246 |
| 242 void InputDeviceSettings::UpdateTouchDevicesStatusFromActiveProfilePrefs() { | 247 void InputDeviceSettings::UpdateTouchDevicesStatusFromPrefs() { |
| 248 UpdateTouchscreenStatusFromPrefs(); | |
| 249 | |
| 243 PrefService* user_prefs = GetActiveProfilePrefs(); | 250 PrefService* user_prefs = GetActiveProfilePrefs(); |
| 244 if (!user_prefs) | 251 if (!user_prefs) |
| 245 return; | 252 return; |
| 246 | 253 |
| 247 const bool touch_screen_status = | |
| 248 user_prefs->HasPrefPath(::prefs::kTouchScreenEnabled) | |
| 249 ? user_prefs->GetBoolean(::prefs::kTouchScreenEnabled) | |
| 250 : true; | |
| 251 | |
| 252 const bool touch_pad_status = | 254 const bool touch_pad_status = |
| 253 user_prefs->HasPrefPath(::prefs::kTouchPadEnabled) | 255 user_prefs->HasPrefPath(::prefs::kTouchPadEnabled) |
| 254 ? user_prefs->GetBoolean(::prefs::kTouchPadEnabled) | 256 ? user_prefs->GetBoolean(::prefs::kTouchPadEnabled) |
| 255 : true; | 257 : true; |
| 256 | |
| 257 SetTouchscreensEnabled(touch_screen_status); | |
| 258 SetInternalTouchpadEnabled(touch_pad_status); | 258 SetInternalTouchpadEnabled(touch_pad_status); |
| 259 } | 259 } |
| 260 | 260 |
| 261 void InputDeviceSettings::ToggleTouchscreen() { | 261 bool InputDeviceSettings::IsTouchscreenEnabledInPrefs(bool is_local) const { |
| 262 PrefService* user_prefs = GetActiveProfilePrefs(); | 262 if (is_local) { |
| 263 if (!user_prefs) | 263 PrefService* local_state = g_browser_process->local_state(); |
| 264 return; | 264 DCHECK(local_state); |
| 265 | 265 |
| 266 const bool touch_screen_status = | 266 return local_state->HasPrefPath(::prefs::kLocalTouchScreenEnabled) |
| 267 user_prefs->HasPrefPath(::prefs::kTouchScreenEnabled) | 267 ? local_state->GetBoolean(::prefs::kLocalTouchScreenEnabled) |
| 268 ? user_prefs->GetBoolean(::prefs::kTouchScreenEnabled) | 268 : true; |
| 269 : true; | 269 } else { |
| 270 PrefService* user_prefs = GetActiveProfilePrefs(); | |
| 271 if (!user_prefs) | |
| 272 return true; | |
| 270 | 273 |
| 271 user_prefs->SetBoolean(::prefs::kTouchScreenEnabled, !touch_screen_status); | 274 return user_prefs->HasPrefPath(::prefs::kTouchScreenEnabled) |
| 272 SetTouchscreensEnabled(!touch_screen_status); | 275 ? user_prefs->GetBoolean(::prefs::kTouchScreenEnabled) |
| 276 : true; | |
| 277 } | |
| 278 } | |
| 279 | |
| 280 void InputDeviceSettings::SetTouchscreenEnabledInPrefs(bool enabled, | |
| 281 bool is_local) { | |
| 282 if (is_local) { | |
| 283 PrefService* local_state = g_browser_process->local_state(); | |
| 284 DCHECK(local_state); | |
| 285 local_state->SetBoolean(::prefs::kLocalTouchScreenEnabled, enabled); | |
| 286 } else { | |
| 287 PrefService* user_prefs = GetActiveProfilePrefs(); | |
| 288 if (!user_prefs) | |
|
Daniel Erat
2016/12/02 21:48:56
is this expected to happen or should a warning/err
Qiang(Joe) Xu
2016/12/02 23:55:11
I take a look at this: https://cs.chromium.org/chr
| |
| 289 return; | |
| 290 user_prefs->SetBoolean(::prefs::kTouchScreenEnabled, enabled); | |
| 291 } | |
| 292 } | |
| 293 | |
| 294 void InputDeviceSettings::UpdateTouchscreenStatusFromPrefs() { | |
| 295 SetTouchscreensEnabled(IsTouchscreenEnabledInPrefs(true) == | |
|
Daniel Erat
2016/12/02 21:48:56
this is a bit tricky, so i'd probably write it out
afakhry
2016/12/02 22:33:20
I discussed with him offline. This should be an AN
Qiang(Joe) Xu
2016/12/02 23:55:11
Done.
| |
| 296 IsTouchscreenEnabledInPrefs(false)); | |
| 273 } | 297 } |
| 274 | 298 |
| 275 void InputDeviceSettings::ToggleTouchpad() { | 299 void InputDeviceSettings::ToggleTouchpad() { |
| 276 PrefService* user_prefs = GetActiveProfilePrefs(); | 300 PrefService* user_prefs = GetActiveProfilePrefs(); |
| 277 if (!user_prefs) | 301 if (!user_prefs) |
| 278 return; | 302 return; |
| 279 | 303 |
| 280 const bool touch_pad_status = | 304 const bool touch_pad_status = |
| 281 user_prefs->HasPrefPath(::prefs::kTouchPadEnabled) | 305 user_prefs->HasPrefPath(::prefs::kTouchPadEnabled) |
| 282 ? user_prefs->GetBoolean(::prefs::kTouchPadEnabled) | 306 ? user_prefs->GetBoolean(::prefs::kTouchPadEnabled) |
| 283 : true; | 307 : true; |
| 284 | 308 |
| 285 user_prefs->SetBoolean(::prefs::kTouchPadEnabled, !touch_pad_status); | 309 user_prefs->SetBoolean(::prefs::kTouchPadEnabled, !touch_pad_status); |
| 286 SetInternalTouchpadEnabled(!touch_pad_status); | 310 SetInternalTouchpadEnabled(!touch_pad_status); |
| 287 } | 311 } |
| 288 | 312 |
| 289 } // namespace system | 313 } // namespace system |
| 290 } // namespace chromeos | 314 } // namespace chromeos |
| OLD | NEW |