Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(409)

Side by Side Diff: base/win_util.cc

Issue 115553: Remove TRACK_HWND_CREATION/TRACK_HWND_DESTRUCTION macro since the bug it was ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/win_util.h ('k') | chrome/browser/plugin_process_host.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/win_util.h" 5 #include "base/win_util.h"
6 6
7 #include <map>
8 #include <sddl.h> 7 #include <sddl.h>
9 8
10 #include "base/logging.h" 9 #include "base/logging.h"
11 #include "base/registry.h" 10 #include "base/registry.h"
12 #include "base/scoped_handle.h" 11 #include "base/scoped_handle.h"
13 #include "base/scoped_ptr.h" 12 #include "base/scoped_ptr.h"
14 #include "base/singleton.h"
15 #include "base/string_util.h" 13 #include "base/string_util.h"
16 #include "base/tracked.h"
17 14
18 namespace win_util { 15 namespace win_util {
19 16
20 #define SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(struct_name, member) \ 17 #define SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(struct_name, member) \
21 offsetof(struct_name, member) + \ 18 offsetof(struct_name, member) + \
22 (sizeof static_cast<struct_name*>(NULL)->member) 19 (sizeof static_cast<struct_name*>(NULL)->member)
23 #define NONCLIENTMETRICS_SIZE_PRE_VISTA \ 20 #define NONCLIENTMETRICS_SIZE_PRE_VISTA \
24 SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(NONCLIENTMETRICS, lfMessageFont) 21 SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(NONCLIENTMETRICS, lfMessageFont)
25 22
26 void GetNonClientMetrics(NONCLIENTMETRICS* metrics) { 23 void GetNonClientMetrics(NONCLIENTMETRICS* metrics) {
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 // The formating failed. simply convert the message value into a string. 366 // The formating failed. simply convert the message value into a string.
370 SStringPrintf(&formatted_string, L"message number %d", messageid); 367 SStringPrintf(&formatted_string, L"message number %d", messageid);
371 } 368 }
372 return formatted_string; 369 return formatted_string;
373 } 370 }
374 371
375 std::wstring FormatLastWin32Error() { 372 std::wstring FormatLastWin32Error() {
376 return FormatMessage(GetLastError()); 373 return FormatMessage(GetLastError());
377 } 374 }
378 375
379 typedef std::map<HWND, tracked_objects::Location> HWNDInfoMap;
380 struct HWNDBirthMapTrait : public DefaultSingletonTraits<HWNDInfoMap> {
381 };
382 struct HWNDDeathMapTrait : public DefaultSingletonTraits<HWNDInfoMap> {
383 };
384
385 void NotifyHWNDCreation(const tracked_objects::Location& from_here, HWND hwnd) {
386 HWNDInfoMap* birth_map = Singleton<HWNDInfoMap, HWNDBirthMapTrait>::get();
387 HWNDInfoMap::iterator birth_iter = birth_map->find(hwnd);
388 if (birth_iter != birth_map->end()) {
389 birth_map->erase(birth_iter);
390
391 // We have already seen this HWND, was it destroyed?
392 HWNDInfoMap* death_map = Singleton<HWNDInfoMap, HWNDDeathMapTrait>::get();
393 HWNDInfoMap::iterator death_iter = death_map->find(hwnd);
394 if (death_iter == death_map->end()) {
395 // We did not get a destruction notification. The code is probably not
396 // calling NotifyHWNDDestruction for that HWND.
397 NOTREACHED() << "Creation of HWND reported for already tracked HWND. The "
398 "HWND destruction is probably not tracked properly. "
399 "Fix it!";
400 } else {
401 death_map->erase(death_iter);
402 }
403 }
404 birth_map->insert(std::pair<HWND, tracked_objects::Location>(hwnd,
405 from_here));
406 }
407
408 void NotifyHWNDDestruction(const tracked_objects::Location& from_here,
409 HWND hwnd) {
410 HWNDInfoMap* death_map = Singleton<HWNDInfoMap, HWNDDeathMapTrait>::get();
411 HWNDInfoMap::iterator death_iter = death_map->find(hwnd);
412
413 HWNDInfoMap* birth_map = Singleton<HWNDInfoMap, HWNDBirthMapTrait>::get();
414 HWNDInfoMap::iterator birth_iter = birth_map->find(hwnd);
415
416 if (death_iter != death_map->end()) {
417 std::string allocation, first_delete, second_delete;
418 if (birth_iter != birth_map->end())
419 birth_iter->second.Write(true, true, &allocation);
420 death_iter->second.Write(true, true, &first_delete);
421 from_here.Write(true, true, &second_delete);
422 LOG(FATAL) << "Double delete of an HWND. Please file a bug with info on "
423 "how you got that assertion and the following information:\n"
424 "Double delete of HWND 0x" << hwnd << "\n" <<
425 "Allocated at " << allocation << "\n" <<
426 "Deleted first at " << first_delete << "\n" <<
427 "Deleted again at " << second_delete;
428 death_map->erase(death_iter);
429 }
430
431 if (birth_iter == birth_map->end()) {
432 NOTREACHED() << "Destruction of HWND reported for unknown HWND. The HWND "
433 "construction is probably not tracked properly. Fix it!";
434 }
435 death_map->insert(std::pair<HWND, tracked_objects::Location>(hwnd,
436 from_here));
437 }
438
439 } // namespace win_util 376 } // namespace win_util
440 377
441 #ifdef _MSC_VER 378 #ifdef _MSC_VER
442 // 379 //
443 // If the ASSERT below fails, please install Visual Studio 2005 Service Pack 1. 380 // If the ASSERT below fails, please install Visual Studio 2005 Service Pack 1.
444 // 381 //
445 extern char VisualStudio2005ServicePack1Detection[10]; 382 extern char VisualStudio2005ServicePack1Detection[10];
446 COMPILE_ASSERT(sizeof(&VisualStudio2005ServicePack1Detection) == sizeof(void*), 383 COMPILE_ASSERT(sizeof(&VisualStudio2005ServicePack1Detection) == sizeof(void*),
447 VS2005SP1Detect); 384 VS2005SP1Detect);
448 // 385 //
449 // Chrome requires at least Service Pack 1 for Visual Studio 2005. 386 // Chrome requires at least Service Pack 1 for Visual Studio 2005.
450 // 387 //
451 #endif // _MSC_VER 388 #endif // _MSC_VER
452 389
453 #ifndef COPY_FILE_COPY_SYMLINK 390 #ifndef COPY_FILE_COPY_SYMLINK
454 #error You must install the Windows 2008 or Vista Software Development Kit and \ 391 #error You must install the Windows 2008 or Vista Software Development Kit and \
455 set it as your default include path to build this library. You can grab it by \ 392 set it as your default include path to build this library. You can grab it by \
456 searching for "download windows sdk 2008" in your favorite web search engine. \ 393 searching for "download windows sdk 2008" in your favorite web search engine. \
457 Also make sure you register the SDK with Visual Studio, by selecting \ 394 Also make sure you register the SDK with Visual Studio, by selecting \
458 "Integrate Windows SDK with Visual Studio 2005" from the Windows SDK \ 395 "Integrate Windows SDK with Visual Studio 2005" from the Windows SDK \
459 menu (see Start - All Programs - Microsoft Windows SDK - \ 396 menu (see Start - All Programs - Microsoft Windows SDK - \
460 Visual Studio Registration). 397 Visual Studio Registration).
461 #endif 398 #endif
OLDNEW
« no previous file with comments | « base/win_util.h ('k') | chrome/browser/plugin_process_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698