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

Issue 3010883002: Implement concrete class RefCountedBase.

Created:
3 years, 3 months ago by nisse-webrtc
Modified:
3 years, 3 months ago
Reviewers:
kwiberg-webrtc
CC:
webrtc-reviews_webrtc.org, tterriberry_mozilla.com
Target Ref:
refs/heads/master
Project:
webrtc
Visibility:
Public.

Description

Implement concrete class RefCountedBase. BUG=

Patch Set 1 #

Total comments: 6

Patch Set 2 : Use "= default" for destructors. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+28 lines, -17 lines) Patch
M webrtc/rtc_base/refcountedobject.h View 1 2 chunks +28 lines, -17 lines 0 comments Download

Messages

Total messages: 4 (1 generated)
nisse-webrtc
Please have a look, it didn't get so bad. https://codereview.webrtc.org/3010883002/diff/1/webrtc/rtc_base/refcountedobject.h File webrtc/rtc_base/refcountedobject.h (right): https://codereview.webrtc.org/3010883002/diff/1/webrtc/rtc_base/refcountedobject.h#newcode49 webrtc/rtc_base/refcountedobject.h:49: ...
3 years, 3 months ago (2017-09-01 08:56:14 UTC) #2
kwiberg-webrtc
https://codereview.webrtc.org/3010883002/diff/1/webrtc/rtc_base/refcountedobject.h File webrtc/rtc_base/refcountedobject.h (right): https://codereview.webrtc.org/3010883002/diff/1/webrtc/rtc_base/refcountedobject.h#newcode43 webrtc/rtc_base/refcountedobject.h:43: virtual ~RefCountedBase() {} This one doesn't have to be ...
3 years, 3 months ago (2017-09-01 09:08:19 UTC) #3
nisse-webrtc
3 years, 3 months ago (2017-09-01 09:32:51 UTC) #4
https://codereview.webrtc.org/3010883002/diff/1/webrtc/rtc_base/refcountedobj...
File webrtc/rtc_base/refcountedobject.h (right):

https://codereview.webrtc.org/3010883002/diff/1/webrtc/rtc_base/refcountedobj...
webrtc/rtc_base/refcountedobject.h:43: virtual ~RefCountedBase() {}
On 2017/09/01 09:08:19, kwiberg-webrtc wrote:
> This one doesn't have to be virtual, right?

I think it has to, to make sure that Release calls the right destructor. The way
I understand it, this class can be inherited in several steps, and it's just
that the AddRef and Release methods which are supposed to not be overridden
(BTW, whould they be marked final?)

> And you should probably define it with =default, since that will allow the
> compiler to treat it as trivially destructible IIRC.

I'll change to default, but if it's virtual, that shouldn't make much
difference, I guess?

https://codereview.webrtc.org/3010883002/diff/1/webrtc/rtc_base/refcountedobj...
webrtc/rtc_base/refcountedobject.h:49: class RefCountedObject : public T,
protected virtual RefCountedBase {
On 2017/09/01 09:08:19, kwiberg-webrtc wrote:
> On 2017/09/01 08:56:14, nisse-webrtc wrote:
> > I understand roughly why "protected virtual" inheritance is needed. Scary...
> 
> I would have thought that just "private" would suffice. 

Changing protected to private gives this error:

In file included from ../../webrtc/pc/rtpreceiver.cc:11:
../../webrtc/pc/rtpreceiver.h:42:7: error: inherited virtual base class
'rtc::RefCountedBase' has private destructor
class AudioRtpReceiver : public ObserverInterface,
      ^
../../webrtc/rtc_base/refcountedobject.h:49:36: note: declared private here
class RefCountedObject : public T, private virtual RefCountedBase {
                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

> Why does it have to be virtual?

If I drop virtual, I get this error:

../../webrtc/rtc_base/refcountedobject.h:49:36: error: direct base
'rtc::RefCountedBase' is inaccessible due to ambiguity:
    class rtc::RefCountedObject<class webrtc::MockRtpSender> -> class
webrtc::MockRtpSender -> rtc::RefCountedObject<RtpSenderInterface> -> class
rtc::RefCountedBase
    class rtc::RefCountedObject<class webrtc::MockRtpSender> -> class
rtc::RefCountedBase [-Werror,-Winaccessible-base]
class RefCountedObject : public T, protected RefCountedBase {
                                   ^~~~~~~~~~~~~~~~~~~~~~~~
../../webrtc/pc/trackmediainfomap_unittest.cc:55:11: note: in instantiation of
template class 'rtc::RefCountedObject<webrtc::MockRtpSender>' requested here
      new rtc::RefCountedObject<MockRtpSender>());
          ^

Maybe this is a bug elsewhere in the code where we get multiple RefCountedObject
wrappers, which earlier just gave us multiple unused ref_count_ members?

Powered by Google App Engine
This is Rietveld 408576698