diff options
author | gab@chromium.org <gab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-03 07:29:56 +0000 |
---|---|---|
committer | gab@chromium.org <gab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-03 07:29:56 +0000 |
commit | 76602ffe79164dfcc39b001e15d9950418bb7998 (patch) | |
tree | adf004a007a8793f3d74f135a84ec8a4d653e3eb /media | |
parent | fae2fb0a99eec92ee3d1024b181c47fda265bdb5 (diff) | |
download | chromium_src-76602ffe79164dfcc39b001e15d9950418bb7998.zip chromium_src-76602ffe79164dfcc39b001e15d9950418bb7998.tar.gz chromium_src-76602ffe79164dfcc39b001e15d9950418bb7998.tar.bz2 |
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
Diffstat (limited to 'media')
-rw-r--r-- | media/audio/win/audio_low_latency_output_win.cc | 14 | ||||
-rw-r--r-- | media/audio/win/core_audio_util_win.cc | 42 | ||||
-rw-r--r-- | media/audio/win/device_enumeration_win.cc | 12 |
3 files changed, 18 insertions, 50 deletions
diff --git a/media/audio/win/audio_low_latency_output_win.cc b/media/audio/win/audio_low_latency_output_win.cc index 3037589..a53e03c 100644 --- a/media/audio/win/audio_low_latency_output_win.cc +++ b/media/audio/win/audio_low_latency_output_win.cc @@ -11,6 +11,7 @@ #include "base/memory/scoped_ptr.h" #include "base/metrics/histogram.h" #include "base/utf_string_conversions.h" +#include "base/win/scoped_propvariant.h" #include "media/audio/audio_util.h" #include "media/audio/win/audio_manager_win.h" #include "media/audio/win/avrt_wrapper_win.h" @@ -940,14 +941,13 @@ std::string WASAPIAudioOutputStream::GetDeviceName(LPCWSTR device_id) const { ScopedComPtr<IPropertyStore> properties; hr = audio_device->OpenPropertyStore(STGM_READ, properties.Receive()); if (SUCCEEDED(hr)) { - PROPVARIANT friendly_name; - PropVariantInit(&friendly_name); - hr = properties->GetValue(PKEY_Device_FriendlyName, &friendly_name); - if (SUCCEEDED(hr) && friendly_name.vt == VT_LPWSTR) { - if (friendly_name.pwszVal) - name = WideToUTF8(friendly_name.pwszVal); + base::win::ScopedPropVariant friendly_name; + hr = properties->GetValue(PKEY_Device_FriendlyName, + friendly_name.Receive()); + if (SUCCEEDED(hr) && friendly_name.get().vt == VT_LPWSTR) { + if (friendly_name.get().pwszVal) + name = WideToUTF8(friendly_name.get().pwszVal); } - PropVariantClear(&friendly_name); } } return name; diff --git a/media/audio/win/core_audio_util_win.cc b/media/audio/win/core_audio_util_win.cc index 2c262b4..54ff590 100644 --- a/media/audio/win/core_audio_util_win.cc +++ b/media/audio/win/core_audio_util_win.cc @@ -13,6 +13,7 @@ #include "base/utf_string_conversions.h" #include "base/win/scoped_co_mem.h" #include "base/win/scoped_handle.h" +#include "base/win/scoped_propvariant.h" #include "base/win/windows_version.h" #include "media/base/media_switches.h" @@ -75,39 +76,6 @@ bool LoadAudiosesDll() { return (LoadLibraryExW(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH) != NULL); } -// Scoped PROPVARIANT class for automatically freeing a COM PROPVARIANT -// structure at the end of a scope. -class ScopedPropertyVariant { - public: - ScopedPropertyVariant() { - PropVariantInit(&propvar_); - } - ~ScopedPropertyVariant() { - PropVariantClear(&propvar_); - } - - // Retrieves the pointer address. - // Used to receive a PROPVARIANT as an out argument (and take ownership). - PROPVARIANT* Receive() { - DCHECK_EQ(propvar_.vt, VT_EMPTY); - return &propvar_; - } - - VARTYPE type() const { - return propvar_.vt; - } - - LPWSTR as_wide_string() const { - DCHECK_EQ(type(), VT_LPWSTR); - return propvar_.pwszVal; - } - - private: - PROPVARIANT propvar_; - - DISALLOW_COPY_AND_ASSIGN(ScopedPropertyVariant); -}; - bool CoreAudioUtil::IsSupported() { // Microsoft does not plan to make the Core Audio APIs available for use // with earlier versions of Windows, including Microsoft Windows Server 2003, @@ -253,13 +221,13 @@ HRESULT CoreAudioUtil::GetDeviceName(IMMDevice* device, AudioDeviceName* name) { hr = device->OpenPropertyStore(STGM_READ, properties.Receive()); if (FAILED(hr)) return hr; - ScopedPropertyVariant friendly_name; + base::win::ScopedPropVariant friendly_name; hr = properties->GetValue(PKEY_Device_FriendlyName, friendly_name.Receive()); if (FAILED(hr)) return hr; - if (friendly_name.as_wide_string()) { - WideToUTF8(friendly_name.as_wide_string(), - wcslen(friendly_name.as_wide_string()), + if (friendly_name.get().vt == VT_LPWSTR && friendly_name.get().pwszVal) { + WideToUTF8(friendly_name.get().pwszVal, + wcslen(friendly_name.get().pwszVal), &device_name.device_name); } diff --git a/media/audio/win/device_enumeration_win.cc b/media/audio/win/device_enumeration_win.cc index 46aacb0..4edee7e 100644 --- a/media/audio/win/device_enumeration_win.cc +++ b/media/audio/win/device_enumeration_win.cc @@ -12,6 +12,7 @@ #include "base/utf_string_conversions.h" #include "base/win/scoped_co_mem.h" #include "base/win/scoped_comptr.h" +#include "base/win/scoped_propvariant.h" using media::AudioDeviceNames; using base::win::ScopedComPtr; @@ -76,16 +77,15 @@ bool GetInputDeviceNamesWin(AudioDeviceNames* device_names) { ScopedComPtr<IPropertyStore> properties; hr = audio_device->OpenPropertyStore(STGM_READ, properties.Receive()); if (SUCCEEDED(hr)) { - PROPVARIANT friendly_name; - PropVariantInit(&friendly_name); - hr = properties->GetValue(PKEY_Device_FriendlyName, &friendly_name); + base::win::ScopedPropVariant friendly_name; + hr = properties->GetValue(PKEY_Device_FriendlyName, + friendly_name.Receive()); // Store the user-friendly name. if (SUCCEEDED(hr) && - friendly_name.vt == VT_LPWSTR && friendly_name.pwszVal) { - device.device_name = WideToUTF8(friendly_name.pwszVal); + friendly_name.get().vt == VT_LPWSTR && friendly_name.get().pwszVal) { + device.device_name = WideToUTF8(friendly_name.get().pwszVal); } - PropVariantClear(&friendly_name); } // Add combination of user-friendly and unique name to the output list. |