diff options
author | tommi@chromium.org <tommi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-21 07:00:22 +0000 |
---|---|---|
committer | tommi@chromium.org <tommi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-21 07:00:22 +0000 |
commit | b4966382d5d5b72c2fa1ba76aa045128eaf90418 (patch) | |
tree | f57004fa72e42181b6e3186528ca331ceb05cfd6 /chrome | |
parent | f44d1193f728c17cc4fd7adfe11a3fce82cddb9b (diff) | |
download | chromium_src-b4966382d5d5b72c2fa1ba76aa045128eaf90418.zip chromium_src-b4966382d5d5b72c2fa1ba76aa045128eaf90418.tar.gz chromium_src-b4966382d5d5b72c2fa1ba76aa045128eaf90418.tar.bz2 |
Move ScopedCoMem to base/win. This is to allow the class to be used from folders that aren't allowed to depend on chrome/common (and besides, ScopedCoMem belongs in base/win anyway).
I'm also adding a DCHECK to ScopedComInitializer that checks if the construction thread is the same as the destruction thread. The reason for this is that I've noticed cases where an instance is created on the heap (as opposed to the usual stack usecase) which could leave the door open to incorrect COM uninitialization.
Review URL: http://codereview.chromium.org/8354035
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106687 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/importer/ie_importer.cc | 4 | ||||
-rw-r--r-- | chrome/browser/platform_util_win.cc | 6 | ||||
-rw-r--r-- | chrome/chrome_common.gypi | 1 | ||||
-rw-r--r-- | chrome/common/chrome_paths_win.cc | 4 | ||||
-rw-r--r-- | chrome/common/scoped_co_mem.h | 65 |
5 files changed, 7 insertions, 73 deletions
diff --git a/chrome/browser/importer/ie_importer.cc b/chrome/browser/importer/ie_importer.cc index 3577bb0..90810d1 100644 --- a/chrome/browser/importer/ie_importer.cc +++ b/chrome/browser/importer/ie_importer.cc @@ -22,6 +22,7 @@ #include "base/time.h" #include "base/utf_string_conversions.h" #include "base/win/registry.h" +#include "base/win/scoped_co_mem.h" #include "base/win/scoped_com_initializer.h" #include "base/win/scoped_comptr.h" #include "base/win/scoped_handle.h" @@ -32,7 +33,6 @@ #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_prepopulate_data.h" #include "chrome/browser/search_engines/template_url_service.h" -#include "chrome/common/scoped_co_mem.h" #include "chrome/common/time_format.h" #include "chrome/common/url_constants.h" #include "googleurl/src/gurl.h" @@ -463,7 +463,7 @@ void IEImporter::ImportHomepage() { } std::wstring IEImporter::ResolveInternetShortcut(const std::wstring& file) { - chrome::common::ScopedCoMem<wchar_t> url; + base::win::ScopedCoMem<wchar_t> url; base::win::ScopedComPtr<IUniformResourceLocator> url_locator; HRESULT result = url_locator.CreateInstance(CLSID_InternetShortcut, NULL, CLSCTX_INPROC_SERVER); diff --git a/chrome/browser/platform_util_win.cc b/chrome/browser/platform_util_win.cc index a11cc13..4193d0b 100644 --- a/chrome/browser/platform_util_win.cc +++ b/chrome/browser/platform_util_win.cc @@ -15,8 +15,8 @@ #include "base/string_util.h" #include "base/utf_string_conversions.h" #include "base/win/registry.h" +#include "base/win/scoped_co_mem.h" #include "base/win/scoped_comptr.h" -#include "chrome/common/scoped_co_mem.h" #include "googleurl/src/gurl.h" #include "ui/base/win/shell.h" #include "ui/gfx/native_widget_types.h" @@ -64,14 +64,14 @@ void ShowItemInFolder(const FilePath& full_path) { if (FAILED(hr)) return; - chrome::common::ScopedCoMem<ITEMIDLIST> dir_item; + base::win::ScopedCoMem<ITEMIDLIST> dir_item; hr = desktop->ParseDisplayName(NULL, NULL, const_cast<wchar_t *>(dir.value().c_str()), NULL, &dir_item, NULL); if (FAILED(hr)) return; - chrome::common::ScopedCoMem<ITEMIDLIST> file_item; + base::win::ScopedCoMem<ITEMIDLIST> file_item; hr = desktop->ParseDisplayName(NULL, NULL, const_cast<wchar_t *>(full_path.value().c_str()), NULL, &file_item, NULL); diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index 51abedf..e67806b 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -197,7 +197,6 @@ 'common/render_messages.cc', 'common/render_messages.h', 'common/safe_browsing/safebrowsing_messages.h', - 'common/scoped_co_mem.h', 'common/search_provider.h', 'common/service_messages.h', 'common/service_process_util.cc', diff --git a/chrome/common/chrome_paths_win.cc b/chrome/common/chrome_paths_win.cc index e8cf7e0..f8a4b3a 100644 --- a/chrome/common/chrome_paths_win.cc +++ b/chrome/common/chrome_paths_win.cc @@ -12,8 +12,8 @@ #include "base/file_path.h" #include "base/path_service.h" +#include "base/win/scoped_co_mem.h" #include "chrome/common/chrome_constants.h" -#include "chrome/common/scoped_co_mem.h" #include "chrome/installer/util/browser_distribution.h" namespace chrome { @@ -71,7 +71,7 @@ bool GetUserDownloadsDirectory(FilePath* result) { REFKNOWNFOLDERID, DWORD, HANDLE, PWSTR*); GetKnownFolderPath f = reinterpret_cast<GetKnownFolderPath>( GetProcAddress(GetModuleHandle(L"shell32.dll"), "SHGetKnownFolderPath")); - chrome::common::ScopedCoMem<wchar_t> path_buf; + base::win::ScopedCoMem<wchar_t> path_buf; if (f && SUCCEEDED(f(FOLDERID_Downloads, 0, NULL, &path_buf))) { *result = FilePath(std::wstring(path_buf)); return true; diff --git a/chrome/common/scoped_co_mem.h b/chrome/common/scoped_co_mem.h deleted file mode 100644 index 6af28fd..0000000 --- a/chrome/common/scoped_co_mem.h +++ /dev/null @@ -1,65 +0,0 @@ -// 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" -#include "base/logging.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: - ScopedCoMem() : mem_ptr_(NULL) {} - ~ScopedCoMem() { - Reset(NULL); - } - - T** operator&() { // NOLINT - DCHECK(mem_ptr_ == NULL); // To catch memory leaks. - return &mem_ptr_; - } - - operator T*() { - return mem_ptr_; - } - - T* operator->() { - DCHECK(mem_ptr_ != NULL); - return mem_ptr_; - } - - const T* operator->() const { - DCHECK(mem_ptr_ != NULL); - return mem_ptr_; - } - - void Reset(T* ptr) { - if (mem_ptr_) - CoTaskMemFree(mem_ptr_); - mem_ptr_ = ptr; - } - - private: - T* mem_ptr_; - - DISALLOW_COPY_AND_ASSIGN(ScopedCoMem); -}; - -} // namespace common -} // namespace chrome - -#endif // CHROME_COMMON_SCOPED_CO_MEM_H_ |