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

Issue 9817007: ui/base/models: Add protected virtual destructor to ComboboxModel. (Closed)

Created:
8 years, 9 months ago by tfarina
Modified:
8 years ago
Reviewers:
sky
CC:
chromium-reviews
Visibility:
Public.

Description

ui/base/models: Add protected virtual destructor to ComboboxModel. The use of a protected virtual destructor is to prevent the destruction of a derived object via a base-class pointer. That's it, ComboboxModel should only be deleted through derived class. Example 1: class FooComboboxModel : public ComboboxModel { }; ComboboxModel* model = new FooComboboxModel; delete model; // It should prevent this situation! Also, a protected virtual destructor makes it clear that someone else owns the object. Example 2: class Foo { public: void SetModel(ComboboxModel* model); }; If you see that the model has a protected destructor, you know Foo doesn't own |model|. R=sky@chromium.org Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=128132

Patch Set 1 #

Patch Set 2 : fix unittest #

Unified diffs Side-by-side diffs Delta from patch set Stats (+10 lines, -9 lines) Patch
M ui/base/models/combobox_model.h View 1 chunk +6 lines, -5 lines 0 comments Download
M ui/views/controls/combobox/native_combobox_views_unittest.cc View 1 1 chunk +4 lines, -4 lines 0 comments Download

Messages

Total messages: 5 (0 generated)
tfarina
8 years, 9 months ago (2012-03-21 16:18:25 UTC) #1
sky
LGTM
8 years, 9 months ago (2012-03-21 16:28:23 UTC) #2
Evan Stade
I don't understand the purpose of this change. It's useful to allow Example 1. As ...
8 years ago (2012-11-28 03:51:08 UTC) #3
sky
We generally use this pattern to make it clear the consumer of the ComboboxModel doesn't ...
8 years ago (2012-11-28 05:18:58 UTC) #4
Evan Stade
8 years ago (2012-11-28 21:31:33 UTC) #5
Message was sent while issue was closed.
On 2012/11/28 05:18:58, sky wrote:
> We generally use this pattern to make it clear the consumer of the
ComboboxModel
> doesn't own it, since it can't delete it. You'll see this pattern used for
> Observers too.

I do see that for some observers as well as some delegates, but sometimes the
owner does not know the type. For example, WebContentsViewAura owns a pointer of
type WebContentsViewDelegate. Do you think that this is a valid exception that
justifies WebContentsViewDelegate's public destructor, or that that usage should
be adjusted? If the former, what constitutes a valid justification? If the
latter, how could that be done gracefully?

Powered by Google App Engine
This is Rietveld 408576698