Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Unified Diff: content/browser/devtools/devtools_agent_host_impl.cc

Issue 467653002: Revert of [DevTools] Make DevTools clients talk directly to DevToolsAgentHost instead of using DevToolsManage… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/devtools/devtools_agent_host_impl.cc
diff --git a/content/browser/devtools/devtools_agent_host_impl.cc b/content/browser/devtools/devtools_agent_host_impl.cc
index 1309eac12e157356ebe73352f9d731bc1c935470..9d4e707165c79fdac8713cf9ad15964809a19573 100644
--- a/content/browser/devtools/devtools_agent_host_impl.cc
+++ b/content/browser/devtools/devtools_agent_host_impl.cc
@@ -5,7 +5,6 @@
#include "content/browser/devtools/devtools_agent_host_impl.h"
#include <map>
-#include <vector>
#include "base/basictypes.h"
#include "base/guid.h"
@@ -13,23 +12,17 @@
#include "content/browser/devtools/devtools_manager_impl.h"
#include "content/browser/devtools/forwarding_agent_host.h"
#include "content/public/browser/browser_thread.h"
-#include "content/public/browser/devtools_manager_delegate.h"
namespace content {
namespace {
typedef std::map<std::string, DevToolsAgentHostImpl*> Instances;
base::LazyInstance<Instances>::Leaky g_instances = LAZY_INSTANCE_INITIALIZER;
-
-typedef std::vector<const DevToolsAgentHost::AgentStateCallback*>
- AgentStateCallbacks;
-base::LazyInstance<AgentStateCallbacks>::Leaky g_callbacks =
- LAZY_INSTANCE_INITIALIZER;
} // namespace
DevToolsAgentHostImpl::DevToolsAgentHostImpl()
- : id_(base::GenerateGUID()),
- client_(NULL) {
+ : close_listener_(NULL),
+ id_(base::GenerateGUID()) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
g_instances.Get()[id_] = this;
}
@@ -56,30 +49,8 @@
return new ForwardingAgentHost(delegate);
}
-void DevToolsAgentHostImpl::AttachClient(DevToolsAgentHostClient* client) {
- scoped_refptr<DevToolsAgentHostImpl> protect(this);
- if (client_) {
- client_->AgentHostClosed(this, true);
- Detach();
- } else {
- DevToolsManagerImpl::GetInstance()->OnClientAttached();
- }
- client_ = client;
- Attach();
-}
-
-void DevToolsAgentHostImpl::DetachClient() {
- if (!client_)
- return;
-
- scoped_refptr<DevToolsAgentHostImpl> protect(this);
- client_ = NULL;
- Detach();
- DevToolsManagerImpl::GetInstance()->OnClientDetached();
-}
-
bool DevToolsAgentHostImpl::IsAttached() {
- return !!client_;
+ return !!DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(this);
}
void DevToolsAgentHostImpl::InspectElement(int x, int y) {
@@ -103,76 +74,12 @@
return false;
}
-void DevToolsAgentHostImpl::HostClosed() {
- if (!client_)
- return;
-
- scoped_refptr<DevToolsAgentHostImpl> protect(this);
- client_->AgentHostClosed(this, false);
- client_ = NULL;
- DevToolsManagerImpl::GetInstance()->OnClientDetached();
-}
-
-void DevToolsAgentHostImpl::SendMessageToClient(const std::string& message) {
- if (!client_)
- return;
- client_->DispatchProtocolMessage(this, message);
-}
-
-// static
-void DevToolsAgentHost::DetachAllClients() {
- if (g_instances == NULL)
- return;
-
- // Make a copy, since detaching may lead to agent destruction, which
- // removes it from the instances.
- Instances copy = g_instances.Get();
- for (Instances::iterator it(copy.begin()); it != copy.end(); ++it) {
- DevToolsAgentHostImpl* agent_host = it->second;
- if (agent_host->client_) {
- scoped_refptr<DevToolsAgentHostImpl> protect(agent_host);
- agent_host->client_->AgentHostClosed(agent_host, true);
- agent_host->client_ = NULL;
- agent_host->Detach();
- DevToolsManagerImpl::GetInstance()->OnClientDetached();
- }
+void DevToolsAgentHostImpl::NotifyCloseListener() {
+ if (close_listener_) {
+ scoped_refptr<DevToolsAgentHostImpl> protect(this);
+ close_listener_->AgentHostClosing(this);
+ close_listener_ = NULL;
}
}
-// static
-void DevToolsAgentHost::AddAgentStateCallback(
- const AgentStateCallback& callback) {
- g_callbacks.Get().push_back(&callback);
-}
-
-// static
-void DevToolsAgentHost::RemoveAgentStateCallback(
- const AgentStateCallback& callback) {
- if (g_callbacks == NULL)
- return;
-
- AgentStateCallbacks* callbacks_ = g_callbacks.Pointer();
- AgentStateCallbacks::iterator it =
- std::find(callbacks_->begin(), callbacks_->end(), &callback);
- DCHECK(it != callbacks_->end());
- callbacks_->erase(it);
-}
-
-// static
-void DevToolsAgentHostImpl::NotifyCallbacks(
- DevToolsAgentHostImpl* agent_host, bool attached) {
- AgentStateCallbacks copy(g_callbacks.Get());
- DevToolsManagerImpl* manager = DevToolsManagerImpl::GetInstance();
- if (manager->delegate())
- manager->delegate()->DevToolsAgentStateChanged(agent_host, attached);
- for (AgentStateCallbacks::iterator it = copy.begin(); it != copy.end(); ++it)
- (*it)->Run(agent_host, attached);
-}
-
-void DevToolsAgentHostImpl::Inspect(BrowserContext* browser_context) {
- DevToolsManagerImpl* manager = DevToolsManagerImpl::GetInstance();
- if (manager->delegate())
- manager->delegate()->Inspect(browser_context, this);
-}
-
} // namespace content
« no previous file with comments | « content/browser/devtools/devtools_agent_host_impl.h ('k') | content/browser/devtools/devtools_http_handler_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698