diff options
author | gene@chromium.org <gene@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-08 00:33:40 +0000 |
---|---|---|
committer | gene@chromium.org <gene@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-08 00:33:40 +0000 |
commit | 55ce288f21207b58778bbd39b171eb02ed62be95 (patch) | |
tree | 939e865b6478286704dcba891fa8cde307438abc | |
parent | 7a801a64f1533207dcd591035c9ade1d8ddf144e (diff) | |
download | chromium_src-55ce288f21207b58778bbd39b171eb02ed62be95.zip chromium_src-55ce288f21207b58778bbd39b171eb02ed62be95.tar.gz chromium_src-55ce288f21207b58778bbd39b171eb02ed62be95.tar.bz2 |
Fixed memory leak. Untangled confusing code with menu initialization and ownership.
BUG=141037
TEST=Make sure memory bots passed.
Review URL: https://chromiumcodereview.appspot.com/10832184
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150469 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/ui/views/button_dropdown_test.cc | 4 | ||||
-rw-r--r-- | chrome/browser/ui/views/toolbar_view.cc | 9 | ||||
-rw-r--r-- | chrome/browser/ui/views/toolbar_view.h | 3 | ||||
-rw-r--r-- | ui/views/controls/button/button_dropdown.cc | 4 | ||||
-rw-r--r-- | ui/views/controls/button/button_dropdown.h | 3 | ||||
-rw-r--r-- | ui/views/view_unittest.cc | 3 |
6 files changed, 9 insertions, 17 deletions
diff --git a/chrome/browser/ui/views/button_dropdown_test.cc b/chrome/browser/ui/views/button_dropdown_test.cc index 4defa09..14a9f9b 100644 --- a/chrome/browser/ui/views/button_dropdown_test.cc +++ b/chrome/browser/ui/views/button_dropdown_test.cc @@ -15,7 +15,6 @@ class ButtonDropDownDragTest : public ViewEventTestBase, public: ButtonDropDownDragTest() : button_(NULL), - ALLOW_THIS_IN_INITIALIZER_LIST(menu_model_(this)), menu_shown_(false), menu_closed_(false) { } @@ -25,7 +24,7 @@ class ButtonDropDownDragTest : public ViewEventTestBase, // ViewEventTestBase implementation. virtual void SetUp() OVERRIDE { - button_ = new views::ButtonDropDown(NULL, &menu_model_); + button_ = new views::ButtonDropDown(NULL, new ui::SimpleMenuModel(this)); ViewEventTestBase::SetUp(); } @@ -125,7 +124,6 @@ class ButtonDropDownDragTest : public ViewEventTestBase, private: views::ButtonDropDown* button_; - ui::SimpleMenuModel menu_model_; bool menu_shown_; bool menu_closed_; }; diff --git a/chrome/browser/ui/views/toolbar_view.cc b/chrome/browser/ui/views/toolbar_view.cc index 82979b39..5e6e927 100644 --- a/chrome/browser/ui/views/toolbar_view.cc +++ b/chrome/browser/ui/views/toolbar_view.cc @@ -220,12 +220,8 @@ ToolbarView::~ToolbarView() { void ToolbarView::Init(views::View* location_bar_parent, views::View* popup_parent_view) { - back_menu_model_.reset(new BackForwardMenuModel( + back_ = new views::ButtonDropDown(this, new BackForwardMenuModel( browser_, BackForwardMenuModel::BACKWARD_MENU)); - forward_menu_model_.reset(new BackForwardMenuModel( - browser_, BackForwardMenuModel::FORWARD_MENU)); - - back_ = new views::ButtonDropDown(this, back_menu_model_.get()); back_->set_triggerable_event_flags(ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON); back_->set_tag(IDC_BACK); @@ -235,7 +231,8 @@ void ToolbarView::Init(views::View* location_bar_parent, back_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_BACK)); back_->set_id(VIEW_ID_BACK_BUTTON); - forward_ = new views::ButtonDropDown(this, forward_menu_model_.get()); + forward_ = new views::ButtonDropDown(this, new BackForwardMenuModel( + browser_, BackForwardMenuModel::FORWARD_MENU)); forward_->set_triggerable_event_flags(ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON); forward_->set_tag(IDC_FORWARD); diff --git a/chrome/browser/ui/views/toolbar_view.h b/chrome/browser/ui/views/toolbar_view.h index 037efe5..0d68369 100644 --- a/chrome/browser/ui/views/toolbar_view.h +++ b/chrome/browser/ui/views/toolbar_view.h @@ -214,9 +214,6 @@ class ToolbarView : public views::AccessiblePaneView, // of |this|. void SetLocationBarContainerBounds(const gfx::Rect& bounds); - scoped_ptr<BackForwardMenuModel> back_menu_model_; - scoped_ptr<BackForwardMenuModel> forward_menu_model_; - // The model that contains the security level, text, icon to display... ToolbarModel* model_; diff --git a/ui/views/controls/button/button_dropdown.cc b/ui/views/controls/button/button_dropdown.cc index 5ee98b3..236eca4 100644 --- a/ui/views/controls/button/button_dropdown.cc +++ b/ui/views/controls/button/button_dropdown.cc @@ -175,8 +175,8 @@ void ButtonDropDown::ShowDropDownMenu() { menu_showing_ = true; // Create and run menu. Display an empty menu if model is NULL. - if (model_) { - MenuModelAdapter menu_delegate(model_); + if (model_.get()) { + MenuModelAdapter menu_delegate(model_.get()); menu_delegate.set_triggerable_event_flags(triggerable_event_flags()); menu_runner_.reset(new MenuRunner(menu_delegate.CreateMenu())); MenuRunner::RunResult result = diff --git a/ui/views/controls/button/button_dropdown.h b/ui/views/controls/button/button_dropdown.h index d58e640..8e57222 100644 --- a/ui/views/controls/button/button_dropdown.h +++ b/ui/views/controls/button/button_dropdown.h @@ -29,6 +29,7 @@ class VIEWS_EXPORT ButtonDropDown : public ImageButton { // The button's class name. static const char kViewClassName[]; + // Takes ownership of the |model|. ButtonDropDown(ButtonListener* listener, ui::MenuModel* model); virtual ~ButtonDropDown(); @@ -67,7 +68,7 @@ class VIEWS_EXPORT ButtonDropDown : public ImageButton { private: // The model that populates the attached menu. - ui::MenuModel* model_; + scoped_ptr<ui::MenuModel> model_; // Indicates if menu is currently showing. bool menu_showing_; diff --git a/ui/views/view_unittest.cc b/ui/views/view_unittest.cc index ef607be..3759915 100644 --- a/ui/views/view_unittest.cc +++ b/ui/views/view_unittest.cc @@ -1762,7 +1762,7 @@ class ButtonDropDownTest : public ViewTest { virtual void SetUp() OVERRIDE { ViewTest::SetUp(); - test_dialog_ = new TestDialog(&mock_menu_model_); + test_dialog_ = new TestDialog(new MockMenuModel()); Widget* window = Widget::CreateWindowWithBounds(test_dialog_, gfx::Rect(0, 0, 100, 100)); test_dialog_->widget_ = window; @@ -1779,7 +1779,6 @@ class ButtonDropDownTest : public ViewTest { } TestDialog* test_dialog_; - MockMenuModel mock_menu_model_; // This is owned by test_dialog_. View* button_as_view_; |