summaryrefslogtreecommitdiff
path: root/chromium/fuchsia/engine/context_provider_impl.h
blob: 1804e1bb5e41e0c974194bbcecb792d018fb2ed0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef FUCHSIA_ENGINE_CONTEXT_PROVIDER_IMPL_H_
#define FUCHSIA_ENGINE_CONTEXT_PROVIDER_IMPL_H_

#include <fuchsia/web/cpp/fidl.h>
#include <lib/fidl/cpp/binding_set.h>
#include <lib/fidl/cpp/interface_ptr_set.h>
#include <memory>

#include "base/callback.h"
#include "base/macros.h"
#include "base/values.h"
#include "fuchsia/engine/web_engine_export.h"

namespace base {
class CommandLine;
struct LaunchOptions;
class Process;
}  // namespace base

class WEB_ENGINE_EXPORT ContextProviderImpl
    : public fuchsia::web::ContextProvider,
      public fuchsia::web::Debug {
 public:
  using LaunchCallbackForTest = base::RepeatingCallback<base::Process(
      const base::CommandLine& command,
      const base::LaunchOptions& options)>;

  // Handle Id used to pass the request channel to Context processes.
  static const uint32_t kContextRequestHandleId;

  ContextProviderImpl();
  ~ContextProviderImpl() override;

  // fuchsia::web::ContextProvider implementation.
  void Create(
      fuchsia::web::CreateContextParams params,
      fidl::InterfaceRequest<fuchsia::web::Context> context_request) override;

  // Sets a |launch| callback to use instead of calling LaunchProcess() to
  // create Context processes.
  void SetLaunchCallbackForTest(LaunchCallbackForTest launch);

  // Sets a config to use for the test, instead of looking for the config file.
  void set_config_for_test(base::Value config) {
    config_for_test_ = std::move(config);
  }

 private:
  // fuchsia::web::Debug implementation.
  void EnableDevTools(
      fidl::InterfaceHandle<fuchsia::web::DevToolsListener> listener,
      EnableDevToolsCallback callback) override;

  // Set by tests to use to launch Context child processes, e.g. to allow a
  // fake Context process to be launched.
  LaunchCallbackForTest launch_for_test_;

  // Set by configuration tests.
  base::Value config_for_test_;

  // The DevToolsListeners registered via the Debug interface.
  fidl::InterfacePtrSet<fuchsia::web::DevToolsListener> devtools_listeners_;

  DISALLOW_COPY_AND_ASSIGN(ContextProviderImpl);
};

#endif  // FUCHSIA_ENGINE_CONTEXT_PROVIDER_IMPL_H_