Chromium Code Reviews| Index: content/browser/devtools/devtools_manager.cc |
| diff --git a/content/browser/devtools/devtools_manager.cc b/content/browser/devtools/devtools_manager.cc |
| index 70059c6f251b0ac8fe56d3ea1301d41a18db70ab..0af55b0200f8d4904d79c34397731a5e31d63db5 100644 |
| --- a/content/browser/devtools/devtools_manager.cc |
| +++ b/content/browser/devtools/devtools_manager.cc |
| @@ -10,6 +10,7 @@ |
| #include "content/browser/devtools/devtools_agent_host_impl.h" |
| #include "content/browser/devtools/devtools_http_handler.h" |
| #include "content/browser/loader/netlog_observer.h" |
| +#include "content/browser/web_contents/web_contents_impl.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/content_browser_client.h" |
| #include "content/public/browser/devtools_socket_factory.h" |
| @@ -25,10 +26,10 @@ void DevToolsAgentHost::StartRemoteDebuggingServer( |
| const std::string& product_name, |
| const std::string& user_agent) { |
| DevToolsManager* manager = DevToolsManager::GetInstance(); |
| - if (!manager->delegate()) |
| + if (!manager->GetDelegate()) |
| return; |
| manager->SetHttpHandler(base::WrapUnique(new DevToolsHttpHandler( |
| - manager->delegate(), std::move(server_socket_factory), frontend_url, |
| + manager->GetDelegate(), std::move(server_socket_factory), frontend_url, |
| active_port_output_directory, debug_frontend_dir, product_name, |
| user_agent))); |
| } |
| @@ -45,14 +46,61 @@ DevToolsManager* DevToolsManager::GetInstance() { |
| } |
| DevToolsManager::DevToolsManager() |
| - : delegate_(GetContentClient()->browser()->GetDevToolsManagerDelegate()), |
| + : delegate_initialized_(false), |
| attached_hosts_count_(0) { |
| } |
| DevToolsManager::~DevToolsManager() { |
| + for (DevToolsAgentHostImpl* agent_host : agent_hosts_) { |
|
pfeldman
2016/10/12 23:11:18
How can this happen?
dgozman
2016/10/12 23:23:12
Service workers shutdown later (I think on IO) tha
pfeldman
2016/10/13 17:58:10
Could you mention it the comments here? Also, what
|
| + for (auto& observer : observers_) |
| + observer.AgentHostDestroyed(agent_host); |
| + } |
| + agent_hosts_.clear(); |
| DCHECK(!attached_hosts_count_); |
| } |
| +DevToolsManagerDelegate* DevToolsManager::GetDelegate() { |
| + if (!delegate_initialized_) { |
|
pfeldman
2016/10/12 23:11:18
What is wrong with !delegate_ ?
dgozman
2016/10/12 23:23:12
Client can pass a null one, I don't want to ask fo
|
| + delegate_initialized_ = true; |
| + delegate_.reset( |
| + GetContentClient()->browser()->GetDevToolsManagerDelegate()); |
| + } |
| + return delegate_.get(); |
| +} |
| + |
| +void DevToolsManager::AddObserver(Observer* observer) { |
| + if (!observers_.might_have_observers()) { |
| + // Force all agent hosts when first observer is added. |
| + DevToolsAgentHost::GetOrCreateAll(); |
| + } |
| + observers_.AddObserver(observer); |
| + for (DevToolsAgentHostImpl* agent_host : agent_hosts_) |
| + observer->AgentHostCreated(agent_host); |
| +} |
| + |
| +void DevToolsManager::RemoveObserver(Observer* observer) { |
| + observers_.RemoveObserver(observer); |
| +} |
| + |
| +void DevToolsManager::WebContentsCreated(WebContentsImpl* web_contents) { |
| + if (observers_.might_have_observers()) { |
| + // Force agent host. |
| + DevToolsAgentHost::GetOrCreateFor(web_contents); |
| + } |
| +} |
| + |
| +void DevToolsManager::AgentHostCreated(DevToolsAgentHostImpl* agent_host) { |
| + agent_hosts_.insert(agent_host); |
| + for (auto& observer : observers_) |
| + observer.AgentHostCreated(agent_host); |
| +} |
| + |
| +void DevToolsManager::AgentHostDestroyed(DevToolsAgentHostImpl* agent_host) { |
| + for (auto& observer : observers_) |
| + observer.AgentHostDestroyed(agent_host); |
| + agent_hosts_.erase(agent_host); |
| +} |
| + |
| void DevToolsManager::AgentHostStateChanged( |
| DevToolsAgentHostImpl* agent_host, bool attached) { |
| if (attached) { |