| OLD | NEW |
| 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 #pragma comment(lib, "wtsapi32.lib") | 8 #pragma comment(lib, "wtsapi32.lib") |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
| 17 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 18 #include "base/task_runner.h" | 18 #include "base/task_runner.h" |
| 19 #include "ui/gfx/win/singleton_hwnd.h" | 19 #include "ui/gfx/win/singleton_hwnd.h" |
| 20 #include "ui/gfx/win/singleton_hwnd_observer.h" | 20 #include "ui/gfx/win/singleton_hwnd_observer.h" |
| 21 #include "ui/views/views_delegate.h" | 21 #include "ui/views/views_delegate.h" |
| 22 | 22 |
| 23 namespace views { | 23 namespace views { |
| 24 | 24 |
| 25 class WindowsSessionChangeObserver::WtsRegistrationNotificationManager { | 25 class WindowsSessionChangeObserver::WtsRegistrationNotificationManager { |
| 26 public: | 26 public: |
| 27 static WtsRegistrationNotificationManager* GetInstance() { | 27 static WtsRegistrationNotificationManager* GetInstance() { |
| 28 return Singleton<WtsRegistrationNotificationManager>::get(); | 28 return base::Singleton<WtsRegistrationNotificationManager>::get(); |
| 29 } | 29 } |
| 30 | 30 |
| 31 WtsRegistrationNotificationManager() { | 31 WtsRegistrationNotificationManager() { |
| 32 AddSingletonHwndObserver(); | 32 AddSingletonHwndObserver(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 ~WtsRegistrationNotificationManager() { | 35 ~WtsRegistrationNotificationManager() { |
| 36 RemoveSingletonHwndObserver(); | 36 RemoveSingletonHwndObserver(); |
| 37 } | 37 } |
| 38 | 38 |
| 39 void AddObserver(WindowsSessionChangeObserver* observer) { | 39 void AddObserver(WindowsSessionChangeObserver* observer) { |
| 40 DCHECK(singleton_hwnd_observer_); | 40 DCHECK(singleton_hwnd_observer_); |
| 41 observer_list_.AddObserver(observer); | 41 observer_list_.AddObserver(observer); |
| 42 } | 42 } |
| 43 | 43 |
| 44 void RemoveObserver(WindowsSessionChangeObserver* observer) { | 44 void RemoveObserver(WindowsSessionChangeObserver* observer) { |
| 45 observer_list_.RemoveObserver(observer); | 45 observer_list_.RemoveObserver(observer); |
| 46 } | 46 } |
| 47 | 47 |
| 48 private: | 48 private: |
| 49 friend struct DefaultSingletonTraits<WtsRegistrationNotificationManager>; | 49 friend struct base::DefaultSingletonTraits< |
| 50 WtsRegistrationNotificationManager>; |
| 50 | 51 |
| 51 void OnWndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { | 52 void OnWndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { |
| 52 switch (message) { | 53 switch (message) { |
| 53 case WM_WTSSESSION_CHANGE: | 54 case WM_WTSSESSION_CHANGE: |
| 54 FOR_EACH_OBSERVER(WindowsSessionChangeObserver, | 55 FOR_EACH_OBSERVER(WindowsSessionChangeObserver, |
| 55 observer_list_, | 56 observer_list_, |
| 56 OnSessionChange(wparam)); | 57 OnSessionChange(wparam)); |
| 57 break; | 58 break; |
| 58 case WM_DESTROY: | 59 case WM_DESTROY: |
| 59 RemoveSingletonHwndObserver(); | 60 RemoveSingletonHwndObserver(); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 } | 122 } |
| 122 | 123 |
| 123 void WindowsSessionChangeObserver::ClearCallback() { | 124 void WindowsSessionChangeObserver::ClearCallback() { |
| 124 if (!callback_.is_null()) { | 125 if (!callback_.is_null()) { |
| 125 callback_.Reset(); | 126 callback_.Reset(); |
| 126 WtsRegistrationNotificationManager::GetInstance()->RemoveObserver(this); | 127 WtsRegistrationNotificationManager::GetInstance()->RemoveObserver(this); |
| 127 } | 128 } |
| 128 } | 129 } |
| 129 | 130 |
| 130 } // namespace views | 131 } // namespace views |
| OLD | NEW |