 Chromium Code Reviews
 Chromium Code Reviews Issue 11776040:
  Add Windows implementation for base/debug/crash_logging.h.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 11776040:
  Add Windows implementation for base/debug/crash_logging.h.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| Index: chrome/app/breakpad_win.cc | 
| diff --git a/chrome/app/breakpad_win.cc b/chrome/app/breakpad_win.cc | 
| index d141b7cfa12e7147eb08d083bc5cebce560cb1f8..4366cd35e0aea9dbcf85f86edf7f3b873949af7f 100644 | 
| --- a/chrome/app/breakpad_win.cc | 
| +++ b/chrome/app/breakpad_win.cc | 
| @@ -14,6 +14,7 @@ | 
| #include "base/base_switches.h" | 
| #include "base/command_line.h" | 
| +#include "base/debug/crash_logging.h" | 
| #include "base/environment.h" | 
| #include "base/file_util.h" | 
| #include "base/file_version_info.h" | 
| @@ -32,6 +33,7 @@ | 
| #include "chrome/common/child_process_logging.h" | 
| #include "chrome/common/chrome_result_codes.h" | 
| #include "chrome/common/chrome_switches.h" | 
| +#include "chrome/common/crash_keys.h" | 
| #include "chrome/common/env_vars.h" | 
| #include "chrome/installer/util/google_chrome_sxs_distribution.h" | 
| #include "chrome/installer/util/google_update_settings.h" | 
| @@ -103,6 +105,11 @@ static size_t g_printer_info_offset = 0; | 
| static size_t g_num_of_views_offset = 0; | 
| static size_t g_num_switches_offset = 0; | 
| static size_t g_switches_offset = 0; | 
| +static size_t g_dynamic_keys_offset = 0; | 
| +typedef std::map<std::string, google_breakpad::CustomInfoEntry*> | 
| + DynamicEntriesMap; | 
| +DynamicEntriesMap* g_dynamic_entries = NULL; | 
| 
Nico
2013/01/24 18:01:14
nit: Why is this not static too?
(I realize it's
 | 
| +static size_t g_dynamic_entries_count = 0; | 
| // Maximum length for plugin path to include in plugin crash reports. | 
| const size_t kMaxPluginPathLength = 256; | 
| @@ -464,6 +471,15 @@ google_breakpad::CustomClientInfo* GetCustomInfo(const std::wstring& exe_path, | 
| base::StringPrintf(L"experiment-chunk-%i", i).c_str(), L"")); | 
| } | 
| + // Create space for dynamic ad-hoc keys. The names and values are set using | 
| + // the API defined in base/debug/crash_logging.h. | 
| + g_dynamic_entries_count = crash_keys::RegisterChromeCrashKeys(); | 
| + g_dynamic_keys_offset = g_custom_entries->size(); | 
| + for (size_t i = 0; i < g_dynamic_entries_count; ++i) { | 
| + g_custom_entries->push_back(google_breakpad::CustomInfoEntry()); | 
| + } | 
| + g_dynamic_entries = new DynamicEntriesMap; | 
| + | 
| static google_breakpad::CustomClientInfo custom_client_info; | 
| custom_client_info.entries = &g_custom_entries->front(); | 
| custom_client_info.count = g_custom_entries->size(); | 
| @@ -665,6 +681,32 @@ extern "C" void __declspec(dllexport) __cdecl SetNumberOfViews( | 
| SetIntegerValue(g_num_of_views_offset, number_of_views); | 
| } | 
| +void SetCrashKeyValue(const base::StringPiece& key, | 
| + const base::StringPiece& value) { | 
| + std::string key_string = key.as_string(); | 
| + | 
| + DynamicEntriesMap::iterator it = g_dynamic_entries->find(key_string); | 
| + google_breakpad::CustomInfoEntry* entry = NULL; | 
| + if (it == g_dynamic_entries->end()) { | 
| 
eroman
2013/01/24 00:47:13
There is nothing to stop callers from inserting a
 
Robert Sesek
2013/01/24 01:03:45
For now, yes. The base::debug API will prevent thi
 | 
| + if (g_dynamic_keys_offset >= g_dynamic_entries_count) | 
| + return; | 
| + entry = &(*g_custom_entries)[g_dynamic_keys_offset++]; | 
| + g_dynamic_entries->insert(std::make_pair(key_string, entry)); | 
| + } else { | 
| + entry = it->second; | 
| + } | 
| + | 
| + entry->set(UTF8ToWide(key).data(), UTF8ToWide(value).data()); | 
| +} | 
| + | 
| +void ClearCrashKeyValue(const base::StringPiece& key) { | 
| + DynamicEntriesMap::iterator it = g_dynamic_entries->find(key.as_string()); | 
| + if (it == g_dynamic_entries->end()) | 
| + return; | 
| + | 
| + it->second->set(NULL, NULL); | 
| +} | 
| + | 
| } // namespace | 
| namespace testing { | 
| @@ -866,8 +908,11 @@ void InitCrashReporter() { | 
| GoogleUpdateSettings::GetChromeChannelAndModifiers(!is_per_user_install, | 
| &channel_string); | 
| + base::debug::SetCrashKeyReportingFunctions( | 
| + &SetCrashKeyValue, &ClearCrashKeyValue); | 
| + | 
| google_breakpad::CustomClientInfo* custom_info = | 
| - GetCustomInfo(exe_path, process_type, channel_string); | 
| + GetCustomInfo(exe_path, process_type, channel_string); | 
| google_breakpad::ExceptionHandler::MinidumpCallback callback = NULL; | 
| LPTOP_LEVEL_EXCEPTION_FILTER default_filter = NULL; |