Skip to content

Commit

Permalink
Add crash reporting to the long running Chrome Frame helper process.
Browse files Browse the repository at this point in the history
BUG=53127
TEST=chrome_frame_helper.exe connects to the crash process.

Review URL: http://codereview.chromium.org/3287008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58530 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
robertshield@chromium.org committed Sep 3, 2010
1 parent e2abdeb commit e4fe427
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 72 deletions.
10 changes: 9 additions & 1 deletion chrome_frame/chrome_frame.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,16 @@
'type': 'static_library',
'dependencies': [
'../base/base.gyp:base_i18n',
],
'../breakpad/breakpad.gyp:breakpad_handler',
'../chrome/chrome.gyp:chrome_version_header',
],
'include_dirs': [
# To allow including "chrome_tab.h"
'<(SHARED_INTERMEDIATE_DIR)',
],
'sources': [
'crash_server_init.cc',
'crash_server_init.h',
'simple_resource_loader.cc',
'simple_resource_loader.h',
],
Expand Down
7 changes: 5 additions & 2 deletions chrome_frame/chrome_frame_helper_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <crtdbg.h>
#include <windows.h>

#include "chrome_frame/crash_server_init.h"

// Window class and window names.
const wchar_t kChromeFrameHelperWindowClassName[] =
L"ChromeFrameHelperWindowClass";
Expand Down Expand Up @@ -100,8 +102,9 @@ HWND RegisterAndCreateWindow(HINSTANCE hinstance) {
}

int APIENTRY wWinMain(HINSTANCE hinstance, HINSTANCE, wchar_t*, int show_cmd) {
// TODO(robertshield): Before this actually gets used, add breakpad
// integration.
const wchar_t* cmd_line = ::GetCommandLine();
google_breakpad::scoped_ptr<google_breakpad::ExceptionHandler> breakpad(
InitializeCrashReporting(cmd_line));

// Create a window with a known class and title just to listen for WM_CLOSE
// messages that will shut us down.
Expand Down
4 changes: 3 additions & 1 deletion chrome_frame/chrome_frame_launcher.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
'dependencies': [
'../breakpad/breakpad.gyp:breakpad_handler',
'../chrome/chrome.gyp:chrome_version_header',
'chrome_frame.gyp:chrome_frame_utils',
],
'resource_include_dirs': [
'<(INTERMEDIATE_DIR)',
Expand All @@ -90,7 +91,7 @@
'shlwapi.lib',
],
},
},
},
},
{
'target_name': 'chrome_frame_helper',
Expand All @@ -99,6 +100,7 @@
'dependencies': [
'../breakpad/breakpad.gyp:breakpad_handler',
'../chrome/chrome.gyp:chrome_version_header',
'chrome_frame.gyp:chrome_frame_utils',
'chrome_frame_helper_dll',
],
'resource_include_dirs': [
Expand Down
69 changes: 1 addition & 68 deletions chrome_frame/chrome_launcher_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,75 +8,8 @@
#include <string>

#include "chrome_frame/chrome_launcher.h"
#include "breakpad/src/client/windows/handler/exception_handler.h"
#include "chrome_frame/crash_server_init.h"

// TODO(robertshield): Much of the crash report init code is shared with CF and
// probably Chrome too. If this pans out, consider refactoring it into a
// common lib.

namespace {

// Possible names for Pipes:
// Headless (testing) mode: "NamedPipe\ChromeCrashServices"
// System-wide install: "NamedPipe\GoogleCrashServices\S-1-5-18"
// Per-user install: "NamedPipe\GoogleCrashServices\<user SID>"
const wchar_t kChromePipeName[] = L"\\\\.\\pipe\\ChromeCrashServices";
const wchar_t kGoogleUpdatePipeName[] = L"\\\\.\\pipe\\GoogleCrashServices\\";
const wchar_t kSystemPrincipalSid[] = L"S-1-5-18";

// Assume this implies headless mode and use kChromePipeName if it shows
// up in the command line.
const wchar_t kFullMemoryCrashReport[] = L"full-memory-crash-report";

const MINIDUMP_TYPE kLargerDumpType = static_cast<MINIDUMP_TYPE>(
MiniDumpWithProcessThreadData | // Get PEB and TEB.
MiniDumpWithUnloadedModules | // Get unloaded modules when available.
MiniDumpWithIndirectlyReferencedMemory); // Get memory referenced by stack.

} // namespace

google_breakpad::CustomClientInfo* GetCustomInfo() {
// TODO(robertshield): Populate this with actual data.
std::wstring product(L"ChromeFrame");
std::wstring version(L"0.1.0.0");
static google_breakpad::CustomInfoEntry ver_entry(L"ver", version.c_str());
static google_breakpad::CustomInfoEntry prod_entry(L"prod", product.c_str());
static google_breakpad::CustomInfoEntry plat_entry(L"plat", L"Win32");
static google_breakpad::CustomInfoEntry type_entry(L"ptype", L"chrome_frame");
static google_breakpad::CustomInfoEntry entries[] = {
ver_entry, prod_entry, plat_entry, type_entry };
static google_breakpad::CustomClientInfo custom_info = {
entries, arraysize(entries) };
return &custom_info;
}

google_breakpad::ExceptionHandler* InitializeCrashReporting(
const wchar_t* cmd_line) {
if (cmd_line == NULL) {
return NULL;
}

wchar_t temp_path[MAX_PATH + 1] = {0};
DWORD path_len = ::GetTempPath(MAX_PATH, temp_path);

std::wstring pipe_name;
if (wcsstr(cmd_line, kFullMemoryCrashReport) != NULL) {
pipe_name = kChromePipeName;
} else {
// TODO(robertshield): Figure out if we're a per-user install and connect
// to the per-user named pipe instead.
pipe_name = kGoogleUpdatePipeName;
pipe_name += kSystemPrincipalSid;
}

google_breakpad::ExceptionHandler* breakpad =
new google_breakpad::ExceptionHandler(
temp_path, NULL, NULL, NULL,
google_breakpad::ExceptionHandler::HANDLER_ALL, kLargerDumpType,
pipe_name.c_str(), GetCustomInfo());

return breakpad;
}

int APIENTRY wWinMain(HINSTANCE, HINSTANCE, wchar_t*, int) {
const wchar_t* cmd_line = ::GetCommandLine();
Expand Down
59 changes: 59 additions & 0 deletions chrome_frame/crash_server_init.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome_frame/crash_server_init.h"

#include "version.h" // NOLINT

const wchar_t kChromePipeName[] = L"\\\\.\\pipe\\ChromeCrashServices";
const wchar_t kGoogleUpdatePipeName[] = L"\\\\.\\pipe\\GoogleCrashServices\\";
const wchar_t kSystemPrincipalSid[] = L"S-1-5-18";

const wchar_t kFullMemoryCrashReport[] = L"full-memory-crash-report";

const MINIDUMP_TYPE kLargerDumpType = static_cast<MINIDUMP_TYPE>(
MiniDumpWithProcessThreadData | // Get PEB and TEB.
MiniDumpWithUnloadedModules | // Get unloaded modules when available.
MiniDumpWithIndirectlyReferencedMemory); // Get memory referenced by stack.

google_breakpad::CustomClientInfo* GetCustomInfo() {
static google_breakpad::CustomInfoEntry ver_entry(
L"ver", TEXT(CHROME_VERSION_STRING));
static google_breakpad::CustomInfoEntry prod_entry(L"prod", L"ChromeFrame");
static google_breakpad::CustomInfoEntry plat_entry(L"plat", L"Win32");
static google_breakpad::CustomInfoEntry type_entry(L"ptype", L"chrome_frame");
static google_breakpad::CustomInfoEntry entries[] = {
ver_entry, prod_entry, plat_entry, type_entry };
static google_breakpad::CustomClientInfo custom_info = {
entries, ARRAYSIZE(entries) };
return &custom_info;
}

google_breakpad::ExceptionHandler* InitializeCrashReporting(
const wchar_t* cmd_line) {
if (cmd_line == NULL) {
return NULL;
}

wchar_t temp_path[MAX_PATH + 1] = {0};
DWORD path_len = ::GetTempPath(MAX_PATH, temp_path);

std::wstring pipe_name;
if (wcsstr(cmd_line, kFullMemoryCrashReport) != NULL) {
pipe_name = kChromePipeName;
} else {
// TODO(robertshield): Figure out if we're a per-user install and connect
// to the per-user named pipe instead.
pipe_name = kGoogleUpdatePipeName;
pipe_name += kSystemPrincipalSid;
}

google_breakpad::ExceptionHandler* breakpad =
new google_breakpad::ExceptionHandler(
temp_path, NULL, NULL, NULL,
google_breakpad::ExceptionHandler::HANDLER_ALL, kLargerDumpType,
pipe_name.c_str(), GetCustomInfo());

return breakpad;
}
34 changes: 34 additions & 0 deletions chrome_frame/crash_server_init.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_FRAME_CRASH_SERVER_INIT_H_
#define CHROME_FRAME_CRASH_SERVER_INIT_H_

#include "breakpad/src/client/windows/handler/exception_handler.h"

// Possible names for Pipes:
// Headless (testing) mode: "NamedPipe\ChromeCrashServices"
// System-wide install: "NamedPipe\GoogleCrashServices\S-1-5-18"
// Per-user install: "NamedPipe\GoogleCrashServices\<user SID>"
extern const wchar_t kChromePipeName[];
extern const wchar_t kGoogleUpdatePipeName[];
extern const wchar_t kSystemPrincipalSid[];

// Assume this implies headless mode and use kChromePipeName if it shows
// up in the command line.
extern const wchar_t kFullMemoryCrashReport[];

extern const MINIDUMP_TYPE kLargerDumpType;

// Returns a pointer to a static instance of a CustomClientInfo structure
// containing Chrome Frame specific data.
google_breakpad::CustomClientInfo* GetCustomInfo();

// Initializes breakpad crash reporting and returns a pointer to a newly
// constructed ExceptionHandler object. It is the responsibility of the caller
// to delete this object which will shut down the crash reporting machinery.
google_breakpad::ExceptionHandler* InitializeCrashReporting(
const wchar_t* cmd_line);

#endif // CHROME_FRAME_CRASH_SERVER_INIT_H_

0 comments on commit e4fe427

Please sign in to comment.