Index: content/browser/devtools/protocol/target_auto_attacher.cc |
diff --git a/content/browser/devtools/protocol/target_auto_attacher.cc b/content/browser/devtools/protocol/target_auto_attacher.cc |
index dbccd7b1292946e8f334c65b7d2191ffbe2cf7bb..bc082c5e6e18fe143fc6fb1875d89806b025c8a1 100644 |
--- a/content/browser/devtools/protocol/target_auto_attacher.cc |
+++ b/content/browser/devtools/protocol/target_auto_attacher.cc |
@@ -134,7 +134,7 @@ void TargetAutoAttacher::UpdateFrames() { |
} |
void TargetAutoAttacher::AgentHostClosed(DevToolsAgentHost* host) { |
- auto_attached_hosts_.erase(host); |
+ auto_attached_hosts_.erase(make_scoped_refptr(host)); |
danakj
2017/07/20 15:52:52
Not for this CL but looks like we should make a co
dyaroshev
2017/07/20 16:03:18
I agree. We discussed that earlier in this CL, I e
|
} |
void TargetAutoAttacher::ReattachServiceWorkers(bool waiting_for_debugger) { |
@@ -165,20 +165,29 @@ void TargetAutoAttacher::ReattachServiceWorkers(bool waiting_for_debugger) { |
void TargetAutoAttacher::ReattachTargetsOfType(const Hosts& new_hosts, |
const std::string& type, |
bool waiting_for_debugger) { |
- Hosts old_hosts = auto_attached_hosts_; |
- for (auto& it : old_hosts) { |
- DevToolsAgentHost* host = it.get(); |
- if (host->GetType() == type && new_hosts.find(host) == new_hosts.end()) { |
- auto_attached_hosts_.erase(host); |
- detach_callback_.Run(host); |
- } |
+ // Detach. |
+ { |
+ Hosts removed_hosts = |
+ base::STLSetDifference<Hosts>(new_hosts, auto_attached_hosts_); |
+ for (const auto& h : removed_hosts) |
dyaroshev
2017/07/19 23:38:41
And I missed GetType check. Ok than, I'll revert t
danakj
2017/07/20 15:52:52
I'll wait for your update then.
|
+ detach_callback_.Run(h.get()); |
} |
- for (auto& it : new_hosts) { |
- DevToolsAgentHost* host = it.get(); |
- if (old_hosts.find(host) == old_hosts.end()) { |
- if (attach_callback_.Run(host, waiting_for_debugger)) |
- auto_attached_hosts_.insert(host); |
- } |
+ |
+ // Attach. |
+ { |
+ Hosts newly_attached_hosts = |
+ base::STLSetDifference<Hosts>(auto_attached_hosts_, new_hosts); |
+ |
+ auto_attached_hosts_.clear(); |
+ |
+ // Since newly_attached is already a set, inserting in the end is faster |
+ // than buffer + sort. |
+ std::copy_if( |
+ newly_attached_hosts.begin(), newly_attached_hosts.end(), |
+ std::inserter(auto_attached_hosts_, auto_attached_hosts_.end()), |
+ [&](const scoped_refptr<DevToolsAgentHost>& h) { |
+ return attach_callback_.Run(h.get(), waiting_for_debugger); |
+ }); |
} |
} |