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

Side by Side Diff: headless/lib/browser/headless_content_browser_client.cc

Issue 2693943004: headless: Add support for minidump generation on Linux (Closed)
Patch Set: Review comments Created 3 years, 10 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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 "headless/lib/browser/headless_content_browser_client.h" 5 #include "headless/lib/browser/headless_content_browser_client.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <unordered_set> 8 #include <unordered_set>
9 9
10 #include "base/base_switches.h"
10 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/command_line.h"
11 #include "base/json/json_reader.h" 13 #include "base/json/json_reader.h"
12 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/path_service.h"
13 #include "content/public/browser/browser_context.h" 16 #include "content/public/browser/browser_context.h"
14 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/render_process_host.h" 18 #include "content/public/browser/render_process_host.h"
16 #include "content/public/browser/render_view_host.h" 19 #include "content/public/browser/render_view_host.h"
17 #include "content/public/browser/storage_partition.h" 20 #include "content/public/browser/storage_partition.h"
21 #include "content/public/common/content_switches.h"
18 #include "content/public/common/service_names.mojom.h" 22 #include "content/public/common/service_names.mojom.h"
19 #include "headless/grit/headless_lib_resources.h" 23 #include "headless/grit/headless_lib_resources.h"
20 #include "headless/lib/browser/headless_browser_context_impl.h" 24 #include "headless/lib/browser/headless_browser_context_impl.h"
21 #include "headless/lib/browser/headless_browser_impl.h" 25 #include "headless/lib/browser/headless_browser_impl.h"
22 #include "headless/lib/browser/headless_browser_main_parts.h" 26 #include "headless/lib/browser/headless_browser_main_parts.h"
23 #include "headless/lib/browser/headless_devtools_manager_delegate.h" 27 #include "headless/lib/browser/headless_devtools_manager_delegate.h"
28 #include "headless/lib/headless_macros.h"
24 #include "storage/browser/quota/quota_settings.h" 29 #include "storage/browser/quota/quota_settings.h"
25 #include "ui/base/resource/resource_bundle.h" 30 #include "ui/base/resource/resource_bundle.h"
26 31
32 #if defined(HEADLESS_USE_BREAKPAD)
33 #include "base/debug/leak_annotations.h"
34 #include "components/crash/content/app/breakpad_linux.h"
35 #include "components/crash/content/browser/crash_handler_host_linux.h"
36 #include "content/public/common/content_descriptors.h"
37 #endif // defined(HEADLESS_USE_BREAKPAD)
38
27 namespace headless { 39 namespace headless {
28 40
29 namespace { 41 namespace {
30 const char kCapabilityPath[] = 42 const char kCapabilityPath[] =
31 "interface_provider_specs.navigation:frame.provides.renderer"; 43 "interface_provider_specs.navigation:frame.provides.renderer";
44
45 #if defined(HEADLESS_USE_BREAKPAD)
46 breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost(
47 const std::string& process_type,
48 const HeadlessBrowser::Options& options) {
49 base::FilePath dumps_path = options.crash_dumps_dir;
50 if (dumps_path.empty()) {
51 bool ok = PathService::Get(base::DIR_MODULE, &dumps_path);
52 DCHECK(ok);
53 }
54
55 {
56 ANNOTATE_SCOPED_MEMORY_LEAK;
57 #if defined(OFFICIAL_BUILD)
58 // Upload crash dumps in official builds, unless we're running in unattended
59 // mode (not to be confused with headless mode in general -- see
60 // chrome/common/env_vars.cc).
61 static const char kHeadless[] = "CHROME_HEADLESS";
62 bool upload = (getenv(kHeadless) == nullptr);
63 #else
64 bool upload = false;
65 #endif
66 breakpad::CrashHandlerHostLinux* crash_handler =
67 new breakpad::CrashHandlerHostLinux(process_type, dumps_path, upload);
68 crash_handler->StartUploaderThread();
69 return crash_handler;
70 }
71 }
72
73 int GetCrashSignalFD(const base::CommandLine& command_line,
74 const HeadlessBrowser::Options& options) {
75 if (!breakpad::IsCrashReporterEnabled())
76 return -1;
77
78 std::string process_type =
79 command_line.GetSwitchValueASCII(switches::kProcessType);
80
81 if (process_type == switches::kRendererProcess) {
82 static breakpad::CrashHandlerHostLinux* crash_handler =
83 CreateCrashHandlerHost(process_type, options);
84 return crash_handler->GetDeathSignalSocket();
85 }
86
87 if (process_type == switches::kPpapiPluginProcess) {
88 static breakpad::CrashHandlerHostLinux* crash_handler =
89 CreateCrashHandlerHost(process_type, options);
90 return crash_handler->GetDeathSignalSocket();
91 }
92
93 if (process_type == switches::kGpuProcess) {
94 static breakpad::CrashHandlerHostLinux* crash_handler =
95 CreateCrashHandlerHost(process_type, options);
96 return crash_handler->GetDeathSignalSocket();
97 }
98
99 return -1;
100 }
101 #endif // defined(HEADLESS_USE_BREAKPAD)
102
32 } // namespace 103 } // namespace
33 104
34 HeadlessContentBrowserClient::HeadlessContentBrowserClient( 105 HeadlessContentBrowserClient::HeadlessContentBrowserClient(
35 HeadlessBrowserImpl* browser) 106 HeadlessBrowserImpl* browser)
36 : browser_(browser) {} 107 : browser_(browser) {}
37 108
38 HeadlessContentBrowserClient::~HeadlessContentBrowserClient() {} 109 HeadlessContentBrowserClient::~HeadlessContentBrowserClient() {}
39 110
40 content::BrowserMainParts* HeadlessContentBrowserClient::CreateBrowserMainParts( 111 content::BrowserMainParts* HeadlessContentBrowserClient::CreateBrowserMainParts(
41 const content::MainFunctionParams&) { 112 const content::MainFunctionParams&) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 content::BrowserContext* context, 163 content::BrowserContext* context,
93 content::StoragePartition* partition, 164 content::StoragePartition* partition,
94 const storage::OptionalQuotaSettingsCallback& callback) { 165 const storage::OptionalQuotaSettingsCallback& callback) {
95 content::BrowserThread::PostTaskAndReplyWithResult( 166 content::BrowserThread::PostTaskAndReplyWithResult(
96 content::BrowserThread::FILE, FROM_HERE, 167 content::BrowserThread::FILE, FROM_HERE,
97 base::Bind(&storage::CalculateNominalDynamicSettings, 168 base::Bind(&storage::CalculateNominalDynamicSettings,
98 partition->GetPath(), context->IsOffTheRecord()), 169 partition->GetPath(), context->IsOffTheRecord()),
99 callback); 170 callback);
100 } 171 }
101 172
173 void HeadlessContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
174 const base::CommandLine& command_line,
175 int child_process_id,
176 content::FileDescriptorInfo* mappings) {
177 #if defined(HEADLESS_USE_BREAKPAD)
178 int crash_signal_fd = GetCrashSignalFD(command_line, *browser_->options());
179 if (crash_signal_fd >= 0)
180 mappings->Share(kCrashDumpSignal, crash_signal_fd);
181 #endif // defined(HEADLESS_USE_BREAKPAD)
182 }
183
184 void HeadlessContentBrowserClient::AppendExtraCommandLineSwitches(
185 base::CommandLine* command_line,
186 int child_process_id) {
187 #if defined(HEADLESS_USE_BREAKPAD)
188 // This flag tells child processes to also turn on crash reporting.
189 if (breakpad::IsCrashReporterEnabled())
190 command_line->AppendSwitch(switches::kEnableCrashReporter);
191 #endif // defined(HEADLESS_USE_BREAKPAD)
192 }
193
102 } // namespace headless 194 } // namespace headless
OLDNEW
« no previous file with comments | « headless/lib/browser/headless_content_browser_client.h ('k') | headless/lib/embedder_mojo_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698