summaryrefslogtreecommitdiffstats
path: root/views/widget
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-01 16:57:13 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-01 16:57:13 +0000
commit7c9d829192359328576965fe8a4a52a5ad6c7da3 (patch)
tree6f06ef0a1bd4f797ad2c9f2968950b625867136c /views/widget
parent9d3fcf8bc99dfdfef66b983af69802ddbe76514d (diff)
downloadchromium_src-7c9d829192359328576965fe8a4a52a5ad6c7da3.zip
chromium_src-7c9d829192359328576965fe8a4a52a5ad6c7da3.tar.gz
chromium_src-7c9d829192359328576965fe8a4a52a5ad6c7da3.tar.bz2
Attempt at fixing leaks from SetProp. Apparently there is a finite
amount of memory reserved for properties and Windows doesn't always automatically free up the memory if the window is deleted without an explicit remove. For the time being I've made it easier to track SetProp leaks, but we may want to move to using something other than SetProp in the future that isn't as fragile. I didn't fix a couple of places that were trickier. I'm going to file separate bugs on them. BUG=44991 TEST=none Review URL: http://codereview.chromium.org/4195003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64619 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/widget')
-rw-r--r--views/widget/widget_win.cc28
-rw-r--r--views/widget/widget_win.h15
2 files changed, 28 insertions, 15 deletions
diff --git a/views/widget/widget_win.cc b/views/widget/widget_win.cc
index 102b48d..bb6ca8d 100644
--- a/views/widget/widget_win.cc
+++ b/views/widget/widget_win.cc
@@ -8,6 +8,7 @@
#include "app/l10n_util_win.h"
#include "app/system_monitor.h"
#include "app/win_util.h"
+#include "app/win/scoped_prop.h"
#include "base/string_util.h"
#include "base/win_util.h"
#include "gfx/canvas_skia.h"
@@ -36,10 +37,6 @@ bool WidgetWin::screen_reader_active_ = false;
// listening for MSAA events.
#define OBJID_CUSTOM 1
-bool SetRootViewForHWND(HWND hwnd, RootView* root_view) {
- return SetProp(hwnd, kRootViewWindowProperty, root_view) ? true : false;
-}
-
RootView* GetRootViewForHWND(HWND hwnd) {
return reinterpret_cast<RootView*>(::GetProp(hwnd, kRootViewWindowProperty));
}
@@ -168,7 +165,7 @@ void WidgetWin::Init(gfx::NativeView parent, const gfx::Rect& bounds) {
default_theme_provider_.reset(new DefaultThemeProvider());
- SetWindowSupportsRerouteMouseWheel(hwnd());
+ props_.push_back(SetWindowSupportsRerouteMouseWheel(hwnd()));
drop_target_ = new DropTargetWin(root_view_.get());
@@ -183,7 +180,7 @@ void WidgetWin::Init(gfx::NativeView parent, const gfx::Rect& bounds) {
}
// Sets the RootView as a property, so the automation can introspect windows.
- SetRootViewForHWND(hwnd(), root_view_.get());
+ SetNativeWindowProperty(kRootViewWindowProperty, root_view_.get());
MessageLoopForUI::current()->AddObserver(this);
@@ -421,12 +418,17 @@ const Window* WidgetWin::GetWindow() const {
return GetWindowImpl(hwnd());
}
-void WidgetWin::SetNativeWindowProperty(const std::wstring& name,
- void* value) {
+void WidgetWin::SetNativeWindowProperty(const std::wstring& name, void* value) {
+ // Remove the existing property (if any).
+ for (ScopedProps::iterator i = props_.begin(); i != props_.end(); ++i) {
+ if ((*i)->key() == name) {
+ props_.erase(i);
+ break;
+ }
+ }
+
if (value)
- SetProp(hwnd(), name.c_str(), value);
- else
- RemoveProp(hwnd(), name.c_str());
+ props_.push_back(new app::win::ScopedProp(hwnd(), name, value));
}
void* WidgetWin::GetNativeWindowProperty(const std::wstring& name) {
@@ -583,14 +585,12 @@ LRESULT WidgetWin::OnCreate(CREATESTRUCT* create_struct) {
}
void WidgetWin::OnDestroy() {
- SetNativeWindowProperty(kWidgetKey, NULL);
-
if (drop_target_.get()) {
RevokeDragDrop(hwnd());
drop_target_ = NULL;
}
- RemoveProp(hwnd(), kRootViewWindowProperty);
+ props_.reset();
}
void WidgetWin::OnDisplayChange(UINT bits_per_pixel, CSize screen_size) {
diff --git a/views/widget/widget_win.h b/views/widget/widget_win.h
index 029f34e..bfb9137 100644
--- a/views/widget/widget_win.h
+++ b/views/widget/widget_win.h
@@ -11,15 +11,23 @@
#include <atlcrack.h>
#include <atlmisc.h>
+#include <string>
#include <vector>
#include "base/message_loop.h"
#include "base/scoped_comptr_win.h"
+#include "base/scoped_vector.h"
#include "gfx/window_impl.h"
#include "views/focus/focus_manager.h"
#include "views/layout_manager.h"
#include "views/widget/widget.h"
+namespace app {
+namespace win {
+class ScopedProp;
+}
+}
+
namespace gfx {
class CanvasSkia;
class Rect;
@@ -34,7 +42,6 @@ class RootView;
class TooltipManagerWin;
class Window;
-bool SetRootViewForHWND(HWND hwnd, RootView* root_view);
RootView* GetRootViewForHWND(HWND hwnd);
// A Windows message reflected from other windows. This message is sent
@@ -480,6 +487,8 @@ class WidgetWin : public gfx::WindowImpl,
bool is_window_;
private:
+ typedef ScopedVector<app::win::ScopedProp> ScopedProps;
+
// Implementation of GetWindow. Ascends the parents of |hwnd| returning the
// first ancestor that is a Window.
static Window* GetWindowImpl(HWND hwnd);
@@ -585,6 +594,10 @@ class WidgetWin : public gfx::WindowImpl,
// The current position of the view events vector. When incrementing,
// we always mod this value with the max view events above .
int accessibility_view_events_index_;
+
+ ScopedProps props_;
+
+ DISALLOW_COPY_AND_ASSIGN(WidgetWin);
};
} // namespace views