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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
11 #include "content/public/browser/browser_main_runner.h" | 11 #include "content/public/browser/browser_main_runner.h" |
12 #include "content/public/common/content_switches.h" | 12 #include "content/public/common/content_switches.h" |
13 #include "headless/lib/browser/headless_browser_impl.h" | 13 #include "headless/lib/browser/headless_browser_impl.h" |
14 #include "headless/lib/browser/headless_content_browser_client.h" | 14 #include "headless/lib/browser/headless_content_browser_client.h" |
15 #include "headless/lib/renderer/headless_content_renderer_client.h" | 15 #include "headless/lib/renderer/headless_content_renderer_client.h" |
16 #include "headless/lib/utility/headless_content_utility_client.h" | 16 #include "headless/lib/utility/headless_content_utility_client.h" |
17 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
| 18 #include "ui/gfx/switches.h" |
18 #include "ui/gl/gl_switches.h" | 19 #include "ui/gl/gl_switches.h" |
19 #include "ui/ozone/public/ozone_switches.h" | 20 #include "ui/ozone/public/ozone_switches.h" |
20 | 21 |
21 namespace headless { | 22 namespace headless { |
22 namespace { | 23 namespace { |
23 // Keep in sync with content/common/content_constants_internal.h. | 24 // Keep in sync with content/common/content_constants_internal.h. |
24 // TODO(skyostil): Add a tracing test for this. | 25 // TODO(skyostil): Add a tracing test for this. |
25 const int kTraceEventBrowserProcessSortIndex = -6; | 26 const int kTraceEventBrowserProcessSortIndex = -6; |
26 | 27 |
27 HeadlessContentMainDelegate* g_current_headless_content_main_delegate = nullptr; | 28 HeadlessContentMainDelegate* g_current_headless_content_main_delegate = nullptr; |
28 } // namespace | 29 } // namespace |
29 | 30 |
30 HeadlessContentMainDelegate::HeadlessContentMainDelegate( | 31 HeadlessContentMainDelegate::HeadlessContentMainDelegate( |
31 std::unique_ptr<HeadlessBrowserImpl> browser) | 32 std::unique_ptr<HeadlessBrowserImpl> browser) |
32 : content_client_(browser->options()), browser_(std::move(browser)) { | 33 : content_client_(browser->options()), browser_(std::move(browser)) { |
33 DCHECK(!g_current_headless_content_main_delegate); | 34 DCHECK(!g_current_headless_content_main_delegate); |
34 g_current_headless_content_main_delegate = this; | 35 g_current_headless_content_main_delegate = this; |
35 } | 36 } |
36 | 37 |
37 HeadlessContentMainDelegate::~HeadlessContentMainDelegate() { | 38 HeadlessContentMainDelegate::~HeadlessContentMainDelegate() { |
38 DCHECK(g_current_headless_content_main_delegate == this); | 39 DCHECK(g_current_headless_content_main_delegate == this); |
39 g_current_headless_content_main_delegate = nullptr; | 40 g_current_headless_content_main_delegate = nullptr; |
40 } | 41 } |
41 | 42 |
42 bool HeadlessContentMainDelegate::BasicStartupComplete(int* exit_code) { | 43 bool HeadlessContentMainDelegate::BasicStartupComplete(int* exit_code) { |
43 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 44 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
44 | 45 |
| 46 // Make sure all processes know that we're in headless mode. |
| 47 if (!command_line->HasSwitch(switches::kHeadless)) |
| 48 command_line->AppendSwitch(switches::kHeadless); |
| 49 |
45 if (browser_->options()->single_process_mode) | 50 if (browser_->options()->single_process_mode) |
46 command_line->AppendSwitch(switches::kSingleProcess); | 51 command_line->AppendSwitch(switches::kSingleProcess); |
47 | 52 |
48 if (browser_->options()->disable_sandbox) | 53 if (browser_->options()->disable_sandbox) |
49 command_line->AppendSwitch(switches::kNoSandbox); | 54 command_line->AppendSwitch(switches::kNoSandbox); |
50 | 55 |
| 56 #if defined(USE_OZONE) |
51 // The headless backend is automatically chosen for a headless build, but also | 57 // The headless backend is automatically chosen for a headless build, but also |
52 // adding it here allows us to run in a non-headless build too. | 58 // adding it here allows us to run in a non-headless build too. |
53 command_line->AppendSwitchASCII(switches::kOzonePlatform, "headless"); | 59 command_line->AppendSwitchASCII(switches::kOzonePlatform, "headless"); |
| 60 #endif |
54 | 61 |
55 if (!browser_->options()->gl_implementation.empty()) { | 62 if (!browser_->options()->gl_implementation.empty()) { |
56 command_line->AppendSwitchASCII(switches::kUseGL, | 63 command_line->AppendSwitchASCII(switches::kUseGL, |
57 browser_->options()->gl_implementation); | 64 browser_->options()->gl_implementation); |
58 } else { | 65 } else { |
59 command_line->AppendSwitch(switches::kDisableGpu); | 66 command_line->AppendSwitch(switches::kDisableGpu); |
60 } | 67 } |
61 | 68 |
62 SetContentClient(&content_client_); | 69 SetContentClient(&content_client_); |
63 return false; | 70 return false; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 return renderer_client_.get(); | 130 return renderer_client_.get(); |
124 } | 131 } |
125 | 132 |
126 content::ContentUtilityClient* | 133 content::ContentUtilityClient* |
127 HeadlessContentMainDelegate::CreateContentUtilityClient() { | 134 HeadlessContentMainDelegate::CreateContentUtilityClient() { |
128 utility_client_.reset(new HeadlessContentUtilityClient); | 135 utility_client_.reset(new HeadlessContentUtilityClient); |
129 return utility_client_.get(); | 136 return utility_client_.get(); |
130 } | 137 } |
131 | 138 |
132 } // namespace headless | 139 } // namespace headless |
OLD | NEW |