From 76602ffe79164dfcc39b001e15d9950418bb7998 Mon Sep 17 00:00:00 2001 From: "gab@chromium.org" Date: Sun, 3 Feb 2013 07:29:56 +0000 Subject: Replace all PROPVARIANTs by base::win::ScopedPropVariant across the entire codebase. Follow-up to crrev.com/177951. Fixes a memory leak in ie_importer.cc. BUG=None Review URL: https://chromiumcodereview.appspot.com/12092077 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@180297 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/jumplist_win.cc | 47 +++++++++--------------------------------- 1 file changed, 10 insertions(+), 37 deletions(-) (limited to 'chrome/browser/jumplist_win.cc') diff --git a/chrome/browser/jumplist_win.cc b/chrome/browser/jumplist_win.cc index 660c9b6..97891f9 100644 --- a/chrome/browser/jumplist_win.cc +++ b/chrome/browser/jumplist_win.cc @@ -21,6 +21,7 @@ #include "base/threading/thread.h" #include "base/utf_string_conversions.h" #include "base/win/scoped_comptr.h" +#include "base/win/scoped_propvariant.h" #include "base/win/windows_version.h" #include "chrome/browser/favicon/favicon_service.h" #include "chrome/browser/favicon/favicon_service_factory.h" @@ -140,40 +141,6 @@ const CLSID CLSID_EnumerableObjectCollection = { namespace { -// Represents a class which encapsulates a PROPVARIANT object containing a -// string for AddShellLink(). -// This class automatically deletes all the resources attached to the -// PROPVARIANT object in its destructor. -class PropVariantString { - public: - PropVariantString() { - property_.vt = VT_EMPTY; - } - - HRESULT Init(const std::wstring& value) { - // Call InitPropVariantFromString() to initialize this PROPVARIANT object. - // To read , it seems InitPropVariantFromString() is an - // inline function that initialize a PROPVARIANT object and calls - // SHStrDupW() to set a copy of its input string. - // So, we just calls it without creating a copy. - return InitPropVariantFromString(value.c_str(), &property_); - } - - ~PropVariantString() { - if (property_.vt != VT_EMPTY) - PropVariantClear(&property_); - } - - const PROPVARIANT& Get() { - return property_; - } - - private: - PROPVARIANT property_; - - DISALLOW_COPY_AND_ASSIGN(PropVariantString); -}; - // Creates an IShellLink object. // An IShellLink object is almost the same as an application shortcut, and it // requires three items: the absolute path to an application, an argument @@ -233,12 +200,18 @@ HRESULT AddShellLink(base::win::ScopedComPtr collection, if (FAILED(result)) return result; - PropVariantString property_title; - result = property_title.Init(item->title()); + base::win::ScopedPropVariant property_title; + // Call InitPropVariantFromString() to initialize |property_title|. Reading + // , it seems InitPropVariantFromString() is an inline function + // that initializes a PROPVARIANT object and calls SHStrDupW() to set a copy + // of its input string. It is thus safe to call it without first creating a + // copy here. + result = InitPropVariantFromString(item->title().c_str(), + property_title.Receive()); if (FAILED(result)) return result; - result = property_store->SetValue(PKEY_Title, property_title.Get()); + result = property_store->SetValue(PKEY_Title, property_title.get()); if (FAILED(result)) return result; -- cgit v1.1