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

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: Fix android build 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 5fea9376ec96e467a0f77fe6f0c46649c4f23a27..6b2d3246ae39fdb71d392b0e3e5e9ad06053af14 100644
--- a/chrome/browser/ui/autofill/autofill_popup_controller_impl.cc
+++ b/chrome/browser/ui/autofill/autofill_popup_controller_impl.cc
@@ -21,6 +21,7 @@
#include "ui/gfx/screen.h"
#include "ui/gfx/vector2d.h"
+using base::WeakPtr;
using WebKit::WebAutofillClient;
namespace {
@@ -71,8 +72,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::RectF& element_bounds) {
@@ -87,8 +88,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(
@@ -102,16 +104,14 @@ AutofillPopupControllerImpl::AutofillPopupControllerImpl(
selected_line_(kNoSelection),
delete_icon_hovered_(false),
is_hiding_(false),
- inform_delegate_of_destruction_(true) {
+ 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,
@@ -165,6 +165,8 @@ void AutofillPopupControllerImpl::Show(
} else {
UpdateBoundsAndRedrawPopup();
}
+
+ delegate_->OnPopupShown(this);
}
void AutofillPopupControllerImpl::Hide() {
@@ -333,6 +335,9 @@ void AutofillPopupControllerImpl::HideInternal() {
SetSelectedLine(kNoSelection);
+ if (inform_delegate_of_destruction_)
+ delegate_->OnPopupHidden(this);
+
if (view_)
view_->Hide();
else
@@ -580,6 +585,10 @@ void AutofillPopupControllerImpl::UpdatePopupBounds() {
}
#endif // !defined(OS_ANDROID)
+WeakPtr<AutofillPopupControllerImpl> AutofillPopupControllerImpl::GetWeakPtr() {
+ return weak_ptr_factory_.GetWeakPtr();
+}
+
const gfx::Rect AutofillPopupControllerImpl::RoundedElementBounds() const {
return gfx::ToNearestRect(element_bounds_);
}

Powered by Google App Engine
This is Rietveld 408576698