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

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

Issue 2590293003: [DevTools] Rework DevToolsSession interaction with domain handlers. (Closed)
Patch Set: Created 4 years 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 f09727799a94ab48dce47cb8ef1b775850268e2c..24a707118f312a45eb8a7b5e744dd5aaccd337da 100644
--- a/content/browser/devtools/devtools_agent_host_impl.cc
+++ b/content/browser/devtools/devtools_agent_host_impl.cc
@@ -106,8 +106,7 @@ scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::GetForWorker(
DevToolsAgentHostImpl::DevToolsAgentHostImpl(const std::string& id)
: id_(id),
- last_session_id_(0),
- client_(NULL) {
+ last_session_id_(0) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
}
@@ -139,17 +138,17 @@ scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::Forward(
bool DevToolsAgentHostImpl::InnerAttach(DevToolsAgentHostClient* client,
caseq 2016/12/20 23:13:19 Let's rename to InnerAttachClient
dgozman 2016/12/21 00:29:40 Done.
bool force) {
- if (client_ && !force)
+ if (session_ && !force)
return false;
scoped_refptr<DevToolsAgentHostImpl> protect(this);
- if (client_) {
- client_->AgentHostClosed(this, true);
+ if (session_) {
+ session_->client()->AgentHostClosed(this, true);
InnerDetach();
}
- client_ = client;
- session_.reset(new DevToolsSession(this, ++last_session_id_));
- Attach();
+ session_.reset(new DevToolsSession(this, client, ++last_session_id_));
+ Attach(session_.get());
caseq 2016/12/20 23:13:19 AttachSession?
dgozman 2016/12/21 00:29:40 Done.
+ session_->Attach();
NotifyAttached();
return true;
}
@@ -163,11 +162,10 @@ void DevToolsAgentHostImpl::ForceAttachClient(DevToolsAgentHostClient* client) {
}
bool DevToolsAgentHostImpl::DetachClient(DevToolsAgentHostClient* client) {
- if (!client_ || client_ != client)
+ if (!session_ || session_->client() != client)
return false;
scoped_refptr<DevToolsAgentHostImpl> protect(this);
- client_ = NULL;
InnerDetach();
return true;
}
@@ -175,30 +173,30 @@ bool DevToolsAgentHostImpl::DetachClient(DevToolsAgentHostClient* client) {
bool DevToolsAgentHostImpl::DispatchProtocolMessage(
DevToolsAgentHostClient* client,
const std::string& message) {
- if (!client_ || client_ != client)
+ if (!session_ || session_->client() != client)
return false;
- return DispatchProtocolMessage(message);
+ return DispatchProtocolMessage(session_.get(), message);
}
void DevToolsAgentHostImpl::InnerDetach() {
- session_->ResetDispatcher();
- Detach();
+ session_->Detach();
+ Detach(session_.get());
io_context_.DiscardAllStreams();
session_.reset();
NotifyDetached();
}
bool DevToolsAgentHostImpl::IsAttached() {
- return !!client_;
+ return !!session_;
}
void DevToolsAgentHostImpl::InspectElement(
DevToolsAgentHostClient* client,
int x,
int y) {
- if (!client_ || client_ != client)
+ if (!session_ || session_->client() != client)
return;
- InspectElement(x, y);
+ InspectElement(session_.get(), x, y);
}
std::string DevToolsAgentHostImpl::GetId() {
@@ -249,28 +247,28 @@ bool DevToolsAgentHostImpl::Inspect() {
}
void DevToolsAgentHostImpl::HostClosed() {
- if (!client_)
+ if (!session_)
return;
scoped_refptr<DevToolsAgentHostImpl> protect(this);
// Clear |client_| before notifying it.
- DevToolsAgentHostClient* client = client_;
- client_ = NULL;
- client->AgentHostClosed(this, false);
+ DevToolsAgentHostClient* client = session_->client();
InnerDetach();
+ client->AgentHostClosed(this, false);
}
-void DevToolsAgentHostImpl::InspectElement(int x, int y) {
+void DevToolsAgentHostImpl::InspectElement(
+ DevToolsSession* session,
+ int x,
+ int y) {
}
void DevToolsAgentHostImpl::SendMessageToClient(int session_id,
const std::string& message) {
- if (!client_)
- return;
// Filter any messages from previous sessions.
if (!session_ || session_id != session_->session_id())
return;
- client_->DispatchProtocolMessage(this, message);
+ session_->client()->DispatchProtocolMessage(this, message);
}
// static
@@ -283,13 +281,12 @@ void DevToolsAgentHost::DetachAllClients() {
Instances copy = g_instances.Get();
for (Instances::iterator it(copy.begin()); it != copy.end(); ++it) {
DevToolsAgentHostImpl* agent_host = it->second;
- if (agent_host->client_) {
+ if (agent_host->session_) {
scoped_refptr<DevToolsAgentHostImpl> protect(agent_host);
// Clear |client_| before notifying it.
- DevToolsAgentHostClient* client = agent_host->client_;
- agent_host->client_ = NULL;
- client->AgentHostClosed(agent_host, true);
+ DevToolsAgentHostClient* client = agent_host->session_->client();
agent_host->InnerDetach();
+ client->AgentHostClosed(agent_host, true);
}
}
}

Powered by Google App Engine
This is Rietveld 408576698