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

Side by Side Diff: headless/app/headless_shell_main_delegate.cc

Issue 1430673002: Headless demo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "headless/app/headless_shell_main_delegate.h"
6
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "base/path_service.h"
10 #include "base/trace_event/trace_event.h"
11 #include "content/common/content_constants_internal.h"
12 #include "content/public/browser/browser_main_runner.h"
13 #include "content/public/common/content_switches.h"
14 #include "content/shell/browser/shell_browser_main.h"
15 #include "content/shell/browser/shell_content_browser_client.h"
16 #include "content/shell/renderer/shell_content_renderer_client.h"
17 #include "content/shell/utility/shell_content_utility_client.h"
18 #include "ui/base/resource/resource_bundle.h"
19 #include "ui/ozone/public/ozone_switches.h"
20 #include "headless/app/headless_browser_main.h"
21
22 namespace {
23
24 void InitLogging() {
25 base::FilePath log_filename;
26 PathService::Get(base::DIR_EXE, &log_filename);
27 log_filename = log_filename.AppendASCII("headless_test_shell.log");
28 logging::LoggingSettings settings;
29 settings.logging_dest = logging::LOG_TO_ALL;
30 settings.log_file = log_filename.value().c_str();
31 settings.delete_old = logging::DELETE_OLD_LOG_FILE;
32 logging::InitLogging(settings);
33 logging::SetLogItems(true, true, true, true);
34 }
35
36 } // namespace
37
38 namespace content {
39
40 HeadlessShellMainDelegate::HeadlessShellMainDelegate() {}
41
42 HeadlessShellMainDelegate::~HeadlessShellMainDelegate() {}
43
44 bool HeadlessShellMainDelegate::BasicStartupComplete(int* exit_code) {
45 base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
46
47 InitLogging();
48
49 command_line.AppendSwitch(switches::kNoSandbox);
50 command_line.AppendSwitch(switches::kSingleProcess);
51
52 // TODO(skyostil): Investigate using Mesa/SwiftShader for output.
53 command_line.AppendSwitch(switches::kDisableGpu);
54
55 SetContentClient(&content_client_);
56 return false;
57 }
58
59 void HeadlessShellMainDelegate::PreSandboxStartup() {
60 InitializeResourceBundle();
61 }
62
63 int HeadlessShellMainDelegate::RunProcess(
64 const std::string& process_type,
65 const MainFunctionParams& main_function_params) {
66 if (!process_type.empty())
67 return -1;
68
69 base::trace_event::TraceLog::GetInstance()->SetProcessName("HeadlessBrowser");
70 base::trace_event::TraceLog::GetInstance()->SetProcessSortIndex(
71 kTraceEventBrowserProcessSortIndex);
72
73 scoped_ptr<BrowserMainRunner> browser_runner_(BrowserMainRunner::Create());
74 return HeadlessBrowserMain(main_function_params, browser_runner_.Pass());
75 }
76
77 void HeadlessShellMainDelegate::ZygoteForked() {
78 // TODO(skyostil): Disable the zygote host.
79 }
80
81 // static
82 void HeadlessShellMainDelegate::InitializeResourceBundle() {
83 base::FilePath pak_file;
84 bool r = PathService::Get(base::DIR_MODULE, &pak_file);
85 DCHECK(r);
86 pak_file = pak_file.Append(FILE_PATH_LITERAL("content_shell.pak"));
87 ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file);
88 }
89
90 ContentBrowserClient*
91 HeadlessShellMainDelegate::CreateContentBrowserClient() {
92 browser_client_.reset(new ShellContentBrowserClient);
93 return browser_client_.get();
94 }
95
96 ContentRendererClient*
97 HeadlessShellMainDelegate::CreateContentRendererClient() {
98 renderer_client_.reset(new ShellContentRendererClient);
99 return renderer_client_.get();
100 }
101
102 ContentUtilityClient*
103 HeadlessShellMainDelegate::CreateContentUtilityClient() {
104 utility_client_.reset(new ShellContentUtilityClient);
105 return utility_client_.get();
106 }
107
108 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698