blob: 1804e1bb5e41e0c974194bbcecb792d018fb2ed0 [file] [log] [blame]
Kevin Marshall323013a92018-06-18 21:02:141// Copyright 2018 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
Fabrice de Gans-Riberi3fa1c0fa2019-02-08 18:55:275#ifndef FUCHSIA_ENGINE_CONTEXT_PROVIDER_IMPL_H_
6#define FUCHSIA_ENGINE_CONTEXT_PROVIDER_IMPL_H_
Kevin Marshall323013a92018-06-18 21:02:147
Fabrice de Gans-Riberifbfefa3f2019-04-11 19:13:318#include <fuchsia/web/cpp/fidl.h>
Kevin Marshall323013a92018-06-18 21:02:149#include <lib/fidl/cpp/binding_set.h>
Fabrice de Gans-Riberia16cac82019-06-03 19:03:2010#include <lib/fidl/cpp/interface_ptr_set.h>
Kevin Marshallb68b558b2018-08-21 06:26:3411#include <memory>
Kevin Marshall323013a92018-06-18 21:02:1412
13#include "base/callback.h"
14#include "base/macros.h"
Wez4a2ffcb82019-11-20 03:32:0615#include "base/values.h"
Wez0f962c22019-02-12 04:34:3016#include "fuchsia/engine/web_engine_export.h"
Kevin Marshall323013a92018-06-18 21:02:1417
18namespace base {
Sergey Ulanov9c6f36a2018-07-30 15:19:2719class CommandLine;
Kevin Marshall323013a92018-06-18 21:02:1420struct LaunchOptions;
21class Process;
22} // namespace base
23
Wez0f962c22019-02-12 04:34:3024class WEB_ENGINE_EXPORT ContextProviderImpl
Fabrice de Gans-Riberia16cac82019-06-03 19:03:2025 : public fuchsia::web::ContextProvider,
26 public fuchsia::web::Debug {
Kevin Marshall323013a92018-06-18 21:02:1427 public:
Wezf8b14ab2019-02-27 19:19:4028 using LaunchCallbackForTest = base::RepeatingCallback<base::Process(
29 const base::CommandLine& command,
30 const base::LaunchOptions& options)>;
31
Wez7067ee42019-10-03 02:01:0932 // Handle Id used to pass the request channel to Context processes.
33 static const uint32_t kContextRequestHandleId;
34
Kevin Marshall323013a92018-06-18 21:02:1435 ContextProviderImpl();
36 ~ContextProviderImpl() override;
37
Fabrice de Gans-Riberifbfefa3f2019-04-11 19:13:3138 // fuchsia::web::ContextProvider implementation.
39 void Create(
40 fuchsia::web::CreateContextParams params,
41 fidl::InterfaceRequest<fuchsia::web::Context> context_request) override;
Kevin Marshall323013a92018-06-18 21:02:1442
Wezf8b14ab2019-02-27 19:19:4043 // Sets a |launch| callback to use instead of calling LaunchProcess() to
44 // create Context processes.
45 void SetLaunchCallbackForTest(LaunchCallbackForTest launch);
46
Wez4a2ffcb82019-11-20 03:32:0647 // Sets a config to use for the test, instead of looking for the config file.
48 void set_config_for_test(base::Value config) {
49 config_for_test_ = std::move(config);
50 }
51
Kevin Marshall323013a92018-06-18 21:02:1452 private:
Fabrice de Gans-Riberia16cac82019-06-03 19:03:2053 // fuchsia::web::Debug implementation.
54 void EnableDevTools(
55 fidl::InterfaceHandle<fuchsia::web::DevToolsListener> listener,
56 EnableDevToolsCallback callback) override;
57
Wezf8b14ab2019-02-27 19:19:4058 // Set by tests to use to launch Context child processes, e.g. to allow a
59 // fake Context process to be launched.
60 LaunchCallbackForTest launch_for_test_;
Kevin Marshallb68b558b2018-08-21 06:26:3461
Wez4a2ffcb82019-11-20 03:32:0662 // Set by configuration tests.
63 base::Value config_for_test_;
64
Fabrice de Gans-Riberia16cac82019-06-03 19:03:2065 // The DevToolsListeners registered via the Debug interface.
66 fidl::InterfacePtrSet<fuchsia::web::DevToolsListener> devtools_listeners_;
67
Kevin Marshall323013a92018-06-18 21:02:1468 DISALLOW_COPY_AND_ASSIGN(ContextProviderImpl);
69};
70
Fabrice de Gans-Riberi3fa1c0fa2019-02-08 18:55:2771#endif // FUCHSIA_ENGINE_CONTEXT_PROVIDER_IMPL_H_