Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_DEBUGGER_DEVTOOLS_MANAGER_H_ | 5 #ifndef CONTENT_BROWSER_DEBUGGER_DEVTOOLS_MANAGER_IMPL_H_ |
| 6 #define CONTENT_BROWSER_DEBUGGER_DEVTOOLS_MANAGER_H_ | 6 #define CONTENT_BROWSER_DEBUGGER_DEVTOOLS_MANAGER_IMPL_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/singleton.h" | |
| 13 #include "content/browser/debugger/devtools_agent_host.h" | 14 #include "content/browser/debugger/devtools_agent_host.h" |
| 14 #include "content/browser/debugger/devtools_client_host.h" | |
| 15 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
| 16 #include "content/public/browser/devtools/devtools_client_host.h" | |
| 17 #include "content/public/browser/devtools/devtools_manager.h" | |
| 18 #include "content/public/browser/notification_observer.h" | |
| 19 #include "content/public/browser/notification_registrar.h" | |
| 16 | 20 |
| 17 class DevToolsAgentHost; | |
| 18 class GURL; | 21 class GURL; |
| 19 class RenderViewHost; | 22 class RenderViewHost; |
| 20 class TabContents; | 23 class TabContents; |
| 21 | 24 |
| 22 namespace IPC { | 25 namespace IPC { |
| 23 class Message; | 26 class Message; |
| 24 } | 27 } |
| 25 | 28 |
| 29 namespace content { | |
| 30 | |
| 31 class DevToolsAgentHost; | |
| 32 | |
| 26 // This class is a singleton that manages DevToolsClientHost instances and | 33 // This class is a singleton that manages DevToolsClientHost instances and |
| 27 // routes messages between developer tools clients and agents. | 34 // routes messages between developer tools clients and agents. |
| 28 // | 35 // |
| 29 // Methods below that accept inspected RenderViewHost as a parameter are | 36 // Methods below that accept inspected RenderViewHost as a parameter are |
| 30 // just convenience methods that call corresponding methods accepting | 37 // just convenience methods that call corresponding methods accepting |
| 31 // DevToolAgentHost. | 38 // DevToolAgentHost. |
| 32 class CONTENT_EXPORT DevToolsManager | 39 class CONTENT_EXPORT DevToolsManagerImpl |
| 33 : public DevToolsClientHost::CloseListener, | 40 : public DevToolsClientHost::CloseListener, |
| 34 public DevToolsAgentHost::CloseListener { | 41 public DevToolsAgentHost::CloseListener, |
| 42 public NotificationObserver, | |
| 43 public DevToolsManager { | |
| 35 public: | 44 public: |
| 36 static DevToolsManager* GetInstance(); | 45 // Returns single instance of this class. The instance is destroyed on the |
| 46 // browser main loop exit so this method MUST NOT be called after that point. | |
| 47 static DevToolsManagerImpl* GetInstance(); | |
| 37 | 48 |
| 38 DevToolsManager(); | 49 DevToolsManagerImpl(); |
| 39 virtual ~DevToolsManager(); | 50 virtual ~DevToolsManagerImpl(); |
| 40 | 51 |
| 41 // Returns DevToolsClientHost registered for |inspected_rvh| or NULL if | 52 virtual bool ForwardToDevToolsAgent(DevToolsClientHost* from, |
| 42 // there is no alive DevToolsClientHost registered for |inspected_rvh|. | 53 const IPC::Message& message) OVERRIDE; |
| 43 DevToolsClientHost* GetDevToolsClientHostFor(RenderViewHost* inspected_rvh); | |
| 44 | |
| 45 // Registers new DevToolsClientHost for |inspected_rvh|. There must be no | |
| 46 // other DevToolsClientHosts registered for the RenderViewHost at the moment. | |
| 47 void RegisterDevToolsClientHostFor(RenderViewHost* inspected_rvh, | |
| 48 DevToolsClientHost* client_host); | |
| 49 void UnregisterDevToolsClientHostFor(RenderViewHost* inspected_rvh); | |
| 50 | |
| 51 bool ForwardToDevToolsAgent(DevToolsClientHost* from, | |
| 52 const IPC::Message& message); | |
| 53 void ForwardToDevToolsClient(DevToolsAgentHost* agent_host, | 54 void ForwardToDevToolsClient(DevToolsAgentHost* agent_host, |
| 54 const IPC::Message& message); | 55 const IPC::Message& message); |
| 55 | 56 |
| 56 void SaveAgentRuntimeState(DevToolsAgentHost* agent_host, | 57 void SaveAgentRuntimeState(DevToolsAgentHost* agent_host, |
| 57 const std::string& state); | 58 const std::string& state); |
| 58 | 59 |
| 59 // Sends 'Attach' message to the agent using |dest_rvh| in case | 60 // Sends 'Attach' message to the agent using |dest_rvh| in case |
| 60 // there is a DevToolsClientHost registered for the |inspected_rvh|. | 61 // there is a DevToolsClientHost registered for the |inspected_rvh|. |
| 61 void OnNavigatingToPendingEntry(RenderViewHost* inspected_rvh, | 62 void OnNavigatingToPendingEntry(RenderViewHost* inspected_rvh, |
| 62 RenderViewHost* dest_rvh, | 63 RenderViewHost* dest_rvh, |
| 63 const GURL& gurl); | 64 const GURL& gurl); |
| 64 void OnCancelPendingNavigation(RenderViewHost* pending, | 65 void OnCancelPendingNavigation(RenderViewHost* pending, |
| 65 RenderViewHost* current); | 66 RenderViewHost* current); |
| 66 | 67 |
| 67 // Invoked when a tab is replaced by another tab. This is triggered by | 68 // Invoked when a tab is replaced by another tab. This is triggered by |
| 68 // TabStripModel::ReplaceTabContentsAt. | 69 // TabStripModel::ReplaceTabContentsAt. |
| 69 void TabReplaced(TabContents* old_tab, TabContents* new_tab); | 70 virtual void TabReplaced(TabContents* old_tab, TabContents* new_tab) OVERRIDE; |
| 70 | |
| 71 // Detaches client host and returns cookie that can be used in | |
| 72 // AttachClientHost. | |
| 73 int DetachClientHost(RenderViewHost* from_rvh); | |
| 74 | |
| 75 // Attaches orphan client host to new render view host. | |
| 76 void AttachClientHost(int client_host_cookie, | |
| 77 RenderViewHost* to_rvh); | |
| 78 | 71 |
| 79 // Closes all open developer tools windows. | 72 // Closes all open developer tools windows. |
| 80 void CloseAllClientHosts(); | 73 virtual void CloseAllClientHosts() OVERRIDE; |
| 81 | 74 |
| 82 void AttachClientHost(int client_host_cookie, | 75 virtual void AttachClientHost(int client_host_cookie, |
| 83 DevToolsAgentHost* to_agent); | 76 DevToolsAgentHost* to_agent) OVERRIDE; |
| 84 DevToolsClientHost* GetDevToolsClientHostFor(DevToolsAgentHost* agent_host); | 77 virtual DevToolsClientHost* GetDevToolsClientHostFor( |
| 85 void RegisterDevToolsClientHostFor(DevToolsAgentHost* agent_host, | 78 DevToolsAgentHost* agent_host) OVERRIDE; |
| 86 DevToolsClientHost* client_host); | 79 virtual void RegisterDevToolsClientHostFor( |
| 87 void UnregisterDevToolsClientHostFor(DevToolsAgentHost* agent_host); | 80 DevToolsAgentHost* agent_host, |
| 88 int DetachClientHost(DevToolsAgentHost* from_agent); | 81 DevToolsClientHost* client_host) OVERRIDE; |
| 82 virtual void UnregisterDevToolsClientHostFor( | |
| 83 DevToolsAgentHost* agent_host) OVERRIDE; | |
| 84 virtual int DetachClientHost(DevToolsAgentHost* from_agent) OVERRIDE; | |
| 89 | 85 |
| 90 private: | 86 private: |
| 87 friend struct DefaultSingletonTraits<DevToolsManagerImpl>; | |
| 88 | |
| 91 // DevToolsClientHost::CloseListener override. | 89 // DevToolsClientHost::CloseListener override. |
| 92 // This method will remove all references from the manager to the | 90 // This method will remove all references from the manager to the |
| 93 // DevToolsClientHost and unregister all listeners related to the | 91 // DevToolsClientHost and unregister all listeners related to the |
| 94 // DevToolsClientHost. | 92 // DevToolsClientHost. |
| 95 virtual void ClientHostClosing(DevToolsClientHost* host) OVERRIDE; | 93 virtual void ClientHostClosing(DevToolsClientHost* host) OVERRIDE; |
| 96 | 94 |
| 97 // DevToolsAgentHost::CloseListener implementation. | 95 // DevToolsAgentHost::CloseListener implementation. |
| 98 virtual void AgentHostClosing(DevToolsAgentHost* host) OVERRIDE; | 96 virtual void AgentHostClosing(DevToolsAgentHost* host) OVERRIDE; |
| 99 | 97 |
| 98 // NotificationObserver implementation. | |
| 99 virtual void Observe(int type, | |
| 100 const content::NotificationSource& source, | |
| 101 const content::NotificationDetails& details) OVERRIDE; | |
| 102 | |
| 100 // Returns DevToolsAgentHost inspected by the DevToolsClientHost. | 103 // Returns DevToolsAgentHost inspected by the DevToolsClientHost. |
| 101 DevToolsAgentHost* GetAgentHost(DevToolsClientHost* client_host); | 104 DevToolsAgentHost* GetAgentHost(DevToolsClientHost* client_host); |
| 102 | 105 |
| 103 void BindClientHost(DevToolsAgentHost* agent_host, | 106 void BindClientHost(DevToolsAgentHost* agent_host, |
| 104 DevToolsClientHost* client_host); | 107 DevToolsClientHost* client_host); |
| 105 void UnbindClientHost(DevToolsAgentHost* agent_host, | 108 void UnbindClientHost(DevToolsAgentHost* agent_host, |
| 106 DevToolsClientHost* client_host); | 109 DevToolsClientHost* client_host); |
| 107 | 110 |
| 111 int DetachClientHost(RenderViewHost* from_rvh); | |
|
pfeldman
2011/11/21 14:52:21
Could you leave comments to these methods?
yurys
2011/11/21 15:07:14
Done.
| |
| 112 void AttachClientHost(int client_host_cookie, | |
| 113 RenderViewHost* to_rvh); | |
| 114 | |
| 108 // These two maps are for tracking dependencies between inspected tabs and | 115 // These two maps are for tracking dependencies between inspected tabs and |
| 109 // their DevToolsClientHosts. They are useful for routing devtools messages | 116 // their DevToolsClientHosts. They are useful for routing devtools messages |
| 110 // and allow us to have at most one devtools client host per tab. | 117 // and allow us to have at most one devtools client host per tab. |
| 111 // | 118 // |
| 112 // DevToolsManager start listening to DevToolsClientHosts when they are put | 119 // DevToolsManagerImpl starts listening to DevToolsClientHosts when they are |
| 113 // into these maps and removes them when they are closing. | 120 // put into these maps and removes them when they are closing. |
| 114 typedef std::map<DevToolsAgentHost*, DevToolsClientHost*> | 121 typedef std::map<DevToolsAgentHost*, DevToolsClientHost*> |
| 115 AgentToClientHostMap; | 122 AgentToClientHostMap; |
| 116 AgentToClientHostMap agent_to_client_host_; | 123 AgentToClientHostMap agent_to_client_host_; |
| 117 | 124 |
| 118 typedef std::map<DevToolsClientHost*, DevToolsAgentHost*> | 125 typedef std::map<DevToolsClientHost*, DevToolsAgentHost*> |
| 119 ClientHostToInspectedRvhMap; | 126 ClientHostToInspectedRvhMap; |
| 120 ClientHostToInspectedRvhMap client_to_agent_host_; | 127 ClientHostToInspectedRvhMap client_to_agent_host_; |
| 121 | 128 |
| 122 typedef std::map<DevToolsAgentHost*, std::string> AgentRuntimeStates; | 129 typedef std::map<DevToolsAgentHost*, std::string> AgentRuntimeStates; |
| 123 AgentRuntimeStates agent_runtime_states_; | 130 AgentRuntimeStates agent_runtime_states_; |
| 124 | 131 |
| 125 typedef std::map<int, std::pair<DevToolsClientHost*, std::string> > | 132 typedef std::map<int, std::pair<DevToolsClientHost*, std::string> > |
| 126 OrphanClientHosts; | 133 OrphanClientHosts; |
| 127 OrphanClientHosts orphan_client_hosts_; | 134 OrphanClientHosts orphan_client_hosts_; |
| 128 int last_orphan_cookie_; | 135 int last_orphan_cookie_; |
| 136 content::NotificationRegistrar notification_registrar_; | |
| 129 | 137 |
| 130 DISALLOW_COPY_AND_ASSIGN(DevToolsManager); | 138 DISALLOW_COPY_AND_ASSIGN(DevToolsManagerImpl); |
| 131 }; | 139 }; |
| 132 | 140 |
| 133 #endif // CONTENT_BROWSER_DEBUGGER_DEVTOOLS_MANAGER_H_ | 141 } // namespace content |
| 142 | |
| 143 #endif // CONTENT_BROWSER_DEBUGGER_DEVTOOLS_MANAGER_IMPL_H_ | |
| OLD | NEW |