| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef APP_WIN_SCOPED_CO_MEM_H_ | |
| 6 #define APP_WIN_SCOPED_CO_MEM_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <objbase.h> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 | |
| 13 namespace app { | |
| 14 namespace win { | |
| 15 | |
| 16 // Simple scoped memory releaser class for COM allocated memory. | |
| 17 // Example: | |
| 18 // app::win::ScopedCoMem<ITEMIDLIST> file_item; | |
| 19 // SHGetSomeInfo(&file_item, ...); | |
| 20 // ... | |
| 21 // return; <-- memory released | |
| 22 template<typename T> | |
| 23 class ScopedCoMem { | |
| 24 public: | |
| 25 explicit ScopedCoMem() : mem_ptr_(NULL) {} | |
| 26 | |
| 27 ~ScopedCoMem() { | |
| 28 if (mem_ptr_) | |
| 29 CoTaskMemFree(mem_ptr_); | |
| 30 } | |
| 31 | |
| 32 T** operator&() { // NOLINT | |
| 33 return &mem_ptr_; | |
| 34 } | |
| 35 | |
| 36 operator T*() { | |
| 37 return mem_ptr_; | |
| 38 } | |
| 39 | |
| 40 private: | |
| 41 T* mem_ptr_; | |
| 42 | |
| 43 DISALLOW_COPY_AND_ASSIGN(ScopedCoMem); | |
| 44 }; | |
| 45 | |
| 46 } // namespace win | |
| 47 } // namespace app | |
| 48 | |
| 49 #endif // APP_WIN_SCOPED_CO_MEM_H_ | |
| OLD | NEW |