Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(543)

Side by Side Diff: chrome_frame/crash_server_init.cc

Issue 7219007: Fix up crash reporting in unit tests and the Chrome Frame helper processes: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome_frame/crash_server_init.h" 5 #include "chrome_frame/crash_server_init.h"
6 6
7 #include <sddl.h>
8 #include <Shlobj.h>
9 #include <stdlib.h>
7 #include "version.h" // NOLINT 10 #include "version.h" // NOLINT
8 11
9 const wchar_t kChromePipeName[] = L"\\\\.\\pipe\\ChromeCrashServices"; 12 const wchar_t kChromePipeName[] = L"\\\\.\\pipe\\ChromeCrashServices";
10 const wchar_t kGoogleUpdatePipeName[] = L"\\\\.\\pipe\\GoogleCrashServices\\"; 13 const wchar_t kGoogleUpdatePipeName[] = L"\\\\.\\pipe\\GoogleCrashServices\\";
11 const wchar_t kSystemPrincipalSid[] = L"S-1-5-18"; 14 const wchar_t kSystemPrincipalSid[] = L"S-1-5-18";
12 15
13 const wchar_t kFullMemoryCrashReport[] = L"full-memory-crash-report";
14
15 const MINIDUMP_TYPE kLargerDumpType = static_cast<MINIDUMP_TYPE>( 16 const MINIDUMP_TYPE kLargerDumpType = static_cast<MINIDUMP_TYPE>(
16 MiniDumpWithProcessThreadData | // Get PEB and TEB. 17 MiniDumpWithProcessThreadData | // Get PEB and TEB.
17 MiniDumpWithUnloadedModules | // Get unloaded modules when available. 18 MiniDumpWithUnloadedModules | // Get unloaded modules when available.
18 MiniDumpWithIndirectlyReferencedMemory); // Get memory referenced by stack. 19 MiniDumpWithIndirectlyReferencedMemory); // Get memory referenced by stack.
19 20
21 extern "C" IMAGE_DOS_HEADER __ImageBase;
22
23 // Builds a string representation of the user's SID and places it in user_sid.
24 bool GetUserSidString(std::wstring* user_sid) {
25 bool success = false;
26 if (user_sid) {
27 struct {
28 TOKEN_USER token_user;
29 BYTE buffer[SECURITY_MAX_SID_SIZE];
30 } token_info_buffer;
31
32 HANDLE token = NULL;
33 if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token)) {
34 DWORD out_size;
35 if (GetTokenInformation(token, TokenUser, &token_info_buffer.token_user,
36 sizeof(token_info_buffer), &out_size)) {
37 wchar_t* user_sid_value = NULL;
38 if (token_info_buffer.token_user.User.Sid &&
39 ConvertSidToStringSid(token_info_buffer.token_user.User.Sid,
40 &user_sid_value)) {
41 *user_sid = user_sid_value;
42 LocalFree(user_sid_value);
43 user_sid_value = NULL;
44 success = true;
45 }
46 }
47 CloseHandle(token);
48 }
49 }
50
51 return success;
52 }
53
54 bool IsRunningSystemInstall() {
55 wchar_t exe_path[MAX_PATH * 2] = {0};
56 GetModuleFileName(reinterpret_cast<HMODULE>(&__ImageBase),
57 exe_path,
58 _countof(exe_path));
59
60 bool is_system = false;
61
62 wchar_t program_files_path[MAX_PATH] = {0};
63 if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL,
64 SHGFP_TYPE_CURRENT, program_files_path))) {
65 if (wcsstr(exe_path, program_files_path) == exe_path) {
66 is_system = true;
67 }
68 }
69
70 return is_system;
71 }
72
20 google_breakpad::CustomClientInfo* GetCustomInfo() { 73 google_breakpad::CustomClientInfo* GetCustomInfo() {
21 static google_breakpad::CustomInfoEntry ver_entry( 74 static google_breakpad::CustomInfoEntry ver_entry(
22 L"ver", TEXT(CHROME_VERSION_STRING)); 75 L"ver", TEXT(CHROME_VERSION_STRING));
23 static google_breakpad::CustomInfoEntry prod_entry(L"prod", L"ChromeFrame"); 76 static google_breakpad::CustomInfoEntry prod_entry(L"prod", L"ChromeFrame");
24 static google_breakpad::CustomInfoEntry plat_entry(L"plat", L"Win32"); 77 static google_breakpad::CustomInfoEntry plat_entry(L"plat", L"Win32");
25 static google_breakpad::CustomInfoEntry type_entry(L"ptype", L"chrome_frame"); 78 static google_breakpad::CustomInfoEntry type_entry(L"ptype", L"chrome_frame");
26 static google_breakpad::CustomInfoEntry entries[] = { 79 static google_breakpad::CustomInfoEntry entries[] = {
27 ver_entry, prod_entry, plat_entry, type_entry }; 80 ver_entry, prod_entry, plat_entry, type_entry };
28 static google_breakpad::CustomClientInfo custom_info = { 81 static google_breakpad::CustomClientInfo custom_info = {
29 entries, ARRAYSIZE(entries) }; 82 entries, ARRAYSIZE(entries) };
30 return &custom_info; 83 return &custom_info;
31 } 84 }
32 85
33 google_breakpad::ExceptionHandler* InitializeCrashReporting( 86 google_breakpad::ExceptionHandler* InitializeCrashReporting(
34 const wchar_t* cmd_line) { 87 CrashReportingMode flags) {
grt (UTC plus 2) 2011/06/23 03:28:22 flags -> mode
robertshield 2011/06/23 13:52:08 Done.
35 if (cmd_line == NULL) {
36 return NULL;
37 }
38
39 wchar_t temp_path[MAX_PATH + 1] = {0}; 88 wchar_t temp_path[MAX_PATH + 1] = {0};
40 DWORD path_len = ::GetTempPath(MAX_PATH, temp_path); 89 DWORD path_len = ::GetTempPath(MAX_PATH, temp_path);
41 90
42 std::wstring pipe_name; 91 std::wstring pipe_name;
43 if (wcsstr(cmd_line, kFullMemoryCrashReport) != NULL) { 92 if (flags == HEADLESS) {
93 // This flag is used for testing, connect to the test crash service.
44 pipe_name = kChromePipeName; 94 pipe_name = kChromePipeName;
45 } else { 95 } else {
46 // TODO(robertshield): Figure out if we're a per-user install and connect 96 // Otherwise, build a pipe name corresponding to either user or
47 // to the per-user named pipe instead. 97 // system-level Omaha.
48 pipe_name = kGoogleUpdatePipeName; 98 pipe_name = kGoogleUpdatePipeName;
49 pipe_name += kSystemPrincipalSid; 99 if (IsRunningSystemInstall()) {
100 pipe_name += kSystemPrincipalSid;
101 } else {
102 std::wstring user_sid;
103 if (GetUserSidString(&user_sid)) {
104 pipe_name += user_sid;
105 } else {
106 // We don't think we're a system install, but we couldn't get the
107 // user SID. Try connecting to the system-level crash service as a
108 // last ditch effort.
109 pipe_name += kSystemPrincipalSid;
110 }
111 }
50 } 112 }
51 113
52 google_breakpad::ExceptionHandler* breakpad = 114 google_breakpad::ExceptionHandler* breakpad =
53 new google_breakpad::ExceptionHandler( 115 new google_breakpad::ExceptionHandler(
54 temp_path, NULL, NULL, NULL, 116 temp_path, NULL, NULL, NULL,
55 google_breakpad::ExceptionHandler::HANDLER_ALL, kLargerDumpType, 117 google_breakpad::ExceptionHandler::HANDLER_ALL, kLargerDumpType,
56 pipe_name.c_str(), GetCustomInfo()); 118 pipe_name.c_str(), GetCustomInfo());
57 119
58 return breakpad; 120 return breakpad;
59 } 121 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698