- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / common / child_process_logging_win.cc
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/common/child_process_logging.h"
6
7 #include <windows.h>
8
9 #include "base/debug/crash_logging.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/common/chrome_constants.h"
12 #include "chrome/common/crash_keys.h"
13
14 namespace child_process_logging {
15
16 namespace {
17
18 // exported in breakpad_win.cc:
19 //    void __declspec(dllexport) __cdecl SetCrashKeyValueImpl.
20 typedef void (__cdecl *SetCrashKeyValue)(const wchar_t*, const wchar_t*);
21
22 // exported in breakpad_win.cc:
23 //    void __declspec(dllexport) __cdecl ClearCrashKeyValueImpl.
24 typedef void (__cdecl *ClearCrashKeyValue)(const wchar_t*);
25
26 void SetCrashKeyValueTrampoline(const base::StringPiece& key,
27                                 const base::StringPiece& value) {
28   static SetCrashKeyValue set_crash_key = NULL;
29   if (!set_crash_key) {
30     HMODULE exe_module = GetModuleHandle(chrome::kBrowserProcessExecutableName);
31     if (!exe_module)
32       return;
33     set_crash_key = reinterpret_cast<SetCrashKeyValue>(
34         GetProcAddress(exe_module, "SetCrashKeyValueImpl"));
35   }
36
37   if (set_crash_key)
38     (set_crash_key)(UTF8ToWide(key).data(), UTF8ToWide(value).data());
39 }
40
41 void ClearCrashKeyValueTrampoline(const base::StringPiece& key) {
42   static ClearCrashKeyValue clear_crash_key = NULL;
43   if (!clear_crash_key) {
44     HMODULE exe_module = GetModuleHandle(chrome::kBrowserProcessExecutableName);
45     if (!exe_module)
46       return;
47     clear_crash_key = reinterpret_cast<ClearCrashKeyValue>(
48         GetProcAddress(exe_module, "ClearCrashKeyValueImpl"));
49   }
50
51   if (clear_crash_key)
52     (clear_crash_key)(UTF8ToWide(key).data());
53 }
54
55 }  // namespace
56
57 void Init() {
58   // Note: on other platforms, this is set up during Breakpad initialization,
59   // in ChromeBreakpadClient. But on Windows, that is before the DLL module is
60   // loaded, which is a prerequisite of the crash key system.
61   crash_keys::RegisterChromeCrashKeys();
62   base::debug::SetCrashKeyReportingFunctions(
63       &SetCrashKeyValueTrampoline, &ClearCrashKeyValueTrampoline);
64 }
65
66 }  // namespace child_process_logging