4cf9b0a8793f3cf2aac8cfda6817bd9f269c652c
[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)(base::UTF8ToWide(key).data(),
39                     base::UTF8ToWide(value).data());
40   }
41 }
42
43 void ClearCrashKeyValueTrampoline(const base::StringPiece& key) {
44   static ClearCrashKeyValue clear_crash_key = NULL;
45   if (!clear_crash_key) {
46     HMODULE exe_module = GetModuleHandle(chrome::kBrowserProcessExecutableName);
47     if (!exe_module)
48       return;
49     clear_crash_key = reinterpret_cast<ClearCrashKeyValue>(
50         GetProcAddress(exe_module, "ClearCrashKeyValueImpl"));
51   }
52
53   if (clear_crash_key)
54     (clear_crash_key)(base::UTF8ToWide(key).data());
55 }
56
57 }  // namespace
58
59 void Init() {
60   // Note: on other platforms, this is set up during Breakpad initialization,
61   // in ChromeBreakpadClient. But on Windows, that is before the DLL module is
62   // loaded, which is a prerequisite of the crash key system.
63   crash_keys::RegisterChromeCrashKeys();
64   base::debug::SetCrashKeyReportingFunctions(
65       &SetCrashKeyValueTrampoline, &ClearCrashKeyValueTrampoline);
66 }
67
68 }  // namespace child_process_logging