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

Side by Side Diff: ui/gfx/win/singleton_hwnd.cc

Issue 480503002: [Win] Battery Status API: use SingletonHwnd for notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added thread checker Created 6 years, 3 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
« no previous file with comments | « ui/gfx/win/singleton_hwnd.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/gfx/win/singleton_hwnd.h" 5 #include "ui/gfx/win/singleton_hwnd.h"
6 6
7 #include "base/memory/singleton.h" 7 #include "base/memory/singleton.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 9
10 namespace gfx { 10 namespace gfx {
11 11
12 // static 12 // static
13 SingletonHwnd* SingletonHwnd::GetInstance() { 13 SingletonHwnd* SingletonHwnd::GetInstance() {
14 return Singleton<SingletonHwnd>::get(); 14 return Singleton<SingletonHwnd>::get();
15 } 15 }
16 16
17 void SingletonHwnd::AddObserver(Observer* observer) { 17 void SingletonHwnd::AddObserver(Observer* observer) {
18 DCHECK(thread_checker_.CalledOnValidThread());
18 observer_list_.AddObserver(observer); 19 observer_list_.AddObserver(observer);
19 } 20 }
20 21
21 void SingletonHwnd::RemoveObserver(Observer* observer) { 22 void SingletonHwnd::RemoveObserver(Observer* observer) {
23 DCHECK(thread_checker_.CalledOnValidThread());
22 if (!hwnd()) 24 if (!hwnd())
23 return; 25 return;
24 observer_list_.RemoveObserver(observer); 26 observer_list_.RemoveObserver(observer);
25 } 27 }
26 28
27 BOOL SingletonHwnd::ProcessWindowMessage(HWND window, 29 BOOL SingletonHwnd::ProcessWindowMessage(HWND window,
28 UINT message, 30 UINT message,
29 WPARAM wparam, 31 WPARAM wparam,
30 LPARAM lparam, 32 LPARAM lparam,
31 LRESULT& result, 33 LRESULT& result,
32 DWORD msg_map_id) { 34 DWORD msg_map_id) {
33 FOR_EACH_OBSERVER(Observer, 35 FOR_EACH_OBSERVER(Observer,
34 observer_list_, 36 observer_list_,
35 OnWndProc(window, message, wparam, lparam)); 37 OnWndProc(window, message, wparam, lparam));
36 return false; 38 return false;
37 } 39 }
38 40
39 SingletonHwnd::SingletonHwnd() { 41 SingletonHwnd::SingletonHwnd() {
42 DCHECK(thread_checker_.CalledOnValidThread());
40 if (!base::MessageLoopForUI::IsCurrent()) { 43 if (!base::MessageLoopForUI::IsCurrent()) {
41 // Creating this window in (e.g.) a renderer inhibits shutdown on 44 // Creating this window in (e.g.) a renderer inhibits shutdown on
42 // Windows. See http://crbug.com/230122 and http://crbug.com/236039. 45 // Windows. See http://crbug.com/230122 and http://crbug.com/236039.
43 DLOG(ERROR) << "Cannot create windows on non-UI thread!"; 46 DLOG(FATAL) << "Cannot create windows on non-UI thread!";
44 return; 47 return;
45 } 48 }
46 WindowImpl::Init(NULL, Rect()); 49 WindowImpl::Init(NULL, Rect());
47 } 50 }
48 51
49 SingletonHwnd::~SingletonHwnd() { 52 SingletonHwnd::~SingletonHwnd() {
50 } 53 }
51 54
52 } // namespace gfx 55 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/win/singleton_hwnd.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698