Chromium Code Reviews| Index: components/browser_watcher/endsession_watcher_window_win.cc |
| diff --git a/components/browser_watcher/endsession_watcher_window_win.cc b/components/browser_watcher/endsession_watcher_window_win.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1547710e5aef3a733572adaedaa3c46c161bfb03 |
| --- /dev/null |
| +++ b/components/browser_watcher/endsession_watcher_window_win.cc |
| @@ -0,0 +1,75 @@ |
| +// Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| +#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.
|
| + |
| +#include "base/logging.h" |
| +#include "base/win/wrapped_window_proc.h" |
| + |
| +namespace browser_watcher { |
| + |
| +namespace { |
| + |
| +const wchar_t kWindowClassName[] = L"Chrome_BrowserWatcherWindow"; |
| + |
| +} // namespace |
| + |
| +EndSessionWatcherWindow::EndSessionWatcherWindow( |
| + EndSessionCallback on_end_session) : on_end_session_(on_end_session) { |
| + WNDCLASSEX window_class; |
|
erikwright (departed)
2015/01/13 21:01:28
= {0}
Sigurður Ásgeirsson
2015/01/13 22:41:56
Done.
|
| + base::win::InitializeWindowClass( |
| + kWindowClassName, |
| + &base::win::WrappedWindowProc<EndSessionWatcherWindow::WndProcThunk>, |
| + 0, 0, 0, NULL, NULL, NULL, NULL, NULL, |
| + &window_class); |
| + instance_ = window_class.hInstance; |
| + ATOM clazz = ::RegisterClassEx(&window_class); |
| + DCHECK(clazz); |
| + |
| + // TODO(siggi): will a message window do here? |
| + window_ = ::CreateWindow(kWindowClassName, |
| + 0, 0, 0, 0, 0, 0, 0, 0, instance_, 0); |
| + ::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
|
| +} |
| + |
| +EndSessionWatcherWindow::~EndSessionWatcherWindow() { |
| + if (window_) { |
| + ::DestroyWindow(window_); |
| + ::UnregisterClass(kWindowClassName, instance_); |
| + } |
| +} |
| + |
| +LRESULT EndSessionWatcherWindow::OnEndSession(WPARAM wparam, LPARAM lparam) { |
| + on_end_session_.Run(lparam); |
| + return 0; |
| +} |
| + |
| +LRESULT CALLBACK EndSessionWatcherWindow::WndProcThunk(HWND hwnd, |
| + UINT message, |
| + WPARAM wparam, |
| + LPARAM lparam) { |
| + EndSessionWatcherWindow* msg_wnd = |
| + reinterpret_cast<EndSessionWatcherWindow*>( |
| + ::GetWindowLongPtr(hwnd, GWLP_USERDATA)); |
| + if (msg_wnd) |
| + return msg_wnd->WndProc(hwnd, message, wparam, lparam); |
| + |
| + return ::DefWindowProc(hwnd, message, wparam, lparam); |
| +} |
| + |
| +LRESULT EndSessionWatcherWindow::WndProc(HWND hwnd, |
| + UINT message, |
| + WPARAM wparam, |
| + LPARAM lparam) { |
| + switch (message) { |
| + case WM_ENDSESSION: |
| + return OnEndSession(wparam, lparam); |
| + default: |
| + break; |
| + } |
| + |
| + return ::DefWindowProc(hwnd, message, wparam, lparam); |
| +} |
| + |
|
erikwright (departed)
2015/01/13 21:01:28
only one blank
Sigurður Ásgeirsson
2015/01/13 22:41:56
Done.
|
| + |
| +} // namespace browser_watcher |