| 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. | |
| 27 class ScopedProp { | 21 class ScopedProp { |
| 28 public: | 22 public: |
| 29 // Registers the key value pair for the specified window. ScopedProp does not | 23 // Registers the key value pair for the specified window. ScopedProp does not |
| 30 // maintain the value, just the key/value pair. | 24 // maintain the value, just the key/value pair. |
| 31 ScopedProp(HWND hwnd, const std::wstring& key, HANDLE data); | 25 ScopedProp(HWND hwnd, const std::wstring& key, HANDLE data); |
| 32 ~ScopedProp(); | 26 ~ScopedProp(); |
| 33 | 27 |
| 34 const std::wstring& key() const { return key_; } | 28 const std::wstring& key() const { return key_; } |
| 35 | 29 |
| 36 private: | 30 private: |
| 37 HWND hwnd_; | 31 HWND hwnd_; |
| 38 const std::wstring key_; | 32 const std::wstring key_; |
| 39 | 33 |
| 40 DISALLOW_COPY_AND_ASSIGN(ScopedProp); | 34 DISALLOW_COPY_AND_ASSIGN(ScopedProp); |
| 41 }; | 35 }; |
| 42 | 36 |
| 43 } // namespace win | 37 } // namespace win |
| 44 } // namespace app | 38 } // namespace app |
| 45 | 39 |
| 46 #endif // APP_WIN_SCOPED_PROP_H_ | 40 #endif // APP_WIN_SCOPED_PROP_H_ |
| OLD | NEW |