Don't preload rarely seen large images
[chromium-blink-merge.git] / components / browser_watcher / endsession_watcher_window_win.cc
blobddf9932788f0705591c5e8bc9a512e0f06a9c3a2
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.
5 #include "components/browser_watcher/endsession_watcher_window_win.h"
7 #include "base/logging.h"
8 #include "base/profiler/scoped_tracker.h"
9 #include "base/win/wrapped_window_proc.h"
11 namespace browser_watcher {
13 namespace {
15 const wchar_t kWindowClassName[] = L"Chrome_BrowserWatcherWindow";
17 } // namespace
19 EndSessionWatcherWindow::EndSessionWatcherWindow(
20 const EndSessionMessageCallback& on_end_session_message) :
21 on_end_session_message_(on_end_session_message) {
22 WNDCLASSEX window_class = {0};
23 base::win::InitializeWindowClass(
24 kWindowClassName,
25 &base::win::WrappedWindowProc<EndSessionWatcherWindow::WndProcThunk>,
26 0, 0, 0, NULL, NULL, NULL, NULL, NULL,
27 &window_class);
28 instance_ = window_class.hInstance;
29 ATOM clazz = ::RegisterClassEx(&window_class);
30 DCHECK(clazz);
32 // TODO(siggi): will a message window do here?
33 window_ = ::CreateWindow(kWindowClassName,
34 0, 0, 0, 0, 0, 0, 0, 0, instance_, 0);
35 ::SetWindowLongPtr(window_, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
36 DCHECK_EQ(::GetWindowLongPtr(window_, GWLP_USERDATA),
37 reinterpret_cast<LONG_PTR>(this));
40 EndSessionWatcherWindow::~EndSessionWatcherWindow() {
41 if (window_) {
42 ::DestroyWindow(window_);
43 ::UnregisterClass(kWindowClassName, instance_);
47 LRESULT EndSessionWatcherWindow::OnEndSessionMessage(UINT message,
48 WPARAM wparam,
49 LPARAM lparam) {
50 on_end_session_message_.Run(message, lparam);
51 return 0;
54 LRESULT CALLBACK EndSessionWatcherWindow::WndProcThunk(HWND hwnd,
55 UINT message,
56 WPARAM wparam,
57 LPARAM lparam) {
58 EndSessionWatcherWindow* msg_wnd =
59 reinterpret_cast<EndSessionWatcherWindow*>(
60 ::GetWindowLongPtr(hwnd, GWLP_USERDATA));
61 if (msg_wnd)
62 return msg_wnd->WndProc(hwnd, message, wparam, lparam);
64 return ::DefWindowProc(hwnd, message, wparam, lparam);
67 LRESULT EndSessionWatcherWindow::WndProc(HWND hwnd,
68 UINT message,
69 WPARAM wparam,
70 LPARAM lparam) {
71 switch (message) {
72 case WM_ENDSESSION:
73 case WM_QUERYENDSESSION:
74 return OnEndSessionMessage(message, wparam, lparam);
75 default:
76 break;
79 return ::DefWindowProc(hwnd, message, wparam, lparam);
82 } // namespace browser_watcher