Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 #include "components/browser_watcher/endsession_watcher_window_win.h" | |
|
erikwright (departed)
2015/01/13 21:01:28
blank line before
Sigurður Ásgeirsson
2015/01/13 22:41:56
Done.
| |
| 5 | |
| 6 #include "base/logging.h" | |
| 7 #include "base/win/wrapped_window_proc.h" | |
| 8 | |
| 9 namespace browser_watcher { | |
| 10 | |
| 11 namespace { | |
| 12 | |
| 13 const wchar_t kWindowClassName[] = L"Chrome_BrowserWatcherWindow"; | |
| 14 | |
| 15 } // namespace | |
| 16 | |
| 17 EndSessionWatcherWindow::EndSessionWatcherWindow( | |
| 18 EndSessionCallback on_end_session) : on_end_session_(on_end_session) { | |
| 19 WNDCLASSEX window_class; | |
|
erikwright (departed)
2015/01/13 21:01:28
= {0}
Sigurður Ásgeirsson
2015/01/13 22:41:56
Done.
| |
| 20 base::win::InitializeWindowClass( | |
| 21 kWindowClassName, | |
| 22 &base::win::WrappedWindowProc<EndSessionWatcherWindow::WndProcThunk>, | |
| 23 0, 0, 0, NULL, NULL, NULL, NULL, NULL, | |
| 24 &window_class); | |
| 25 instance_ = window_class.hInstance; | |
| 26 ATOM clazz = ::RegisterClassEx(&window_class); | |
| 27 DCHECK(clazz); | |
| 28 | |
| 29 // TODO(siggi): will a message window do here? | |
| 30 window_ = ::CreateWindow(kWindowClassName, | |
| 31 0, 0, 0, 0, 0, 0, 0, 0, instance_, 0); | |
| 32 ::SetWindowLongPtr(window_, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this)); | |
|
erikwright (departed)
2015/01/13 21:01:28
Is it crazy to check for an error?
Apparently it
Sigurður Ásgeirsson
2015/01/13 22:41:56
Not crazy - maybe a little ... deranged :).
Added
| |
| 33 } | |
| 34 | |
| 35 EndSessionWatcherWindow::~EndSessionWatcherWindow() { | |
| 36 if (window_) { | |
| 37 ::DestroyWindow(window_); | |
| 38 ::UnregisterClass(kWindowClassName, instance_); | |
| 39 } | |
| 40 } | |
| 41 | |
| 42 LRESULT EndSessionWatcherWindow::OnEndSession(WPARAM wparam, LPARAM lparam) { | |
| 43 on_end_session_.Run(lparam); | |
| 44 return 0; | |
| 45 } | |
| 46 | |
| 47 LRESULT CALLBACK EndSessionWatcherWindow::WndProcThunk(HWND hwnd, | |
| 48 UINT message, | |
| 49 WPARAM wparam, | |
| 50 LPARAM lparam) { | |
| 51 EndSessionWatcherWindow* msg_wnd = | |
| 52 reinterpret_cast<EndSessionWatcherWindow*>( | |
| 53 ::GetWindowLongPtr(hwnd, GWLP_USERDATA)); | |
| 54 if (msg_wnd) | |
| 55 return msg_wnd->WndProc(hwnd, message, wparam, lparam); | |
| 56 | |
| 57 return ::DefWindowProc(hwnd, message, wparam, lparam); | |
| 58 } | |
| 59 | |
| 60 LRESULT EndSessionWatcherWindow::WndProc(HWND hwnd, | |
| 61 UINT message, | |
| 62 WPARAM wparam, | |
| 63 LPARAM lparam) { | |
| 64 switch (message) { | |
| 65 case WM_ENDSESSION: | |
| 66 return OnEndSession(wparam, lparam); | |
| 67 default: | |
| 68 break; | |
| 69 } | |
| 70 | |
| 71 return ::DefWindowProc(hwnd, message, wparam, lparam); | |
| 72 } | |
| 73 | |
|
erikwright (departed)
2015/01/13 21:01:28
only one blank
Sigurður Ásgeirsson
2015/01/13 22:41:56
Done.
| |
| 74 | |
| 75 } // namespace browser_watcher | |
| OLD | NEW |