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