Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Unified Diff: components/browser_watcher/endsession_watcher_window_win.cc

Issue 843113002: EndSessionWatcherWindow implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge ToT. Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
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..a4847024015c86c99ade668331e091934ccef4aa
--- /dev/null
+++ b/components/browser_watcher/endsession_watcher_window_win.cc
@@ -0,0 +1,78 @@
+// 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"
+
+#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(
+ const EndSessionCallback& on_end_session) :
+ on_end_session_(on_end_session) {
+ WNDCLASSEX window_class = {0};
+ 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));
+ DCHECK_EQ(::GetWindowLongPtr(window_, GWLP_USERDATA),
+ reinterpret_cast<LONG_PTR>(this));
+}
+
+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);
+}
+
+} // namespace browser_watcher

Powered by Google App Engine
This is Rietveld 408576698