blob: dfb3e4cc45fa035aaf81fb84bfbf315d76adf83c [file] [log] [blame]
Avi Drissman8ba1bad2022-09-13 19:22:361// Copyright 2016 The Chromium Authors
mhashmie2445fe732016-10-29 20:46:322// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef COMPONENTS_UI_DEVTOOLS_DEVTOOLS_BASE_AGENT_H_
6#define COMPONENTS_UI_DEVTOOLS_DEVTOOLS_BASE_AGENT_H_
7
Andrey Kosyakov103b8f2a2021-11-16 08:06:268#include "components/ui_devtools/protocol.h"
mhashmie2445fe732016-10-29 20:46:329
thanhph3f3968512017-06-21 00:37:2310namespace ui_devtools {
mhashmie2445fe732016-10-29 20:46:3211
12class UiDevToolsAgent {
13 public:
Sorin Jianu64e6e7592024-10-09 14:15:2614 UiDevToolsAgent() = default;
15 virtual ~UiDevToolsAgent() = default;
mhashmie2445fe732016-10-29 20:46:3216
17 virtual void Init(protocol::UberDispatcher*) = 0;
mhashmica5eebc2016-11-03 15:17:4518 virtual void Disable() = 0;
mhashmie2445fe732016-10-29 20:46:3219};
20
21// A base agent so that any Backend implementation has access to the
22// corresponding frontend instance. This also wires the backend with
23// the dispatcher. When initializing an instance of this class,
24// the template argument is simply the generated Metainfo class of
25// any domain type such as DOM or CSS.
26template <typename DomainMetainfo>
27class UiDevToolsBaseAgent : public UiDevToolsAgent,
28 public DomainMetainfo::BackendClass {
29 public:
Peter Boström9f667c382021-10-01 20:09:3130 UiDevToolsBaseAgent(const UiDevToolsBaseAgent&) = delete;
31 UiDevToolsBaseAgent& operator=(const UiDevToolsBaseAgent&) = delete;
32
mhashmica5eebc2016-11-03 15:17:4533 // UiDevToolsAgent:
34 void Init(protocol::UberDispatcher* dispatcher) override {
mhashmie2445fe732016-10-29 20:46:3235 frontend_.reset(
36 new typename DomainMetainfo::FrontendClass(dispatcher->channel()));
37 DomainMetainfo::DispatcherClass::wire(dispatcher, this);
38 }
39
mhashmica5eebc2016-11-03 15:17:4540 void Disable() override { disable(); }
41
42 // Common methods between all generated Backends, subclasses may
43 // choose to override them (but not necessary).
Johannes Henkeld5fead72020-03-20 02:09:0144 protocol::Response enable() override { return protocol::Response::Success(); }
mhashmica5eebc2016-11-03 15:17:4545
Johannes Henkeld5fead72020-03-20 02:09:0146 protocol::Response disable() override {
47 return protocol::Response::Success();
48 }
mhashmica5eebc2016-11-03 15:17:4549
mhashmie2445fe732016-10-29 20:46:3250 protected:
Johannes Henkeld5fead72020-03-20 02:09:0151 UiDevToolsBaseAgent() = default;
mhashmie2445fe732016-10-29 20:46:3252 typename DomainMetainfo::FrontendClass* frontend() const {
53 return frontend_.get();
54 }
55
56 private:
57 std::unique_ptr<typename DomainMetainfo::FrontendClass> frontend_;
mhashmie2445fe732016-10-29 20:46:3258};
59
thanhph3f3968512017-06-21 00:37:2360} // namespace ui_devtools
mhashmie2445fe732016-10-29 20:46:3261
62#endif // COMPONENTS_UI_DEVTOOLS_DEVTOOLS_BASE_AGENT_H_