Commit 745395c5 authored by Sidney San Martín's avatar Sidney San Martín Committed by Commit Bot

Fix a leak in Touch Bar text suggestions.

Each leaked NSCandidateListTouchBarItem carried a CALayer and other
resources; holding on to them caused a major slowdown.

This change makes |-createCandidateListItem| return an autoreleased
NSCandidateListTouchBarItem instead of a retained one, and renames it to
|-makeCandidateListItem| to match the naming and ownership semantics of
|-makeTouchBar| (and be consistent with the create rule).

Bug: 877137
Change-Id: Icfb335c341cb86e8691562ade4c222a59c990bf7
Reviewed-on: https://chromium-review.googlesource.com/1208428Reviewed-by: default avatarSarah Chan <spqchan@chromium.org>
Commit-Queue: Sidney San Martín <sdy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589195}
parent ec92aa02
...@@ -37,7 +37,7 @@ class Range; ...@@ -37,7 +37,7 @@ class Range;
// Creates a NSCandidateListTouchBarItem that contains text suggestions // Creates a NSCandidateListTouchBarItem that contains text suggestions
// based on the current text selection. // based on the current text selection.
- (NSCandidateListTouchBarItem*)createCandidateListItem - (NSCandidateListTouchBarItem*)makeCandidateListItem
API_AVAILABLE(macos(10.12.2)); API_AVAILABLE(macos(10.12.2));
- (void)candidateListTouchBarItem:(NSCandidateListTouchBarItem*)anItem - (void)candidateListTouchBarItem:(NSCandidateListTouchBarItem*)anItem
...@@ -77,4 +77,4 @@ class Range; ...@@ -77,4 +77,4 @@ class Range;
@end @end
#endif // CHROME_BROWSER_UI_COCOA_TOUCHBAR_SUGGESTED_TEXT_TOUCH_BAR_CONTROLLER_H_ #endif // CHROME_BROWSER_UI_COCOA_TOUCHBAR_SUGGESTED_TEXT_TOUCH_BAR_CONTROLLER_H_
\ No newline at end of file
...@@ -126,23 +126,23 @@ class WebContentsTextObserver : public content::WebContentsObserver { ...@@ -126,23 +126,23 @@ class WebContentsTextObserver : public content::WebContentsObserver {
if (![identifier hasSuffix:kTextSuggestionsItemsTouchId]) if (![identifier hasSuffix:kTextSuggestionsItemsTouchId])
return nil; return nil;
return [self createCandidateListItem]; return [self makeCandidateListItem];
} }
- (NSCandidateListTouchBarItem*)createCandidateListItem { - (NSCandidateListTouchBarItem*)makeCandidateListItem {
NSCandidateListTouchBarItem* candidateListItem = base::scoped_nsobject<NSCandidateListTouchBarItem> candidateListItem(
[[NSCandidateListTouchBarItem alloc] [[NSCandidateListTouchBarItem alloc]
initWithIdentifier:kTextSuggestionsItemsTouchId]; initWithIdentifier:kTextSuggestionsItemsTouchId]);
candidateListItem.delegate = self; [candidateListItem setDelegate:self];
if (selectionRange_.length) if (selectionRange_.length)
candidateListItem.collapsed = YES; [candidateListItem setCollapsed:YES];
[candidateListItem setCandidates:suggestions_ [candidateListItem setCandidates:suggestions_
forSelectedRange:selectionRange_ forSelectedRange:selectionRange_
inString:text_]; inString:text_];
return candidateListItem; return candidateListItem.autorelease();
} }
- (void)candidateListTouchBarItem:(NSCandidateListTouchBarItem*)anItem - (void)candidateListTouchBarItem:(NSCandidateListTouchBarItem*)anItem
......
...@@ -38,15 +38,11 @@ class TextSuggestionsTouchBarControllerTest : public CocoaTest { ...@@ -38,15 +38,11 @@ class TextSuggestionsTouchBarControllerTest : public CocoaTest {
// Tests that the NSCandidateListTouchBarItem collapses properly. // Tests that the NSCandidateListTouchBarItem collapses properly.
TEST_F(TextSuggestionsTouchBarControllerTest, CollapsedCandidateList) { TEST_F(TextSuggestionsTouchBarControllerTest, CollapsedCandidateList) {
if (@available(macOS 10.12.2, *)) { if (@available(macOS 10.12.2, *)) {
base::scoped_nsobject<NSCandidateListTouchBarItem> item;
[controller_ setSelectionRange:gfx::Range()]; [controller_ setSelectionRange:gfx::Range()];
item.reset([controller_ createCandidateListItem]); EXPECT_FALSE([[controller_ makeCandidateListItem] isCollapsed]);
EXPECT_FALSE([item isCollapsed]);
[controller_ setSelectionRange:gfx::Range(0, 1)]; [controller_ setSelectionRange:gfx::Range(0, 1)];
item.reset([controller_ createCandidateListItem]); EXPECT_TRUE([[controller_ makeCandidateListItem] isCollapsed]);
EXPECT_TRUE([item isCollapsed]);
} }
} }
...@@ -142,4 +138,4 @@ TEST_F(TextSuggestionsTouchBarControllerTest, TouchBarMetrics) { ...@@ -142,4 +138,4 @@ TEST_F(TextSuggestionsTouchBarControllerTest, TouchBarMetrics) {
histogram_tester.ExpectBucketCount("TouchBar.Default.Metrics", histogram_tester.ExpectBucketCount("TouchBar.Default.Metrics",
ui::TouchBarAction::TEXT_SUGGESTION, 1); ui::TouchBarAction::TEXT_SUGGESTION, 1);
} }
} }
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment