Revert 268405 "Make sure that ScratchBuffer::Allocate() always r..."
[chromium-blink-merge.git] / content / browser / devtools / devtools_manager_impl.h
bloba14b2f1ca115b8616c3b33228113a5fa23b0668d
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.
5 #ifndef CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_MANAGER_IMPL_H_
6 #define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_MANAGER_IMPL_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/compiler_specific.h"
13 #include "base/memory/singleton.h"
14 #include "content/browser/devtools/devtools_agent_host_impl.h"
15 #include "content/common/content_export.h"
16 #include "content/public/browser/devtools_client_host.h"
17 #include "content/public/browser/devtools_manager.h"
19 class GURL;
21 namespace IPC {
22 class Message;
25 namespace content {
27 class RenderViewHost;
29 // This class is a singleton that manages DevToolsClientHost instances and
30 // routes messages between developer tools clients and agents.
32 // Methods below that accept inspected RenderViewHost as a parameter are
33 // just convenience methods that call corresponding methods accepting
34 // DevToolAgentHost.
35 class CONTENT_EXPORT DevToolsManagerImpl
36 : public DevToolsAgentHostImpl::CloseListener,
37 public DevToolsManager {
38 public:
39 // Returns single instance of this class. The instance is destroyed on the
40 // browser main loop exit so this method MUST NOT be called after that point.
41 static DevToolsManagerImpl* GetInstance();
43 DevToolsManagerImpl();
44 virtual ~DevToolsManagerImpl();
46 void DispatchOnInspectorFrontend(DevToolsAgentHost* agent_host,
47 const std::string& message);
49 // DevToolsManager implementation
50 virtual bool DispatchOnInspectorBackend(DevToolsClientHost* from,
51 const std::string& message) OVERRIDE;
52 virtual void CloseAllClientHosts() OVERRIDE;
53 virtual DevToolsAgentHost* GetDevToolsAgentHostFor(
54 DevToolsClientHost* client_host) OVERRIDE;
55 virtual void RegisterDevToolsClientHostFor(
56 DevToolsAgentHost* agent_host,
57 DevToolsClientHost* client_host) OVERRIDE;
58 virtual void ClientHostClosing(DevToolsClientHost* host) OVERRIDE;
59 virtual void AddAgentStateCallback(const Callback& callback) OVERRIDE;
60 virtual void RemoveAgentStateCallback(const Callback& callback) OVERRIDE;
62 private:
63 friend class DevToolsAgentHostImpl;
64 friend class RenderViewDevToolsAgentHost;
65 friend struct DefaultSingletonTraits<DevToolsManagerImpl>;
67 // DevToolsAgentHost::CloseListener implementation.
68 virtual void AgentHostClosing(DevToolsAgentHostImpl* host) OVERRIDE;
70 void BindClientHost(DevToolsAgentHostImpl* agent_host,
71 DevToolsClientHost* client_host);
72 void UnbindClientHost(DevToolsAgentHostImpl* agent_host,
73 DevToolsClientHost* client_host);
75 DevToolsClientHost* GetDevToolsClientHostFor(
76 DevToolsAgentHostImpl* agent_host);
78 void UnregisterDevToolsClientHostFor(DevToolsAgentHostImpl* agent_host);
80 void NotifyObservers(DevToolsAgentHost* agent_host, bool attached);
82 // These two maps are for tracking dependencies between inspected contents and
83 // their DevToolsClientHosts. They are useful for routing devtools messages
84 // and allow us to have at most one devtools client host per contents.
86 // DevToolsManagerImpl starts listening to DevToolsClientHosts when they are
87 // put into these maps and removes them when they are closing.
88 typedef std::map<DevToolsAgentHostImpl*, DevToolsClientHost*>
89 AgentToClientHostMap;
90 AgentToClientHostMap agent_to_client_host_;
92 typedef std::map<DevToolsClientHost*, scoped_refptr<DevToolsAgentHostImpl> >
93 ClientToAgentHostMap;
94 ClientToAgentHostMap client_to_agent_host_;
96 typedef std::vector<const Callback*> CallbackContainer;
97 CallbackContainer callbacks_;
99 DISALLOW_COPY_AND_ASSIGN(DevToolsManagerImpl);
102 } // namespace content
104 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_MANAGER_IMPL_H_