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

Unified Diff: chrome/browser/ui/autofill/autofill_popup_controller_impl.cc

Issue 12217024: Use WeakPtr to simplify AutofillPopupControllerImpl memory management (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments and fix test Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/autofill/autofill_popup_controller_impl.cc
diff --git a/chrome/browser/ui/autofill/autofill_popup_controller_impl.cc b/chrome/browser/ui/autofill/autofill_popup_controller_impl.cc
index 7e28e376c01d1f46981d08adedc6f8fedd9f4110..5e732dc61db8650c27e1c0839d8380996bd7233f 100644
--- a/chrome/browser/ui/autofill/autofill_popup_controller_impl.cc
+++ b/chrome/browser/ui/autofill/autofill_popup_controller_impl.cc
@@ -20,6 +20,7 @@
#include "ui/gfx/screen.h"
#include "ui/gfx/vector2d.h"
+using base::WeakPtr;
using WebKit::WebAutofillClient;
namespace {
@@ -70,8 +71,8 @@ const DataResource kDataResources[] = {
} // end namespace
// static
-AutofillPopupControllerImpl* AutofillPopupControllerImpl::GetOrCreate(
- AutofillPopupControllerImpl* previous,
+WeakPtr<AutofillPopupControllerImpl> AutofillPopupControllerImpl::GetOrCreate(
+ WeakPtr<AutofillPopupControllerImpl> previous,
AutofillPopupDelegate* delegate,
gfx::NativeView container_view,
const gfx::Rect& element_bounds) {
@@ -86,8 +87,9 @@ AutofillPopupControllerImpl* AutofillPopupControllerImpl::GetOrCreate(
if (previous)
previous->Hide();
- return new AutofillPopupControllerImpl(
- delegate, container_view, element_bounds);
+ AutofillPopupControllerImpl* controller =
+ new AutofillPopupControllerImpl(delegate, container_view, element_bounds);
+ return controller->GetWeakPtr();
}
AutofillPopupControllerImpl::AutofillPopupControllerImpl(
@@ -101,16 +103,13 @@ AutofillPopupControllerImpl::AutofillPopupControllerImpl(
selected_line_(kNoSelection),
delete_icon_hovered_(false),
is_hiding_(false),
- inform_delegate_of_destruction_(true) {
+ weak_ptr_factory_(this) {
#if !defined(OS_ANDROID)
subtext_font_ = name_font_.DeriveFont(kLabelFontSizeDelta);
#endif
}
-AutofillPopupControllerImpl::~AutofillPopupControllerImpl() {
- if (inform_delegate_of_destruction_)
- delegate_->ControllerDestroyed();
-}
+AutofillPopupControllerImpl::~AutofillPopupControllerImpl() {}
void AutofillPopupControllerImpl::Show(
const std::vector<string16>& names,
@@ -164,11 +163,23 @@ void AutofillPopupControllerImpl::Show(
} else {
UpdateBoundsAndRedrawPopup();
}
+
+ delegate_->OnPopupShown(this);
}
void AutofillPopupControllerImpl::Hide() {
- inform_delegate_of_destruction_ = false;
- HideInternal();
+ if (is_hiding_)
+ return;
+ is_hiding_ = true;
+
+ SetSelectedLine(kNoSelection);
+
+ delegate_->OnPopupHidden(this);
+
+ if (view_)
+ view_->Hide();
+ else
+ delete this;
}
bool AutofillPopupControllerImpl::HandleKeyPressEvent(
@@ -187,7 +198,7 @@ bool AutofillPopupControllerImpl::HandleKeyPressEvent(
SetSelectedLine(names().size() - 1);
return true;
case ui::VKEY_ESCAPE:
- HideInternal();
+ Hide();
return true;
case ui::VKEY_DELETE:
return (event.modifiers & content::NativeWebKeyboardEvent::ShiftKey) &&
@@ -325,19 +336,6 @@ bool AutofillPopupControllerImpl::delete_icon_hovered() const {
return delete_icon_hovered_;
}
-void AutofillPopupControllerImpl::HideInternal() {
- if (is_hiding_)
- return;
- is_hiding_ = true;
-
- SetSelectedLine(kNoSelection);
-
- if (view_)
- view_->Hide();
- else
- delete this;
-}
-
void AutofillPopupControllerImpl::SetSelectedLine(int selected_line) {
if (selected_line_ == selected_line)
return;
@@ -426,7 +424,7 @@ bool AutofillPopupControllerImpl::RemoveSelectedLine() {
delegate_->ClearPreviewedForm();
UpdateBoundsAndRedrawPopup();
} else {
- HideInternal();
+ Hide();
}
return true;
@@ -528,6 +526,10 @@ int AutofillPopupControllerImpl::GetDesiredPopupHeight() const {
return popup_height;
}
+WeakPtr<AutofillPopupControllerImpl> AutofillPopupControllerImpl::GetWeakPtr() {
+ return weak_ptr_factory_.GetWeakPtr();
+}
+
int AutofillPopupControllerImpl::RowWidthWithoutText(int row) const {
int row_size = kEndPadding + kNamePadding;

Powered by Google App Engine
This is Rietveld 408576698