Commit f47d2153 authored by Sergey Ulanov's avatar Sergey Ulanov Committed by Commit Bot

[Fuchsia] Use presence of context request to determine process type in webrunner

After http://crrev.com/575378 webrunner used --type=web-context argument
to distinguish between web::ContextProvider and web::Context processes.
This approach didn't work properly because there is a lot of code that
assumes that process_type is not set (or empty) in the browser
process, which corresponds to web::Context. This CL removes
--type=web-context. Instead webrunner uses presense of the Context
request handle in the startup info to distinguish between the two
process types.

Also updated ContextProviderMain() to initialize MessageLoop as it's
required on all threads that use FIDL.

Bug: 852145
Change-Id: I2d308c712530f5802a4783cbebcffa49fade326d
Reviewed-on: https://chromium-review.googlesource.com/1141174
Commit-Queue: Sergey Ulanov <sergeyu@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#576140}
parent 038300d6
...@@ -53,6 +53,7 @@ executable("service_exe") { ...@@ -53,6 +53,7 @@ executable("service_exe") {
":service_lib", ":service_lib",
"//base", "//base",
"//content/public/app:both", "//content/public/app:both",
"//services/service_manager/embedder:embedder_switches",
] ]
sources = [ sources = [
"service/web_content_service_main.cc", "service/web_content_service_main.cc",
...@@ -75,7 +76,6 @@ component("service_lib") { ...@@ -75,7 +76,6 @@ component("service_lib") {
"//content/public/common", "//content/public/common",
"//content/public/renderer", "//content/public/renderer",
"//services/network/public/cpp", "//services/network/public/cpp",
"//services/service_manager/embedder:embedder_switches",
"//ui/aura", "//ui/aura",
"//ui/display", "//ui/display",
"//ui/platform_window", "//ui/platform_window",
......
...@@ -7,11 +7,13 @@ ...@@ -7,11 +7,13 @@
#include "webrunner/browser/context_impl.h" #include "webrunner/browser/context_impl.h"
#include "webrunner/browser/webrunner_browser_context.h" #include "webrunner/browser/webrunner_browser_context.h"
#include "webrunner/browser/webrunner_screen.h" #include "webrunner/browser/webrunner_screen.h"
#include "webrunner/service/common.h"
namespace webrunner { namespace webrunner {
WebRunnerBrowserMainParts::WebRunnerBrowserMainParts() = default; WebRunnerBrowserMainParts::WebRunnerBrowserMainParts(
zx::channel context_channel)
: context_channel_(std::move(context_channel)) {}
WebRunnerBrowserMainParts::~WebRunnerBrowserMainParts() = default; WebRunnerBrowserMainParts::~WebRunnerBrowserMainParts() = default;
void WebRunnerBrowserMainParts::PreMainMessageLoopRun() { void WebRunnerBrowserMainParts::PreMainMessageLoopRun() {
...@@ -22,12 +24,8 @@ void WebRunnerBrowserMainParts::PreMainMessageLoopRun() { ...@@ -22,12 +24,8 @@ void WebRunnerBrowserMainParts::PreMainMessageLoopRun() {
DCHECK(!browser_context_); DCHECK(!browser_context_);
browser_context_ = std::make_unique<WebRunnerBrowserContext>(); browser_context_ = std::make_unique<WebRunnerBrowserContext>();
// Get the Context InterfaceRequest which was passed to the process by
// the ContextProvider.
zx::channel context_handle{zx_take_startup_handle(kContextRequestHandleId)};
CHECK(context_handle) << "Could not find the Context request startup handle.";
fidl::InterfaceRequest<chromium::web::Context> context_request( fidl::InterfaceRequest<chromium::web::Context> context_request(
std::move(context_handle)); std::move(context_channel_));
context_impl_ = std::make_unique<ContextImpl>(browser_context_.get()); context_impl_ = std::make_unique<ContextImpl>(browser_context_.get());
context_binding_ = std::make_unique<fidl::Binding<chromium::web::Context>>( context_binding_ = std::make_unique<fidl::Binding<chromium::web::Context>>(
......
...@@ -20,7 +20,7 @@ class WebRunnerScreen; ...@@ -20,7 +20,7 @@ class WebRunnerScreen;
class WebRunnerBrowserMainParts : public content::BrowserMainParts { class WebRunnerBrowserMainParts : public content::BrowserMainParts {
public: public:
WebRunnerBrowserMainParts(); explicit WebRunnerBrowserMainParts(zx::channel context_channel);
~WebRunnerBrowserMainParts() override; ~WebRunnerBrowserMainParts() override;
// content::BrowserMainParts overrides. // content::BrowserMainParts overrides.
...@@ -28,6 +28,8 @@ class WebRunnerBrowserMainParts : public content::BrowserMainParts { ...@@ -28,6 +28,8 @@ class WebRunnerBrowserMainParts : public content::BrowserMainParts {
void PreDefaultMainMessageLoopRun(base::OnceClosure quit_closure) override; void PreDefaultMainMessageLoopRun(base::OnceClosure quit_closure) override;
private: private:
zx::channel context_channel_;
std::unique_ptr<WebRunnerScreen> screen_; std::unique_ptr<WebRunnerScreen> screen_;
std::unique_ptr<WebRunnerBrowserContext> browser_context_; std::unique_ptr<WebRunnerBrowserContext> browser_context_;
......
...@@ -8,13 +8,17 @@ ...@@ -8,13 +8,17 @@
namespace webrunner { namespace webrunner {
WebRunnerContentBrowserClient::WebRunnerContentBrowserClient() = default; WebRunnerContentBrowserClient::WebRunnerContentBrowserClient(
zx::channel context_channel)
: context_channel_(std::move(context_channel)) {}
WebRunnerContentBrowserClient::~WebRunnerContentBrowserClient() = default; WebRunnerContentBrowserClient::~WebRunnerContentBrowserClient() = default;
content::BrowserMainParts* content::BrowserMainParts*
WebRunnerContentBrowserClient::CreateBrowserMainParts( WebRunnerContentBrowserClient::CreateBrowserMainParts(
const content::MainFunctionParams& parameters) { const content::MainFunctionParams& parameters) {
return new WebRunnerBrowserMainParts(); DCHECK(context_channel_);
return new WebRunnerBrowserMainParts(std::move(context_channel_));
} }
} // namespace webrunner } // namespace webrunner
\ No newline at end of file
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef WEBRUNNER_BROWSER_WEBRUNNER_CONTENT_BROWSER_CLIENT_H_ #ifndef WEBRUNNER_BROWSER_WEBRUNNER_CONTENT_BROWSER_CLIENT_H_
#define WEBRUNNER_BROWSER_WEBRUNNER_CONTENT_BROWSER_CLIENT_H_ #define WEBRUNNER_BROWSER_WEBRUNNER_CONTENT_BROWSER_CLIENT_H_
#include <lib/zx/channel.h>
#include "base/macros.h" #include "base/macros.h"
#include "content/public/browser/content_browser_client.h" #include "content/public/browser/content_browser_client.h"
...@@ -12,7 +14,7 @@ namespace webrunner { ...@@ -12,7 +14,7 @@ namespace webrunner {
class WebRunnerContentBrowserClient : public content::ContentBrowserClient { class WebRunnerContentBrowserClient : public content::ContentBrowserClient {
public: public:
WebRunnerContentBrowserClient(); explicit WebRunnerContentBrowserClient(zx::channel context_channel);
~WebRunnerContentBrowserClient() override; ~WebRunnerContentBrowserClient() override;
// ContentBrowserClient overrides. // ContentBrowserClient overrides.
...@@ -20,6 +22,8 @@ class WebRunnerContentBrowserClient : public content::ContentBrowserClient { ...@@ -20,6 +22,8 @@ class WebRunnerContentBrowserClient : public content::ContentBrowserClient {
const content::MainFunctionParams& parameters) override; const content::MainFunctionParams& parameters) override;
private: private:
zx::channel context_channel_;
DISALLOW_COPY_AND_ASSIGN(WebRunnerContentBrowserClient); DISALLOW_COPY_AND_ASSIGN(WebRunnerContentBrowserClient);
}; };
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include "base/fuchsia/fuchsia_logging.h" #include "base/fuchsia/fuchsia_logging.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/process/launch.h" #include "base/process/launch.h"
#include "services/service_manager/embedder/switches.h"
#include "webrunner/service/common.h" #include "webrunner/service/common.h"
namespace webrunner { namespace webrunner {
...@@ -26,9 +25,6 @@ namespace { ...@@ -26,9 +25,6 @@ namespace {
// Relaunches the current executable as a Context process. // Relaunches the current executable as a Context process.
base::Process LaunchContextProcess(const base::LaunchOptions& launch_options) { base::Process LaunchContextProcess(const base::LaunchOptions& launch_options) {
base::CommandLine launch_command = *base::CommandLine::ForCurrentProcess(); base::CommandLine launch_command = *base::CommandLine::ForCurrentProcess();
DCHECK(!launch_command.HasSwitch(service_manager::switches::kProcessType));
launch_command.AppendSwitchASCII(service_manager::switches::kProcessType,
kProcessTypeWebContext);
return base::LaunchProcess(launch_command, launch_options); return base::LaunchProcess(launch_command, launch_options);
} }
......
...@@ -7,12 +7,14 @@ ...@@ -7,12 +7,14 @@
#include "base/fuchsia/scoped_service_binding.h" #include "base/fuchsia/scoped_service_binding.h"
#include "base/fuchsia/service_directory.h" #include "base/fuchsia/service_directory.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "webrunner/service/context_provider_impl.h" #include "webrunner/service/context_provider_impl.h"
namespace webrunner { namespace webrunner {
int ContextProviderMain() { int ContextProviderMain() {
base::MessageLoopForUI message_loop;
base::fuchsia::ServiceDirectory* directory = base::fuchsia::ServiceDirectory* directory =
base::fuchsia::ServiceDirectory::GetDefault(); base::fuchsia::ServiceDirectory::GetDefault();
ContextProviderImpl context_provider; ContextProviderImpl context_provider;
......
...@@ -5,14 +5,14 @@ ...@@ -5,14 +5,14 @@
#ifndef WEBRUNNER_SERVICE_CONTEXT_PROVIDER_MAIN_H_ #ifndef WEBRUNNER_SERVICE_CONTEXT_PROVIDER_MAIN_H_
#define WEBRUNNER_SERVICE_CONTEXT_PROVIDER_MAIN_H_ #define WEBRUNNER_SERVICE_CONTEXT_PROVIDER_MAIN_H_
#include "webrunner/service/context_provider_main.h" #include "webrunner/common/webrunner_export.h"
namespace webrunner { namespace webrunner {
// Main function for the process that implements web::ContextProvider interface. // Main function for the process that implements web::ContextProvider interface.
// Called by WebRunnerMainDelegate when the process is started without --type // Called by WebRunnerMainDelegate when the process is started without --type
// argument. // argument.
int ContextProviderMain(); WEBRUNNER_EXPORT int ContextProviderMain();
} // namespace webrunner } // namespace webrunner
......
...@@ -2,13 +2,44 @@ ...@@ -2,13 +2,44 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include <zircon/process.h>
#include "base/command_line.h"
#include "content/public/app/content_main.h" #include "content/public/app/content_main.h"
#include "services/service_manager/embedder/switches.h"
#include "webrunner/service/common.h"
#include "webrunner/service/context_provider_main.h"
#include "webrunner/service/webrunner_main_delegate.h" #include "webrunner/service/webrunner_main_delegate.h"
int main(int argc, const char** argv) { int main(int argc, const char** argv) {
webrunner::WebRunnerMainDelegate delegate; base::CommandLine::Init(argc, argv);
std::string process_type =
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
service_manager::switches::kProcessType);
zx::channel context_channel;
if (process_type.empty()) {
// zx_take_startup_handle() is called only when process_type is empty (i.e.
// for Browser and ContextProvider processes). Renderer and other child
// processes may use the same handle id for other handles.
context_channel.reset(
zx_take_startup_handle(webrunner::kContextRequestHandleId));
// If |process_type| is empty then this may be a Browser process, or the
// main ContextProvider process. Browser processes will have a
// |context_channel| set
if (!context_channel)
return webrunner::ContextProviderMain();
}
webrunner::WebRunnerMainDelegate delegate(std::move(context_channel));
content::ContentMainParams params(&delegate); content::ContentMainParams params(&delegate);
params.argc = argc;
params.argv = argv; // Repeated base::CommandLine::Init() is ignored, so it's safe to pass null
// args here.
params.argc = 0;
params.argv = nullptr;
return content::ContentMain(params); return content::ContentMain(params);
} }
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "webrunner/browser/webrunner_content_browser_client.h" #include "webrunner/browser/webrunner_content_browser_client.h"
#include "webrunner/common/webrunner_content_client.h" #include "webrunner/common/webrunner_content_client.h"
#include "webrunner/service/common.h" #include "webrunner/service/common.h"
#include "webrunner/service/context_provider_main.h"
namespace webrunner { namespace webrunner {
...@@ -48,7 +47,9 @@ void InitializeResourceBundle() { ...@@ -48,7 +47,9 @@ void InitializeResourceBundle() {
} // namespace } // namespace
WebRunnerMainDelegate::WebRunnerMainDelegate() = default; WebRunnerMainDelegate::WebRunnerMainDelegate(zx::channel context_channel)
: context_channel_(std::move(context_channel)) {}
WebRunnerMainDelegate::~WebRunnerMainDelegate() = default; WebRunnerMainDelegate::~WebRunnerMainDelegate() = default;
bool WebRunnerMainDelegate::BasicStartupComplete(int* exit_code) { bool WebRunnerMainDelegate::BasicStartupComplete(int* exit_code) {
...@@ -66,19 +67,17 @@ void WebRunnerMainDelegate::PreSandboxStartup() { ...@@ -66,19 +67,17 @@ void WebRunnerMainDelegate::PreSandboxStartup() {
int WebRunnerMainDelegate::RunProcess( int WebRunnerMainDelegate::RunProcess(
const std::string& process_type, const std::string& process_type,
const content::MainFunctionParams& main_function_params) { const content::MainFunctionParams& main_function_params) {
if (process_type == kProcessTypeWebContext)
return WebRunnerBrowserMain(main_function_params);
if (!process_type.empty()) if (!process_type.empty())
return -1; return -1;
return ContextProviderMain(); return WebRunnerBrowserMain(main_function_params);
} }
content::ContentBrowserClient* content::ContentBrowserClient*
WebRunnerMainDelegate::CreateContentBrowserClient() { WebRunnerMainDelegate::CreateContentBrowserClient() {
DCHECK(!browser_client_); DCHECK(!browser_client_);
browser_client_ = std::make_unique<WebRunnerContentBrowserClient>(); browser_client_ = std::make_unique<WebRunnerContentBrowserClient>(
std::move(context_channel_));
return browser_client_.get(); return browser_client_.get();
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef WEBRUNNER_SERVICE_WEBRUNNER_MAIN_DELEGATE_H_ #ifndef WEBRUNNER_SERVICE_WEBRUNNER_MAIN_DELEGATE_H_
#define WEBRUNNER_SERVICE_WEBRUNNER_MAIN_DELEGATE_H_ #define WEBRUNNER_SERVICE_WEBRUNNER_MAIN_DELEGATE_H_
#include <lib/zx/channel.h>
#include <memory> #include <memory>
#include "base/macros.h" #include "base/macros.h"
...@@ -20,7 +21,7 @@ namespace webrunner { ...@@ -20,7 +21,7 @@ namespace webrunner {
class WEBRUNNER_EXPORT WebRunnerMainDelegate class WEBRUNNER_EXPORT WebRunnerMainDelegate
: public content::ContentMainDelegate { : public content::ContentMainDelegate {
public: public:
WebRunnerMainDelegate(); explicit WebRunnerMainDelegate(zx::channel context_channel);
~WebRunnerMainDelegate() override; ~WebRunnerMainDelegate() override;
// ContentMainDelegate implementation. // ContentMainDelegate implementation.
...@@ -35,6 +36,8 @@ class WEBRUNNER_EXPORT WebRunnerMainDelegate ...@@ -35,6 +36,8 @@ class WEBRUNNER_EXPORT WebRunnerMainDelegate
std::unique_ptr<content::ContentClient> content_client_; std::unique_ptr<content::ContentClient> content_client_;
std::unique_ptr<content::ContentBrowserClient> browser_client_; std::unique_ptr<content::ContentBrowserClient> browser_client_;
zx::channel context_channel_;
DISALLOW_COPY_AND_ASSIGN(WebRunnerMainDelegate); DISALLOW_COPY_AND_ASSIGN(WebRunnerMainDelegate);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment