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

Unified Diff: ui/gfx/font_render_params_win.cc

Issue 1092183005: Fix Up SingletonHwnd Observer Lifetime Issues (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed WndProc null guard Created 5 years, 8 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: ui/gfx/font_render_params_win.cc
diff --git a/ui/gfx/font_render_params_win.cc b/ui/gfx/font_render_params_win.cc
index 5709feab4c939eaae776aca1880c9e91fef77375..7ca55f0a4176c4c95a66522c54bf0332592abb50 100644
--- a/ui/gfx/font_render_params_win.cc
+++ b/ui/gfx/font_render_params_win.cc
@@ -2,13 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/files/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/singleton.h"
#include "base/win/registry.h"
#include "ui/gfx/font_render_params.h"
#include "ui/gfx/win/direct_write.h"
-#include "ui/gfx/win/singleton_hwnd.h"
+#include "ui/gfx/win/singleton_hwnd_observer.h"
namespace gfx {
@@ -42,7 +44,7 @@ FontRenderParams::SubpixelRendering GetSubpixelRenderingGeometry() {
}
// Caches font render params and updates them on system notifications.
-class CachedFontRenderParams : public gfx::SingletonHwnd::Observer {
+class CachedFontRenderParams {
public:
static CachedFontRenderParams* GetInstance() {
return Singleton<CachedFontRenderParams>::get();
@@ -72,7 +74,9 @@ class CachedFontRenderParams : public gfx::SingletonHwnd::Observer {
params_->subpixel_rendering = GetSubpixelRenderingGeometry();
}
}
- gfx::SingletonHwnd::GetInstance()->AddObserver(this);
+ singleton_hwnd_observer_.reset(new SingletonHwndObserver(
+ base::Bind(&CachedFontRenderParams::OnSettingsChange,
+ base::Unretained(this))));
return *params_;
}
@@ -80,22 +84,17 @@ class CachedFontRenderParams : public gfx::SingletonHwnd::Observer {
friend struct DefaultSingletonTraits<CachedFontRenderParams>;
CachedFontRenderParams() {}
- virtual ~CachedFontRenderParams() {
- // Can't remove the SingletonHwnd observer here since SingletonHwnd may have
- // been destroyed already (both singletons).
- }
+ ~CachedFontRenderParams() {}
- void OnWndProc(HWND hwnd,
- UINT message,
- WPARAM wparam,
- LPARAM lparam) override {
+ void OnSettingsChange(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
sky 2015/04/28 23:35:04 Naming these functions OnFooChange implies they ar
robliao 2015/04/29 00:25:43 Done.
if (message == WM_SETTINGCHANGE) {
params_.reset();
- gfx::SingletonHwnd::GetInstance()->RemoveObserver(this);
+ singleton_hwnd_observer_.reset(nullptr);
}
}
scoped_ptr<FontRenderParams> params_;
+ scoped_ptr<SingletonHwndObserver> singleton_hwnd_observer_;
DISALLOW_COPY_AND_ASSIGN(CachedFontRenderParams);
};
« no previous file with comments | « ui/gfx/BUILD.gn ('k') | ui/gfx/gfx.gyp » ('j') | ui/gfx/win/singleton_hwnd_observer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698