summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-04 19:38:30 +0000
committerjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-04 19:38:30 +0000
commita3153c47d3b5308e7a55c0924a0baa1a6e02dcd0 (patch)
treeb37c85641aef8df14c732e4b187444e040a11555 /base
parenta93e517bfe25f11b2c4cc7d69f386424b93a2efa (diff)
downloadchromium_src-a3153c47d3b5308e7a55c0924a0baa1a6e02dcd0.zip
chromium_src-a3153c47d3b5308e7a55c0924a0baa1a6e02dcd0.tar.gz
chromium_src-a3153c47d3b5308e7a55c0924a0baa1a6e02dcd0.tar.bz2
This CL adds macro used to track the creation and destruction
of HWNDs, in an attempt to detect potential double-delete. A double-delete of a HWND might be responsible for the crasher http://crbug.com/4714 Note: this CL was previously committed and reverted because it broke the sandbox integration module. Review URL: http://codereview.chromium.org/21032 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9161 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/stats_table.cc6
-rw-r--r--base/time.cc3
-rw-r--r--base/win_util.cc63
-rw-r--r--base/win_util.h18
4 files changed, 87 insertions, 3 deletions
diff --git a/base/stats_table.cc b/base/stats_table.cc
index 31570b5..a812b92 100644
--- a/base/stats_table.cc
+++ b/base/stats_table.cc
@@ -8,7 +8,9 @@
#include "base/platform_thread.h"
#include "base/process_util.h"
#include "base/shared_memory.h"
+#include "base/string_piece.h"
#include "base/string_util.h"
+#include "base/sys_string_conversions.h"
#include "base/thread_local_storage.h"
#if defined(OS_POSIX)
@@ -167,8 +169,8 @@ StatsTablePrivate* StatsTablePrivate::New(const std::string& name,
int max_threads,
int max_counters) {
scoped_ptr<StatsTablePrivate> priv(new StatsTablePrivate());
-
- if (!priv->shared_memory_.Create(UTF8ToWide(name), false, true, size))
+ if (!priv->shared_memory_.Create(base::SysUTF8ToWide(name), false, true,
+ size))
return NULL;
if (!priv->shared_memory_.Map(size))
return NULL;
diff --git a/base/time.cc b/base/time.cc
index 12519aa..5ce1f80 100644
--- a/base/time.cc
+++ b/base/time.cc
@@ -4,6 +4,7 @@
#include "base/time.h"
#include "base/string_util.h"
+#include "base/sys_string_conversions.h"
#include "base/third_party/nspr/prtime.h"
#include "base/logging.h"
@@ -79,7 +80,7 @@ Time Time::LocalMidnight() const {
// static
bool Time::FromString(const wchar_t* time_string, Time* parsed_time) {
DCHECK((time_string != NULL) && (parsed_time != NULL));
- std::string ascii_time_string = WideToUTF8(time_string);
+ std::string ascii_time_string = SysWideToUTF8(time_string);
if (ascii_time_string.length() == 0)
return false;
PRTime result_time = 0;
diff --git a/base/win_util.cc b/base/win_util.cc
index cfd7f2b..e18007b 100644
--- a/base/win_util.cc
+++ b/base/win_util.cc
@@ -4,12 +4,15 @@
#include "base/win_util.h"
+#include <map>
#include <sddl.h>
#include "base/logging.h"
#include "base/registry.h"
#include "base/scoped_handle.h"
+#include "base/singleton.h"
#include "base/string_util.h"
+#include "base/tracked.h"
namespace win_util {
@@ -361,6 +364,66 @@ std::wstring FormatLastWin32Error() {
return FormatMessage(GetLastError());
}
+typedef std::map<HWND, tracked_objects::Location> HWNDInfoMap;
+struct HWNDBirthMapTrait : public DefaultSingletonTraits<HWNDInfoMap> {
+};
+struct HWNDDeathMapTrait : public DefaultSingletonTraits<HWNDInfoMap> {
+};
+
+void NotifyHWNDCreation(const tracked_objects::Location& from_here, HWND hwnd) {
+ HWNDInfoMap* birth_map = Singleton<HWNDInfoMap, HWNDBirthMapTrait>::get();
+ HWNDInfoMap::iterator birth_iter = birth_map->find(hwnd);
+ if (birth_iter != birth_map->end()) {
+ birth_map->erase(birth_iter);
+
+ // We have already seen this HWND, was it destroyed?
+ HWNDInfoMap* death_map = Singleton<HWNDInfoMap, HWNDDeathMapTrait>::get();
+ HWNDInfoMap::iterator death_iter = death_map->find(hwnd);
+ if (death_iter == death_map->end()) {
+ // We did not get a destruction notification. The code is probably not
+ // calling NotifyHWNDDestruction for that HWND.
+ NOTREACHED() << "Creation of HWND reported for already tracked HWND. The "
+ "HWND destruction is probably not tracked properly. "
+ "Fix it!";
+ } else {
+ death_map->erase(death_iter);
+ }
+ }
+ birth_map->insert(std::pair<HWND, tracked_objects::Location>(hwnd,
+ from_here));
+}
+
+void NotifyHWNDDestruction(const tracked_objects::Location& from_here,
+ HWND hwnd) {
+ HWNDInfoMap* death_map = Singleton<HWNDInfoMap, HWNDDeathMapTrait>::get();
+ HWNDInfoMap::iterator death_iter = death_map->find(hwnd);
+
+ HWNDInfoMap* birth_map = Singleton<HWNDInfoMap, HWNDBirthMapTrait>::get();
+ HWNDInfoMap::iterator birth_iter = birth_map->find(hwnd);
+
+ if (death_iter != death_map->end()) {
+ std::string allocation, first_delete, second_delete;
+ if (birth_iter != birth_map->end())
+ birth_iter->second.Write(true, true, &allocation);
+ death_iter->second.Write(true, true, &first_delete);
+ from_here.Write(true, true, &second_delete);
+ NOTREACHED() << "Double delete of an HWND. Please file a bug with info on "
+ "how you got that assertion and the following information:\n"
+ "Double delete of HWND 0x" << hwnd << "\n" <<
+ "Allocated at " << allocation << "\n" <<
+ "Deleted first at " << first_delete << "\n" <<
+ "Deleted again at " << second_delete;
+ death_map->erase(death_iter);
+ }
+
+ if (birth_iter == birth_map->end()) {
+ NOTREACHED() << "Destruction of HWND reported for unknown HWND. The HWND "
+ "construction is probably not tracked properly. Fix it!";
+ }
+ death_map->insert(std::pair<HWND, tracked_objects::Location>(hwnd,
+ from_here));
+}
+
} // namespace win_util
#ifdef _MSC_VER
diff --git a/base/win_util.h b/base/win_util.h
index 317c332..f6ce1c2 100644
--- a/base/win_util.h
+++ b/base/win_util.h
@@ -10,6 +10,8 @@
#include <string>
+#include "base/tracked.h"
+
namespace win_util {
// NOTE: Keep these in order so callers can do things like
@@ -102,6 +104,22 @@ std::wstring FormatMessage(unsigned messageid);
// Uses the last Win32 error to generate a human readable message string.
std::wstring FormatLastWin32Error();
+// These 2 methods are used to track HWND creation/destruction to investigate
+// a mysterious crasher http://crbugs.com/4714 (crasher in on NCDestroy) that
+// might be caused by a multiple delete of an HWND.
+void NotifyHWNDCreation(const tracked_objects::Location& from_here, HWND hwnd);
+void NotifyHWNDDestruction(const tracked_objects::Location& from_here,
+ HWND hwnd);
+
+#ifdef NDEBUG
+#define TRACK_HWND_CREATION(hwnd)
+#define TRACK_HWND_DESTRUCTION(hwnd)
+#else
+#define TRACK_HWND_CREATION(hwnd) win_util::NotifyHWNDCreation(FROM_HERE, hwnd)
+#define TRACK_HWND_DESTRUCTION(hwnd) \
+ win_util::NotifyHWNDDestruction(FROM_HERE, hwnd)
+#endif
+
} // namespace win_util
#endif // BASE_WIN_UTIL_H__