summaryrefslogtreecommitdiffstats
path: root/chrome/common/scoped_co_mem.h
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-25 12:18:51 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-25 12:18:51 +0000
commitdcd5776135982012e99ea7b7030b3412f61235c7 (patch)
tree2853a787d4c09e4a8417a0c74a312917a05dce08 /chrome/common/scoped_co_mem.h
parent05ba8b8dd541632486513221795d45e4fe71b47f (diff)
downloadchromium_src-dcd5776135982012e99ea7b7030b3412f61235c7.zip
chromium_src-dcd5776135982012e99ea7b7030b3412f61235c7.tar.gz
chromium_src-dcd5776135982012e99ea7b7030b3412f61235c7.tar.bz2
Reland "Move app/win/* files to base/win/, ui/base/win and chrome/common/ directories."
The issue with the r90464 was that in the win shared build we build dlls and we need BASE_API to export functions and symbols. BUG=72317 TEST=None TBR=rsesek@chromium.org,brettw@chromium.org Review URL: http://codereview.chromium.org/7263009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@90505 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/scoped_co_mem.h')
-rw-r--r--chrome/common/scoped_co_mem.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/chrome/common/scoped_co_mem.h b/chrome/common/scoped_co_mem.h
new file mode 100644
index 0000000..33d6cc4
--- /dev/null
+++ b/chrome/common/scoped_co_mem.h
@@ -0,0 +1,49 @@
+// Copyright (c) 2011 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.
+
+#ifndef CHROME_COMMON_SCOPED_CO_MEM_H_
+#define CHROME_COMMON_SCOPED_CO_MEM_H_
+#pragma once
+
+#include <objbase.h>
+
+#include "base/basictypes.h"
+
+namespace chrome {
+namespace common {
+
+// Simple scoped memory releaser class for COM allocated memory.
+// Example:
+// chrome::common::ScopedCoMem<ITEMIDLIST> file_item;
+// SHGetSomeInfo(&file_item, ...);
+// ...
+// return; <-- memory released
+template<typename T>
+class ScopedCoMem {
+ public:
+ explicit ScopedCoMem() : mem_ptr_(NULL) {}
+
+ ~ScopedCoMem() {
+ if (mem_ptr_)
+ CoTaskMemFree(mem_ptr_);
+ }
+
+ T** operator&() { // NOLINT
+ return &mem_ptr_;
+ }
+
+ operator T*() {
+ return mem_ptr_;
+ }
+
+ private:
+ T* mem_ptr_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedCoMem);
+};
+
+} // namespace common
+} // namespace chrome
+
+#endif // CHROME_COMMON_SCOPED_CO_MEM_H_