1// Copyright (c) 2012 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
5#ifndef CONTENT_PUBLIC_BROWSER_DEVTOOLS_MANAGER_H_
6#define CONTENT_PUBLIC_BROWSER_DEVTOOLS_MANAGER_H_
7
8#include <string>
9
10#include "base/callback.h"
11#include "content/common/content_export.h"
12
13namespace IPC {
14class Message;
15}
16
17namespace content {
18
19class DevToolsAgentHost;
20class DevToolsClientHost;
21
22// DevToolsManager connects a devtools client to inspected agent and routes
23// devtools messages between the inspected instance represented by the agent
24// and devtools front-end represented by the client. If inspected agent
25// gets terminated DevToolsManager will notify corresponding client and
26// remove it from the map.
27class CONTENT_EXPORT DevToolsManager {
28 public:
29  static DevToolsManager* GetInstance();
30
31  virtual ~DevToolsManager() {}
32
33  // Routes devtools message from |from| client to corresponding
34  // DevToolsAgentHost.
35  virtual bool DispatchOnInspectorBackend(DevToolsClientHost* from,
36                                          const std::string& message) = 0;
37
38  // Disconnects all client hostst.
39  virtual void CloseAllClientHosts() = 0;
40
41  // Returns agent that has |client_host| attached to it if there is one.
42  virtual DevToolsAgentHost* GetDevToolsAgentHostFor(
43      DevToolsClientHost* client_host) = 0;
44
45  // Registers new DevToolsClientHost for inspected |agent_host|. If there is
46  // another DevToolsClientHost registered for the |agent_host| at the moment
47  // it is disconnected.
48  virtual void RegisterDevToolsClientHostFor(
49      DevToolsAgentHost* agent_host,
50      DevToolsClientHost* client_host) = 0;
51
52  // This method will remove all references from the manager to the
53  // DevToolsClientHost and unregister all listeners related to the
54  // DevToolsClientHost. Called by closing client.
55  virtual void ClientHostClosing(DevToolsClientHost* client_host) = 0;
56
57  typedef base::Callback<void(DevToolsAgentHost*, bool attached)> Callback;
58
59  virtual void AddAgentStateCallback(const Callback& callback) = 0;
60  virtual void RemoveAgentStateCallback(const Callback& callback) = 0;
61};
62
63}  // namespace content
64
65#endif  // CONTENT_PUBLIC_BROWSER_DEVTOOLS_MANAGER_H_
66