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

Side by Side Diff: headless/lib/headless_content_main_delegate.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/headless_content_main_delegate.h" 5 #include "headless/lib/headless_content_main_delegate.h"
6 6
7 #include "base/base_switches.h"
7 #include "base/command_line.h" 8 #include "base/command_line.h"
8 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/lazy_instance.h"
9 #include "base/path_service.h" 11 #include "base/path_service.h"
10 #include "base/run_loop.h" 12 #include "base/run_loop.h"
11 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
12 #include "base/trace_event/trace_event.h" 14 #include "base/trace_event/trace_event.h"
15 #include "components/crash/content/app/breakpad_linux.h"
13 #include "content/public/browser/browser_main_runner.h" 16 #include "content/public/browser/browser_main_runner.h"
14 #include "content/public/common/content_switches.h" 17 #include "content/public/common/content_switches.h"
15 #include "headless/lib/browser/headless_browser_impl.h" 18 #include "headless/lib/browser/headless_browser_impl.h"
16 #include "headless/lib/browser/headless_content_browser_client.h" 19 #include "headless/lib/browser/headless_content_browser_client.h"
20 #include "headless/lib/headless_crash_reporter_client.h"
21 #include "headless/lib/headless_macros.h"
17 #include "ui/base/resource/resource_bundle.h" 22 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/base/ui_base_switches.h" 23 #include "ui/base/ui_base_switches.h"
19 #include "ui/gfx/switches.h" 24 #include "ui/gfx/switches.h"
20 #include "ui/gl/gl_switches.h" 25 #include "ui/gl/gl_switches.h"
21 #include "ui/ozone/public/ozone_switches.h" 26 #include "ui/ozone/public/ozone_switches.h"
22 27
23 #ifdef HEADLESS_USE_EMBEDDED_RESOURCES 28 #ifdef HEADLESS_USE_EMBEDDED_RESOURCES
24 #include "headless/embedded_resource_pak.h" 29 #include "headless/embedded_resource_pak.h"
25 #endif 30 #endif
26 31
27 namespace headless { 32 namespace headless {
28 namespace { 33 namespace {
29 // Keep in sync with content/common/content_constants_internal.h. 34 // Keep in sync with content/common/content_constants_internal.h.
30 // TODO(skyostil): Add a tracing test for this. 35 // TODO(skyostil): Add a tracing test for this.
31 const int kTraceEventBrowserProcessSortIndex = -6; 36 const int kTraceEventBrowserProcessSortIndex = -6;
32 37
33 HeadlessContentMainDelegate* g_current_headless_content_main_delegate = nullptr; 38 HeadlessContentMainDelegate* g_current_headless_content_main_delegate = nullptr;
39
40 base::LazyInstance<HeadlessCrashReporterClient>::Leaky g_headless_crash_client =
41 LAZY_INSTANCE_INITIALIZER;
34 } // namespace 42 } // namespace
35 43
36 HeadlessContentMainDelegate::HeadlessContentMainDelegate( 44 HeadlessContentMainDelegate::HeadlessContentMainDelegate(
37 std::unique_ptr<HeadlessBrowserImpl> browser) 45 std::unique_ptr<HeadlessBrowserImpl> browser)
38 : content_client_(browser->options()), browser_(std::move(browser)) { 46 : content_client_(browser->options()), browser_(std::move(browser)) {
39 DCHECK(!g_current_headless_content_main_delegate); 47 DCHECK(!g_current_headless_content_main_delegate);
40 g_current_headless_content_main_delegate = this; 48 g_current_headless_content_main_delegate = this;
41 } 49 }
42 50
43 HeadlessContentMainDelegate::~HeadlessContentMainDelegate() { 51 HeadlessContentMainDelegate::~HeadlessContentMainDelegate() {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 132
125 settings.logging_dest = log_mode; 133 settings.logging_dest = log_mode;
126 settings.log_file = log_path.value().c_str(); 134 settings.log_file = log_path.value().c_str();
127 settings.lock_log = logging::DONT_LOCK_LOG_FILE; 135 settings.lock_log = logging::DONT_LOCK_LOG_FILE;
128 settings.delete_old = process_type.empty() ? logging::DELETE_OLD_LOG_FILE 136 settings.delete_old = process_type.empty() ? logging::DELETE_OLD_LOG_FILE
129 : logging::APPEND_TO_OLD_LOG_FILE; 137 : logging::APPEND_TO_OLD_LOG_FILE;
130 bool success = logging::InitLogging(settings); 138 bool success = logging::InitLogging(settings);
131 DCHECK(success); 139 DCHECK(success);
132 } 140 }
133 141
142 void HeadlessContentMainDelegate::InitCrashReporter(
143 const base::CommandLine& command_line) {
144 const std::string process_type =
145 command_line.GetSwitchValueASCII(switches::kProcessType);
146 crash_reporter::SetCrashReporterClient(g_headless_crash_client.Pointer());
147 g_headless_crash_client.Pointer()->set_crash_dumps_dir(
148 browser_->options()->crash_dumps_dir);
149
150 if (!browser_->options()->enable_crash_reporter) {
151 DCHECK(!breakpad::IsCrashReporterEnabled());
152 return;
153 }
154 #if defined(HEADLESS_USE_BREAKPAD)
155 if (process_type != switches::kZygoteProcess)
156 breakpad::InitCrashReporter(process_type);
157 #endif // defined(HEADLESS_USE_BREAKPAD)
158 }
159
134 void HeadlessContentMainDelegate::PreSandboxStartup() { 160 void HeadlessContentMainDelegate::PreSandboxStartup() {
135 InitLogging(*base::CommandLine::ForCurrentProcess()); 161 const base::CommandLine& command_line(
162 *base::CommandLine::ForCurrentProcess());
163 const std::string process_type =
164 command_line.GetSwitchValueASCII(switches::kProcessType);
165 InitLogging(command_line);
166 InitCrashReporter(command_line);
136 InitializeResourceBundle(); 167 InitializeResourceBundle();
137 } 168 }
138 169
139 int HeadlessContentMainDelegate::RunProcess( 170 int HeadlessContentMainDelegate::RunProcess(
140 const std::string& process_type, 171 const std::string& process_type,
141 const content::MainFunctionParams& main_function_params) { 172 const content::MainFunctionParams& main_function_params) {
142 if (!process_type.empty()) 173 if (!process_type.empty())
143 return -1; 174 return -1;
144 175
145 base::trace_event::TraceLog::GetInstance()->SetProcessName("HeadlessBrowser"); 176 base::trace_event::TraceLog::GetInstance()->SetProcessName("HeadlessBrowser");
(...skipping 10 matching lines...) Expand all
156 browser_->RunOnStartCallback(); 187 browser_->RunOnStartCallback();
157 browser_runner->Run(); 188 browser_runner->Run();
158 browser_.reset(); 189 browser_.reset();
159 browser_runner->Shutdown(); 190 browser_runner->Shutdown();
160 191
161 // Return value >=0 here to disable calling content::BrowserMain. 192 // Return value >=0 here to disable calling content::BrowserMain.
162 return 0; 193 return 0;
163 } 194 }
164 195
165 void HeadlessContentMainDelegate::ZygoteForked() { 196 void HeadlessContentMainDelegate::ZygoteForked() {
166 // TODO(skyostil): Disable the zygote host. 197 const base::CommandLine& command_line(
198 *base::CommandLine::ForCurrentProcess());
199 const std::string process_type =
200 command_line.GetSwitchValueASCII(switches::kProcessType);
201 // Unconditionally try to turn on crash reporting since we do not have access
202 // to the latest browser options at this point when testing. Breakpad will
203 // bail out gracefully if the browser process hasn't enabled crash reporting.
204 breakpad::InitCrashReporter(process_type);
167 } 205 }
168 206
169 // static 207 // static
170 HeadlessContentMainDelegate* HeadlessContentMainDelegate::GetInstance() { 208 HeadlessContentMainDelegate* HeadlessContentMainDelegate::GetInstance() {
171 return g_current_headless_content_main_delegate; 209 return g_current_headless_content_main_delegate;
172 } 210 }
173 211
174 // static 212 // static
175 void HeadlessContentMainDelegate::InitializeResourceBundle() { 213 void HeadlessContentMainDelegate::InitializeResourceBundle() {
176 base::FilePath dir_module; 214 base::FilePath dir_module;
(...skipping 24 matching lines...) Expand all
201 #endif 239 #endif
202 } 240 }
203 241
204 content::ContentBrowserClient* 242 content::ContentBrowserClient*
205 HeadlessContentMainDelegate::CreateContentBrowserClient() { 243 HeadlessContentMainDelegate::CreateContentBrowserClient() {
206 browser_client_.reset(new HeadlessContentBrowserClient(browser_.get())); 244 browser_client_.reset(new HeadlessContentBrowserClient(browser_.get()));
207 return browser_client_.get(); 245 return browser_client_.get();
208 } 246 }
209 247
210 } // namespace headless 248 } // namespace headless
OLDNEW
« no previous file with comments | « headless/lib/headless_content_main_delegate.h ('k') | headless/lib/headless_crash_reporter_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698