Skip to content

Commit

Permalink
[CodeHealth] browser/extensions base::Value refactor I
Browse files Browse the repository at this point in the history
This CL carries out several base::Value modernisations across different
files under chrome/browser/extensions, replacing the use of the
deprecated methods where possible with their updated counterparts.

Bug: 1187001, 1352780
Change-Id: Iabb44bb1f93f2a05a3e53255903d1714512381d3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3830010
Commit-Queue: Claudio DeSouza <cdesouza@igalia.com>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1035162}
  • Loading branch information
cdesouza-chromium authored and Chromium LUCI CQ committed Aug 15, 2022
1 parent d10758b commit ad0c57d
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ api::users_private::User CreateUnknownApiUser(const std::string& email) {
return api_user;
}

std::unique_ptr<base::ListValue> GetUsersList(
content::BrowserContext* browser_context) {
std::unique_ptr<base::ListValue> user_list(new base::ListValue);
base::Value::List GetUsersList(content::BrowserContext* browser_context) {
base::Value::List user_list;

if (!CanModifyUserList(browser_context))
return user_list;
Expand Down Expand Up @@ -140,7 +139,7 @@ std::unique_ptr<base::ListValue> GetUsersList(
std::string email = maybe_email ? *maybe_email : std::string();
AccountId account_id = AccountId::FromUserEmail(email);
const user_manager::User* user = user_manager->FindUser(account_id);
user_list->Append(base::Value::FromUniquePtrValue(
user_list.Append(base::Value::FromUniquePtrValue(
(user ? CreateApiUser(email, *user) : CreateUnknownApiUser(email))
.ToValue()));
}
Expand All @@ -164,8 +163,7 @@ UsersPrivateGetUsersFunction::UsersPrivateGetUsersFunction() = default;
UsersPrivateGetUsersFunction::~UsersPrivateGetUsersFunction() = default;

ExtensionFunction::ResponseAction UsersPrivateGetUsersFunction::Run() {
return RespondNow(OneArgument(
base::Value::FromUniquePtrValue(GetUsersList(browser_context()))));
return RespondNow(WithArguments(GetUsersList(browser_context())));
}

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -182,9 +180,9 @@ ExtensionFunction::ResponseAction UsersPrivateIsUserInListFunction::Run() {

std::string username = gaia::CanonicalizeEmail(parameters->email);
if (IsExistingUser(username)) {
return RespondNow(OneArgument(base::Value(true)));
return RespondNow(WithArguments(true));
}
return RespondNow(OneArgument(base::Value(false)));
return RespondNow(WithArguments(false));
}

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -201,12 +199,12 @@ ExtensionFunction::ResponseAction UsersPrivateAddUserFunction::Run() {

// Non-owners should not be able to add users.
if (!CanModifyUserList(browser_context())) {
return RespondNow(OneArgument(base::Value(false)));
return RespondNow(WithArguments(false));
}

std::string username = gaia::CanonicalizeEmail(parameters->email);
if (IsExistingUser(username)) {
return RespondNow(OneArgument(base::Value(false)));
return RespondNow(WithArguments(false));
}

base::Value username_value(username);
Expand All @@ -216,7 +214,7 @@ ExtensionFunction::ResponseAction UsersPrivateAddUserFunction::Run() {
PrefsUtil* prefs_util = delegate->GetPrefsUtil();
bool added = prefs_util->AppendToListCrosSetting(ash::kAccountsPrefUsers,
username_value);
return RespondNow(OneArgument(base::Value(added)));
return RespondNow(WithArguments(added));
}

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -233,7 +231,7 @@ ExtensionFunction::ResponseAction UsersPrivateRemoveUserFunction::Run() {

// Non-owners should not be able to remove users.
if (!CanModifyUserList(browser_context())) {
return RespondNow(OneArgument(base::Value(false)));
return RespondNow(WithArguments(false));
}

base::Value canonical_email(gaia::CanonicalizeEmail(parameters->email));
Expand All @@ -247,7 +245,7 @@ ExtensionFunction::ResponseAction UsersPrivateRemoveUserFunction::Run() {
AccountId::FromUserEmail(parameters->email),
user_manager::UserRemovalReason::LOCAL_USER_INITIATED,
/*delegate=*/nullptr);
return RespondNow(OneArgument(base::Value(removed)));
return RespondNow(WithArguments(removed));
}

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -260,7 +258,7 @@ UsersPrivateIsUserListManagedFunction::
~UsersPrivateIsUserListManagedFunction() {}

ExtensionFunction::ResponseAction UsersPrivateIsUserListManagedFunction::Run() {
return RespondNow(OneArgument(base::Value(IsDeviceEnterpriseManaged())));
return RespondNow(WithArguments(IsDeviceEnterpriseManaged()));
}

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -275,7 +273,7 @@ UsersPrivateGetCurrentUserFunction::~UsersPrivateGetCurrentUserFunction() =
ExtensionFunction::ResponseAction UsersPrivateGetCurrentUserFunction::Run() {
const user_manager::User* user = ash::ProfileHelper::Get()->GetUserByProfile(
Profile::FromBrowserContext(browser_context()));
return user ? RespondNow(OneArgument(base::Value::FromUniquePtrValue(
return user ? RespondNow(WithArguments(base::Value::FromUniquePtrValue(
CreateApiUser(user->GetAccountId().GetUserEmail(), *user)
.ToValue())))
: RespondNow(Error("No Current User"));
Expand All @@ -296,11 +294,10 @@ ExtensionFunction::ResponseAction UsersPrivateGetLoginStatusFunction::Run() {
const bool is_screen_locked =
session_manager::SessionManager::Get()->IsScreenLocked();

auto result = std::make_unique<base::DictionaryValue>();
result->SetKey("isLoggedIn", base::Value(is_logged_in));
result->SetKey("isScreenLocked", base::Value(is_screen_locked));
return RespondNow(
OneArgument(base::Value::FromUniquePtrValue(std::move(result))));
base::Value::Dict result;
result.Set("isLoggedIn", base::Value(is_logged_in));
result.Set("isScreenLocked", base::Value(is_screen_locked));
return RespondNow(WithArguments(std::move(result)));
}

} // namespace extensions
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ ExtensionFunction::ResponseAction AutofillPrivateSaveAddressFunction::Run() {
personal_data->AddProfile(profile);
}

return RespondNow(NoArguments());
return RespondNow(WithArguments());
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -337,7 +337,7 @@ AutofillPrivateGetAddressComponentsFunction::Run() {
address_components.Set("components", std::move(rows));
address_components.Set("languageCode", language_code);

return RespondNow(OneArgument(base::Value(std::move(address_components))));
return RespondNow(WithArguments(std::move(address_components)));
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -414,7 +414,7 @@ ExtensionFunction::ResponseAction AutofillPrivateSaveCreditCardFunction::Run() {
if (use_existing_card) {
// Only updates when the card info changes.
if (existing_card && existing_card->Compare(credit_card) == 0)
return RespondNow(NoArguments());
return RespondNow(WithArguments());

// Record when nickname is updated.
if (credit_card.HasNonEmptyValidNickname() &&
Expand All @@ -434,7 +434,7 @@ ExtensionFunction::ResponseAction AutofillPrivateSaveCreditCardFunction::Run() {
}
}

return RespondNow(NoArguments());
return RespondNow(WithArguments());
}

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -453,7 +453,7 @@ ExtensionFunction::ResponseAction AutofillPrivateRemoveEntryFunction::Run() {

personal_data->RemoveByGUID(parameters->guid);

return RespondNow(NoArguments());
return RespondNow(WithArguments());
}

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -477,7 +477,7 @@ AutofillPrivateValidatePhoneNumbersFunction::Run() {
RemoveDuplicatePhoneNumberAtIndex(params->index_of_new_number,
params->country_code, phone_numbers);

return RespondNow(OneArgument(base::Value(std::move(phone_numbers))));
return RespondNow(WithArguments(std::move(phone_numbers)));
}

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -496,7 +496,7 @@ ExtensionFunction::ResponseAction AutofillPrivateMaskCreditCardFunction::Run() {

personal_data->ResetFullServerCard(parameters->guid);

return RespondNow(NoArguments());
return RespondNow(WithArguments());
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -554,7 +554,7 @@ AutofillPrivateMigrateCreditCardsFunction::Run() {
local_card_migration_manager->GetMigratableCreditCards();
local_card_migration_manager->AttemptToOfferLocalCardMigration(
/*is_from_settings_page=*/true);
return RespondNow(NoArguments());
return RespondNow(WithArguments());
}

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -570,7 +570,7 @@ AutofillPrivateLogServerCardLinkClickedFunction::Run() {
return RespondNow(Error(kErrorDataUnavailable));

personal_data->LogServerCardLinkClicked();
return RespondNow(NoArguments());
return RespondNow(WithArguments());
}

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -596,7 +596,7 @@ AutofillPrivateSetCreditCardFIDOAuthEnabledStateFunction::Run() {

credit_card_access_manager->OnSettingsPageFIDOAuthToggled(
parameters->enabled);
return RespondNow(NoArguments());
return RespondNow(WithArguments());
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -650,7 +650,7 @@ ExtensionFunction::ResponseAction AutofillPrivateAddVirtualCardFunction::Run() {

virtual_card_enrollment_manager->InitVirtualCardEnroll(
*card, autofill::VirtualCardEnrollmentSource::kSettingsPage);
return RespondNow(NoArguments());
return RespondNow(WithArguments());
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -692,7 +692,7 @@ AutofillPrivateRemoveVirtualCardFunction::Run() {
virtual_card_enrollment_manager->Unenroll(
card->instrument_id(),
/*virtual_card_enrollment_update_response_callback=*/absl::nullopt);
return RespondNow(NoArguments());
return RespondNow(WithArguments());
}

} // namespace extensions
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ ExtensionFunction::ResponseValue ClipboardBookmarkManagerFunction::CopyOrCut(
if (cut && HasPermanentNodes(nodes))
return Error(bookmark_keys::kModifySpecialError);
bookmarks::CopyToClipboard(model, nodes, cut);
return NoArguments();
return WithArguments();
}

ExtensionFunction::ResponseValue
Expand Down Expand Up @@ -395,7 +395,7 @@ BookmarkManagerPrivatePasteFunction::RunOnReady() {
highest_index = parent_node->children().size();

bookmarks::PasteFromClipboard(model, parent_node, highest_index);
return NoArguments();
return WithArguments();
}

ExtensionFunction::ResponseValue
Expand All @@ -406,15 +406,15 @@ BookmarkManagerPrivateCanPasteFunction::RunOnReady() {

PrefService* prefs = user_prefs::UserPrefs::Get(GetProfile());
if (!prefs->GetBoolean(bookmarks::prefs::kEditBookmarksEnabled))
return OneArgument(base::Value(false));
return WithArguments(false);

BookmarkModel* model =
BookmarkModelFactory::GetForBrowserContext(GetProfile());
const BookmarkNode* parent_node = GetNodeFromString(model, params->parent_id);
if (!parent_node)
return Error(bookmark_keys::kNoParentError);
bool can_paste = bookmarks::CanPasteFromClipboard(model, parent_node);
return OneArgument(base::Value(can_paste));
return WithArguments(can_paste);
}

ExtensionFunction::ResponseValue
Expand All @@ -434,7 +434,7 @@ BookmarkManagerPrivateSortChildrenFunction::RunOnReady() {
if (!CanBeModified(parent_node, &error))
return Error(error);
model->SortChildren(parent_node);
return NoArguments();
return WithArguments();
}

ExtensionFunction::ResponseValue
Expand Down Expand Up @@ -463,7 +463,7 @@ BookmarkManagerPrivateStartDragFunction::RunOnReady() {
GetProfile(), {std::move(nodes), params->drag_node_index, web_contents,
source, gfx::Point(params->x, params->y)});

return NoArguments();
return WithArguments();
}

ExtensionFunction::ResponseValue
Expand Down Expand Up @@ -502,7 +502,7 @@ BookmarkManagerPrivateDropFunction::RunOnReady() {
GetProfile(), *drag_data, drop_parent, drop_index, copy);

router->ClearBookmarkNodeData();
return NoArguments();
return WithArguments();
}

ExtensionFunction::ResponseValue
Expand Down Expand Up @@ -556,7 +556,7 @@ BookmarkManagerPrivateRemoveTreesFunction::RunOnReady() {
return Error(error);
}

return NoArguments();
return WithArguments();
}

ExtensionFunction::ResponseValue
Expand All @@ -566,7 +566,7 @@ BookmarkManagerPrivateUndoFunction::RunOnReady() {

BookmarkUndoServiceFactory::GetForProfile(GetProfile())->undo_manager()->
Undo();
return NoArguments();
return WithArguments();
}

ExtensionFunction::ResponseValue
Expand All @@ -576,7 +576,7 @@ BookmarkManagerPrivateRedoFunction::RunOnReady() {

BookmarkUndoServiceFactory::GetForProfile(GetProfile())->undo_manager()->
Redo();
return NoArguments();
return WithArguments();
}

ExtensionFunction::ResponseValue
Expand Down Expand Up @@ -604,7 +604,7 @@ BookmarkManagerPrivateOpenInNewTabFunction::RunOnReady() {
if (!result)
return Error(error);

return NoArguments();
return WithArguments();
}

ExtensionFunction::ResponseValue
Expand Down Expand Up @@ -678,7 +678,7 @@ BookmarkManagerPrivateOpenInNewWindowFunction::RunOnReady() {
first_tab = false;
}

return NoArguments();
return WithArguments();
}

WEB_CONTENTS_USER_DATA_KEY_IMPL(BookmarkManagerPrivateDragEventRouter);
Expand Down

0 comments on commit ad0c57d

Please sign in to comment.