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

Side by Side Diff: chrome/browser/devtools/devtools_target_impl.cc

Issue 562513003: [DevTools] Unify workers and web contents handling in inspect_ui. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased, fixed comment Created 6 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/devtools/devtools_target_impl.h" 5 #include "chrome/browser/devtools/devtools_target_impl.h"
6 6
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/devtools/devtools_window.h" 9 #include "chrome/browser/devtools/devtools_window.h"
10 #include "chrome/browser/extensions/extension_tab_util.h" 10 #include "chrome/browser/extensions/extension_tab_util.h"
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 default: 180 default:
181 break; 181 break;
182 } 182 }
183 return kTargetTypeOther; 183 return kTargetTypeOther;
184 } 184 }
185 185
186 void WorkerTarget::Inspect(Profile* profile) const { 186 void WorkerTarget::Inspect(Profile* profile) const {
187 DevToolsWindow::OpenDevToolsWindowForWorker(profile, GetAgentHost()); 187 DevToolsWindow::OpenDevToolsWindowForWorker(profile, GetAgentHost());
188 } 188 }
189 189
190 // Enumeration ----------------------------------------------------------------
191
192 DevToolsTargetImpl::List EnumerateWebContentsTargets() {
193 std::set<WebContents*> tab_web_contents;
194 for (TabContentsIterator it; !it.done(); it.Next())
195 tab_web_contents.insert(*it);
196
197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
198 DevToolsTargetImpl::List result;
199 DevToolsAgentHost::List agents = DevToolsAgentHost::GetOrCreateAll();
200 for (DevToolsAgentHost::List::iterator it = agents.begin();
201 it != agents.end(); ++it) {
202 if (WebContents* web_contents = (*it)->GetWebContents()) {
203 bool is_tab =
204 tab_web_contents.find(web_contents) != tab_web_contents.end();
205 result.push_back(new WebContentsTarget(web_contents, is_tab));
206 }
207 }
208 return result;
209 }
210
211 void CreateWorkerTargets(
212 const std::vector<WorkerService::WorkerInfo>& worker_info,
213 DevToolsTargetImpl::Callback callback) {
214 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
215 DevToolsTargetImpl::List result;
216 for (size_t i = 0; i < worker_info.size(); ++i) {
217 result.push_back(new WorkerTarget(worker_info[i]));
218 }
219 callback.Run(result);
220 }
221
222 void EnumerateWorkerTargets(DevToolsTargetImpl::Callback callback) {
223 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
224 content::BrowserThread::PostTask(
225 content::BrowserThread::UI,
226 FROM_HERE,
227 base::Bind(&CreateWorkerTargets,
228 WorkerService::GetInstance()->GetWorkers(),
229 callback));
230 }
231
232 void CollectAllTargets(
233 DevToolsTargetImpl::Callback callback,
234 const DevToolsTargetImpl::List& worker_targets) {
235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
236 DevToolsTargetImpl::List result = EnumerateWebContentsTargets();
237 result.insert(result.end(), worker_targets.begin(), worker_targets.end());
238
239 DevToolsAgentHost::List agents = DevToolsAgentHost::GetOrCreateAll();
240 for (DevToolsAgentHost::List::iterator it = agents.begin();
241 it != agents.end(); ++it) {
242 if ((*it)->GetType() == DevToolsAgentHost::TYPE_SERVICE_WORKER)
243 result.push_back(new WorkerTarget(*it));
244 }
245 callback.Run(result);
246 }
247
190 } // namespace 248 } // namespace
191 249
192 // DevToolsTargetImpl ---------------------------------------------------------- 250 // DevToolsTargetImpl ----------------------------------------------------------
193 251
194 DevToolsTargetImpl::~DevToolsTargetImpl() { 252 DevToolsTargetImpl::~DevToolsTargetImpl() {
195 } 253 }
196 254
197 DevToolsTargetImpl::DevToolsTargetImpl( 255 DevToolsTargetImpl::DevToolsTargetImpl(
198 scoped_refptr<DevToolsAgentHost> agent_host) 256 scoped_refptr<DevToolsAgentHost> agent_host)
199 : agent_host_(agent_host), 257 : agent_host_(agent_host),
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 328
271 // static 329 // static
272 scoped_ptr<DevToolsTargetImpl> DevToolsTargetImpl::CreateForWebContents( 330 scoped_ptr<DevToolsTargetImpl> DevToolsTargetImpl::CreateForWebContents(
273 content::WebContents* web_contents, 331 content::WebContents* web_contents,
274 bool is_tab) { 332 bool is_tab) {
275 return scoped_ptr<DevToolsTargetImpl>( 333 return scoped_ptr<DevToolsTargetImpl>(
276 new WebContentsTarget(web_contents, is_tab)); 334 new WebContentsTarget(web_contents, is_tab));
277 } 335 }
278 336
279 // static 337 // static
280 DevToolsTargetImpl::List DevToolsTargetImpl::EnumerateWebContentsTargets() {
281 std::set<WebContents*> tab_web_contents;
282 for (TabContentsIterator it; !it.done(); it.Next())
283 tab_web_contents.insert(*it);
284
285 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
286 DevToolsTargetImpl::List result;
287 DevToolsAgentHost::List agents = DevToolsAgentHost::GetOrCreateAll();
288 for (DevToolsAgentHost::List::iterator it = agents.begin();
289 it != agents.end(); ++it) {
290 if (WebContents* web_contents = (*it)->GetWebContents()) {
291 bool is_tab =
292 tab_web_contents.find(web_contents) != tab_web_contents.end();
293 result.push_back(new WebContentsTarget(web_contents, is_tab));
294 }
295 }
296 return result;
297 }
298
299 static void CreateWorkerTargets(
300 const std::vector<WorkerService::WorkerInfo>& worker_info,
301 DevToolsTargetImpl::Callback callback) {
302 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
303 DevToolsTargetImpl::List result;
304 for (size_t i = 0; i < worker_info.size(); ++i) {
305 result.push_back(new WorkerTarget(worker_info[i]));
306 }
307 callback.Run(result);
308 }
309
310 // static
311 void DevToolsTargetImpl::EnumerateWorkerTargets(Callback callback) {
312 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
313 content::BrowserThread::PostTask(
314 content::BrowserThread::UI,
315 FROM_HERE,
316 base::Bind(&CreateWorkerTargets,
317 WorkerService::GetInstance()->GetWorkers(),
318 callback));
319 }
320
321 static void CollectAllTargets(
322 DevToolsTargetImpl::Callback callback,
323 const DevToolsTargetImpl::List& worker_targets) {
324 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
325 DevToolsTargetImpl::List result =
326 DevToolsTargetImpl::EnumerateWebContentsTargets();
327 result.insert(result.end(), worker_targets.begin(), worker_targets.end());
328
329 DevToolsAgentHost::List agents = DevToolsAgentHost::GetOrCreateAll();
330 for (DevToolsAgentHost::List::iterator it = agents.begin();
331 it != agents.end(); ++it) {
332 if ((*it)->GetType() == DevToolsAgentHost::TYPE_SERVICE_WORKER)
333 result.push_back(new WorkerTarget(*it));
334 }
335 callback.Run(result);
336 }
337
338 // static
339 void DevToolsTargetImpl::EnumerateAllTargets(Callback callback) { 338 void DevToolsTargetImpl::EnumerateAllTargets(Callback callback) {
340 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 339 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
341 content::BrowserThread::PostTask( 340 content::BrowserThread::PostTask(
342 content::BrowserThread::IO, 341 content::BrowserThread::IO,
343 FROM_HERE, 342 FROM_HERE,
344 base::Bind(&DevToolsTargetImpl::EnumerateWorkerTargets, 343 base::Bind(&EnumerateWorkerTargets,
345 base::Bind(&CollectAllTargets, callback))); 344 base::Bind(&CollectAllTargets, callback)));
346 } 345 }
OLDNEW
« no previous file with comments | « chrome/browser/devtools/devtools_target_impl.h ('k') | chrome/browser/devtools/devtools_targets_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698