summaryrefslogtreecommitdiffstats
path: root/app/win/scoped_prop.cc
blob: 8d48bc52bb1b5b39c6c0becd7f180d99831a5c42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Copyright (c) 2010 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 "app/win/scoped_prop.h"

namespace app {

namespace win {

ScopedProp::ScopedProp(HWND hwnd, const std::wstring& key, HANDLE data)
    : hwnd_(hwnd),
      key_(key) {
  BOOL result = SetProp(hwnd, key.c_str(), data);
  // Failure to set a propery on a window is typically fatal. It means someone
  // is going to ask for the property and get NULL. So, rather than crash later
  // on when someone expects a non-NULL value we crash here in hopes of
  // diagnosing the failure.
  CHECK(result) << ::GetLastError();
}

ScopedProp::~ScopedProp() {
  DCHECK(IsWindow(hwnd_));
  RemoveProp(hwnd_, key_.c_str());
}


}  // namespace win

}  // namespace app