OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/devtools/protocol/target_auto_attacher.h" | 5 #include "content/browser/devtools/protocol/target_auto_attacher.h" |
6 | 6 |
7 #include "content/browser/devtools/render_frame_devtools_agent_host.h" | 7 #include "content/browser/devtools/render_frame_devtools_agent_host.h" |
8 #include "content/browser/devtools/service_worker_devtools_agent_host.h" | 8 #include "content/browser/devtools/service_worker_devtools_agent_host.h" |
9 #include "content/browser/frame_host/frame_tree.h" | 9 #include "content/browser/frame_host/frame_tree.h" |
10 #include "content/browser/frame_host/frame_tree_node.h" | 10 #include "content/browser/frame_host/frame_tree_node.h" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 queue.push(node->child_at(i)); | 127 queue.push(node->child_at(i)); |
128 } | 128 } |
129 } | 129 } |
130 } | 130 } |
131 | 131 |
132 // TODO(dgozman): support wait_for_debugger_on_start_. | 132 // TODO(dgozman): support wait_for_debugger_on_start_. |
133 ReattachTargetsOfType(new_hosts, DevToolsAgentHost::kTypeFrame, false); | 133 ReattachTargetsOfType(new_hosts, DevToolsAgentHost::kTypeFrame, false); |
134 } | 134 } |
135 | 135 |
136 void TargetAutoAttacher::AgentHostClosed(DevToolsAgentHost* host) { | 136 void TargetAutoAttacher::AgentHostClosed(DevToolsAgentHost* host) { |
137 auto_attached_hosts_.erase(host); | 137 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
| |
138 } | 138 } |
139 | 139 |
140 void TargetAutoAttacher::ReattachServiceWorkers(bool waiting_for_debugger) { | 140 void TargetAutoAttacher::ReattachServiceWorkers(bool waiting_for_debugger) { |
141 if (!auto_attach_) | 141 if (!auto_attach_) |
142 return; | 142 return; |
143 | 143 |
144 frame_urls_.clear(); | 144 frame_urls_.clear(); |
145 BrowserContext* browser_context = nullptr; | 145 BrowserContext* browser_context = nullptr; |
146 if (render_frame_host_) { | 146 if (render_frame_host_) { |
147 // TODO(dgozman): do not traverse inside cross-process subframes. | 147 // TODO(dgozman): do not traverse inside cross-process subframes. |
(...skipping 10 matching lines...) Expand all Loading... | |
158 if (pair.second->IsReadyForInspection()) | 158 if (pair.second->IsReadyForInspection()) |
159 new_hosts.insert(pair.second); | 159 new_hosts.insert(pair.second); |
160 } | 160 } |
161 ReattachTargetsOfType(new_hosts, DevToolsAgentHost::kTypeServiceWorker, | 161 ReattachTargetsOfType(new_hosts, DevToolsAgentHost::kTypeServiceWorker, |
162 waiting_for_debugger); | 162 waiting_for_debugger); |
163 } | 163 } |
164 | 164 |
165 void TargetAutoAttacher::ReattachTargetsOfType(const Hosts& new_hosts, | 165 void TargetAutoAttacher::ReattachTargetsOfType(const Hosts& new_hosts, |
166 const std::string& type, | 166 const std::string& type, |
167 bool waiting_for_debugger) { | 167 bool waiting_for_debugger) { |
168 Hosts old_hosts = auto_attached_hosts_; | 168 // Detach. |
169 for (auto& it : old_hosts) { | 169 { |
170 DevToolsAgentHost* host = it.get(); | 170 Hosts removed_hosts = |
171 if (host->GetType() == type && new_hosts.find(host) == new_hosts.end()) { | 171 base::STLSetDifference<Hosts>(new_hosts, auto_attached_hosts_); |
172 auto_attached_hosts_.erase(host); | 172 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.
| |
173 detach_callback_.Run(host); | 173 detach_callback_.Run(h.get()); |
174 } | |
175 } | 174 } |
176 for (auto& it : new_hosts) { | 175 |
177 DevToolsAgentHost* host = it.get(); | 176 // Attach. |
178 if (old_hosts.find(host) == old_hosts.end()) { | 177 { |
179 if (attach_callback_.Run(host, waiting_for_debugger)) | 178 Hosts newly_attached_hosts = |
180 auto_attached_hosts_.insert(host); | 179 base::STLSetDifference<Hosts>(auto_attached_hosts_, new_hosts); |
181 } | 180 |
181 auto_attached_hosts_.clear(); | |
182 | |
183 // Since newly_attached is already a set, inserting in the end is faster | |
184 // than buffer + sort. | |
185 std::copy_if( | |
186 newly_attached_hosts.begin(), newly_attached_hosts.end(), | |
187 std::inserter(auto_attached_hosts_, auto_attached_hosts_.end()), | |
188 [&](const scoped_refptr<DevToolsAgentHost>& h) { | |
189 return attach_callback_.Run(h.get(), waiting_for_debugger); | |
190 }); | |
182 } | 191 } |
183 } | 192 } |
184 | 193 |
185 void TargetAutoAttacher::SetAutoAttach(bool auto_attach, | 194 void TargetAutoAttacher::SetAutoAttach(bool auto_attach, |
186 bool wait_for_debugger_on_start) { | 195 bool wait_for_debugger_on_start) { |
187 wait_for_debugger_on_start_ = wait_for_debugger_on_start; | 196 wait_for_debugger_on_start_ = wait_for_debugger_on_start; |
188 if (auto_attach_ == auto_attach) | 197 if (auto_attach_ == auto_attach) |
189 return; | 198 return; |
190 auto_attach_ = auto_attach; | 199 auto_attach_ = auto_attach; |
191 if (auto_attach_) { | 200 if (auto_attach_) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 ServiceWorkerDevToolsAgentHost* host) { | 256 ServiceWorkerDevToolsAgentHost* host) { |
248 ReattachServiceWorkers(false); | 257 ReattachServiceWorkers(false); |
249 } | 258 } |
250 | 259 |
251 void TargetAutoAttacher::WorkerDestroyed(ServiceWorkerDevToolsAgentHost* host) { | 260 void TargetAutoAttacher::WorkerDestroyed(ServiceWorkerDevToolsAgentHost* host) { |
252 ReattachServiceWorkers(false); | 261 ReattachServiceWorkers(false); |
253 } | 262 } |
254 | 263 |
255 } // namespace protocol | 264 } // namespace protocol |
256 } // namespace content | 265 } // namespace content |
OLD | NEW |