1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
ash / system / input_device_settings / pref_handlers / touchpad_pref_handler_impl.cc [blame]
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/input_device_settings/pref_handlers/touchpad_pref_handler_impl.h"
#include "ash/constants/ash_features.h"
#include "ash/constants/ash_pref_names.h"
#include "ash/public/mojom/input_device_settings.mojom-forward.h"
#include "ash/public/mojom/input_device_settings.mojom.h"
#include "ash/shell.h"
#include "ash/system/input_device_settings/input_device_settings_defaults.h"
#include "ash/system/input_device_settings/input_device_settings_pref_names.h"
#include "ash/system/input_device_settings/input_device_settings_utils.h"
#include "ash/system/input_device_settings/input_device_tracker.h"
#include "ash/system/input_device_settings/settings_updated_metrics_info.h"
#include "base/check.h"
#include "base/json/values_util.h"
#include "base/values.h"
#include "components/account_id/account_id.h"
#include "components/prefs/pref_service.h"
#include "components/user_manager/known_user.h"
#include "ui/events/ash/mojom/simulate_right_click_modifier.mojom-shared.h"
namespace ash {
namespace {
// Whether or not settings taken during the transition period should be
// persisted to the prefs. Values should only ever be true if the original
// setting was a user-configured value.
struct ForceTouchpadSettingPersistence {
bool sensitivity = false;
bool reverse_scrolling = false;
bool acceleration_enabled = false;
bool tap_to_click_enabled = false;
bool tap_dragging_enabled = false;
bool scroll_sensitivity = false;
bool scroll_acceleration = false;
bool haptic_sensitivity = false;
bool haptic_enabled = false;
bool three_finger_click_enabled = false;
};
ui::mojom::SimulateRightClickModifier GetSimulateRightClickModifierFromPrefs(
PrefService* prefs) {
if (!prefs) {
return kDefaultSimulateRightClick;
}
const auto* alt_right_click_preference =
prefs->GetUserPrefValue(prefs::kAltEventRemappedToRightClick);
const auto* search_right_click_preference =
prefs->GetUserPrefValue(prefs::kSearchEventRemappedToRightClick);
const auto alt_count =
alt_right_click_preference ? alt_right_click_preference->GetInt() : 0;
const auto search_count = search_right_click_preference
? search_right_click_preference->GetInt()
: 0;
// Disable (Alt/Search+Click) remapping if the user never performs this
// action.
if (alt_count == 0 && search_count == 0) {
return ui::mojom::SimulateRightClickModifier::kNone;
}
// Return the modifier used more frequently, in case of a tie, Search will
// be preferred to avoid Alt-based issues.
return search_count >= alt_count
? ui::mojom::SimulateRightClickModifier::kSearch
: ui::mojom::SimulateRightClickModifier::kAlt;
}
// GetTouchpadSettingsFromPrefs returns a touchpad settings based on user prefs
// to be used as settings for new touchpads.
mojom::TouchpadSettingsPtr GetTouchpadSettingsFromPrefs(
PrefService* prefs,
ForceTouchpadSettingPersistence& force_persistence) {
mojom::TouchpadSettingsPtr settings = mojom::TouchpadSettings::New();
const auto* sensitivity_preference =
prefs->GetUserPrefValue(prefs::kTouchpadSensitivity);
settings->sensitivity = sensitivity_preference
? sensitivity_preference->GetInt()
: kDefaultSensitivity;
force_persistence.sensitivity = sensitivity_preference != nullptr;
const auto* reverse_scrolling_preference =
prefs->GetUserPrefValue(prefs::kNaturalScroll);
settings->reverse_scrolling = reverse_scrolling_preference
? reverse_scrolling_preference->GetBool()
: kDefaultReverseScrolling;
force_persistence.reverse_scrolling = reverse_scrolling_preference != nullptr;
const auto* acceleration_enabled_preference =
prefs->GetUserPrefValue(prefs::kTouchpadAcceleration);
settings->acceleration_enabled =
acceleration_enabled_preference
? acceleration_enabled_preference->GetBool()
: kDefaultAccelerationEnabled;
force_persistence.acceleration_enabled =
acceleration_enabled_preference != nullptr;
const auto* tap_to_click_enabled_preference =
prefs->GetUserPrefValue(prefs::kTapToClickEnabled);
settings->tap_to_click_enabled =
tap_to_click_enabled_preference
? tap_to_click_enabled_preference->GetBool()
: kDefaultTapToClickEnabled;
force_persistence.tap_to_click_enabled =
tap_to_click_enabled_preference != nullptr;
// Three finger click does not update `force_persistence` as it will soon be
// removed.
const auto* three_finger_click_enabled_preference =
prefs->GetUserPrefValue(prefs::kEnableTouchpadThreeFingerClick);
settings->three_finger_click_enabled =
three_finger_click_enabled_preference
? three_finger_click_enabled_preference->GetBool()
: kDefaultThreeFingerClickEnabled;
const auto* tap_dragging_enabled_preference =
prefs->GetUserPrefValue(prefs::kTapDraggingEnabled);
settings->tap_dragging_enabled =
tap_dragging_enabled_preference
? tap_dragging_enabled_preference->GetBool()
: kDefaultTapDraggingEnabled;
force_persistence.tap_dragging_enabled =
tap_dragging_enabled_preference != nullptr;
const auto* scroll_sensitivity_preference =
prefs->GetUserPrefValue(prefs::kTouchpadScrollSensitivity);
settings->scroll_sensitivity = scroll_sensitivity_preference
? scroll_sensitivity_preference->GetInt()
: kDefaultScrollSensitivity;
force_persistence.scroll_sensitivity =
scroll_sensitivity_preference != nullptr;
const auto* scroll_acceleration_preference =
prefs->GetUserPrefValue(prefs::kTouchpadScrollAcceleration);
settings->scroll_acceleration =
scroll_acceleration_preference ? scroll_acceleration_preference->GetBool()
: kDefaultScrollAccelerationEnabled;
force_persistence.scroll_acceleration =
scroll_acceleration_preference != nullptr;
const auto* haptic_sensitivity_preference =
prefs->GetUserPrefValue(prefs::kTouchpadHapticClickSensitivity);
settings->haptic_sensitivity = haptic_sensitivity_preference
? haptic_sensitivity_preference->GetInt()
: kDefaultHapticSensitivity;
force_persistence.haptic_sensitivity =
haptic_sensitivity_preference != nullptr;
const auto* haptic_enabled_preference =
prefs->GetUserPrefValue(prefs::kTouchpadHapticFeedback);
settings->haptic_enabled = haptic_enabled_preference
? haptic_enabled_preference->GetBool()
: kDefaultHapticFeedbackEnabled;
force_persistence.haptic_enabled = haptic_enabled_preference != nullptr;
if (features::IsAltClickAndSixPackCustomizationEnabled()) {
settings->simulate_right_click =
GetSimulateRightClickModifierFromPrefs(prefs);
}
return settings;
}
mojom::TouchpadSettingsPtr RetrieveTouchpadSettings(
PrefService* pref_service,
const mojom::Touchpad& touchpad,
const base::Value::Dict& settings_dict) {
mojom::TouchpadSettingsPtr settings = mojom::TouchpadSettings::New();
settings->sensitivity =
settings_dict.FindInt(prefs::kTouchpadSettingSensitivity)
.value_or(kDefaultSensitivity);
settings->reverse_scrolling =
settings_dict.FindBool(prefs::kTouchpadSettingReverseScrolling)
.value_or(kDefaultReverseScrolling);
settings->acceleration_enabled =
settings_dict.FindBool(prefs::kTouchpadSettingAccelerationEnabled)
.value_or(kDefaultAccelerationEnabled);
settings->tap_to_click_enabled =
settings_dict.FindBool(prefs::kTouchpadSettingTapToClickEnabled)
.value_or(kDefaultTapToClickEnabled);
settings->three_finger_click_enabled =
settings_dict.FindBool(prefs::kTouchpadSettingThreeFingerClickEnabled)
.value_or(kDefaultThreeFingerClickEnabled);
settings->tap_dragging_enabled =
settings_dict.FindBool(prefs::kTouchpadSettingTapDraggingEnabled)
.value_or(kDefaultTapDraggingEnabled);
settings->scroll_sensitivity =
settings_dict.FindInt(prefs::kTouchpadSettingScrollSensitivity)
.value_or(kDefaultScrollSensitivity);
settings->scroll_acceleration =
settings_dict.FindBool(prefs::kTouchpadSettingScrollAcceleration)
.value_or(kDefaultScrollAccelerationEnabled);
if (touchpad.is_haptic) {
settings->haptic_sensitivity =
settings_dict.FindInt(prefs::kTouchpadSettingHapticSensitivity)
.value_or(kDefaultSensitivity);
settings->haptic_enabled =
settings_dict.FindBool(prefs::kTouchpadSettingHapticEnabled)
.value_or(kDefaultHapticFeedbackEnabled);
} else {
settings->haptic_sensitivity = kDefaultSensitivity;
settings->haptic_enabled = kDefaultHapticFeedbackEnabled;
}
if (features::IsAltClickAndSixPackCustomizationEnabled()) {
settings->simulate_right_click =
static_cast<ui::mojom::SimulateRightClickModifier>(
settings_dict.FindInt(prefs::kTouchpadSettingSimulateRightClick)
.value_or(static_cast<int>(
GetSimulateRightClickModifierFromPrefs(pref_service))));
}
return settings;
}
mojom::TouchpadSettingsPtr GetDefaultTouchpadSettings(
PrefService* pref_service,
const mojom::Touchpad& touchpad) {
if (pref_service) {
return RetrieveTouchpadSettings(
pref_service, touchpad,
pref_service->GetDict(prefs::kTouchpadDefaultSettings));
}
return RetrieveTouchpadSettings(pref_service, touchpad, /*settings_dict=*/{});
}
base::Value::Dict ConvertSettingsToDict(
const mojom::Touchpad& touchpad,
const ForceTouchpadSettingPersistence& force_persistence,
const base::Value::Dict* existing_settings_dict) {
// Populate `settings_dict` with all settings in `settings`.
base::Value::Dict settings_dict;
if (ShouldPersistSetting(prefs::kTouchpadSettingSensitivity,
static_cast<int>(touchpad.settings->sensitivity),
kDefaultSensitivity, force_persistence.sensitivity,
existing_settings_dict)) {
settings_dict.Set(prefs::kTouchpadSettingSensitivity,
touchpad.settings->sensitivity);
}
if (ShouldPersistSetting(
prefs::kTouchpadSettingReverseScrolling,
touchpad.settings->reverse_scrolling, kDefaultReverseScrolling,
force_persistence.reverse_scrolling, existing_settings_dict)) {
settings_dict.Set(prefs::kTouchpadSettingReverseScrolling,
touchpad.settings->reverse_scrolling);
}
if (ShouldPersistSetting(
prefs::kTouchpadSettingAccelerationEnabled,
touchpad.settings->acceleration_enabled, kDefaultAccelerationEnabled,
force_persistence.acceleration_enabled, existing_settings_dict)) {
settings_dict.Set(prefs::kTouchpadSettingAccelerationEnabled,
touchpad.settings->acceleration_enabled);
}
if (ShouldPersistSetting(
prefs::kTouchpadSettingScrollSensitivity,
static_cast<int>(touchpad.settings->scroll_sensitivity),
kDefaultScrollSensitivity, force_persistence.scroll_sensitivity,
existing_settings_dict)) {
settings_dict.Set(prefs::kTouchpadSettingScrollSensitivity,
touchpad.settings->scroll_sensitivity);
}
if (ShouldPersistSetting(prefs::kTouchpadSettingScrollAcceleration,
touchpad.settings->scroll_acceleration,
kDefaultScrollAccelerationEnabled,
force_persistence.scroll_acceleration,
existing_settings_dict)) {
settings_dict.Set(prefs::kTouchpadSettingScrollAcceleration,
touchpad.settings->scroll_acceleration);
}
if (ShouldPersistSetting(
prefs::kTouchpadSettingTapToClickEnabled,
touchpad.settings->tap_to_click_enabled, kDefaultTapToClickEnabled,
force_persistence.tap_to_click_enabled, existing_settings_dict)) {
settings_dict.Set(prefs::kTouchpadSettingTapToClickEnabled,
touchpad.settings->tap_to_click_enabled);
}
if (ShouldPersistSetting(prefs::kTouchpadSettingThreeFingerClickEnabled,
touchpad.settings->three_finger_click_enabled,
kDefaultThreeFingerClickEnabled,
force_persistence.three_finger_click_enabled,
existing_settings_dict)) {
settings_dict.Set(prefs::kTouchpadSettingThreeFingerClickEnabled,
touchpad.settings->three_finger_click_enabled);
}
if (ShouldPersistSetting(
prefs::kTouchpadSettingTapDraggingEnabled,
touchpad.settings->tap_dragging_enabled, kDefaultTapDraggingEnabled,
force_persistence.tap_dragging_enabled, existing_settings_dict)) {
settings_dict.Set(prefs::kTouchpadSettingTapDraggingEnabled,
touchpad.settings->tap_dragging_enabled);
}
if (touchpad.is_haptic &&
ShouldPersistSetting(
prefs::kTouchpadSettingHapticSensitivity,
static_cast<int>(touchpad.settings->haptic_sensitivity),
kDefaultSensitivity, force_persistence.haptic_sensitivity,
existing_settings_dict)) {
settings_dict.Set(prefs::kTouchpadSettingHapticSensitivity,
touchpad.settings->haptic_sensitivity);
}
if (touchpad.is_haptic &&
ShouldPersistSetting(
prefs::kTouchpadSettingHapticEnabled,
touchpad.settings->haptic_enabled, kDefaultHapticFeedbackEnabled,
force_persistence.haptic_enabled, existing_settings_dict)) {
settings_dict.Set(prefs::kTouchpadSettingHapticEnabled,
touchpad.settings->haptic_enabled);
}
if (features::IsAltClickAndSixPackCustomizationEnabled()) {
settings_dict.Set(
prefs::kTouchpadSettingSimulateRightClick,
static_cast<int>(touchpad.settings->simulate_right_click));
}
return settings_dict;
}
void UpdateInternalTouchpadSettingsImpl(
PrefService* pref_service,
const mojom::Touchpad& touchpad,
const ForceTouchpadSettingPersistence& force_persistence) {
CHECK(touchpad.settings);
CHECK(!touchpad.is_external);
base::Value::Dict existing_settings_dict =
pref_service->GetDict(prefs::kTouchpadInternalSettings).Clone();
base::Value::Dict settings_dict = ConvertSettingsToDict(
touchpad, force_persistence, &existing_settings_dict);
// Merge the new settings into the old settings so that all settings are
// transferred over (including ones that might not work on the current
// touchpad such as haptic settings)
existing_settings_dict.Merge(std::move(settings_dict));
pref_service->SetDict(prefs::kTouchpadInternalSettings,
std::move(existing_settings_dict));
}
void UpdateTouchpadSettingsImpl(
PrefService* pref_service,
const mojom::Touchpad& touchpad,
const ForceTouchpadSettingPersistence& force_persistence) {
CHECK(touchpad.settings);
if (!touchpad.is_external) {
UpdateInternalTouchpadSettingsImpl(pref_service, touchpad,
force_persistence);
return;
}
base::Value::Dict devices_dict =
pref_service->GetDict(prefs::kTouchpadDeviceSettingsDictPref).Clone();
base::Value::Dict* existing_settings_dict =
devices_dict.FindDict(touchpad.device_key);
base::Value::Dict settings_dict = ConvertSettingsToDict(
touchpad, force_persistence, existing_settings_dict);
const base::Time time_stamp = base::Time::Now();
settings_dict.Set(prefs::kLastUpdatedKey, base::TimeToValue(time_stamp));
// If an old settings dict already exists for the device, merge the updated
// settings into the old settings. Otherwise, insert the dict at
// `touchpad.device_key`.
if (existing_settings_dict) {
existing_settings_dict->Merge(std::move(settings_dict));
} else {
devices_dict.Set(touchpad.device_key, std::move(settings_dict));
}
pref_service->SetDict(std::string(prefs::kTouchpadDeviceSettingsDictPref),
std::move(devices_dict));
}
mojom::TouchpadSettingsPtr GetTouchpadSettingsFromOldLocalStatePrefs(
PrefService* local_state,
const AccountId& account_id,
const mojom::Touchpad& touchpad) {
mojom::TouchpadSettingsPtr settings =
GetDefaultTouchpadSettings(/*pref_service=*/nullptr, touchpad);
settings->tap_to_click_enabled =
user_manager::KnownUser(local_state)
.FindBoolPath(account_id, prefs::kOwnerTapToClickEnabled)
.value_or(kDefaultTapToClickEnabled);
return settings;
}
bool HasDefaultSettings(PrefService* pref_service) {
const auto* pref =
pref_service->FindPreference(prefs::kTouchpadDefaultSettings);
return pref && pref->HasUserSetting();
}
void InitializeSettingsUpdateMetricInfo(
PrefService* pref_service,
const mojom::Touchpad& touchpad,
SettingsUpdatedMetricsInfo::Category category) {
CHECK(pref_service);
const auto& settings_metric_info =
pref_service->GetDict(prefs::kTouchpadUpdateSettingsMetricInfo);
const auto* device_metric_info =
settings_metric_info.Find(touchpad.device_key);
if (device_metric_info) {
return;
}
auto updated_metric_info = settings_metric_info.Clone();
const SettingsUpdatedMetricsInfo metrics_info(category, base::Time::Now());
updated_metric_info.Set(touchpad.device_key, metrics_info.ToDict());
pref_service->SetDict(prefs::kTouchpadUpdateSettingsMetricInfo,
std::move(updated_metric_info));
}
void InitializeTouchpadSettingsImpl(PrefService* pref_service,
mojom::Touchpad* touchpad,
bool force_initialize_to_default_settings) {
if (!pref_service) {
touchpad->settings = GetDefaultTouchpadSettings(pref_service, *touchpad);
return;
}
const base::Value::Dict* settings_dict = nullptr;
if (!touchpad->is_external) {
settings_dict = &pref_service->GetDict(prefs::kTouchpadInternalSettings);
if (settings_dict->empty()) {
settings_dict = nullptr;
}
} else {
const auto& devices_dict =
pref_service->GetDict(prefs::kTouchpadDeviceSettingsDictPref);
settings_dict = devices_dict.FindDict(touchpad->device_key);
}
// Do not lookup settings dict if we are force refreshing back to default
// settings.
if (force_initialize_to_default_settings) {
settings_dict = nullptr;
}
ForceTouchpadSettingPersistence force_persistence;
SettingsUpdatedMetricsInfo::Category category;
if (settings_dict) {
category = SettingsUpdatedMetricsInfo::Category::kSynced;
touchpad->settings =
RetrieveTouchpadSettings(pref_service, *touchpad, *settings_dict);
} else if (Shell::Get()->input_device_tracker()->WasDevicePreviouslyConnected(
InputDeviceTracker::InputDeviceCategory::kTouchpad,
touchpad->device_key)) {
category = SettingsUpdatedMetricsInfo::Category::kDefault;
touchpad->settings =
GetTouchpadSettingsFromPrefs(pref_service, force_persistence);
} else {
category = HasDefaultSettings(pref_service)
? SettingsUpdatedMetricsInfo::Category::kDefault
: SettingsUpdatedMetricsInfo::Category::kFirstEver;
touchpad->settings = GetDefaultTouchpadSettings(pref_service, *touchpad);
}
DCHECK(touchpad->settings);
InitializeSettingsUpdateMetricInfo(pref_service, *touchpad, category);
UpdateTouchpadSettingsImpl(pref_service, *touchpad, force_persistence);
}
} // namespace
TouchpadPrefHandlerImpl::TouchpadPrefHandlerImpl() = default;
TouchpadPrefHandlerImpl::~TouchpadPrefHandlerImpl() = default;
void TouchpadPrefHandlerImpl::InitializeTouchpadSettings(
PrefService* pref_service,
mojom::Touchpad* touchpad) {
InitializeTouchpadSettingsImpl(
pref_service, touchpad,
/*force_initialize_to_default_settings=*/false);
}
void TouchpadPrefHandlerImpl::UpdateTouchpadSettings(
PrefService* pref_service,
const mojom::Touchpad& touchpad) {
UpdateTouchpadSettingsImpl(pref_service, touchpad,
/*force_persistence=*/{});
}
void TouchpadPrefHandlerImpl::InitializeLoginScreenTouchpadSettings(
PrefService* local_state,
const AccountId& account_id,
mojom::Touchpad* touchpad) {
// Verify if the flag is enabled.
if (!features::IsInputDeviceSettingsSplitEnabled()) {
return;
}
CHECK(local_state);
const auto* settings_dict = GetLoginScreenSettingsDict(
local_state, account_id,
touchpad->is_external ? prefs::kTouchpadLoginScreenExternalSettingsPref
: prefs::kTouchpadLoginScreenInternalSettingsPref);
if (settings_dict) {
touchpad->settings = RetrieveTouchpadSettings(/*pref_service=*/nullptr,
*touchpad, *settings_dict);
} else {
touchpad->settings = GetTouchpadSettingsFromOldLocalStatePrefs(
local_state, account_id, *touchpad);
}
if (features::IsAltClickAndSixPackCustomizationEnabled()) {
touchpad->settings->simulate_right_click = kDefaultSimulateRightClick;
}
}
void TouchpadPrefHandlerImpl::UpdateLoginScreenTouchpadSettings(
PrefService* local_state,
const AccountId& account_id,
const mojom::Touchpad& touchpad) {
CHECK(local_state);
const auto* pref_name = touchpad.is_external
? prefs::kTouchpadLoginScreenExternalSettingsPref
: prefs::kTouchpadLoginScreenInternalSettingsPref;
auto* settings_dict =
GetLoginScreenSettingsDict(local_state, account_id, pref_name);
user_manager::KnownUser(local_state)
.SetPath(account_id, pref_name,
std::make_optional<base::Value>(ConvertSettingsToDict(
touchpad, /*force_persistence=*/{}, settings_dict)));
}
void TouchpadPrefHandlerImpl::InitializeWithDefaultTouchpadSettings(
mojom::Touchpad* touchpad) {
touchpad->settings =
GetDefaultTouchpadSettings(/*pref_service=*/nullptr, *touchpad);
}
void TouchpadPrefHandlerImpl::UpdateDefaultTouchpadSettings(
PrefService* pref_service,
const mojom::Touchpad& touchpad) {
// All settings should be persisted fully when storing defaults.
auto settings_dict =
ConvertSettingsToDict(touchpad, /*force_persistence=*/{true},
/*existing_settings_dict=*/nullptr);
pref_service->SetDict(prefs::kTouchpadDefaultSettings,
std::move(settings_dict));
}
void TouchpadPrefHandlerImpl::ForceInitializeWithDefaultSettings(
PrefService* pref_service,
mojom::Touchpad* touchpad) {
InitializeTouchpadSettingsImpl(pref_service, touchpad,
/*force_initialize_to_default_settings=*/true);
}
} // namespace ash