OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_MANAGER_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_MANAGER_IMPL_H_ |
6 #define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_MANAGER_IMPL_H_ | 6 #define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_MANAGER_IMPL_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/memory/singleton.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 } |
14 | 24 |
15 namespace content { | 25 namespace content { |
16 | 26 |
| 27 class BrowserContext; |
17 class DevToolsManagerDelegate; | 28 class DevToolsManagerDelegate; |
| 29 class RenderViewHost; |
18 | 30 |
19 // This class is a singleton that manage global DevTools state for the whole | 31 // This class is a singleton that manages DevToolsClientHost instances and |
20 // browser. | 32 // routes messages between developer tools clients and agents. |
21 class DevToolsManagerImpl { | 33 // |
| 34 // Methods below that accept inspected RenderViewHost as a parameter are |
| 35 // just convenience methods that call corresponding methods accepting |
| 36 // DevToolAgentHost. |
| 37 class CONTENT_EXPORT DevToolsManagerImpl |
| 38 : public DevToolsAgentHostImpl::CloseListener, |
| 39 public DevToolsManager { |
22 public: | 40 public: |
23 // Returns single instance of this class. The instance is destroyed on the | 41 // Returns single instance of this class. The instance is destroyed on the |
24 // browser main loop exit so this method MUST NOT be called after that point. | 42 // browser main loop exit so this method MUST NOT be called after that point. |
25 static DevToolsManagerImpl* GetInstance(); | 43 static DevToolsManagerImpl* GetInstance(); |
26 | 44 |
27 DevToolsManagerImpl(); | 45 DevToolsManagerImpl(); |
28 virtual ~DevToolsManagerImpl(); | 46 virtual ~DevToolsManagerImpl(); |
29 | 47 |
| 48 // Opens the inspector for |agent_host|. |
| 49 void Inspect(BrowserContext* browser_context, DevToolsAgentHost* agent_host); |
| 50 |
| 51 void DispatchOnInspectorFrontend(DevToolsAgentHost* agent_host, |
| 52 const std::string& message); |
| 53 |
30 DevToolsManagerDelegate* delegate() const { return delegate_.get(); } | 54 DevToolsManagerDelegate* delegate() const { return delegate_.get(); } |
31 void OnClientAttached(); | 55 |
32 void OnClientDetached(); | 56 // DevToolsManager implementation |
| 57 virtual bool DispatchOnInspectorBackend(DevToolsClientHost* from, |
| 58 const std::string& message) OVERRIDE; |
| 59 virtual void CloseAllClientHosts() OVERRIDE; |
| 60 virtual DevToolsAgentHost* GetDevToolsAgentHostFor( |
| 61 DevToolsClientHost* client_host) OVERRIDE; |
| 62 virtual void RegisterDevToolsClientHostFor( |
| 63 DevToolsAgentHost* agent_host, |
| 64 DevToolsClientHost* client_host) OVERRIDE; |
| 65 virtual void ClientHostClosing(DevToolsClientHost* host) OVERRIDE; |
| 66 virtual void AddAgentStateCallback(const Callback& callback) OVERRIDE; |
| 67 virtual void RemoveAgentStateCallback(const Callback& callback) OVERRIDE; |
33 | 68 |
34 private: | 69 private: |
| 70 friend class DevToolsAgentHostImpl; |
| 71 friend class RenderViewDevToolsAgentHost; |
35 friend struct DefaultSingletonTraits<DevToolsManagerImpl>; | 72 friend struct DefaultSingletonTraits<DevToolsManagerImpl>; |
36 | 73 |
| 74 // DevToolsAgentHost::CloseListener implementation. |
| 75 virtual void AgentHostClosing(DevToolsAgentHostImpl* host) OVERRIDE; |
| 76 |
| 77 void BindClientHost(DevToolsAgentHostImpl* agent_host, |
| 78 DevToolsClientHost* client_host); |
| 79 void UnbindClientHost(DevToolsAgentHostImpl* agent_host, |
| 80 DevToolsClientHost* client_host); |
| 81 |
| 82 DevToolsClientHost* GetDevToolsClientHostFor( |
| 83 DevToolsAgentHostImpl* agent_host); |
| 84 |
| 85 void UnregisterDevToolsClientHostFor(DevToolsAgentHostImpl* agent_host); |
| 86 |
| 87 void NotifyObservers(DevToolsAgentHost* agent_host, bool attached); |
| 88 |
| 89 // These two maps are for tracking dependencies between inspected contents and |
| 90 // their DevToolsClientHosts. They are useful for routing devtools messages |
| 91 // and allow us to have at most one devtools client host per contents. |
| 92 // |
| 93 // DevToolsManagerImpl starts listening to DevToolsClientHosts when they are |
| 94 // put into these maps and removes them when they are closing. |
| 95 typedef std::map<DevToolsAgentHostImpl*, DevToolsClientHost*> |
| 96 AgentToClientHostMap; |
| 97 AgentToClientHostMap agent_to_client_host_; |
| 98 |
| 99 typedef std::map<DevToolsClientHost*, scoped_refptr<DevToolsAgentHostImpl> > |
| 100 ClientToAgentHostMap; |
| 101 ClientToAgentHostMap client_to_agent_host_; |
| 102 |
| 103 typedef std::vector<const Callback*> CallbackContainer; |
| 104 CallbackContainer callbacks_; |
| 105 |
37 scoped_ptr<DevToolsManagerDelegate> delegate_; | 106 scoped_ptr<DevToolsManagerDelegate> delegate_; |
38 int client_count_; | |
39 | 107 |
40 DISALLOW_COPY_AND_ASSIGN(DevToolsManagerImpl); | 108 DISALLOW_COPY_AND_ASSIGN(DevToolsManagerImpl); |
41 }; | 109 }; |
42 | 110 |
43 } // namespace content | 111 } // namespace content |
44 | 112 |
45 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_MANAGER_IMPL_H_ | 113 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_MANAGER_IMPL_H_ |
OLD | NEW |