@@ -31,7 +31,7 @@ namespace {
31
31
// Arbitrary, but reasonable size limit in bytes for prefs file.
32
32
constexpr size_t kPrefsSizeLimit = 1024 * 1024 ;
33
33
34
- absl::optional<base::Value> LoadPrefsFromDisk (
34
+ absl::optional<base::Value::Dict > LoadPrefsFromDisk (
35
35
const base::FilePath& prefs_path) {
36
36
if (!base::PathExists (prefs_path)) {
37
37
LOG (WARNING) << " Demo extensions prefs not found " << prefs_path.value ();
@@ -57,7 +57,7 @@ absl::optional<base::Value> LoadPrefsFromDisk(
57
57
return absl::nullopt;
58
58
}
59
59
60
- return prefs_value;
60
+ return std::move ( prefs_value). value (). TakeDict () ;
61
61
}
62
62
63
63
} // namespace
@@ -81,12 +81,12 @@ DemoExtensionsExternalLoader::~DemoExtensionsExternalLoader() = default;
81
81
82
82
void DemoExtensionsExternalLoader::LoadApp (const std::string& app_id) {
83
83
app_ids_.push_back (app_id);
84
- base::DictionaryValue prefs;
84
+ base::Value::Dict prefs;
85
85
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));
90
90
}
91
91
if (!external_cache_) {
92
92
external_cache_ = std::make_unique<ExternalCacheImpl>(
@@ -101,8 +101,7 @@ void DemoExtensionsExternalLoader::LoadApp(const std::string& app_id) {
101
101
// prefs from the Offline Demo Resources, so we don't call LoadApp() if the
102
102
// enrollment is offline. Instead, we should merge these prefs or treat the
103
103
// 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));
106
105
}
107
106
108
107
void DemoExtensionsExternalLoader::StartLoading () {
@@ -116,8 +115,7 @@ void DemoExtensionsExternalLoader::OnExtensionListsUpdated(
116
115
DCHECK (external_cache_);
117
116
// Notifies the provider that the extensions have either been downloaded or
118
117
// 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 ());
121
119
}
122
120
123
121
void DemoExtensionsExternalLoader::StartLoadingFromOfflineDemoResources () {
@@ -127,7 +125,7 @@ void DemoExtensionsExternalLoader::StartLoadingFromOfflineDemoResources() {
127
125
base::FilePath demo_extension_list =
128
126
demo_session->resources ()->GetExternalExtensionsPrefsPath ();
129
127
if (demo_extension_list.empty ()) {
130
- LoadFinished (std::make_unique<base::DictionaryValue> ());
128
+ LoadFinishedWithDict ( base::Value::Dict ());
131
129
return ;
132
130
}
133
131
@@ -142,46 +140,40 @@ void DemoExtensionsExternalLoader::StartLoadingFromOfflineDemoResources() {
142
140
}
143
141
144
142
void DemoExtensionsExternalLoader::DemoExternalExtensionsPrefsLoaded (
145
- absl::optional<base::Value> prefs) {
143
+ absl::optional<base::Value::Dict > prefs) {
146
144
if (!prefs.has_value ()) {
147
- LoadFinished (std::make_unique<base::DictionaryValue> ());
145
+ LoadFinishedWithDict ( base::Value::Dict ());
148
146
return ;
149
147
}
150
- DCHECK (prefs.value ().is_dict ());
151
-
152
148
DemoSession* demo_session = DemoSession::Get ();
153
149
DCHECK (demo_session);
154
150
155
151
// Adjust CRX paths in the prefs. Prefs on disk contains paths relative to
156
152
// the offline demo resources root - they have to be changed to absolute paths
157
153
// so extensions service knows from where to load them.
158
- for (auto && dict_item : prefs.value (). DictItems () ) {
154
+ for (auto && dict_item : prefs.value ()) {
159
155
if (!dict_item.second .is_dict ())
160
156
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)
166
161
continue ;
167
162
168
- base::FilePath relative_path = base::FilePath (path-> GetString () );
163
+ base::FilePath relative_path = base::FilePath (* path);
169
164
if (relative_path.IsAbsolute ()) {
170
165
LOG (ERROR) << " Ignoring demo extension with an absolute path "
171
166
<< dict_item.first ;
172
- dict_item.second .RemoveKey (
173
- extensions::ExternalProviderImpl::kExternalCrx );
167
+ value_dict.Remove (extensions::ExternalProviderImpl::kExternalCrx );
174
168
continue ;
175
169
}
176
170
177
- dict_item. second . SetKey (
171
+ value_dict. Set (
178
172
extensions::ExternalProviderImpl::kExternalCrx ,
179
- base::Value (
180
- demo_session->resources ()->GetAbsolutePath (relative_path).value ()));
173
+ demo_session->resources ()->GetAbsolutePath (relative_path).value ());
181
174
}
182
175
183
- LoadFinished (base::DictionaryValue::From (
184
- base::Value::ToUniquePtrValue (std::move (prefs.value ()))));
176
+ LoadFinishedWithDict (std::move (prefs).value ());
185
177
}
186
178
187
179
} // namespace ash
0 commit comments