- add sources.
[platform/framework/web/crosswalk.git] / src / content / browser / devtools / devtools_manager_impl.h
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_BROWSER_DEVTOOLS_DEVTOOLS_MANAGER_IMPL_H_
6 #define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_MANAGER_IMPL_H_
7
8 #include <map>
9 #include <string>
10 #include <vector>
11
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"
18
19 class GURL;
20
21 namespace IPC {
22 class Message;
23 }
24
25 namespace content {
26
27 class RenderViewHost;
28
29 // This class is a singleton that manages DevToolsClientHost instances and
30 // routes messages between developer tools clients and agents.
31 //
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();
42
43   DevToolsManagerImpl();
44   virtual ~DevToolsManagerImpl();
45
46   void DispatchOnInspectorFrontend(DevToolsAgentHost* agent_host,
47                                    const std::string& message);
48
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;
61
62  private:
63   friend class DevToolsAgentHostImpl;
64   friend class RenderViewDevToolsAgentHost;
65   friend struct DefaultSingletonTraits<DevToolsManagerImpl>;
66
67   // DevToolsAgentHost::CloseListener implementation.
68   virtual void AgentHostClosing(DevToolsAgentHostImpl* host) OVERRIDE;
69
70   void BindClientHost(DevToolsAgentHostImpl* agent_host,
71                       DevToolsClientHost* client_host);
72   void UnbindClientHost(DevToolsAgentHostImpl* agent_host,
73                         DevToolsClientHost* client_host);
74
75   DevToolsClientHost* GetDevToolsClientHostFor(
76       DevToolsAgentHostImpl* agent_host);
77
78   void UnregisterDevToolsClientHostFor(DevToolsAgentHostImpl* agent_host);
79
80   void NotifyObservers(DevToolsAgentHost* agent_host, bool attached);
81
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.
85   //
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_;
91
92   typedef std::map<DevToolsClientHost*, scoped_refptr<DevToolsAgentHostImpl> >
93       ClientToAgentHostMap;
94   ClientToAgentHostMap client_to_agent_host_;
95
96   typedef std::vector<const Callback*> CallbackContainer;
97   CallbackContainer callbacks_;
98
99   DISALLOW_COPY_AND_ASSIGN(DevToolsManagerImpl);
100 };
101
102 }  // namespace content
103
104 #endif  // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_MANAGER_IMPL_H_