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