Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / win8 / delegate_execute / crash_server_init.cc
blob127265272f260f55b9b6bd59fac28c8e06161227
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.
5 #include "win8/delegate_execute/crash_server_init.h"
7 #include <shlobj.h>
8 #include <windows.h>
10 #include <cwchar>
12 #include "base/file_version_info.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/win/win_util.h"
15 #include "breakpad/src/client/windows/handler/exception_handler.h"
17 const wchar_t kGoogleUpdatePipeName[] = L"\\\\.\\pipe\\GoogleCrashServices\\";
18 const wchar_t kSystemPrincipalSid[] = L"S-1-5-18";
20 const MINIDUMP_TYPE kLargerDumpType = static_cast<MINIDUMP_TYPE>(
21 MiniDumpWithProcessThreadData | // Get PEB and TEB.
22 MiniDumpWithUnloadedModules | // Get unloaded modules when available.
23 MiniDumpWithIndirectlyReferencedMemory); // Get memory referenced by stack.
25 extern "C" IMAGE_DOS_HEADER __ImageBase;
27 namespace {
29 bool IsRunningSystemInstall() {
30 wchar_t exe_path[MAX_PATH * 2] = {0};
31 GetModuleFileName(reinterpret_cast<HMODULE>(&__ImageBase),
32 exe_path,
33 _countof(exe_path));
35 bool is_system = false;
37 wchar_t program_files_path[MAX_PATH] = {0};
38 if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL,
39 SHGFP_TYPE_CURRENT, program_files_path))) {
40 if (wcsstr(exe_path, program_files_path) == exe_path) {
41 is_system = true;
45 return is_system;
48 google_breakpad::CustomClientInfo* GetCustomInfo() {
49 scoped_ptr<FileVersionInfo> version_info(
50 FileVersionInfo::CreateFileVersionInfoForCurrentModule());
52 static google_breakpad::CustomInfoEntry ver_entry(
53 L"ver", version_info->file_version().c_str());
54 static google_breakpad::CustomInfoEntry prod_entry(L"prod", L"Chrome");
55 static google_breakpad::CustomInfoEntry plat_entry(L"plat", L"Win32");
56 static google_breakpad::CustomInfoEntry type_entry(L"ptype",
57 L"delegate_execute");
58 static google_breakpad::CustomInfoEntry entries[] = {
59 ver_entry, prod_entry, plat_entry, type_entry };
60 static google_breakpad::CustomClientInfo custom_info = {
61 entries, ARRAYSIZE(entries) };
62 return &custom_info;
65 } // namespace
67 namespace delegate_execute {
69 scoped_ptr<google_breakpad::ExceptionHandler> InitializeCrashReporting() {
70 wchar_t temp_path[MAX_PATH + 1] = {0};
71 ::GetTempPath(MAX_PATH, temp_path);
73 base::string16 pipe_name;
74 pipe_name = kGoogleUpdatePipeName;
75 if (IsRunningSystemInstall()) {
76 pipe_name += kSystemPrincipalSid;
77 } else {
78 base::string16 user_sid;
79 if (base::win::GetUserSidString(&user_sid)) {
80 pipe_name += user_sid;
81 } else {
82 // We don't think we're a system install, but we couldn't get the
83 // user SID. Try connecting to the system-level crash service as a
84 // last ditch effort.
85 pipe_name += kSystemPrincipalSid;
89 return scoped_ptr<google_breakpad::ExceptionHandler>(
90 new google_breakpad::ExceptionHandler(
91 temp_path, NULL, NULL, NULL,
92 google_breakpad::ExceptionHandler::HANDLER_ALL, kLargerDumpType,
93 pipe_name.c_str(), GetCustomInfo()));
96 } // namespace delegate_execute