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
ash / system / input_device_settings / device_image_storage.cc [blame]
// Copyright 2024 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/device_image_storage.h"
#include "ash/shell.h"
#include "ash/system/input_device_settings/input_device_settings_pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
namespace ash {
std::optional<std::string> DeviceImageStorage::GetImage(
const std::string& device_key) const {
PrefService* local_state = Shell::Get()->local_state();
if (!local_state) {
LOG(WARNING) << "No shell local state available";
return std::nullopt;
}
const std::string* device_image =
local_state->GetDict(prefs::kDeviceImagesDictPref).FindString(device_key);
if (!device_image) {
return std::nullopt;
}
return *device_image;
}
bool DeviceImageStorage::PersistDeviceImage(const std::string& device_key,
const std::string& data_url) {
PrefService* local_state = Shell::Get()->local_state();
if (!local_state) {
LOG(WARNING) << "No shell local state available";
return false;
}
ScopedDictPrefUpdate device_images(local_state, prefs::kDeviceImagesDictPref);
if (!device_images->Set(device_key, data_url)) {
LOG(WARNING) << "Failed to persist image to prefs for device_key: "
<< device_key;
return false;
}
return true;
}
} // namespace ash