Skip to content

Commit

Permalink
[iOS] Remove BlockToOpenURL().
Browse files Browse the repository at this point in the history
The settings utility function BlockToOpenURL returns a block which
accepts a URL parameter and then opens it. All of the dependencies for
this logic are injected into the utility. It was used in four places,
and in three of them, the block was immediately invoked, so it was
just a complicated way of calling a function.

That utility function is removed in this CL, and call sites just
directly open the URL using the same two lines of code that would
be executed in the block. For the one case where the block was used
in a completion handler, it's now encapsulated in a method call.

Since this was the only method in the settings_utils file, that file
is removed.

Change-Id: If80c18bd00953013fbfa24afc05d24d2b29c2c7b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4895671
Reviewed-by: Gauthier Ambard <gambard@chromium.org>
Commit-Queue: Mark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1202604}
  • Loading branch information
marcq authored and Chromium LUCI CQ committed Sep 28, 2023
1 parent 27953e9 commit a3ffdfc
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#import "components/version_info/version_info.h"
#import "ios/chrome/browser/shared/model/url/chrome_url_constants.h"
#import "ios/chrome/browser/shared/public/commands/application_commands.h"
#import "ios/chrome/browser/shared/public/commands/open_new_tab_command.h"
#import "ios/chrome/browser/shared/public/commands/snackbar_commands.h"
#import "ios/chrome/browser/shared/public/features/features.h"
#import "ios/chrome/browser/shared/ui/table_view/cells/table_view_detail_text_item.h"
Expand All @@ -26,7 +27,6 @@
#import "ios/chrome/browser/shared/ui/util/uikit_ui_util.h"
#import "ios/chrome/browser/ui/settings/cells/version_item.h"
#import "ios/chrome/browser/ui/settings/settings_table_view_controller_constants.h"
#import "ios/chrome/browser/ui/settings/utils/settings_utils.h"
#import "ios/chrome/common/channel_info.h"
#import "ios/chrome/common/ui/colors/semantic_color_names.h"
#import "ios/chrome/grit/ios_branded_strings.h"
Expand Down Expand Up @@ -174,7 +174,8 @@ - (void)didTapVersionFooter:(VersionFooter*)footer {
#pragma mark - Private methods

- (void)openURL:(GURL)URL {
BlockToOpenURL(self, self.applicationCommandsHandler)(URL);
OpenNewTabCommand* command = [OpenNewTabCommand commandWithURLFromChrome:URL];
[self.applicationCommandsHandler closeSettingsUIAndOpenURL:command];
}

- (std::string)versionString {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
#import "ios/chrome/browser/ui/settings/settings_root_table_view_controller+toolbar_add.h"
#import "ios/chrome/browser/ui/settings/settings_root_table_view_controller+toolbar_settings.h"
#import "ios/chrome/browser/ui/settings/settings_root_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/utils/settings_utils.h"
#import "ios/chrome/common/string_util.h"
#import "ios/chrome/common/ui/colors/semantic_color_names.h"
#import "ios/chrome/common/ui/elements/popover_label_view_controller.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#import "ios/chrome/browser/ui/settings/password/reauthentication/reauthentication_coordinator.h"
#import "ios/chrome/browser/ui/settings/settings_navigation_controller.h"
#import "ios/chrome/browser/ui/settings/utils/password_utils.h"
#import "ios/chrome/browser/ui/settings/utils/settings_utils.h"
#import "ios/chrome/common/ui/reauthentication/reauthentication_module.h"
#import "ios/chrome/grit/ios_branded_strings.h"
#import "ios/chrome/grit/ios_strings.h"
Expand Down Expand Up @@ -317,15 +316,17 @@ - (void)showPasswordsInOtherAppsScreen {
}

- (void)showOnDeviceEncryptionSetUp {
GURL url = google_util::AppendGoogleLocaleParam(
GURL URL = google_util::AppendGoogleLocaleParam(
GURL(kOnDeviceEncryptionOptInURL),
GetApplicationContext()->GetApplicationLocale());
BlockToOpenURL(self.passwordSettingsViewController, self.dispatcher)(url);
OpenNewTabCommand* command = [OpenNewTabCommand commandWithURLFromChrome:URL];
[self.dispatcher closeSettingsUIAndOpenURL:command];
}

- (void)showOnDeviceEncryptionHelp {
GURL url = GURL(kOnDeviceEncryptionLearnMoreURL);
BlockToOpenURL(self.passwordSettingsViewController, self.dispatcher)(url);
GURL URL = GURL(kOnDeviceEncryptionLearnMoreURL);
OpenNewTabCommand* command = [OpenNewTabCommand commandWithURLFromChrome:URL];
[self.dispatcher closeSettingsUIAndOpenURL:command];
}

#pragma mark - PopoverLabelViewControllerDelegate
Expand Down Expand Up @@ -595,6 +596,13 @@ - (void)willPushReauthenticationViewController {

#pragma mark - Private

// Closes the settings and load the passcode help article in a new tab.
- (void)showPasscodeHelp {
GURL URL = GURL(kPasscodeArticleURL);
OpenNewTabCommand* command = [OpenNewTabCommand commandWithURLFromChrome:URL];
[self.dispatcher closeSettingsUIAndOpenURL:command];
}

// Helper to show the "set passcode" dialog with customizable content.
- (void)showSetPasscodeDialogWithContent:(NSString*)content {
UIAlertController* alertController = [UIAlertController
Expand All @@ -603,14 +611,13 @@ - (void)showSetPasscodeDialogWithContent:(NSString*)content {
message:content
preferredStyle:UIAlertControllerStyleAlert];

void (^blockOpenURL)(const GURL&) =
BlockToOpenURL(self.passwordSettingsViewController, self.dispatcher);
__weak PasswordSettingsCoordinator* weakSelf = self;
UIAlertAction* learnAction = [UIAlertAction
actionWithTitle:l10n_util::GetNSString(
IDS_IOS_SETTINGS_SET_UP_SCREENLOCK_LEARN_HOW)
style:UIAlertActionStyleDefault
handler:^(UIAlertAction*) {
blockOpenURL(GURL(kPasscodeArticleURL));
[weakSelf showPasscodeHelp];
}];
[alertController addAction:learnAction];
UIAlertAction* okAction =
Expand Down
2 changes: 0 additions & 2 deletions ios/chrome/browser/ui/settings/utils/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ source_set("utils") {
"password_auto_fill_status_observer.h",
"password_utils.h",
"password_utils.mm",
"settings_utils.h",
"settings_utils.mm",
]
deps = [
"//base",
Expand Down
20 changes: 0 additions & 20 deletions ios/chrome/browser/ui/settings/utils/settings_utils.h

This file was deleted.

23 changes: 0 additions & 23 deletions ios/chrome/browser/ui/settings/utils/settings_utils.mm

This file was deleted.

0 comments on commit a3ffdfc

Please sign in to comment.