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

Side by Side Diff: chrome/browser/ui/views/reload_button.cc

Issue 10832184: Fixed memory leak. Untangled confusing code with menu initialization and ownership. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/views/reload_button.h ('k') | ui/views/controls/button/button_dropdown.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/reload_button.h" 5 #include "chrome/browser/ui/views/reload_button.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/app/chrome_command_ids.h" 8 #include "chrome/app/chrome_command_ids.h"
9 #include "chrome/browser/command_updater.h" 9 #include "chrome/browser/command_updater.h"
10 #include "chrome/browser/event_disposition.h" 10 #include "chrome/browser/event_disposition.h"
(...skipping 21 matching lines...) Expand all
32 IDS_RELOAD_MENU_NORMAL_RELOAD_ITEM, 32 IDS_RELOAD_MENU_NORMAL_RELOAD_ITEM,
33 IDS_RELOAD_MENU_HARD_RELOAD_ITEM, 33 IDS_RELOAD_MENU_HARD_RELOAD_ITEM,
34 IDS_RELOAD_MENU_EMPTY_AND_HARD_RELOAD_ITEM, 34 IDS_RELOAD_MENU_EMPTY_AND_HARD_RELOAD_ITEM,
35 }; 35 };
36 36
37 //////////////////////////////////////////////////////////////////////////////// 37 ////////////////////////////////////////////////////////////////////////////////
38 // ReloadButton, public: 38 // ReloadButton, public:
39 39
40 ReloadButton::ReloadButton(LocationBarView* location_bar, 40 ReloadButton::ReloadButton(LocationBarView* location_bar,
41 CommandUpdater* command_updater) 41 CommandUpdater* command_updater)
42 : ALLOW_THIS_IN_INITIALIZER_LIST(ButtonDropDown(this, CreateMenuModel())), 42 : ALLOW_THIS_IN_INITIALIZER_LIST(ButtonDropDown(this, NULL)),
43 location_bar_(location_bar), 43 location_bar_(location_bar),
44 command_updater_(command_updater), 44 command_updater_(command_updater),
45 intended_mode_(MODE_RELOAD), 45 intended_mode_(MODE_RELOAD),
46 visible_mode_(MODE_RELOAD), 46 visible_mode_(MODE_RELOAD),
47 double_click_timer_delay_( 47 double_click_timer_delay_(
48 base::TimeDelta::FromMilliseconds(views::GetDoubleClickInterval())), 48 base::TimeDelta::FromMilliseconds(views::GetDoubleClickInterval())),
49 stop_to_reload_timer_delay_(base::TimeDelta::FromMilliseconds(1350)), 49 stop_to_reload_timer_delay_(base::TimeDelta::FromMilliseconds(1350)),
50 menu_enabled_(false), 50 menu_enabled_(false),
51 testing_mouse_hovered_(false), 51 testing_mouse_hovered_(false),
52 testing_reload_count_(0) { 52 testing_reload_count_(0) {
53 menu_model_.reset(new ui::SimpleMenuModel(this));
54 for (size_t i = 0; i < arraysize(kReloadMenuItems); i++) {
55 menu_model_->AddItemWithStringId(kReloadMenuItems[i],
56 kReloadMenuItems[i]);
57 }
58 ButtonDropDown::set_menu_model(menu_model_.get());
53 } 59 }
54 60
55 ReloadButton::~ReloadButton() { 61 ReloadButton::~ReloadButton() {
62 ButtonDropDown::set_menu_model(NULL);
Peter Kasting 2012/08/07 19:43:03 This doesn't seem necessary.
gene 2012/08/07 20:58:34 You are right, it does not now. However ButtonDrop
56 } 63 }
57 64
58 void ReloadButton::ChangeMode(Mode mode, bool force) { 65 void ReloadButton::ChangeMode(Mode mode, bool force) {
59 intended_mode_ = mode; 66 intended_mode_ = mode;
60 67
61 // If the change is forced, or the user isn't hovering the icon, or it's safe 68 // If the change is forced, or the user isn't hovering the icon, or it's safe
62 // to change it to the other image type, make the change immediately; 69 // to change it to the other image type, make the change immediately;
63 // otherwise we'll let it happen later. 70 // otherwise we'll let it happen later.
64 if (force || (!IsMouseHovered() && !testing_mouse_hovered_) || 71 if (force || (!IsMouseHovered() && !testing_mouse_hovered_) ||
65 ((mode == MODE_STOP) ? 72 ((mode == MODE_STOP) ?
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 break; 232 break;
226 default: 233 default:
227 NOTREACHED(); 234 NOTREACHED();
228 } 235 }
229 ExecuteBrowserCommand(browser_command, event_flags); 236 ExecuteBrowserCommand(browser_command, event_flags);
230 } 237 }
231 238
232 //////////////////////////////////////////////////////////////////////////////// 239 ////////////////////////////////////////////////////////////////////////////////
233 // ReloadButton, private: 240 // ReloadButton, private:
234 241
235 ui::SimpleMenuModel* ReloadButton::CreateMenuModel() {
236 ui::SimpleMenuModel* menu_model_ = new ui::SimpleMenuModel(this);
237 for (size_t i = 0; i < arraysize(kReloadMenuItems); i++) {
238 menu_model_->AddItemWithStringId(kReloadMenuItems[i],
239 kReloadMenuItems[i]);
240 }
241 return menu_model_;
242 }
243
244 void ReloadButton::ExecuteBrowserCommand(int command, int event_flags) { 242 void ReloadButton::ExecuteBrowserCommand(int command, int event_flags) {
245 if (!command_updater_) 243 if (!command_updater_)
246 return; 244 return;
247 245
248 WindowOpenDisposition disposition = 246 WindowOpenDisposition disposition =
249 chrome::DispositionFromEventFlags(event_flags); 247 chrome::DispositionFromEventFlags(event_flags);
250 if ((disposition == CURRENT_TAB) && location_bar_) { 248 if ((disposition == CURRENT_TAB) && location_bar_) {
251 // Forcibly reset the location bar, since otherwise it won't discard any 249 // Forcibly reset the location bar, since otherwise it won't discard any
252 // ongoing user edits, since it doesn't realize this is a user-initiated 250 // ongoing user edits, since it doesn't realize this is a user-initiated
253 // action. 251 // action.
(...skipping 14 matching lines...) Expand all
268 266
269 void ReloadButton::OnDoubleClickTimer() { 267 void ReloadButton::OnDoubleClickTimer() {
270 if (!IsMenuShowing()) 268 if (!IsMenuShowing())
271 ChangeMode(intended_mode_, false); 269 ChangeMode(intended_mode_, false);
272 } 270 }
273 271
274 void ReloadButton::OnStopToReloadTimer() { 272 void ReloadButton::OnStopToReloadTimer() {
275 DCHECK(!IsMenuShowing()); 273 DCHECK(!IsMenuShowing());
276 ChangeMode(intended_mode_, true); 274 ChangeMode(intended_mode_, true);
277 } 275 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/reload_button.h ('k') | ui/views/controls/button/button_dropdown.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698