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/headless_content_main_delegate.h" | 5 #include "headless/lib/headless_content_main_delegate.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/base_switches.h" | 9 #include "base/base_switches.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 #include "ui/base/resource/resource_bundle.h" | 26 #include "ui/base/resource/resource_bundle.h" |
| 27 #include "ui/base/ui_base_switches.h" | 27 #include "ui/base/ui_base_switches.h" |
| 28 #include "ui/gfx/switches.h" | 28 #include "ui/gfx/switches.h" |
| 29 #include "ui/gl/gl_switches.h" | 29 #include "ui/gl/gl_switches.h" |
| 30 #include "ui/ozone/public/ozone_switches.h" | 30 #include "ui/ozone/public/ozone_switches.h" |
| 31 | 31 |
| 32 #ifdef HEADLESS_USE_EMBEDDED_RESOURCES | 32 #ifdef HEADLESS_USE_EMBEDDED_RESOURCES |
| 33 #include "headless/embedded_resource_pak.h" | 33 #include "headless/embedded_resource_pak.h" |
| 34 #endif | 34 #endif |
| 35 | 35 |
| 36 #if defined(OS_MACOSX) | |
| 37 #include "components/crash/content/app/crashpad.h" | |
| 38 #endif | |
| 39 | |
| 36 namespace headless { | 40 namespace headless { |
| 37 namespace { | 41 namespace { |
| 38 // Keep in sync with content/common/content_constants_internal.h. | 42 // Keep in sync with content/common/content_constants_internal.h. |
| 39 // TODO(skyostil): Add a tracing test for this. | 43 // TODO(skyostil): Add a tracing test for this. |
| 40 const int kTraceEventBrowserProcessSortIndex = -6; | 44 const int kTraceEventBrowserProcessSortIndex = -6; |
| 41 | 45 |
| 42 HeadlessContentMainDelegate* g_current_headless_content_main_delegate = nullptr; | 46 HeadlessContentMainDelegate* g_current_headless_content_main_delegate = nullptr; |
| 43 | 47 |
| 44 base::LazyInstance<HeadlessCrashReporterClient>::Leaky g_headless_crash_client = | 48 base::LazyInstance<HeadlessCrashReporterClient>::Leaky g_headless_crash_client = |
| 45 LAZY_INSTANCE_INITIALIZER; | 49 LAZY_INSTANCE_INITIALIZER; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 | 148 |
| 145 settings.logging_dest = log_mode; | 149 settings.logging_dest = log_mode; |
| 146 settings.log_file = log_path.value().c_str(); | 150 settings.log_file = log_path.value().c_str(); |
| 147 settings.lock_log = logging::DONT_LOCK_LOG_FILE; | 151 settings.lock_log = logging::DONT_LOCK_LOG_FILE; |
| 148 settings.delete_old = process_type.empty() ? logging::DELETE_OLD_LOG_FILE | 152 settings.delete_old = process_type.empty() ? logging::DELETE_OLD_LOG_FILE |
| 149 : logging::APPEND_TO_OLD_LOG_FILE; | 153 : logging::APPEND_TO_OLD_LOG_FILE; |
| 150 bool success = logging::InitLogging(settings); | 154 bool success = logging::InitLogging(settings); |
| 151 DCHECK(success); | 155 DCHECK(success); |
| 152 } | 156 } |
| 153 | 157 |
| 158 #if defined(OS_MACOSX) | |
| 159 void HeadlessContentMainDelegate::InitMacCrashReporter( | |
| 160 const base::CommandLine& command_line, | |
|
jzfeng
2017/04/12 06:22:04
command_line is not used?
dvallet
2017/04/12 07:04:09
Done.
| |
| 161 const std::string& process_type) { | |
| 162 const bool browser_process = process_type.empty(); | |
| 163 crash_reporter::InitializeCrashpad(browser_process, process_type); | |
| 164 } | |
| 165 #endif // defined(OS_MACOSX) | |
| 166 | |
| 154 void HeadlessContentMainDelegate::InitCrashReporter( | 167 void HeadlessContentMainDelegate::InitCrashReporter( |
| 155 const base::CommandLine& command_line) { | 168 const base::CommandLine& command_line) { |
| 156 const std::string process_type = | 169 const std::string process_type = |
| 157 command_line.GetSwitchValueASCII(switches::kProcessType); | 170 command_line.GetSwitchValueASCII(switches::kProcessType); |
| 158 crash_reporter::SetCrashReporterClient(g_headless_crash_client.Pointer()); | 171 crash_reporter::SetCrashReporterClient(g_headless_crash_client.Pointer()); |
| 159 g_headless_crash_client.Pointer()->set_crash_dumps_dir( | 172 g_headless_crash_client.Pointer()->set_crash_dumps_dir( |
| 160 browser_->options()->crash_dumps_dir); | 173 browser_->options()->crash_dumps_dir); |
| 161 | 174 |
| 162 #if !defined(OS_MACOSX) | 175 #if defined(HEADLESS_USE_BREAKPAD) |
| 163 if (!browser_->options()->enable_crash_reporter) { | 176 if (!browser_->options()->enable_crash_reporter) { |
| 164 DCHECK(!breakpad::IsCrashReporterEnabled()); | 177 DCHECK(!breakpad::IsCrashReporterEnabled()); |
| 165 return; | 178 return; |
| 166 } | 179 } |
| 167 #if defined(HEADLESS_USE_BREAKPAD) | |
| 168 if (process_type != switches::kZygoteProcess) | 180 if (process_type != switches::kZygoteProcess) |
| 169 breakpad::InitCrashReporter(process_type); | 181 breakpad::InitCrashReporter(process_type); |
| 182 #elif defined(OS_MACOSX) | |
| 183 InitMacCrashReporter(command_line, process_type); | |
|
jzfeng
2017/04/12 06:22:04
there is only two line of code, just put them here
dvallet
2017/04/12 07:04:09
Done. I'm expecting to add more stuff later for cr
| |
| 170 #endif // defined(HEADLESS_USE_BREAKPAD) | 184 #endif // defined(HEADLESS_USE_BREAKPAD) |
| 171 #endif // !defined(OS_MACOSX) | |
| 172 } | 185 } |
| 173 | 186 |
| 174 void HeadlessContentMainDelegate::PreSandboxStartup() { | 187 void HeadlessContentMainDelegate::PreSandboxStartup() { |
| 175 const base::CommandLine& command_line( | 188 const base::CommandLine& command_line( |
| 176 *base::CommandLine::ForCurrentProcess()); | 189 *base::CommandLine::ForCurrentProcess()); |
| 177 #if defined(OS_WIN) | 190 #if defined(OS_WIN) |
| 178 // Windows always needs to initialize logging, otherwise you get a renderer | 191 // Windows always needs to initialize logging, otherwise you get a renderer |
| 179 // crash. | 192 // crash. |
| 180 InitLogging(command_line); | 193 InitLogging(command_line); |
| 181 #else | 194 #else |
| 182 if (command_line.HasSwitch(switches::kEnableLogging)) | 195 if (command_line.HasSwitch(switches::kEnableLogging)) |
| 183 InitLogging(command_line); | 196 InitLogging(command_line); |
| 184 #endif | 197 #endif // defined(OS_WIN) |
| 185 #if !defined(OS_MACOSX) | |
| 186 InitCrashReporter(command_line); | 198 InitCrashReporter(command_line); |
| 187 #endif | |
| 188 InitializeResourceBundle(); | 199 InitializeResourceBundle(); |
| 189 } | 200 } |
| 190 | 201 |
| 191 int HeadlessContentMainDelegate::RunProcess( | 202 int HeadlessContentMainDelegate::RunProcess( |
| 192 const std::string& process_type, | 203 const std::string& process_type, |
| 193 const content::MainFunctionParams& main_function_params) { | 204 const content::MainFunctionParams& main_function_params) { |
| 194 if (!process_type.empty()) | 205 if (!process_type.empty()) |
| 195 return -1; | 206 return -1; |
| 196 | 207 |
| 197 base::trace_event::TraceLog::GetInstance()->SetProcessName("HeadlessBrowser"); | 208 base::trace_event::TraceLog::GetInstance()->SetProcessName("HeadlessBrowser"); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 return browser_client_.get(); | 288 return browser_client_.get(); |
| 278 } | 289 } |
| 279 | 290 |
| 280 content::ContentRendererClient* | 291 content::ContentRendererClient* |
| 281 HeadlessContentMainDelegate::CreateContentRendererClient() { | 292 HeadlessContentMainDelegate::CreateContentRendererClient() { |
| 282 renderer_client_ = base::MakeUnique<HeadlessContentRendererClient>(); | 293 renderer_client_ = base::MakeUnique<HeadlessContentRendererClient>(); |
| 283 return renderer_client_.get(); | 294 return renderer_client_.get(); |
| 284 } | 295 } |
| 285 | 296 |
| 286 } // namespace headless | 297 } // namespace headless |
| OLD | NEW |