Skip to content

Commit 5b8f515

Browse files
Roman SorokinChromium LUCI CQ
Roman Sorokin
authored and
Chromium LUCI CQ
committed
[Code Health] Migrate to base::Value::Dict in ..
c/b/ash/login/demo_mode/demo_extensions_external_loader.* Bug: 1366865, 1187061 Change-Id: Ie137b872e6ceb668c4f9670318a50160e4c0ed1b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3945089 Reviewed-by: Toni Barzic <[email protected]> Commit-Queue: Roman Sorokin <[email protected]> Cr-Commit-Position: refs/heads/main@{#1057935}
1 parent eb58167 commit 5b8f515

File tree

2 files changed

+24
-31
lines changed

2 files changed

+24
-31
lines changed

chrome/browser/ash/login/demo_mode/demo_extensions_external_loader.cc

+22-30
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace {
3131
// Arbitrary, but reasonable size limit in bytes for prefs file.
3232
constexpr size_t kPrefsSizeLimit = 1024 * 1024;
3333

34-
absl::optional<base::Value> LoadPrefsFromDisk(
34+
absl::optional<base::Value::Dict> LoadPrefsFromDisk(
3535
const base::FilePath& prefs_path) {
3636
if (!base::PathExists(prefs_path)) {
3737
LOG(WARNING) << "Demo extensions prefs not found " << prefs_path.value();
@@ -57,7 +57,7 @@ absl::optional<base::Value> LoadPrefsFromDisk(
5757
return absl::nullopt;
5858
}
5959

60-
return prefs_value;
60+
return std::move(prefs_value).value().TakeDict();
6161
}
6262

6363
} // namespace
@@ -81,12 +81,12 @@ DemoExtensionsExternalLoader::~DemoExtensionsExternalLoader() = default;
8181

8282
void DemoExtensionsExternalLoader::LoadApp(const std::string& app_id) {
8383
app_ids_.push_back(app_id);
84-
base::DictionaryValue prefs;
84+
base::Value::Dict prefs;
8585
for (const std::string& app : app_ids_) {
86-
base::DictionaryValue app_dict;
87-
app_dict.SetKey(extensions::ExternalProviderImpl::kExternalUpdateUrl,
88-
base::Value(extension_urls::kChromeWebstoreUpdateURL));
89-
prefs.SetKey(app, std::move(app_dict));
86+
base::Value::Dict app_dict;
87+
app_dict.Set(extensions::ExternalProviderImpl::kExternalUpdateUrl,
88+
extension_urls::kChromeWebstoreUpdateURL);
89+
prefs.Set(app, std::move(app_dict));
9090
}
9191
if (!external_cache_) {
9292
external_cache_ = std::make_unique<ExternalCacheImpl>(
@@ -101,8 +101,7 @@ void DemoExtensionsExternalLoader::LoadApp(const std::string& app_id) {
101101
// prefs from the Offline Demo Resources, so we don't call LoadApp() if the
102102
// enrollment is offline. Instead, we should merge these prefs or treat the
103103
// cache as a separate provider.
104-
external_cache_->UpdateExtensionsList(base::DictionaryValue::From(
105-
base::Value::ToUniquePtrValue(std::move(prefs))));
104+
external_cache_->UpdateExtensionsListWithDict(std::move(prefs));
106105
}
107106

108107
void DemoExtensionsExternalLoader::StartLoading() {
@@ -116,8 +115,7 @@ void DemoExtensionsExternalLoader::OnExtensionListsUpdated(
116115
DCHECK(external_cache_);
117116
// Notifies the provider that the extensions have either been downloaded or
118117
// found in cache, and are ready to be installed.
119-
LoadFinished(base::DictionaryValue::From(
120-
base::Value::ToUniquePtrValue(base::Value(prefs.Clone()))));
118+
LoadFinishedWithDict(prefs.Clone());
121119
}
122120

123121
void DemoExtensionsExternalLoader::StartLoadingFromOfflineDemoResources() {
@@ -127,7 +125,7 @@ void DemoExtensionsExternalLoader::StartLoadingFromOfflineDemoResources() {
127125
base::FilePath demo_extension_list =
128126
demo_session->resources()->GetExternalExtensionsPrefsPath();
129127
if (demo_extension_list.empty()) {
130-
LoadFinished(std::make_unique<base::DictionaryValue>());
128+
LoadFinishedWithDict(base::Value::Dict());
131129
return;
132130
}
133131

@@ -142,46 +140,40 @@ void DemoExtensionsExternalLoader::StartLoadingFromOfflineDemoResources() {
142140
}
143141

144142
void DemoExtensionsExternalLoader::DemoExternalExtensionsPrefsLoaded(
145-
absl::optional<base::Value> prefs) {
143+
absl::optional<base::Value::Dict> prefs) {
146144
if (!prefs.has_value()) {
147-
LoadFinished(std::make_unique<base::DictionaryValue>());
145+
LoadFinishedWithDict(base::Value::Dict());
148146
return;
149147
}
150-
DCHECK(prefs.value().is_dict());
151-
152148
DemoSession* demo_session = DemoSession::Get();
153149
DCHECK(demo_session);
154150

155151
// Adjust CRX paths in the prefs. Prefs on disk contains paths relative to
156152
// the offline demo resources root - they have to be changed to absolute paths
157153
// so extensions service knows from where to load them.
158-
for (auto&& dict_item : prefs.value().DictItems()) {
154+
for (auto&& dict_item : prefs.value()) {
159155
if (!dict_item.second.is_dict())
160156
continue;
161-
162-
const base::Value* path = dict_item.second.FindKeyOfType(
163-
extensions::ExternalProviderImpl::kExternalCrx,
164-
base::Value::Type::STRING);
165-
if (!path || !path->is_string())
157+
base::Value::Dict& value_dict = dict_item.second.GetDict();
158+
const std::string* path =
159+
value_dict.FindString(extensions::ExternalProviderImpl::kExternalCrx);
160+
if (!path)
166161
continue;
167162

168-
base::FilePath relative_path = base::FilePath(path->GetString());
163+
base::FilePath relative_path = base::FilePath(*path);
169164
if (relative_path.IsAbsolute()) {
170165
LOG(ERROR) << "Ignoring demo extension with an absolute path "
171166
<< dict_item.first;
172-
dict_item.second.RemoveKey(
173-
extensions::ExternalProviderImpl::kExternalCrx);
167+
value_dict.Remove(extensions::ExternalProviderImpl::kExternalCrx);
174168
continue;
175169
}
176170

177-
dict_item.second.SetKey(
171+
value_dict.Set(
178172
extensions::ExternalProviderImpl::kExternalCrx,
179-
base::Value(
180-
demo_session->resources()->GetAbsolutePath(relative_path).value()));
173+
demo_session->resources()->GetAbsolutePath(relative_path).value());
181174
}
182175

183-
LoadFinished(base::DictionaryValue::From(
184-
base::Value::ToUniquePtrValue(std::move(prefs.value()))));
176+
LoadFinishedWithDict(std::move(prefs).value());
185177
}
186178

187179
} // namespace ash

chrome/browser/ash/login/demo_mode/demo_extensions_external_loader.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ class DemoExtensionsExternalLoader : public extensions::ExternalLoader,
6565

6666
// Called when the external extensions prefs are read from the disk.
6767
// `prefs` - demo extensions prefs.
68-
void DemoExternalExtensionsPrefsLoaded(absl::optional<base::Value> prefs);
68+
void DemoExternalExtensionsPrefsLoaded(
69+
absl::optional<base::Value::Dict> prefs);
6970

7071
std::unique_ptr<ExternalCache> external_cache_;
7172

0 commit comments

Comments
 (0)