New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 701095 link

Starred by 2 users

Issue metadata

Status: WontFix
Owner:
Closed: May 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: iOS
Pri: 3
Type: Bug


Sign in to add a comment

☂ Eliminate multiple inheritance for Tab helper classes

Project Member Reported by kkhorimoto@chromium.org, Mar 13 2017

Issue description

Multiple inheritance is prohibited by the style guide unless only one superclass has an implementation.  All other superclasses must be pure interfaces with an "Interface" suffix: https://google.github.io/styleguide/cppguide.html#Multiple_Inheritance

Classes that break the multiple inheritance rule:
NetworkActivityIndicatorTabHelper
IOSChromeSyncedTabDelegate
InfoBarManagerImpl
RepostFormTabHelper
BlockedPopupTabHelper
FindTabHelper
ReadingListWebStateObserver
ChromeIOSTranslateClient
WebFaviconDriver
WebStateTopSitesObserver
 
Labels: OS-iOS

Comment 2 Deleted

Blockedon: 701115
Blockedon: 701116
Blockedon: 701117
Blockedon: 701118
Blockedon: 701119
Blockedon: 701121
Blockedon: 701123
Blockedon: 701124
Blockedon: 701125
Blockedon: 701126
Blockedon: 701127
Description: Show this description
Cc: a...@chromium.org eugene...@chromium.org sdefresne@chromium.org
I'm not convinced this is something we want to fix, because this is a pattern that's used all over the codebase.  Let's discuss the specific motivation behind this bug (and loop in some //content folks) before we make any changes.
Avi, the tab helper docs specifically say to use WebContentsUserData + WebContentsObserver, but the style guide bans multiple inheritance.  Is this a case where we should ask for an exception?  Or should we make a common base class to satisfy the style guide?

https://chromium.googlesource.com/chromium/src/+/master/docs/tab_helpers.md#Adding-a-feature-to-a-browser-tab
It looks like the Chromium C++ style guide allows (but discourages) multiple inheritance: https://chromium.googlesource.com/chromium/src/+/master/styleguide/c++/c++.md

Comment 18 by a...@chromium.org, Mar 13 2017

If the classes being multiply-inherited from are small and intended as mix-ins, is it a real issue?
Components: Internals
Cc: brettw@chromium.org pkl@chromium.org
+ Brett

As some background, this is not a high priority issue; I just noticed that we had several style guide violations in some of our tab helper implementations on iOS, which is a pattern we've only started using, so I created this bug tree to track these violations.  As far as I can tell, multiple inheritance hasn't caused any issues here.  It just seems that multiple inheritance is generally a C++ anti-pattern that we should avoid.

Brett & Avi: Do you have any context as to why multiple inheritance is prohibited by the Google style guide, but only discouraged by the chromium guide?  I'm not sure if this is an issue worth putting in the effort to fix, as I understand that the pattern is widely used in chromium code for other platforms, but I'd like to get some discussion to help better understand our approach here.
I'm not sure those bugs are worth fixing.

First our observer classes are interface-ish classes (they are not named XXXInterface because it make much more sense to name them XXXObserver) and if they have implementation for their method they are empty (i.e. you never have to call the super class implementation in the derived class). So those inheritance are not cases of implementation inheritance.

Second, those classes (e.g. WebFaviconDriver) are designed to mimic their chrome/ counterpart (e.g. ContentFaviconDriver) and removing the multiple inheritance from the ios/chrome/ implementation would need to be done in sync with removing the inheritance from the chrome/ class too.

Finally some of the bugs are incorrect as the classes inheritance correspond to what is allowed by the style guide (e.g. IOSChromeSyncedTabDelegate inherits from sync_sessions::SyncedTabDelegate and web::WebStateUserData<IOSChromeSyncedTabDelegate> where sync_sessions::SyncedTabDelegate is a pure interface). 
BTW, I read the google style guide as prohibiting "implementation multiple inheritance" (i.e. mix-in) and not prohibiting having a class implementing multiple interfaces (and WebStateObserver is an interface class even though it lack the Interface and has default empty implementation for the events method to allow only implementing the one we are interested in).

I think that those classes are in the spirit of the style guide (i.e. no "multiple inheritance to get the implementation of all super-class" but "multiple inheritance to declare conformance to multiple interfaces") even though they don't conform to the letter (i.e. interfaces are not named "FooInterface").
Owner: kkhorimoto@chromium.org
Status: Assigned (was: Untriaged)
kkhorimoto@ - feel free to close/re-assign once it is decided if we are okay with the current code or not.
Status: WontFix (was: Assigned)

Sign in to add a comment