Make castv2 performance test work.
[chromium-blink-merge.git] / chrome / app / kasko_client.cc
blob97b0def6affa8d19834cb968b52126400adf2bdc
1 // Copyright 2015 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.
5 #if defined(KASKO)
7 #include "chrome/app/kasko_client.h"
9 #include <windows.h>
11 #include <string>
13 #include "base/debug/crash_logging.h"
14 #include "base/guid.h"
15 #include "base/logging.h"
16 #include "base/process/process_handle.h"
17 #include "base/win/wrapped_window_proc.h"
18 #include "breakpad/src/client/windows/common/ipc_protocol.h"
19 #include "chrome/app/chrome_watcher_client_win.h"
20 #include "chrome/chrome_watcher/chrome_watcher_main_api.h"
21 #include "chrome/common/chrome_constants.h"
22 #include "chrome/common/crash_keys.h"
23 #include "components/crash/app/crash_keys_win.h"
24 #include "syzygy/kasko/api/client.h"
26 namespace {
28 ChromeWatcherClient* g_chrome_watcher_client = nullptr;
29 kasko::api::MinidumpType g_minidump_type = kasko::api::SMALL_DUMP_TYPE;
31 } // namespace
33 KaskoClient::KaskoClient(ChromeWatcherClient* chrome_watcher_client,
34 kasko::api::MinidumpType minidump_type) {
35 DCHECK(!g_chrome_watcher_client);
36 g_minidump_type = minidump_type;
37 g_chrome_watcher_client = chrome_watcher_client;
39 kasko::api::InitializeClient(
40 GetKaskoEndpoint(base::GetCurrentProcId()).c_str());
43 KaskoClient::~KaskoClient() {
44 DCHECK(g_chrome_watcher_client);
45 g_chrome_watcher_client = nullptr;
46 kasko::api::ShutdownClient();
49 extern "C" void __declspec(dllexport) ReportCrashWithProtobuf(
50 EXCEPTION_POINTERS* info, const char* protobuf, size_t protobuf_length) {
51 static_assert(
52 sizeof(kasko::api::CrashKey) == sizeof(google_breakpad::CustomInfoEntry),
53 "CrashKey and CustomInfoEntry structs are not compatible.");
54 static_assert(offsetof(kasko::api::CrashKey, name) ==
55 offsetof(google_breakpad::CustomInfoEntry, name),
56 "CrashKey and CustomInfoEntry structs are not compatible.");
57 static_assert(offsetof(kasko::api::CrashKey, value) ==
58 offsetof(google_breakpad::CustomInfoEntry, value),
59 "CrashKey and CustomInfoEntry structs are not compatible.");
60 static_assert(
61 sizeof(reinterpret_cast<kasko::api::CrashKey*>(0)->name) ==
62 sizeof(reinterpret_cast<google_breakpad::CustomInfoEntry*>(0)->name),
63 "CrashKey and CustomInfoEntry structs are not compatible.");
64 static_assert(
65 sizeof(reinterpret_cast<kasko::api::CrashKey*>(0)->value) ==
66 sizeof(reinterpret_cast<google_breakpad::CustomInfoEntry*>(0)->value),
67 "CrashKey and CustomInfoEntry structs are not compatible.");
69 // Assign a GUID that can be used to correlate the Kasko report to the
70 // Breakpad report, to verify data consistency.
71 std::string guid = base::GenerateGUID();
73 base::debug::ScopedCrashKey kasko_guid(crash_keys::kKaskoGuid, guid);
74 size_t crash_key_count =
75 breakpad::CrashKeysWin::keeper()->custom_info_entries().size();
76 const kasko::api::CrashKey* crash_keys =
77 reinterpret_cast<const kasko::api::CrashKey*>(
78 breakpad::CrashKeysWin::keeper()->custom_info_entries().data());
80 if (g_chrome_watcher_client &&
81 g_chrome_watcher_client->EnsureInitialized()) {
82 kasko::api::SendReport(info, g_minidump_type, protobuf, protobuf_length,
83 crash_keys, crash_key_count);
88 base::debug::ScopedCrashKey kasko_equivalent_guid(
89 crash_keys::kKaskoEquivalentGuid, guid);
90 // While Kasko remains experimental, also report via Breakpad.
91 base::win::WinProcExceptionFilter crash_for_exception =
92 reinterpret_cast<base::win::WinProcExceptionFilter>(::GetProcAddress(
93 ::GetModuleHandle(chrome::kBrowserProcessExecutableName),
94 "CrashForException"));
95 crash_for_exception(info);
99 #endif // defined(KASKO)