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

[Fuchsia] Add service_directory field in CreateContextParams

Now a process that creates a WebContext must pass a service_directory
handle. That directory is mounted as /svc in the context process.

Also renamed dataDirectory->data_directory, which is a proper struct
member name according to the FIDL style guide.

Bug: 869216
Change-Id: I63af58a472edf0d45b79b0108082fffcac6eaa72
Reviewed-on: https://chromium-review.googlesource.com/1157196Reviewed-by: default avatarWez <wez@chromium.org>
Commit-Queue: Sergey Ulanov <sergeyu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580010}
parent 3553465e
...@@ -6,7 +6,9 @@ ...@@ -6,7 +6,9 @@
#include <lib/fidl/cpp/binding.h> #include <lib/fidl/cpp/binding.h>
#include <utility> #include <utility>
#include "base/files/file.h"
#include "base/fuchsia/component_context.h" #include "base/fuchsia/component_context.h"
#include "base/fuchsia/file_utils.h"
#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"
...@@ -22,7 +24,15 @@ chromium::web::ContextPtr CreateContext() { ...@@ -22,7 +24,15 @@ chromium::web::ContextPtr CreateContext() {
auto web_context_provider = auto web_context_provider =
base::fuchsia::ComponentContext::GetDefault() base::fuchsia::ComponentContext::GetDefault()
->ConnectToService<chromium::web::ContextProvider>(); ->ConnectToService<chromium::web::ContextProvider>();
chromium::web::CreateContextParams create_params; chromium::web::CreateContextParams create_params;
// Clone /svc to the context.
create_params.service_directory =
zx::channel(base::fuchsia::GetHandleFromFile(
base::File(base::FilePath("/svc"),
base::File::FLAG_OPEN | base::File::FLAG_READ)));
chromium::web::ContextPtr web_context; chromium::web::ContextPtr web_context;
web_context_provider->Create(std::move(create_params), web_context_provider->Create(std::move(create_params),
web_context.NewRequest()); web_context.NewRequest());
......
...@@ -17,8 +17,13 @@ interface ContextProvider { ...@@ -17,8 +17,13 @@ interface ContextProvider {
}; };
struct CreateContextParams { struct CreateContextParams {
// Service directory to be used by the context.
// TODO(https://crbug.com/870057): Document required and optional services
// that Context needs.
handle<channel> service_directory;
// Handle to the directory that will contain the Context's // Handle to the directory that will contain the Context's
// persistent data. If it is left unset, then the created Context will be // persistent data. If it is left unset, then the created Context will be
// stateless, with all of its data discarded upon Context destruction. // stateless, with all of its data discarded upon Context destruction.
handle<channel>? dataDirectory; handle<channel>? data_directory;
}; };
...@@ -67,22 +67,21 @@ void ContextProviderImpl::Create( ...@@ -67,22 +67,21 @@ void ContextProviderImpl::Create(
// Context needs access to the read-only SSL root certificates list. // Context needs access to the read-only SSL root certificates list.
launch_options.paths_to_clone.push_back(base::FilePath("/config/ssl")); launch_options.paths_to_clone.push_back(base::FilePath("/config/ssl"));
// The context process needs /svc to connect to environment services.
// TODO(https://crbug.com/869216): Don't clone /svc. Instead it should be
// passed in CreateContextParams.
launch_options.paths_to_clone.push_back(base::FilePath("/svc"));
// Transfer the ContextRequest handle to a well-known location in the child // Transfer the ContextRequest handle to a well-known location in the child
// process' handle table. // process' handle table.
zx::channel context_handle(context_request.TakeChannel()); zx::channel context_handle(context_request.TakeChannel());
launch_options.handles_to_transfer.push_back( launch_options.handles_to_transfer.push_back(
{kContextRequestHandleId, context_handle.get()}); {kContextRequestHandleId, context_handle.get()});
// Pass /svc directory specified by the caller.
launch_options.paths_to_transfer.push_back(base::PathToTransfer{
base::FilePath("/svc"), std::move(params.service_directory.release())});
// Pass the data directory. If there is no data dir then --incognito flag is // Pass the data directory. If there is no data dir then --incognito flag is
// added instead. // added instead.
if (params.dataDirectory) { if (params.data_directory) {
launch_options.paths_to_transfer.push_back(base::PathToTransfer{ launch_options.paths_to_transfer.push_back(base::PathToTransfer{
base::FilePath(kWebContextDataPath), params.dataDirectory.release()}); base::FilePath(kWebContextDataPath), params.data_directory.release()});
} else { } else {
launch_command.AppendSwitch(kIncognitoSwitch); launch_command.AppendSwitch(kIncognitoSwitch);
} }
......
...@@ -211,7 +211,7 @@ TEST_F(ContextProviderImplTest, WithProfileDir) { ...@@ -211,7 +211,7 @@ TEST_F(ContextProviderImplTest, WithProfileDir) {
0); 0);
// Pass a handle data dir to the context. // Pass a handle data dir to the context.
create_params.dataDirectory.reset( create_params.data_directory.reset(
base::fuchsia::GetHandleFromFile( base::fuchsia::GetHandleFromFile(
base::File(profile_temp_dir.GetPath(), base::File(profile_temp_dir.GetPath(),
base::File::FLAG_OPEN | base::File::FLAG_READ)) base::File::FLAG_OPEN | base::File::FLAG_READ))
......
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