OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef APP_WIN_SCOPED_PROP_H_ | 5 #ifndef APP_WIN_SCOPED_PROP_H_ |
6 #define APP_WIN_SCOPED_PROP_H_ | 6 #define APP_WIN_SCOPED_PROP_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <windows.h> | 9 #include <windows.h> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 | 12 |
13 namespace app { | 13 namespace app { |
14 namespace win { | 14 namespace win { |
15 | 15 |
16 // ScopedProp is a wrapper around SetProp. Use ScopedProp rather than SetProp as | 16 // ScopedProp is a wrapper around SetProp. Use ScopedProp rather than SetProp as |
17 // it handles errors conditions for you and forces you to think about | 17 // it handles errors conditions for you and forces you to think about |
18 // cleanup. ScopedProp must be destroyed before the window is destroyed, else | 18 // cleanup. ScopedProp must be destroyed before the window is destroyed, else |
19 // you're going to leak a property, which could lead to failure to set a | 19 // you're going to leak a property, which could lead to failure to set a |
20 // property later on. | 20 // property later on. |
| 21 // |
| 22 // *WARNING* |
| 23 // SetProp is very fragile. SetProp makes use of a finite chunk of memory that |
| 24 // is very easy to exhaust. Unless you need to share a property across process |
| 25 // boundaries you should instead use ViewProp, which does not cause leaks at the |
| 26 // window manager. |
21 class ScopedProp { | 27 class ScopedProp { |
22 public: | 28 public: |
23 // Registers the key value pair for the specified window. ScopedProp does not | 29 // Registers the key value pair for the specified window. ScopedProp does not |
24 // maintain the value, just the key/value pair. | 30 // maintain the value, just the key/value pair. |
25 ScopedProp(HWND hwnd, const std::wstring& key, HANDLE data); | 31 ScopedProp(HWND hwnd, const std::wstring& key, HANDLE data); |
26 ~ScopedProp(); | 32 ~ScopedProp(); |
27 | 33 |
28 const std::wstring& key() const { return key_; } | 34 const std::wstring& key() const { return key_; } |
29 | 35 |
30 private: | 36 private: |
31 HWND hwnd_; | 37 HWND hwnd_; |
32 const std::wstring key_; | 38 const std::wstring key_; |
33 | 39 |
34 DISALLOW_COPY_AND_ASSIGN(ScopedProp); | 40 DISALLOW_COPY_AND_ASSIGN(ScopedProp); |
35 }; | 41 }; |
36 | 42 |
37 } // namespace win | 43 } // namespace win |
38 } // namespace app | 44 } // namespace app |
39 | 45 |
40 #endif // APP_WIN_SCOPED_PROP_H_ | 46 #endif // APP_WIN_SCOPED_PROP_H_ |
OLD | NEW |