OLD | NEW |
---|---|
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> | |
7 #include <sddl.h> | 8 #include <sddl.h> |
8 | 9 |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/registry.h" | 11 #include "base/registry.h" |
11 #include "base/scoped_handle.h" | 12 #include "base/scoped_handle.h" |
13 #include "base/singleton.h" | |
12 #include "base/string_util.h" | 14 #include "base/string_util.h" |
15 #include "base/tracked.h" | |
13 | 16 |
14 namespace win_util { | 17 namespace win_util { |
15 | 18 |
16 #define SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(struct_name, member) \ | 19 #define SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(struct_name, member) \ |
17 offsetof(struct_name, member) + \ | 20 offsetof(struct_name, member) + \ |
18 (sizeof static_cast<struct_name*>(NULL)->member) | 21 (sizeof static_cast<struct_name*>(NULL)->member) |
19 #define NONCLIENTMETRICS_SIZE_PRE_VISTA \ | 22 #define NONCLIENTMETRICS_SIZE_PRE_VISTA \ |
20 SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(NONCLIENTMETRICS, lfMessageFont) | 23 SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(NONCLIENTMETRICS, lfMessageFont) |
21 | 24 |
22 void GetNonClientMetrics(NONCLIENTMETRICS* metrics) { | 25 void GetNonClientMetrics(NONCLIENTMETRICS* metrics) { |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
354 // The formating failed. simply convert the message value into a string. | 357 // The formating failed. simply convert the message value into a string. |
355 SStringPrintf(&formatted_string, L"message number %d", messageid); | 358 SStringPrintf(&formatted_string, L"message number %d", messageid); |
356 } | 359 } |
357 return formatted_string; | 360 return formatted_string; |
358 } | 361 } |
359 | 362 |
360 std::wstring FormatLastWin32Error() { | 363 std::wstring FormatLastWin32Error() { |
361 return FormatMessage(GetLastError()); | 364 return FormatMessage(GetLastError()); |
362 } | 365 } |
363 | 366 |
367 typedef std::map<HWND, tracked_objects::Location> HWNDInfoMap; | |
368 struct HWNDBirthMapTrait : public DefaultSingletonTraits<HWNDInfoMap> { | |
369 }; | |
370 struct HWNDDeathMapTrait : public DefaultSingletonTraits<HWNDInfoMap> { | |
371 }; | |
372 | |
373 void NotifyHWNDCreation(const tracked_objects::Location& from_here, HWND hwnd) { | |
374 HWNDInfoMap* birth_map = Singleton<HWNDInfoMap, HWNDBirthMapTrait>::get(); | |
375 HWNDInfoMap::iterator birth_iter = birth_map->find(hwnd); | |
376 if (birth_iter != birth_map->end()) { | |
377 birth_map->erase(birth_iter); | |
378 | |
379 // We have already seen this HWND, was it destroyed? | |
380 HWNDInfoMap* death_map = Singleton<HWNDInfoMap, HWNDDeathMapTrait>::get(); | |
381 HWNDInfoMap::iterator death_iter = death_map->find(hwnd); | |
382 if (death_iter == death_map->end()) { | |
383 // We did not get a destruction notification. The code is probably not | |
384 // calling NotifyHWNDDestruction for that HWND. | |
385 NOTREACHED() << "Creation of HWND reported for already tracked HWND. The " | |
386 "HWND destruction is probably not tracked properly. " | |
387 "Fix it!"; | |
388 } else { | |
389 death_map->erase(death_iter); | |
390 } | |
391 } | |
392 birth_map->insert(std::pair<HWND, tracked_objects::Location>(hwnd, | |
393 from_here)); | |
394 } | |
395 | |
396 void NotifyHWNDDestruction(const tracked_objects::Location& from_here, | |
397 HWND hwnd) { | |
398 HWNDInfoMap* death_map = Singleton<HWNDInfoMap, HWNDDeathMapTrait>::get(); | |
399 HWNDInfoMap::iterator death_iter = death_map->find(hwnd); | |
400 | |
401 HWNDInfoMap* birth_map = Singleton<HWNDInfoMap, HWNDBirthMapTrait>::get(); | |
402 HWNDInfoMap::iterator birth_iter = birth_map->find(hwnd); | |
403 | |
404 if (death_iter != death_map->end()) { | |
405 std::string allocation, first_delete, second_delete; | |
406 if (birth_iter != birth_map->end()) | |
407 birth_iter->second.Write(true, true, &allocation); | |
408 death_iter->second.Write(true, true, &first_delete); | |
409 from_here.Write(true, true, &second_delete); | |
410 NOTREACHED() << "Double delete of an HWND. Please file a bug with info on " | |
411 "how you got that assertion and the following information:\n" | |
412 "Double delete of HWND 0x" << hwnd << "\n" << | |
sky
2009/02/03 20:37:24
will "<< hwnd" give you hex, or decimal?
| |
413 "Allocated at " << allocation << "\n" << | |
414 "Deleted first at " << first_delete << "\n" << | |
415 "Deleted again at " << second_delete; | |
416 death_map->erase(death_iter); | |
417 } | |
418 | |
419 if (birth_iter == birth_map->end()) { | |
420 NOTREACHED() << "Destruction of HWND reported for unknown HWND. The HWND " | |
421 "construction is probably not tracked properly. Fix it!"; | |
422 } | |
423 death_map->insert(std::pair<HWND, tracked_objects::Location>(hwnd, | |
424 from_here)); | |
425 } | |
426 | |
364 } // namespace win_util | 427 } // namespace win_util |
365 | 428 |
366 #ifdef _MSC_VER | 429 #ifdef _MSC_VER |
367 // | 430 // |
368 // If the ASSERT below fails, please install Visual Studio 2005 Service Pack 1. | 431 // If the ASSERT below fails, please install Visual Studio 2005 Service Pack 1. |
369 // | 432 // |
370 extern char VisualStudio2005ServicePack1Detection[10]; | 433 extern char VisualStudio2005ServicePack1Detection[10]; |
371 COMPILE_ASSERT(sizeof(&VisualStudio2005ServicePack1Detection) == sizeof(void*), | 434 COMPILE_ASSERT(sizeof(&VisualStudio2005ServicePack1Detection) == sizeof(void*), |
372 VS2005SP1Detect); | 435 VS2005SP1Detect); |
373 // | 436 // |
374 // Chrome requires at least Service Pack 1 for Visual Studio 2005. | 437 // Chrome requires at least Service Pack 1 for Visual Studio 2005. |
375 // | 438 // |
376 #endif // _MSC_VER | 439 #endif // _MSC_VER |
377 | 440 |
378 #ifndef COPY_FILE_COPY_SYMLINK | 441 #ifndef COPY_FILE_COPY_SYMLINK |
379 #error You must install the Windows 2008 or Vista Software Development Kit and \ | 442 #error You must install the Windows 2008 or Vista Software Development Kit and \ |
380 set it as your default include path to build this library. You can grab it by \ | 443 set it as your default include path to build this library. You can grab it by \ |
381 searching for "download windows sdk 2008" in your favorite web search engine. \ | 444 searching for "download windows sdk 2008" in your favorite web search engine. \ |
382 Also make sure you register the SDK with Visual Studio, by selecting \ | 445 Also make sure you register the SDK with Visual Studio, by selecting \ |
383 "Integrate Windows SDK with Visual Studio 2005" from the Windows SDK \ | 446 "Integrate Windows SDK with Visual Studio 2005" from the Windows SDK \ |
384 menu (see Start - All Programs - Microsoft Windows SDK - \ | 447 menu (see Start - All Programs - Microsoft Windows SDK - \ |
385 Visual Studio Registration). | 448 Visual Studio Registration). |
386 #endif | 449 #endif |
OLD | NEW |