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

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

Issue 2408133004: [DevTools] Implement Target.setDiscoverTargets method. (Closed)
Patch Set: force creation Created 4 years, 2 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 802398434410a9e6e3f441eabe0b7e2214a62163..5f4e5449fd16cf72be663cc486309496dab9cbed 100644
--- a/content/browser/devtools/devtools_agent_host_impl.cc
+++ b/content/browser/devtools/devtools_agent_host_impl.cc
@@ -42,6 +42,7 @@ char DevToolsAgentHost::kTypeExternal[] = "external";
char DevToolsAgentHost::kTypeBrowser[] = "browser";
char DevToolsAgentHost::kTypeOther[] = "other";
int DevToolsAgentHostImpl::s_attached_count_ = 0;
+int DevToolsAgentHostImpl::s_force_creation_count_ = 0;
// static
std::string DevToolsAgentHost::GetProtocolVersion() {
@@ -97,13 +98,11 @@ DevToolsAgentHostImpl::DevToolsAgentHostImpl(const std::string& id)
session_id_(0),
client_(NULL) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- DCHECK(g_instances.Get().find(id_) == g_instances.Get().end());
- g_instances.Get()[id_] = this;
}
DevToolsAgentHostImpl::~DevToolsAgentHostImpl() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- g_instances.Get().erase(g_instances.Get().find(id_));
+ NotifyDestroyed();
}
// static
@@ -294,14 +293,38 @@ void DevToolsAgentHost::DetachAllClients() {
// static
void DevToolsAgentHost::AddObserver(DevToolsAgentHostObserver* observer) {
+ if (observer->ShouldForceDevToolsAgentHostCreation()) {
+ if (!DevToolsAgentHostImpl::s_force_creation_count_) {
+ // Force all agent hosts when first observer is added.
+ DevToolsAgentHost::GetOrCreateAll();
pfeldman 2016/10/14 23:58:52 DevToolsAgentHost::GetOrCreateAll DCHECK notified
+ }
+ DevToolsAgentHostImpl::s_force_creation_count_++;
+ }
+
g_observers.Get().AddObserver(observer);
+ for (const auto& id_host : g_instances.Get())
+ observer->DevToolsAgentHostCreated(id_host.second);
}
// static
void DevToolsAgentHost::RemoveObserver(DevToolsAgentHostObserver* observer) {
+ if (observer->ShouldForceDevToolsAgentHostCreation())
+ DevToolsAgentHostImpl::s_force_creation_count_--;
g_observers.Get().RemoveObserver(observer);
}
+// static
+bool DevToolsAgentHostImpl::ShouldForceCreation() {
+ return s_force_creation_count_;
+}
+
+void DevToolsAgentHostImpl::NotifyCreated() {
+ DCHECK(g_instances.Get().find(id_) == g_instances.Get().end());
+ g_instances.Get()[id_] = this;
+ for (auto& observer : g_observers.Get())
+ observer.DevToolsAgentHostCreated(this);
+}
+
void DevToolsAgentHostImpl::NotifyAttached() {
if (!s_attached_count_) {
BrowserThread::PostTask(
@@ -329,6 +352,13 @@ void DevToolsAgentHostImpl::NotifyDetached() {
observer.DevToolsAgentHostDetached(this);
}
+void DevToolsAgentHostImpl::NotifyDestroyed() {
+ DCHECK(g_instances.Get().find(id_) != g_instances.Get().end());
+ for (auto& observer : g_observers.Get())
+ observer.DevToolsAgentHostDestroyed(this);
+ g_instances.Get().erase(g_instances.Get().find(id_));
pfeldman 2016/10/14 23:58:52 Erase by id.
+}
+
// DevToolsMessageChunkProcessor -----------------------------------------------
DevToolsMessageChunkProcessor::DevToolsMessageChunkProcessor(
« no previous file with comments | « content/browser/devtools/devtools_agent_host_impl.h ('k') | content/browser/devtools/forwarding_agent_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698