Kevin Marshall | 323013a9 | 2018-06-18 21:02:14 | [diff] [blame] | 1 | // 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-Riberi | 3fa1c0fa | 2019-02-08 18:55:27 | [diff] [blame] | 5 | #ifndef FUCHSIA_ENGINE_CONTEXT_PROVIDER_IMPL_H_ |
| 6 | #define FUCHSIA_ENGINE_CONTEXT_PROVIDER_IMPL_H_ |
Kevin Marshall | 323013a9 | 2018-06-18 21:02:14 | [diff] [blame] | 7 | |
Fabrice de Gans-Riberi | fbfefa3f | 2019-04-11 19:13:31 | [diff] [blame] | 8 | #include <fuchsia/web/cpp/fidl.h> |
Kevin Marshall | 323013a9 | 2018-06-18 21:02:14 | [diff] [blame] | 9 | #include <lib/fidl/cpp/binding_set.h> |
Fabrice de Gans-Riberi | a16cac8 | 2019-06-03 19:03:20 | [diff] [blame] | 10 | #include <lib/fidl/cpp/interface_ptr_set.h> |
Kevin Marshall | b68b558b | 2018-08-21 06:26:34 | [diff] [blame] | 11 | #include <memory> |
Kevin Marshall | 323013a9 | 2018-06-18 21:02:14 | [diff] [blame] | 12 | |
| 13 | #include "base/callback.h" |
| 14 | #include "base/macros.h" |
Wez | 4a2ffcb8 | 2019-11-20 03:32:06 | [diff] [blame] | 15 | #include "base/values.h" |
Wez | 0f962c2 | 2019-02-12 04:34:30 | [diff] [blame] | 16 | #include "fuchsia/engine/web_engine_export.h" |
Kevin Marshall | 323013a9 | 2018-06-18 21:02:14 | [diff] [blame] | 17 | |
| 18 | namespace base { |
Sergey Ulanov | 9c6f36a | 2018-07-30 15:19:27 | [diff] [blame] | 19 | class CommandLine; |
Kevin Marshall | 323013a9 | 2018-06-18 21:02:14 | [diff] [blame] | 20 | struct LaunchOptions; |
| 21 | class Process; |
| 22 | } // namespace base |
| 23 | |
Wez | 0f962c2 | 2019-02-12 04:34:30 | [diff] [blame] | 24 | class WEB_ENGINE_EXPORT ContextProviderImpl |
Fabrice de Gans-Riberi | a16cac8 | 2019-06-03 19:03:20 | [diff] [blame] | 25 | : public fuchsia::web::ContextProvider, |
| 26 | public fuchsia::web::Debug { |
Kevin Marshall | 323013a9 | 2018-06-18 21:02:14 | [diff] [blame] | 27 | public: |
Wez | f8b14ab | 2019-02-27 19:19:40 | [diff] [blame] | 28 | using LaunchCallbackForTest = base::RepeatingCallback<base::Process( |
| 29 | const base::CommandLine& command, |
| 30 | const base::LaunchOptions& options)>; |
| 31 | |
Wez | 7067ee4 | 2019-10-03 02:01:09 | [diff] [blame] | 32 | // Handle Id used to pass the request channel to Context processes. |
| 33 | static const uint32_t kContextRequestHandleId; |
| 34 | |
Kevin Marshall | 323013a9 | 2018-06-18 21:02:14 | [diff] [blame] | 35 | ContextProviderImpl(); |
| 36 | ~ContextProviderImpl() override; |
| 37 | |
Fabrice de Gans-Riberi | fbfefa3f | 2019-04-11 19:13:31 | [diff] [blame] | 38 | // fuchsia::web::ContextProvider implementation. |
| 39 | void Create( |
| 40 | fuchsia::web::CreateContextParams params, |
| 41 | fidl::InterfaceRequest<fuchsia::web::Context> context_request) override; |
Kevin Marshall | 323013a9 | 2018-06-18 21:02:14 | [diff] [blame] | 42 | |
Wez | f8b14ab | 2019-02-27 19:19:40 | [diff] [blame] | 43 | // Sets a |launch| callback to use instead of calling LaunchProcess() to |
| 44 | // create Context processes. |
| 45 | void SetLaunchCallbackForTest(LaunchCallbackForTest launch); |
| 46 | |
Wez | 4a2ffcb8 | 2019-11-20 03:32:06 | [diff] [blame] | 47 | // 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 Marshall | 323013a9 | 2018-06-18 21:02:14 | [diff] [blame] | 52 | private: |
Fabrice de Gans-Riberi | a16cac8 | 2019-06-03 19:03:20 | [diff] [blame] | 53 | // fuchsia::web::Debug implementation. |
| 54 | void EnableDevTools( |
| 55 | fidl::InterfaceHandle<fuchsia::web::DevToolsListener> listener, |
| 56 | EnableDevToolsCallback callback) override; |
| 57 | |
Wez | f8b14ab | 2019-02-27 19:19:40 | [diff] [blame] | 58 | // 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 Marshall | b68b558b | 2018-08-21 06:26:34 | [diff] [blame] | 61 | |
Wez | 4a2ffcb8 | 2019-11-20 03:32:06 | [diff] [blame] | 62 | // Set by configuration tests. |
| 63 | base::Value config_for_test_; |
| 64 | |
Fabrice de Gans-Riberi | a16cac8 | 2019-06-03 19:03:20 | [diff] [blame] | 65 | // The DevToolsListeners registered via the Debug interface. |
| 66 | fidl::InterfacePtrSet<fuchsia::web::DevToolsListener> devtools_listeners_; |
| 67 | |
Kevin Marshall | 323013a9 | 2018-06-18 21:02:14 | [diff] [blame] | 68 | DISALLOW_COPY_AND_ASSIGN(ContextProviderImpl); |
| 69 | }; |
| 70 | |
Fabrice de Gans-Riberi | 3fa1c0fa | 2019-02-08 18:55:27 | [diff] [blame] | 71 | #endif // FUCHSIA_ENGINE_CONTEXT_PROVIDER_IMPL_H_ |