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

Side by Side Diff: content/browser/time_zone_monitor_win.cc

Issue 1092183005: Fix Up SingletonHwnd Observer Lifetime Issues (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Allow null SingletonHwnd Hwnd Created 5 years, 7 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/browser/time_zone_monitor.h" 5 #include "content/browser/time_zone_monitor.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "ui/gfx/win/singleton_hwnd.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "ui/gfx/win/singleton_hwnd_observer.h"
11 14
12 namespace content { 15 namespace content {
13 16
14 class TimeZoneMonitorWin : public TimeZoneMonitor, 17 class TimeZoneMonitorWin : public TimeZoneMonitor {
15 public gfx::SingletonHwnd::Observer {
16 public: 18 public:
17 TimeZoneMonitorWin() : TimeZoneMonitor() { 19 TimeZoneMonitorWin()
18 gfx::SingletonHwnd::GetInstance()->AddObserver(this); 20 : TimeZoneMonitor(),
19 } 21 singleton_hwnd_observer_(
22 new gfx::SingletonHwndObserver(base::Bind(
23 &TimeZoneMonitorWin::OnWndProc, base::Unretained(this)))) {}
20 24
21 ~TimeZoneMonitorWin() override { 25 ~TimeZoneMonitorWin() override {}
22 gfx::SingletonHwnd::GetInstance()->RemoveObserver(this);
23 }
24 26
25 // gfx::SingletonHwnd::Observer implementation. 27 private:
26 void OnWndProc(HWND hwnd, 28 void OnWndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
27 UINT message,
28 WPARAM wparam,
29 LPARAM lparam) override {
30 if (message != WM_TIMECHANGE) { 29 if (message != WM_TIMECHANGE) {
31 return; 30 return;
32 } 31 }
33 32
34 NotifyRenderers(); 33 NotifyRenderers();
35 } 34 }
36 35
37 private: 36 scoped_ptr<gfx::SingletonHwndObserver> singleton_hwnd_observer_;
37
38 DISALLOW_COPY_AND_ASSIGN(TimeZoneMonitorWin); 38 DISALLOW_COPY_AND_ASSIGN(TimeZoneMonitorWin);
39 }; 39 };
40 40
41 // static 41 // static
42 scoped_ptr<TimeZoneMonitor> TimeZoneMonitor::Create() { 42 scoped_ptr<TimeZoneMonitor> TimeZoneMonitor::Create() {
43 return scoped_ptr<TimeZoneMonitor>(new TimeZoneMonitorWin()); 43 return scoped_ptr<TimeZoneMonitor>(new TimeZoneMonitorWin());
44 } 44 }
45 45
46 } // namespace content 46 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698