diff options
-rw-r--r-- | base/base.gypi | 1 | ||||
-rw-r--r-- | base/win/scoped_co_mem.h (renamed from chrome/common/scoped_co_mem.h) | 16 | ||||
-rw-r--r-- | base/win/scoped_com_initializer.h | 26 | ||||
-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 |
7 files changed, 39 insertions, 19 deletions
diff --git a/base/base.gypi b/base/base.gypi index b3a97af..e2f0a7d 100644 --- a/base/base.gypi +++ b/base/base.gypi @@ -370,6 +370,7 @@ 'win/resource_util.h', 'win/scoped_bstr.cc', 'win/scoped_bstr.h', + 'win/scoped_co_mem.h', 'win/scoped_com_initializer.h', 'win/scoped_comptr.h', 'win/scoped_gdi_object.h', diff --git a/chrome/common/scoped_co_mem.h b/base/win/scoped_co_mem.h index 6af28fd..ccbe707 100644 --- a/chrome/common/scoped_co_mem.h +++ b/base/win/scoped_co_mem.h @@ -2,8 +2,8 @@ // 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_ +#ifndef BASE_WIN_SCOPED_CO_MEM_H_ +#define BASE_WIN_SCOPED_CO_MEM_H_ #pragma once #include <objbase.h> @@ -11,12 +11,12 @@ #include "base/basictypes.h" #include "base/logging.h" -namespace chrome { -namespace common { +namespace base { +namespace win { // Simple scoped memory releaser class for COM allocated memory. // Example: -// chrome::common::ScopedCoMem<ITEMIDLIST> file_item; +// base::win::ScopedCoMem<ITEMIDLIST> file_item; // SHGetSomeInfo(&file_item, ...); // ... // return; <-- memory released @@ -59,7 +59,7 @@ class ScopedCoMem { DISALLOW_COPY_AND_ASSIGN(ScopedCoMem); }; -} // namespace common -} // namespace chrome +} // namespace win +} // namespace base -#endif // CHROME_COMMON_SCOPED_CO_MEM_H_ +#endif // BASE_WIN_SCOPED_CO_MEM_H_ diff --git a/base/win/scoped_com_initializer.h b/base/win/scoped_com_initializer.h index 0ea5199..0cf1ac7 100644 --- a/base/win/scoped_com_initializer.h +++ b/base/win/scoped_com_initializer.h @@ -7,6 +7,7 @@ #pragma once #include "base/basictypes.h" +#include "base/logging.h" #include "build/build_config.h" #if defined(OS_WIN) @@ -24,15 +25,20 @@ class ScopedCOMInitializer { enum SelectMTA { kMTA }; // Constructor for STA initialization. - ScopedCOMInitializer() : hr_(CoInitialize(NULL)) { + ScopedCOMInitializer() { + Initialize(COINIT_APARTMENTTHREADED); } // Constructor for MTA initialization. - explicit ScopedCOMInitializer(SelectMTA mta) - : hr_(CoInitializeEx(NULL, COINIT_MULTITHREADED)) { + explicit ScopedCOMInitializer(SelectMTA mta) { + Initialize(COINIT_MULTITHREADED); } ScopedCOMInitializer::~ScopedCOMInitializer() { +#ifndef NDEBUG + // Using the windows API directly to avoid dependency on platform_thread. + DCHECK_EQ(GetCurrentThreadId(), thread_id_); +#endif if (SUCCEEDED(hr_)) CoUninitialize(); } @@ -40,7 +46,21 @@ class ScopedCOMInitializer { bool succeeded() const { return SUCCEEDED(hr_); } private: + void Initialize(COINIT init) { +#ifndef NDEBUG + thread_id_ = GetCurrentThreadId(); +#endif + hr_ = CoInitializeEx(NULL, init); + } + HRESULT hr_; +#ifndef NDEBUG + // In debug builds we use this variable to catch a potential bug where a + // ScopedCOMInitializer instance is deleted on a different thread than it + // was initially created on. If that ever happens it can have bad + // consequences and the cause can be tricky to track down. + DWORD thread_id_; +#endif DISALLOW_COPY_AND_ASSIGN(ScopedCOMInitializer); }; 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; |