OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Crashpad Authors. All rights reserved. |
| 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at |
| 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. |
| 14 |
| 15 #ifndef CRASHPAD_UTIL_WIN_SESSION_END_WATCHER_H_ |
| 16 #define CRASHPAD_UTIL_WIN_SESSION_END_WATCHER_H_ |
| 17 |
| 18 #include <windows.h> |
| 19 |
| 20 #include "base/macros.h" |
| 21 #include "util/thread/thread.h" |
| 22 #include "util/win/scoped_handle.h" |
| 23 |
| 24 namespace crashpad { |
| 25 |
| 26 //! \brief Creates a hidden window and waits for a `WM_ENDSESSION` message, |
| 27 //! indicating that the session is ending and the application should |
| 28 //! terminate. |
| 29 //! |
| 30 //! A dedicated thread will be created to run the `GetMessage()`-based message |
| 31 //! loop required to monitor for this message. |
| 32 //! |
| 33 //! Users should subclass this class and receive notifications by implementing |
| 34 //! the SessionEndWatcherEvent() method. |
| 35 class SessionEndWatcher : public Thread { |
| 36 public: |
| 37 SessionEndWatcher(); |
| 38 |
| 39 //! \note The destructor waits for the thread that runs the message loop to |
| 40 //! terminate. |
| 41 ~SessionEndWatcher() override; |
| 42 |
| 43 protected: |
| 44 // Exposed for testing. |
| 45 HWND GetWindow() const { return window_; } |
| 46 |
| 47 // Exposed for testing. Blocks until window_ has been created. May be called |
| 48 // multiple times if necessary. |
| 49 void WaitForStart(); |
| 50 |
| 51 // Exposed for testing. Blocks until the message loop ends. May be called |
| 52 // multiple times if necessary. |
| 53 void WaitForStop(); |
| 54 |
| 55 private: |
| 56 // Thread: |
| 57 void ThreadMain() override; |
| 58 |
| 59 static LRESULT CALLBACK WindowProc(HWND window, |
| 60 UINT message, |
| 61 WPARAM w_param, |
| 62 LPARAM l_param); |
| 63 |
| 64 //! \brief A `WM_ENDSESSION` message was received and it indicates that the |
| 65 //! user session will be ending imminently. |
| 66 //! |
| 67 //! This method is called on the thread that runs the message loop. |
| 68 virtual void SessionEnding() = 0; |
| 69 |
| 70 HWND window_; // Conceptually strong, but ownership managed in ThreadMain() |
| 71 ScopedKernelHANDLE started_; |
| 72 ScopedKernelHANDLE stopped_; |
| 73 |
| 74 DISALLOW_COPY_AND_ASSIGN(SessionEndWatcher); |
| 75 }; |
| 76 |
| 77 } // namespace crashpad |
| 78 |
| 79 #endif // CRASHPAD_UTIL_WIN_SESSION_END_WATCHER_H_ |
OLD | NEW |