Chromium Code Reviews| 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/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" |
| 24 #include "storage/browser/quota/quota_settings.h" | 28 #include "storage/browser/quota/quota_settings.h" |
| 25 #include "ui/base/resource/resource_bundle.h" | 29 #include "ui/base/resource/resource_bundle.h" |
| 26 | 30 |
| 31 #if defined(OS_POSIX) && !defined(OS_MACOSX) | |
| 32 #include "base/debug/leak_annotations.h" | |
| 33 #include "components/crash/content/app/breakpad_linux.h" | |
| 34 #include "components/crash/content/browser/crash_handler_host_linux.h" | |
| 35 #include "content/public/common/content_descriptors.h" | |
| 36 #endif | |
| 37 | |
| 27 namespace headless { | 38 namespace headless { |
| 28 | 39 |
| 29 namespace { | 40 namespace { |
| 30 const char kCapabilityPath[] = | 41 const char kCapabilityPath[] = |
| 31 "interface_provider_specs.navigation:frame.provides.renderer"; | 42 "interface_provider_specs.navigation:frame.provides.renderer"; |
| 43 | |
| 44 #if defined(OS_POSIX) && !defined(OS_MACOSX) | |
| 45 breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost( | |
| 46 const std::string& process_type, | |
| 47 const HeadlessBrowser::Options& options) { | |
| 48 base::FilePath dumps_path = options.crash_dumps_dir; | |
| 49 if (dumps_path.empty()) { | |
| 50 bool ok = PathService::Get(base::DIR_MODULE, &dumps_path); | |
| 51 DCHECK(ok); | |
| 52 } | |
| 53 | |
| 54 { | |
| 55 ANNOTATE_SCOPED_MEMORY_LEAK; | |
| 56 #if defined(OFFICIAL_BUILD) | |
| 57 // Upload crash dumps in official builds, unless we're running in unattended | |
| 58 // mode (not to be confused with headless mode in general -- see | |
| 59 // chrome/common/env_vars.cc). | |
| 60 static const char kHeadless[] = "CHROME_HEADLESS"; | |
| 61 bool upload = (getenv(kHeadless) == nullptr); | |
| 62 #else | |
| 63 bool upload = false; | |
| 64 #endif | |
| 65 breakpad::CrashHandlerHostLinux* crash_handler = | |
| 66 new breakpad::CrashHandlerHostLinux(process_type, dumps_path, upload); | |
| 67 crash_handler->StartUploaderThread(); | |
| 68 return crash_handler; | |
| 69 } | |
| 70 } | |
| 71 | |
| 72 int GetCrashSignalFD(const base::CommandLine& command_line, | |
| 73 const HeadlessBrowser::Options& options) { | |
| 74 if (!breakpad::IsCrashReporterEnabled()) | |
| 75 return -1; | |
| 76 | |
| 77 std::string process_type = | |
| 78 command_line.GetSwitchValueASCII(switches::kProcessType); | |
| 79 | |
| 80 if (process_type == switches::kRendererProcess) { | |
| 81 static breakpad::CrashHandlerHostLinux* crash_handler = | |
| 82 CreateCrashHandlerHost(process_type, options); | |
| 83 return crash_handler->GetDeathSignalSocket(); | |
| 84 } | |
| 85 | |
| 86 if (process_type == switches::kPpapiPluginProcess) { | |
| 87 static breakpad::CrashHandlerHostLinux* crash_handler = | |
| 88 CreateCrashHandlerHost(process_type, options); | |
| 89 return crash_handler->GetDeathSignalSocket(); | |
| 90 } | |
| 91 | |
| 92 if (process_type == switches::kGpuProcess) { | |
| 93 static breakpad::CrashHandlerHostLinux* crash_handler = | |
| 94 CreateCrashHandlerHost(process_type, options); | |
| 95 return crash_handler->GetDeathSignalSocket(); | |
| 96 } | |
| 97 | |
| 98 return -1; | |
| 99 } | |
| 100 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) | |
| 101 | |
| 32 } // namespace | 102 } // namespace |
| 33 | 103 |
| 34 HeadlessContentBrowserClient::HeadlessContentBrowserClient( | 104 HeadlessContentBrowserClient::HeadlessContentBrowserClient( |
| 35 HeadlessBrowserImpl* browser) | 105 HeadlessBrowserImpl* browser) |
| 36 : browser_(browser) {} | 106 : browser_(browser) {} |
| 37 | 107 |
| 38 HeadlessContentBrowserClient::~HeadlessContentBrowserClient() {} | 108 HeadlessContentBrowserClient::~HeadlessContentBrowserClient() {} |
| 39 | 109 |
| 40 content::BrowserMainParts* HeadlessContentBrowserClient::CreateBrowserMainParts( | 110 content::BrowserMainParts* HeadlessContentBrowserClient::CreateBrowserMainParts( |
| 41 const content::MainFunctionParams&) { | 111 const content::MainFunctionParams&) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 content::BrowserContext* context, | 162 content::BrowserContext* context, |
| 93 content::StoragePartition* partition, | 163 content::StoragePartition* partition, |
| 94 const storage::OptionalQuotaSettingsCallback& callback) { | 164 const storage::OptionalQuotaSettingsCallback& callback) { |
| 95 content::BrowserThread::PostTaskAndReplyWithResult( | 165 content::BrowserThread::PostTaskAndReplyWithResult( |
| 96 content::BrowserThread::FILE, FROM_HERE, | 166 content::BrowserThread::FILE, FROM_HERE, |
| 97 base::Bind(&storage::CalculateNominalDynamicSettings, | 167 base::Bind(&storage::CalculateNominalDynamicSettings, |
| 98 partition->GetPath(), context->IsOffTheRecord()), | 168 partition->GetPath(), context->IsOffTheRecord()), |
| 99 callback); | 169 callback); |
| 100 } | 170 } |
| 101 | 171 |
| 172 void HeadlessContentBrowserClient::GetAdditionalMappedFilesForChildProcess( | |
| 173 const base::CommandLine& command_line, | |
| 174 int child_process_id, | |
| 175 content::FileDescriptorInfo* mappings) { | |
| 176 #if defined(OS_POSIX) && !defined(OS_MACOSX) | |
|
alex clarke (OOO till 29th)
2017/02/14 15:14:08
Does the crash pad code typically use this pre-pro
Sami
2017/02/14 18:36:46
Good point, I copied this pattern from content/ an
| |
| 177 int crash_signal_fd = GetCrashSignalFD(command_line, *browser_->options()); | |
| 178 if (crash_signal_fd >= 0) | |
| 179 mappings->Share(kCrashDumpSignal, crash_signal_fd); | |
| 180 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) | |
| 181 } | |
| 182 | |
| 183 void HeadlessContentBrowserClient::AppendExtraCommandLineSwitches( | |
| 184 base::CommandLine* command_line, | |
| 185 int child_process_id) { | |
| 186 #if defined(OS_POSIX) && !defined(OS_MACOSX) | |
| 187 // This flag tells child processes to also turn on crash reporting. | |
| 188 if (breakpad::IsCrashReporterEnabled()) | |
| 189 command_line->AppendSwitch(switches::kEnableCrashReporter); | |
| 190 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) | |
| 191 } | |
| 192 | |
| 102 } // namespace headless | 193 } // namespace headless |
| OLD | NEW |