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

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

Issue 1430673002: Headless demo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Better javascript Created 5 years 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/lib/headless_shell_main_delegate.h"
6
7 #include "headless/lib/browser/headless_content_browser_client.h"
8 #include "headless/lib/renderer/headless_content_renderer_client.h"
9 #include "headless/lib/utility/headless_content_utility_client.h"
10
11 #include "base/command_line.h"
12 #include "base/logging.h"
13 #include "base/path_service.h"
14 #include "base/run_loop.h"
15 #include "base/trace_event/trace_event.h"
16 #include "content/common/content_constants_internal.h"
17 #include "content/public/browser/browser_main_runner.h"
18 #include "content/public/common/content_switches.h"
19 #include "ui/base/resource/resource_bundle.h"
20 #include "ui/ozone/public/ozone_switches.h"
21 #include "headless/lib/headless_browser_impl.h"
22
23 namespace {
24
25 void InitLogging() {
26 base::FilePath log_filename;
27 PathService::Get(base::DIR_EXE, &log_filename);
28 log_filename = log_filename.AppendASCII("headless_test_shell.log");
29 logging::LoggingSettings settings;
30 settings.logging_dest = logging::LOG_TO_ALL;
31 settings.log_file = log_filename.value().c_str();
32 settings.delete_old = logging::DELETE_OLD_LOG_FILE;
33 logging::InitLogging(settings);
34 logging::SetLogItems(true, true, true, true);
35 }
36
37 } // namespace
38
39 namespace headless {
40
41 HeadlessShellMainDelegate::HeadlessShellMainDelegate(
42 HeadlessBrowserImpl* browser)
43 : browser_(browser) { }
44
45 HeadlessShellMainDelegate::~HeadlessShellMainDelegate() { }
46
47 bool HeadlessShellMainDelegate::BasicStartupComplete(int* exit_code) {
48 base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
49
50 InitLogging();
51
52 command_line.AppendSwitch(switches::kNoSandbox);
53 command_line.AppendSwitch(switches::kSingleProcess);
54
55 // TODO(skyostil): Investigate using Mesa/SwiftShader for output.
56 command_line.AppendSwitch(switches::kDisableGpu);
57
58 SetContentClient(&content_client_);
59 return false;
60 }
61
62 void HeadlessShellMainDelegate::PreSandboxStartup() {
63 InitializeResourceBundle();
64 }
65
66 int HeadlessShellMainDelegate::RunProcess(
67 const std::string& process_type,
68 const content::MainFunctionParams& main_function_params) {
69 if (!process_type.empty())
70 return -1;
71
72 base::trace_event::TraceLog::GetInstance()->SetProcessName("HeadlessBrowser");
73 base::trace_event::TraceLog::GetInstance()->SetProcessSortIndex(
74 content::kTraceEventBrowserProcessSortIndex);
75
76 scoped_ptr<content::BrowserMainRunner> browser_runner_(
77 content::BrowserMainRunner::Create());
78
79 int exit_code = browser_runner_->Initialize(main_function_params);
80
81 DCHECK_LT(exit_code, 0) << "content::BrowserMainRunner::Initialize failed in "
82 "HeadlessShellMainDelegate::RunProcess";
83
84 browser_->RunOnStartCallback();
85
86 browser_runner_->Run();
87
88 browser_runner_->Shutdown();
89
90 // Return value >=0 here to disable calling content::BrowserMain.
91 return 0;
92 }
93
94 void HeadlessShellMainDelegate::ZygoteForked() {
95 // TODO(skyostil): Disable the zygote host.
96 }
97
98 // static
99 void HeadlessShellMainDelegate::InitializeResourceBundle() {
100 base::FilePath pak_file;
101 bool r = PathService::Get(base::DIR_MODULE, &pak_file);
102 DCHECK(r);
103 pak_file = pak_file.Append(FILE_PATH_LITERAL("content_shell.pak"));
104 ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file);
105 }
106
107 content::ContentBrowserClient*
108 HeadlessShellMainDelegate::CreateContentBrowserClient() {
109 browser_client_.reset(new HeadlessContentBrowserClient(browser_));
110 return browser_client_.get();
111 }
112
113 content::ContentRendererClient*
114 HeadlessShellMainDelegate::CreateContentRendererClient() {
115 renderer_client_.reset(new HeadlessContentRendererClient);
116 return renderer_client_.get();
117 }
118
119 content::ContentUtilityClient*
120 HeadlessShellMainDelegate::CreateContentUtilityClient() {
121 utility_client_.reset(new HeadlessContentUtilityClient);
122 return utility_client_.get();
123 }
124
125 } // namespace headless
OLDNEW
« no previous file with comments | « headless/lib/headless_shell_main_delegate.h ('k') | headless/lib/renderer/headless_content_renderer_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698