Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Issue 2519563002: [Mac] Switch from NSObject categories to forward declarations for Touch Bar support. (Closed)

Created:
4 years, 1 month ago by Sidney San Martín
Modified:
4 years ago
Reviewers:
tapted
CC:
chromium-reviews, mac-reviews_chromium.org, tfarina
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

[Mac] Switch from NSObject categories to forward declarations for Touch Bar support. This fixes a crash when -[BridgedContentView touchBar:] calls -[NSGroupTouchBarItem groupItemWithIdentifier:items:], because NSGroupTouchBarItem was typedef'd to NSObject. BUG=666893 Committed: https://crrev.com/799f1635ddedf7fd2f69f7dca26b0f2bf6399cba Cr-Commit-Position: refs/heads/master@{#433558}

Patch Set 1 #

Total comments: 3

Patch Set 2 : Use availability macros, no longer need NSClassFromString #

Patch Set 3 : Bring back NSClassFromString, keep the availability macros. #

Patch Set 4 : Tweak comment, change `retain` back to `strong` in interfaces from Apple headers. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+79 lines, -29 lines) Patch
M ui/base/cocoa/touch_bar_forward_declarations.h View 1 2 3 1 chunk +73 lines, -26 lines 0 comments Download
M ui/views/cocoa/bridged_content_view_touch_bar.mm View 1 2 3 chunks +6 lines, -3 lines 0 comments Download

Messages

Total messages: 40 (28 generated)
Sidney San Martín
4 years, 1 month ago (2016-11-18 22:30:48 UTC) #7
tapted
Ooh nice - lgtm - thanks! Somehow I'd always assumed this would lead to linker ...
4 years, 1 month ago (2016-11-19 07:27:38 UTC) #8
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2519563002/100001
4 years, 1 month ago (2016-11-21 15:53:44 UTC) #29
commit-bot: I haz the power
Committed patchset #4 (id:100001)
4 years, 1 month ago (2016-11-21 16:34:01 UTC) #31
Sidney San Martín
On 2016/11/19 at 07:27:38, tapted wrote: > Ooh nice - lgtm - thanks! Somehow I'd ...
4 years, 1 month ago (2016-11-21 16:34:18 UTC) #32
commit-bot: I haz the power
Patchset 4 (id:??) landed as https://crrev.com/799f1635ddedf7fd2f69f7dca26b0f2bf6399cba Cr-Commit-Position: refs/heads/master@{#433558}
4 years, 1 month ago (2016-11-21 16:37:19 UTC) #34
Sidney San Martín
On 2016/11/21 at 16:34:18, Sidney San Martín wrote: > we should be able to get ...
4 years, 1 month ago (2016-11-21 16:38:18 UTC) #35
tapted
> On 2016/11/19 at 07:27:38, tapted wrote: > > > https://codereview.chromium.org/2519563002/diff/1/ui/views/cocoa/bridged_content_view_touch_bar.mm > > File ui/views/cocoa/bridged_content_view_touch_bar.mm ...
4 years, 1 month ago (2016-11-21 22:32:25 UTC) #36
tapted
https://codereview.chromium.org/2519563002/diff/1/ui/base/cocoa/touch_bar_forward_declarations.h File ui/base/cocoa/touch_bar_forward_declarations.h (right): https://codereview.chromium.org/2519563002/diff/1/ui/base/cocoa/touch_bar_forward_declarations.h#newcode102 ui/base/cocoa/touch_bar_forward_declarations.h:102: // declarations to suppress the partial availability warnings. On ...
4 years ago (2016-11-23 04:54:22 UTC) #37
tapted
On 2016/11/23 04:54:22, tapted wrote: > https://codereview.chromium.org/2519563002/diff/1/ui/base/cocoa/touch_bar_forward_declarations.h > File ui/base/cocoa/touch_bar_forward_declarations.h (right): > > https://codereview.chromium.org/2519563002/diff/1/ui/base/cocoa/touch_bar_forward_declarations.h#newcode102 > ...
4 years ago (2016-11-23 05:10:32 UTC) #38
tapted
A revert of this CL (patchset #4 id:100001) has been created in https://codereview.chromium.org/2526723002/ by tapted@chromium.org. ...
4 years ago (2016-11-23 05:11:44 UTC) #39
Sidney San Martín
4 years ago (2016-11-23 07:28:41 UTC) #40
Message was sent while issue was closed.
On 2016/11/23 at 05:10:32, tapted wrote:
> On 2016/11/23 04:54:22, tapted wrote:
> >
https://codereview.chromium.org/2519563002/diff/1/ui/base/cocoa/touch_bar_for...
> > File ui/base/cocoa/touch_bar_forward_declarations.h (right):
> > 
> >
https://codereview.chromium.org/2519563002/diff/1/ui/base/cocoa/touch_bar_for...
> > ui/base/cocoa/touch_bar_forward_declarations.h:102: // declarations to
suppress
> > the partial availability warnings.
> > On 2016/11/21 22:32:25, tapted wrote:
> > > I think I'm ok with it for now but, if I understand correctly, I think
it's
> > > possible we will need to bring these back at some point.
> > > 
> > > I don't think there's a precedent for putting `*_AVAILABLE_MAC` macros
through
> > > our own code. In fact `git grep` doesn't show up any `*_AVAILABLE_MAC` in
our
> > > codebase.
> > > 
> > > It's possible that it makes sense for touchbar stuff -- if we can isolate
our
> > > calls to touchbar APIs only within methods that are also declared
> > > NS_AVAILABLE_MAC, then I think that is a good design, and we should
proceed
> > with
> > > that approach.
> > > 
> > > However, it might not always be possible to invoke touchbar APIs only in
> > methods
> > > declared NS_AVAILABLE_MAC -- we might want to just have it between `if
> > > (base::mac::IsAtLeastOS10_Foo())` in a method that can't be declared
> > > NS_AVAILABLE_MAC.
> > 
> > Yeah I think removing these broke compilation against the 10.12.1 SDK.
Googlers
> > are probably insulated from it because of the toolchain updates. See
> > https://echelog.com/logs/browse/chromium/1479855600
> 
> My pal on IRC confirmed that https://codereview.chromium.org/2515253007 will
fix the build errors he was getting, but there are reports of more errors for
official builders in http://crbug.com/667830, so I don't want to layer things on
top of this commit. I think we should get rid of all the macros. Because of
these issues and since the revised patchset didn't go through a proper review,
I'm going to revert this.

Thanks. I should have reverted it immediately, *and* I should have given you a
chance to review the revised CL instead of landing it — sorry for rushing ahead.
I'll upload a fresh CL without the macros.

On 2016/11/21 at 22:32:25, tapted wrote:
> Well, there's no question for non-POD statics
(go/cppguide#Static_and_Global_Variables clearly says they're banned).
> 
> For other cases, if the initializer is a compile-time constant, then it's
often encouraged.
> 
> However, if the initializer is not not a compile-time constant, then it needs
to be assessed whether `static` is appropriate. Sometimes it can cause subtle
bugs (http://crrev.com/2507363003 is one example). Sometimes there are
unexpected overheads (we use -fno-threadsafe-statics to avoid some, but the
C++11 standard requires that the compiler inserts a mutex lock around static
initializers). But it will always require a chunk of memory in every data
segment and, unlike text segments, data segments can get fragmented easily - it
may look like a pointer in size, but in weird cases it could cause an entire ~4k
page of memory to get copied when it gets initialized. But also all these
pointers eventually add up and increase Chrome's memory requirements.
> 
> Since this counts as a performance optimization, we have to weigh up the
potential downsides. Since this isn't "hot" code, we generally don't optimize
for performance.

Thanks for the detailed explanation. The time/memory tradeoff for cold code
makes sense, and I had no idea about the fragmentation and implicit locks.

On 2016/11/21 at 22:32:25, tapted wrote:
> I think I'm ok with it for now but, if I understand correctly, I think it's
possible we will need to bring these back at some point.
> 
> I don't think there's a precedent for putting `*_AVAILABLE_MAC` macros through
our own code. In fact `git grep` doesn't show up any `*_AVAILABLE_MAC` in our
codebase.
> 
> It's possible that it makes sense for touchbar stuff -- if we can isolate our
calls to touchbar APIs only within methods that are also declared
NS_AVAILABLE_MAC, then I think that is a good design, and we should proceed with
that approach.
> 
> However, it might not always be possible to invoke touchbar APIs only in
methods declared NS_AVAILABLE_MAC -- we might want to just have it between `if
(base::mac::IsAtLeastOS10_Foo())` in a method that can't be declared
NS_AVAILABLE_MAC.

I was wrong about how availability annotations work :/. Partially available
functions *aren't* allowed to use partially available types, it just seemed like
they could because the Mac SDK headers use @class liberally, which is enough to
make -Wpartial-availability ignore it. It turns out that NSTouchBar is forward
declared in NSTouchBarItem.h, but NSTouchBarItem never is.

Powered by Google App Engine
This is Rietveld 408576698