Skip to content

Commit 517c487

Browse files
David BertoniChromium LUCI CQ
David Bertoni
authored and
Chromium LUCI CQ
committed
[Extensions] Change UpdateExtensionPref to use absl::optional.
This CL changes ExtensionPrefs::UpdateExtensionPref to use absl::optional instead of std::unique_ptr. Bug: N/A Change-Id: Ieab84db0c422e69164954aecce1dc1dc13a77004 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4283497 Reviewed-by: Xiyuan Xia <[email protected]> Reviewed-by: proberge <[email protected]> Reviewed-by: Emilia Paz <[email protected]> Commit-Queue: David Bertoni <[email protected]> Reviewed-by: Dominick Ng <[email protected]> Reviewed-by: Tim <[email protected]> Reviewed-by: David Tseng <[email protected]> Reviewed-by: Anunoy Ghosh <[email protected]> Cr-Commit-Position: refs/heads/main@{#1109960}
1 parent 3da0db3 commit 517c487

36 files changed

+164
-173
lines changed

apps/saved_files_service.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "extensions/common/permissions/api_permission.h"
2525
#include "extensions/common/permissions/permission_set.h"
2626
#include "extensions/common/permissions/permissions_data.h"
27+
#include "third_party/abseil-cpp/absl/types/optional.h"
2728

2829
namespace apps {
2930

@@ -103,7 +104,7 @@ void RemoveSavedFileEntry(ExtensionPrefs* prefs,
103104
// Clears all SavedFileEntry for the app from ExtensionPrefs.
104105
void ClearSavedFileEntries(ExtensionPrefs* prefs,
105106
const std::string& extension_id) {
106-
prefs->UpdateExtensionPref(extension_id, kFileEntries, nullptr);
107+
prefs->UpdateExtensionPref(extension_id, kFileEntries, absl::nullopt);
107108
}
108109

109110
// Returns all SavedFileEntries for the app.

chrome/browser/ash/app_list/app_service/app_service_app_model_builder_unittest.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -577,9 +577,8 @@ TEST_F(ExtensionAppTest, InvalidOrdinal) {
577577
// Creates a corrupted ordinal case.
578578
extensions::ExtensionPrefs* prefs =
579579
extensions::ExtensionPrefs::Get(profile_.get());
580-
prefs->UpdateExtensionPref(
581-
kHostedAppId, "page_ordinal",
582-
std::make_unique<base::Value>("a corrupted ordinal"));
580+
prefs->UpdateExtensionPref(kHostedAppId, "page_ordinal",
581+
base::Value("a corrupted ordinal"));
583582

584583
// This should not assert or crash.
585584
CreateBuilder();

chrome/browser/extensions/api/commands/command_service.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ void MergeSuggestedKeyPrefs(const std::string& extension_id,
8787
}
8888

8989
extension_prefs->UpdateExtensionPref(
90-
extension_id, kCommands,
91-
std::make_unique<base::Value>(std::move(suggested_key_prefs)));
90+
extension_id, kCommands, base::Value(std::move(suggested_key_prefs)));
9291
}
9392

9493
} // namespace
@@ -608,7 +607,7 @@ void CommandService::RemoveDefunctExtensionSuggestedCommandPrefs(
608607

609608
extension_prefs->UpdateExtensionPref(
610609
extension->id(), kCommands,
611-
std::make_unique<base::Value>(std::move(suggested_key_prefs)));
610+
base::Value(std::move(suggested_key_prefs)));
612611
}
613612
}
614613

chrome/browser/extensions/api/declarative/rules_registry_with_cache_unittest.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,11 @@ TEST_F(RulesRegistryWithCacheTest, DeclarativeRulesStored) {
245245
EXPECT_TRUE(cache_delegate->GetDeclarativeRulesStored(extension1_->id()));
246246

247247
extension_prefs->UpdateExtensionPref(extension1_->id(), rules_stored_key,
248-
std::make_unique<base::Value>(false));
248+
base::Value(false));
249249
EXPECT_FALSE(cache_delegate->GetDeclarativeRulesStored(extension1_->id()));
250250

251251
extension_prefs->UpdateExtensionPref(extension1_->id(), rules_stored_key,
252-
std::make_unique<base::Value>(true));
252+
base::Value(true));
253253
EXPECT_TRUE(cache_delegate->GetDeclarativeRulesStored(extension1_->id()));
254254

255255
// 2. Test writing behavior.
@@ -342,7 +342,7 @@ TEST_F(RulesRegistryWithCacheTest, RulesStoredFlagMultipleRegistries) {
342342

343343
// Update the flag for the first registry.
344344
extension_prefs->UpdateExtensionPref(extension1_->id(), rules_stored_key1,
345-
std::make_unique<base::Value>(false));
345+
base::Value(false));
346346
EXPECT_FALSE(cache_delegate1->GetDeclarativeRulesStored(extension1_->id()));
347347
EXPECT_TRUE(cache_delegate2->GetDeclarativeRulesStored(extension1_->id()));
348348
}

chrome/browser/extensions/api/device_permissions_manager_unittest.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,8 @@ TEST_F(DevicePermissionsManagerTest, LoadPrefs) {
308308
" \"vendor_id\": 0"
309309
" }"
310310
"]");
311-
env_->GetExtensionPrefs()->UpdateExtensionPref(
312-
extension_->id(), "devices",
313-
base::Value::ToUniquePtrValue(std::move(prefs_value)));
311+
env_->GetExtensionPrefs()->UpdateExtensionPref(extension_->id(), "devices",
312+
std::move(prefs_value));
314313

315314
DevicePermissionsManager* manager =
316315
DevicePermissionsManager::Get(env_->profile());

chrome/browser/extensions/api/identity/identity_api.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "extensions/common/permissions/permission_set.h"
3636
#include "extensions/common/permissions/permissions_data.h"
3737
#include "google_apis/gaia/gaia_urls.h"
38+
#include "third_party/abseil-cpp/absl/types/optional.h"
3839
#include "url/gurl.h"
3940

4041
namespace extensions {
@@ -62,7 +63,7 @@ void IdentityAPI::SetGaiaIdForExtension(const std::string& extension_id,
6263
const std::string& gaia_id) {
6364
DCHECK(!gaia_id.empty());
6465
extension_prefs_->UpdateExtensionPref(extension_id, kIdentityGaiaIdPref,
65-
std::make_unique<base::Value>(gaia_id));
66+
base::Value(gaia_id));
6667
}
6768

6869
absl::optional<std::string> IdentityAPI::GetGaiaIdForExtension(
@@ -77,7 +78,7 @@ absl::optional<std::string> IdentityAPI::GetGaiaIdForExtension(
7778

7879
void IdentityAPI::EraseGaiaIdForExtension(const std::string& extension_id) {
7980
extension_prefs_->UpdateExtensionPref(extension_id, kIdentityGaiaIdPref,
80-
nullptr);
81+
absl::nullopt);
8182
}
8283

8384
void IdentityAPI::EraseStaleGaiaIdsForAllExtensions() {

chrome/browser/extensions/api/module/module.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ ExtensionFunction::ResponseAction ExtensionSetUpdateUrlDataFunction::Run() {
3131
}
3232

3333
ExtensionPrefs::Get(browser_context())
34-
->UpdateExtensionPref(extension_id(), kUpdateURLData,
35-
std::make_unique<base::Value>(data));
34+
->UpdateExtensionPref(extension_id(), kUpdateURLData, base::Value(data));
3635
return RespondNow(NoArguments());
3736
}
3837

chrome/browser/extensions/api/omnibox/omnibox_api.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,8 @@ bool SetOmniboxDefaultSuggestion(
8181
// Add the content field so that the dictionary can be used to populate an
8282
// omnibox::SuggestResult.
8383
dict.Set(kSuggestionContent, base::Value(base::Value::Type::STRING));
84-
prefs->UpdateExtensionPref(
85-
extension_id, kOmniboxDefaultSuggestion,
86-
base::Value::ToUniquePtrValue(base::Value(std::move(dict))));
84+
prefs->UpdateExtensionPref(extension_id, kOmniboxDefaultSuggestion,
85+
base::Value(std::move(dict)));
8786

8887
return true;
8988
}

chrome/browser/extensions/api/preference/preference_api.cc

+4-6
Original file line numberDiff line numberDiff line change
@@ -524,15 +524,13 @@ void PreferenceAPI::OnContentSettingChanged(const std::string& extension_id,
524524
if (incognito) {
525525
ExtensionPrefs::Get(profile_)->UpdateExtensionPref(
526526
extension_id, pref_names::kPrefIncognitoContentSettings,
527-
base::Value::ToUniquePtrValue(
528-
base::Value(content_settings_store()->GetSettingsForExtension(
529-
extension_id, kExtensionPrefsScopeIncognitoPersistent))));
527+
base::Value(content_settings_store()->GetSettingsForExtension(
528+
extension_id, kExtensionPrefsScopeIncognitoPersistent)));
530529
} else {
531530
ExtensionPrefs::Get(profile_)->UpdateExtensionPref(
532531
extension_id, pref_names::kPrefContentSettings,
533-
base::Value::ToUniquePtrValue(
534-
base::Value(content_settings_store()->GetSettingsForExtension(
535-
extension_id, kExtensionPrefsScopeRegular))));
532+
base::Value(content_settings_store()->GetSettingsForExtension(
533+
extension_id, kExtensionPrefsScopeRegular)));
536534
}
537535
}
538536

chrome/browser/extensions/chrome_app_sorting.cc

+16-13
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "extensions/common/constants.h"
2929
#include "extensions/common/extension.h"
3030
#include "extensions/common/manifest_handlers/app_display_info.h"
31+
#include "third_party/abseil-cpp/absl/types/optional.h"
3132

3233
#if BUILDFLAG(IS_CHROMEOS_ASH)
3334
#include "chrome/browser/ash/extensions/default_app_order.h"
@@ -135,7 +136,8 @@ void ChromeAppSorting::MigrateAppIndex(
135136

136137
page = PageIntegerAsStringOrdinal(old_page_index);
137138
SetPageOrdinal(*ext_id, page);
138-
prefs->UpdateExtensionPref(*ext_id, kPrefPageIndexDeprecated, nullptr);
139+
prefs->UpdateExtensionPref(*ext_id, kPrefPageIndexDeprecated,
140+
absl::nullopt);
139141
}
140142

141143
int old_app_launch_index = 0;
@@ -151,7 +153,7 @@ void ChromeAppSorting::MigrateAppIndex(
151153
app_launches_to_convert[page][old_app_launch_index] = &*ext_id;
152154

153155
prefs->UpdateExtensionPref(*ext_id, kPrefAppLaunchIndexDeprecated,
154-
nullptr);
156+
absl::nullopt);
155157
}
156158
}
157159

@@ -367,11 +369,11 @@ void ChromeAppSorting::SetAppLaunchOrdinal(
367369
return;
368370
}
369371

370-
std::unique_ptr<base::Value> new_value =
371-
new_app_launch_ordinal.IsValid()
372-
? std::make_unique<base::Value>(
373-
new_app_launch_ordinal.ToInternalValue())
374-
: nullptr;
372+
absl::optional<base::Value> new_value;
373+
if (new_app_launch_ordinal.IsValid()) {
374+
new_value = base::Value(new_app_launch_ordinal.ToInternalValue());
375+
}
376+
375377
ExtensionPrefs::Get(browser_context_)
376378
->UpdateExtensionPref(extension_id, kPrefAppLaunchOrdinal,
377379
std::move(new_value));
@@ -453,10 +455,10 @@ void ChromeAppSorting::SetPageOrdinal(
453455
return;
454456
}
455457

456-
std::unique_ptr<base::Value> new_value =
457-
new_page_ordinal.IsValid()
458-
? std::make_unique<base::Value>(new_page_ordinal.ToInternalValue())
459-
: nullptr;
458+
absl::optional<base::Value> new_value;
459+
if (new_page_ordinal.IsValid()) {
460+
new_value = base::Value(new_page_ordinal.ToInternalValue());
461+
}
460462

461463
ExtensionPrefs::Get(browser_context_)
462464
->UpdateExtensionPref(extension_id, kPrefPageOrdinal,
@@ -470,8 +472,9 @@ void ChromeAppSorting::ClearOrdinals(const std::string& extension_id) {
470472
GetAppLaunchOrdinal(extension_id));
471473

472474
ExtensionPrefs* prefs = ExtensionPrefs::Get(browser_context_);
473-
prefs->UpdateExtensionPref(extension_id, kPrefPageOrdinal, nullptr);
474-
prefs->UpdateExtensionPref(extension_id, kPrefAppLaunchOrdinal, nullptr);
475+
prefs->UpdateExtensionPref(extension_id, kPrefPageOrdinal, absl::nullopt);
476+
prefs->UpdateExtensionPref(extension_id, kPrefAppLaunchOrdinal,
477+
absl::nullopt);
475478
}
476479

477480
int ChromeAppSorting::PageStringOrdinalAsInteger(

chrome/browser/extensions/chrome_app_sorting_unittest.cc

+8-12
Original file line numberDiff line numberDiff line change
@@ -158,22 +158,19 @@ class ChromeAppSortingInitialize : public PrefsPrepopulatedTestBase {
158158

159159
// Setup the deprecated preferences.
160160
prefs()->UpdateExtensionPref(extension1()->id(),
161-
kPrefAppLaunchIndexDeprecated,
162-
std::make_unique<base::Value>(0));
161+
kPrefAppLaunchIndexDeprecated, base::Value(0));
163162
prefs()->UpdateExtensionPref(extension1()->id(), kPrefPageIndexDeprecated,
164-
std::make_unique<base::Value>(0));
163+
base::Value(0));
165164

166165
prefs()->UpdateExtensionPref(extension2()->id(),
167-
kPrefAppLaunchIndexDeprecated,
168-
std::make_unique<base::Value>(1));
166+
kPrefAppLaunchIndexDeprecated, base::Value(1));
169167
prefs()->UpdateExtensionPref(extension2()->id(), kPrefPageIndexDeprecated,
170-
std::make_unique<base::Value>(0));
168+
base::Value(0));
171169

172170
prefs()->UpdateExtensionPref(extension3()->id(),
173-
kPrefAppLaunchIndexDeprecated,
174-
std::make_unique<base::Value>(0));
171+
kPrefAppLaunchIndexDeprecated, base::Value(0));
175172
prefs()->UpdateExtensionPref(extension3()->id(), kPrefPageIndexDeprecated,
176-
std::make_unique<base::Value>(1));
173+
base::Value(1));
177174

178175
// We insert the ids in reverse order so that we have to deal with the
179176
// element on the 2nd page before the 1st page is seen.
@@ -258,10 +255,9 @@ class ChromeAppSortingMigrateAppIndexInvalid
258255

259256
// Setup the deprecated preference.
260257
prefs()->UpdateExtensionPref(extension1()->id(),
261-
kPrefAppLaunchIndexDeprecated,
262-
std::make_unique<base::Value>(0));
258+
kPrefAppLaunchIndexDeprecated, base::Value(0));
263259
prefs()->UpdateExtensionPref(extension1()->id(), kPrefPageIndexDeprecated,
264-
std::make_unique<base::Value>(-1));
260+
base::Value(-1));
265261
}
266262
void Verify() override {
267263
// Make sure that the invalid page_index wasn't converted over.

chrome/browser/extensions/error_console/error_console.cc

+5-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "extensions/common/feature_switch.h"
2525
#include "extensions/common/features/feature_channel.h"
2626
#include "extensions/common/logging_constants.h"
27+
#include "third_party/abseil-cpp/absl/types/optional.h"
2728

2829
namespace extensions {
2930

@@ -95,7 +96,7 @@ void ErrorConsole::SetReportingForExtension(const std::string& extension_id,
9596
mask &= ~(1 << type);
9697

9798
prefs_->UpdateExtensionPref(extension_id, kStoreExtensionErrorsPref,
98-
std::make_unique<base::Value>(mask));
99+
base::Value(mask));
99100
}
100101

101102
void ErrorConsole::SetReportingAllForExtension(
@@ -107,7 +108,7 @@ void ErrorConsole::SetReportingAllForExtension(
107108
int mask = enabled ? (1 << ExtensionError::NUM_ERROR_TYPES) - 1 : 0;
108109

109110
prefs_->UpdateExtensionPref(extension_id, kStoreExtensionErrorsPref,
110-
std::make_unique<base::Value>(mask));
111+
base::Value(mask));
111112
}
112113

113114
bool ErrorConsole::IsReportingEnabledForExtension(
@@ -125,7 +126,8 @@ void ErrorConsole::UseDefaultReportingForExtension(
125126
if (!enabled_ || !crx_file::id_util::IdIsValid(extension_id))
126127
return;
127128

128-
prefs_->UpdateExtensionPref(extension_id, kStoreExtensionErrorsPref, nullptr);
129+
prefs_->UpdateExtensionPref(extension_id, kStoreExtensionErrorsPref,
130+
absl::nullopt);
129131
}
130132

131133
void ErrorConsole::ReportError(std::unique_ptr<ExtensionError> error) {

chrome/browser/extensions/extension_message_bubble_controller.cc

+6-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "extensions/browser/extension_prefs.h"
2323
#include "extensions/browser/extension_system.h"
2424
#include "extensions/common/extension.h"
25+
#include "third_party/abseil-cpp/absl/types/optional.h"
2526
#include "ui/base/l10n/l10n_util.h"
2627

2728
namespace extensions {
@@ -72,9 +73,11 @@ void ExtensionMessageBubbleController::Delegate::SetBubbleInfoBeenAcknowledged(
7273
if (pref_name.empty())
7374
return;
7475
extensions::ExtensionPrefs* prefs = extensions::ExtensionPrefs::Get(profile_);
75-
prefs->UpdateExtensionPref(
76-
extension_id, pref_name,
77-
value ? std::make_unique<base::Value>(value) : nullptr);
76+
absl::optional<base::Value> pref_value;
77+
if (value) {
78+
pref_value = base::Value(value);
79+
}
80+
prefs->UpdateExtensionPref(extension_id, pref_name, std::move(pref_value));
7881
}
7982

8083
std::string

chrome/browser/extensions/extension_message_bubble_controller_unittest.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ void SetInstallTime(const std::string& extension_id,
997997
ExtensionPrefs* prefs) {
998998
std::string time_str = base::NumberToString(time.ToInternalValue());
999999
prefs->UpdateExtensionPref(extension_id, "last_update_time",
1000-
std::make_unique<base::Value>(time_str));
1000+
base::Value(time_str));
10011001
}
10021002

10031003
// The feature this is meant to test is only implemented on Windows and Mac.

0 commit comments

Comments
 (0)