Skip to content

Commit

Permalink
Convert block syntax to the most popular option
Browse files Browse the repository at this point in the history
There are two syntaxes to declare an Objective-C block taking
no arguments and returning no value (so of type void(^)()):
1. ^{ ... } or 2. ^() { ... }.

The syntax 1. appears to be the most popular in the codebase
with at the time of writing 11643 references while 2. only
had 58.

Conversion was automated with the following command:

    sed -i '' -e 's/\^ *() *{/^{/' $(git grep -l '\^ *() *{')

Bug: none
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Ib5c609989af96a145e593c9747af041e4c175f2d
Reviewed-on: https://chromium-review.googlesource.com/1022714
Reviewed-by: Mike Dougherty <michaeldo@chromium.org>
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#552485}
  • Loading branch information
sdefresne authored and Commit Bot committed Apr 20, 2018
1 parent bcb0488 commit 96220f4
Show file tree
Hide file tree
Showing 18 changed files with 43 additions and 44 deletions.
6 changes: 3 additions & 3 deletions ios/chrome/app/application_delegate/app_state_unittest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void swizzleSafeModeShouldStart(BOOL shouldStart) {
void swizzleMetricsMediatorDisableReporting() {
metrics_mediator_called_ = NO;

metrics_mediator_swizzle_block_ = ^() {
metrics_mediator_swizzle_block_ = ^{
metrics_mediator_called_ = YES;
};

Expand Down Expand Up @@ -236,7 +236,7 @@ void swizzleHandleStartupParameters(

stubNullCurrentBrowserState(browser_view_information_);

void (^swizzleBlock)() = ^() {
void (^swizzleBlock)() = ^{
};

ScopedBlockSwizzler swizzler(
Expand Down Expand Up @@ -765,7 +765,7 @@ IOSChromeScopedTestingChromeBrowserProvider provider_(

stubNullCurrentBrowserState(browserViewInformation);

void (^swizzleBlock)() = ^() {
void (^swizzleBlock)() = ^{
};

ScopedBlockSwizzler swizzler(
Expand Down
14 changes: 7 additions & 7 deletions ios/chrome/app/deferred_initialization_runner_unittest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
__block bool secondFlag = NO;
DeferredInitializationRunner* runner =
[DeferredInitializationRunner sharedInstance];
ProceduralBlock firstBlock = ^() {
ProceduralBlock firstBlock = ^{
EXPECT_FALSE(firstFlag);
firstFlag = YES;
};
ProceduralBlock secondBlock = ^() {
ProceduralBlock secondBlock = ^{
EXPECT_FALSE(secondFlag);
secondFlag = YES;
};
Expand Down Expand Up @@ -66,7 +66,7 @@
__block bool slowFlag = NO;
DeferredInitializationRunner* runner =
[DeferredInitializationRunner sharedInstance];
ProceduralBlock quickBlock = ^() {
ProceduralBlock quickBlock = ^{
EXPECT_FALSE(quickFlag);
quickFlag = YES;
// Make sure we have time to go back to this test before running the second
Expand All @@ -76,7 +76,7 @@
ConditionBlock quickBlockRun = ^bool {
return quickFlag;
};
ProceduralBlock slowBlock = ^() {
ProceduralBlock slowBlock = ^{
EXPECT_FALSE(slowFlag);
slowFlag = YES;
};
Expand Down Expand Up @@ -109,7 +109,7 @@
runner.delayBetweenBlocks = 0.01;

[runner enqueueBlockNamed:@"cancel me"
block:^() {
block:^{
blockFinished = YES;
}];
ASSERT_EQ(1U, [runner numberOfBlocksRemaining]);
Expand All @@ -132,7 +132,7 @@
runner.delayBetweenBlocks = 0.01;

[runner enqueueBlockNamed:@"cancel me"
block:^() {
block:^{
blockFinished = YES;
}];

Expand All @@ -150,7 +150,7 @@
TEST_F(DeferredInitializationRunnerTest, TestSecondBlockInvalidatesFirst) {
// Setup.
__block int blockRunCount = 0;
ProceduralBlock runBlock = ^() {
ProceduralBlock runBlock = ^{
++blockRunCount;
};
DeferredInitializationRunner* runner =
Expand Down
4 changes: 2 additions & 2 deletions ios/chrome/browser/find_in_page/find_tab_helper_unittest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void SetUp() override {
void TearDown() override {
// Stop any in-progress find operations when the test completes.
__block BOOL completion_handler_block_was_called = NO;
FindTabHelper::FromWebState(web_state())->StopFinding(^() {
FindTabHelper::FromWebState(web_state())->StopFinding(^{
completion_handler_block_was_called = YES;
});
base::test::ios::WaitUntilCondition(^bool() {
Expand Down Expand Up @@ -114,7 +114,7 @@ void LoadTestHtml(int test_string_count) {
base::test::ios::WaitUntilCondition(wait_block);

// Stop finding and verify that the completion block was called properly.
helper->StopFinding(^() {
helper->StopFinding(^{
completion_handler_block_was_called = YES;
});
base::test::ios::WaitUntilCondition(wait_block);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ void SetFillPasswordFormFailureCount(int target_failure_count) {
WaitForBackgroundTasks();
}
// Wait until suggestions are received.
EXPECT_TRUE(WaitUntilConditionOrTimeout(kWaitForJSCompletionTimeout, ^() {
EXPECT_TRUE(WaitUntilConditionOrTimeout(kWaitForJSCompletionTimeout, ^{
return [GetSuggestionValues() count] > 0;
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
// Create a new file in the passwords directory.
base::PostTaskWithTraits(
FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_BLOCKING},
base::BindBlockArc(^() {
base::BindBlockArc(^{
NSFileManager* file_manager = [NSFileManager defaultManager];
if ([file_manager createDirectoryAtURL:directory_url
withIntermediateDirectories:NO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ - (instancetype)initWithBookmarkModel:(bookmarks::BookmarkModel*)bookmarkModel
object:nil];

__weak ShareExtensionItemReceiver* weakSelf = self;
_taskRunner->PostTask(FROM_HERE, base::BindBlockArc(^() {
_taskRunner->PostTask(FROM_HERE, base::BindBlockArc(^{
[weakSelf createReadingListFolder];
}));
}
Expand Down Expand Up @@ -175,8 +175,7 @@ - (void)createReadingListFolder {
}

__weak ShareExtensionItemReceiver* weakSelf = self;
web::WebThread::PostTask(web::WebThread::UI, FROM_HERE,
base::BindBlockArc(^() {
web::WebThread::PostTask(web::WebThread::UI, FROM_HERE, base::BindBlockArc(^{
[weakSelf readingListFolderCreated];
}));
}
Expand Down Expand Up @@ -243,7 +242,7 @@ - (BOOL)receivedData:(NSData*)data withCompletion:(ProceduralBlock)completion {
SHARE_EXTENSION_SOURCE_COUNT);

// Entry is valid. Add it to the reading list model.
ProceduralBlock processEntryBlock = ^() {
ProceduralBlock processEntryBlock = ^{
if (!_readingListModel || !_bookmarkModel) {
// Models may have been deleted after the file
// processing started.
Expand All @@ -268,7 +267,7 @@ - (BOOL)receivedData:(NSData*)data withCompletion:(ProceduralBlock)completion {
}

if (completion && _taskRunner) {
_taskRunner->PostTask(FROM_HERE, base::BindBlockArc(^() {
_taskRunner->PostTask(FROM_HERE, base::BindBlockArc(^{
completion();
}));
}
Expand Down Expand Up @@ -340,7 +339,7 @@ - (void)applicationDidBecomeActive {
// There may already be files. Process them.
if (_taskRunner) {
__weak ShareExtensionItemReceiver* weakSelf = self;
_taskRunner->PostTask(FROM_HERE, base::BindBlockArc(^() {
_taskRunner->PostTask(FROM_HERE, base::BindBlockArc(^{
[weakSelf processExistingFiles];
}));
}
Expand All @@ -367,7 +366,7 @@ - (void)processExistingFiles {
if ([files count]) {
__weak ShareExtensionItemReceiver* weakSelf = self;
web::WebThread::PostTask(web::WebThread::UI, FROM_HERE,
base::BindBlockArc(^() {
base::BindBlockArc(^{
[weakSelf entriesReceived:files];
}));
}
Expand All @@ -383,12 +382,12 @@ - (void)entriesReceived:(NSArray<NSURL*>*)files {
for (NSURL* fileURL : files) {
__block std::unique_ptr<ReadingListModel::ScopedReadingListBatchUpdate>
batchToken(_readingListModel->BeginBatchUpdates());
_taskRunner->PostTask(FROM_HERE, base::BindBlockArc(^() {
_taskRunner->PostTask(FROM_HERE, base::BindBlockArc(^{
[weakSelf handleFileAtURL:fileURL
withCompletion:^{
web::WebThread::PostTask(
web::WebThread::UI, FROM_HERE,
base::BindBlockArc(^() {
base::BindBlockArc(^{
batchToken.reset();
}));
}];
Expand All @@ -409,7 +408,7 @@ - (void)applicationWillResignActive {
- (void)presentedSubitemDidChangeAtURL:(NSURL*)url {
if (_taskRunner) {
__weak ShareExtensionItemReceiver* weakSelf = self;
_taskRunner->PostTask(FROM_HERE, base::BindBlockArc(^() {
_taskRunner->PostTask(FROM_HERE, base::BindBlockArc(^{
[weakSelf handleFileAtURL:url withCompletion:nil];
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ - (void)presentBookmarkForTab:(Tab*)tab currentlyBookmarked:(BOOL)bookmarked {
} else {
__weak BookmarkInteractionController* weakSelf = self;
__weak Tab* weakTab = tab;
void (^editAction)() = ^() {
void (^editAction)() = ^{
BookmarkInteractionController* strongSelf = weakSelf;
if (!strongSelf || !weakTab || !weakTab.webState)
return;
Expand Down
4 changes: 2 additions & 2 deletions ios/chrome/browser/ui/browser_view_controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2626,7 +2626,7 @@ - (void)dismissRateThisAppDialog {
// the feature engagement tracker will remain pointing to invalid memory if
// its owner (the ChromeBrowserState) is deallocated.
__weak BrowserViewController* weakSelf = self;
void (^dismissalCallback)(void) = ^() {
void (^dismissalCallback)(void) = ^{
BrowserViewController* strongSelf = weakSelf;
if (strongSelf) {
feature_engagement::TrackerFactory::GetForBrowserState(
Expand Down Expand Up @@ -5023,7 +5023,7 @@ - (void)tabModel:(TabModel*)model
// This callback is called before webState is activated (on
// kTabModelNewTabWillOpenNotification notification). Dispatch the
// callback asynchronously to be sure the activation is complete.
dispatch_async(dispatch_get_main_queue(), ^() {
dispatch_async(dispatch_get_main_queue(), ^{
// Test existence again as the block may have been deleted.
if (self.foregroundTabWasAddedCompletionBlock) {
self.foregroundTabWasAddedCompletionBlock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ @interface BubbleViewControllerPresenter (Testing)
initWithText:@"Text"
arrowDirection:BubbleArrowDirectionUp
alignment:BubbleAlignmentCenter
dismissalCallback:^() {
dismissalCallback:^{
dismissalCallbackCount_++;
}]),
window_([[UIWindow alloc]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ - (CollectionViewItem*)headerForSectionInfo:
[[ContentSuggestionsArticlesHeaderItem alloc]
initWithType:ItemTypeHeader
title:sectionInfo.title
callback:^() {
callback:^{
[weakSelf.dataSource toggleArticlesVisibility];
}];
header.expanded = sectionInfo.expanded;
Expand Down
4 changes: 2 additions & 2 deletions ios/chrome/browser/ui/content_suggestions/ntp_home_egtest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ - (void)testTapFakeOmniboxLogsCorrectly {
// Swizzle the method that needs to be called for correct logging.
__block BOOL tapped = NO;
ScopedBlockSwizzler swizzler([LocationBarLegacyCoordinator class],
@selector(focusOmniboxFromFakebox), ^() {
@selector(focusOmniboxFromFakebox), ^{
tapped = YES;
});

Expand All @@ -444,7 +444,7 @@ - (void)testTapOmniboxSearchButtonLogsCorrectly {
// Swizzle the method that needs to be called for correct logging.
__block BOOL tapped = NO;
ScopedBlockSwizzler swizzler([LocationBarCoordinator class],
@selector(focusOmniboxFromSearchButton), ^() {
@selector(focusOmniboxFromSearchButton), ^{
tapped = YES;
});

Expand Down
8 changes: 4 additions & 4 deletions ios/chrome/browser/ui/dialogs/dialog_presenter_unittest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ - (void)dialogPresenter:(DialogPresenter*)presenter
[presenter() runJavaScriptAlertPanelWithMessage:@""
requestURL:GURL()
webState:&webState2
completionHandler:^() {
completionHandler:^{
completion_called = YES;
}];
EXPECT_EQ(1U, delegate().presentedWebStates.size());
Expand Down Expand Up @@ -226,23 +226,23 @@ - (void)dialogPresenter:(DialogPresenter*)presenter
[presenter() runJavaScriptAlertPanelWithMessage:@"1"
requestURL:GURL()
webState:&webState1
completionHandler:^() {
completionHandler:^{
completion1_called = YES;
}];
DialogPresenterTestWebState webState2;
__block BOOL completion2_called = NO;
[presenter() runJavaScriptAlertPanelWithMessage:@"2"
requestURL:GURL()
webState:&webState2
completionHandler:^() {
completionHandler:^{
completion2_called = YES;
}];
DialogPresenterTestWebState webState3;
__block BOOL completion3_called = NO;
[presenter() runJavaScriptAlertPanelWithMessage:@"3"
requestURL:GURL()
webState:&webState3
completionHandler:^() {
completionHandler:^{
completion3_called = YES;
}];
EXPECT_EQ(1U, delegate().presentedWebStates.size());
Expand Down
6 changes: 3 additions & 3 deletions ios/chrome/browser/ui/omnibox_perftest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ void DisableKeyboard(OmniboxTextFieldIOS* textField) {
^base::TimeDelta(int index) {
return EnableKeyboard(textField);
},
^() {
^{
DisableKeyboard(textField);
});
}
Expand All @@ -259,7 +259,7 @@ void DisableKeyboard(OmniboxTextFieldIOS* textField) {
EnableKeyboard(textField);
return TimeInsertText(textField, @"G");
},
^() {
^{
[textField setText:@""];
DisableKeyboard(textField);
});
Expand Down Expand Up @@ -290,7 +290,7 @@ void DisableKeyboard(OmniboxTextFieldIOS* textField) {
NSLog(@"%2d: %@", index, logMessage);
return elapsed;
},
^() {
^{
[textField setText:@""];
DisableKeyboard(textField);
});
Expand Down
4 changes: 2 additions & 2 deletions ios/chrome/browser/ui/settings/password_exporter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ @implementation PasswordFileWriter
- (void)writeData:(NSData*)data
toURL:(NSURL*)fileURL
handler:(void (^)(WriteToURLStatus))handler {
WriteToURLStatus (^writeToFile)() = ^() {
WriteToURLStatus (^writeToFile)() = ^{
base::AssertBlockingAllowed();
NSError* error = nil;

Expand Down Expand Up @@ -336,7 +336,7 @@ - (void)deleteTemporaryFile:(NSURL*)passwordsTempFileURL {
[passwordsTempFileURL URLByDeletingLastPathComponent];
base::PostTaskWithTraits(
FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND},
base::BindBlockArc(^() {
base::BindBlockArc(^{
base::AssertBlockingAllowed();
NSFileManager* fileManager = [NSFileManager defaultManager];
[fileManager removeItemAtURL:uniqueDirectoryURL error:nil];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ - (void)presentViewController:(UIViewController*)viewController {
!preparingPasswordsAlert_.beingDismissed) {
__weak SavePasswordsCollectionViewController* weakSelf = self;
[self dismissViewControllerAnimated:YES
completion:^() {
completion:^{
[weakSelf presentViewController:viewController
animated:YES
completion:nil];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ - (void)showToolbarForForgroundWithAnimator:

- (void)addFullscreenAnimationsToAnimator:(FullscreenAnimator*)animator {
CGFloat finalProgress = animator.finalProgress;
[animator addAnimations:^() {
[animator addAnimations:^{
[self updateForFullscreenProgress:finalProgress];
}];
}
Expand Down
2 changes: 1 addition & 1 deletion ios/chrome/browser/ui/toolbar/legacy/toolbar_controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ - (void)showToolbarForForgroundWithAnimator:

- (void)addFullscreenAnimationsToAnimator:(FullscreenAnimator*)animator {
CGFloat finalProgress = animator.finalProgress;
[animator addAnimations:^() {
[animator addAnimations:^{
[self updateForFullscreenProgress:finalProgress];
}];
}
Expand Down
2 changes: 1 addition & 1 deletion ios/chrome/browser/web/dom_altering_lock.mm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
lockAction(NO);
return;
}
[current_dom_altering_feature_ releaseDOMLockWithCompletionHandler:^() {
[current_dom_altering_feature_ releaseDOMLockWithCompletionHandler:^{
DCHECK_CURRENTLY_ON(web::WebThread::UI);
DCHECK(current_dom_altering_feature_ == nil)
<< "The lock must be released before calling the completion handler.";
Expand Down

0 comments on commit 96220f4

Please sign in to comment.