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/views/win/windows_session_change_observer.cc

Issue 2418983002: ui/views: convert usage of FOR_EACH_OBSERVER macro (Closed)
Patch Set: Created 4 years, 2 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/views/widget/widget.cc ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/views/win/windows_session_change_observer.h" 5 #include "ui/views/win/windows_session_change_observer.h"
6 6
7 #include <wtsapi32.h> 7 #include <wtsapi32.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 observer_list_.RemoveObserver(observer); 46 observer_list_.RemoveObserver(observer);
47 } 47 }
48 48
49 private: 49 private:
50 friend struct base::DefaultSingletonTraits< 50 friend struct base::DefaultSingletonTraits<
51 WtsRegistrationNotificationManager>; 51 WtsRegistrationNotificationManager>;
52 52
53 void OnWndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { 53 void OnWndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
54 switch (message) { 54 switch (message) {
55 case WM_WTSSESSION_CHANGE: 55 case WM_WTSSESSION_CHANGE:
56 FOR_EACH_OBSERVER(WindowsSessionChangeObserver, 56 for (WindowsSessionChangeObserver& observer : observer_list_)
57 observer_list_, 57 observer.OnSessionChange(wparam);
58 OnSessionChange(wparam));
59 break; 58 break;
60 case WM_DESTROY: 59 case WM_DESTROY:
61 RemoveSingletonHwndObserver(); 60 RemoveSingletonHwndObserver();
62 break; 61 break;
63 } 62 }
64 } 63 }
65 64
66 void AddSingletonHwndObserver() { 65 void AddSingletonHwndObserver() {
67 DCHECK(!singleton_hwnd_observer_); 66 DCHECK(!singleton_hwnd_observer_);
68 singleton_hwnd_observer_.reset(new gfx::SingletonHwndObserver( 67 singleton_hwnd_observer_.reset(new gfx::SingletonHwndObserver(
(...skipping 20 matching lines...) Expand all
89 return; 88 return;
90 89
91 singleton_hwnd_observer_.reset(nullptr); 90 singleton_hwnd_observer_.reset(nullptr);
92 // There is no race condition between this code and the worker thread. 91 // There is no race condition between this code and the worker thread.
93 // RemoveSingletonHwndObserver is only called from two places: 92 // RemoveSingletonHwndObserver is only called from two places:
94 // 1) Destruction due to Singleton Destruction. 93 // 1) Destruction due to Singleton Destruction.
95 // 2) WM_DESTROY fired by SingletonHwnd. 94 // 2) WM_DESTROY fired by SingletonHwnd.
96 // Under both cases we are in shutdown, which means no other worker threads 95 // Under both cases we are in shutdown, which means no other worker threads
97 // can be running. 96 // can be running.
98 WTSUnRegisterSessionNotification(gfx::SingletonHwnd::GetInstance()->hwnd()); 97 WTSUnRegisterSessionNotification(gfx::SingletonHwnd::GetInstance()->hwnd());
99 FOR_EACH_OBSERVER(WindowsSessionChangeObserver, 98 for (WindowsSessionChangeObserver& observer : observer_list_)
100 observer_list_, 99 observer.ClearCallback();
101 ClearCallback());
102 } 100 }
103 101
104 base::ObserverList<WindowsSessionChangeObserver, true> observer_list_; 102 base::ObserverList<WindowsSessionChangeObserver, true> observer_list_;
105 std::unique_ptr<gfx::SingletonHwndObserver> singleton_hwnd_observer_; 103 std::unique_ptr<gfx::SingletonHwndObserver> singleton_hwnd_observer_;
106 104
107 DISALLOW_COPY_AND_ASSIGN(WtsRegistrationNotificationManager); 105 DISALLOW_COPY_AND_ASSIGN(WtsRegistrationNotificationManager);
108 }; 106 };
109 107
110 WindowsSessionChangeObserver::WindowsSessionChangeObserver( 108 WindowsSessionChangeObserver::WindowsSessionChangeObserver(
111 const WtsCallback& callback) 109 const WtsCallback& callback)
(...skipping 11 matching lines...) Expand all
123 } 121 }
124 122
125 void WindowsSessionChangeObserver::ClearCallback() { 123 void WindowsSessionChangeObserver::ClearCallback() {
126 if (!callback_.is_null()) { 124 if (!callback_.is_null()) {
127 callback_.Reset(); 125 callback_.Reset();
128 WtsRegistrationNotificationManager::GetInstance()->RemoveObserver(this); 126 WtsRegistrationNotificationManager::GetInstance()->RemoveObserver(this);
129 } 127 }
130 } 128 }
131 129
132 } // namespace views 130 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/widget.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698