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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/devtools/devtools_target_impl.cc
diff --git a/chrome/browser/devtools/devtools_target_impl.cc b/chrome/browser/devtools/devtools_target_impl.cc
index 03947822b9eaa6361dcc23f5ffaa3f4404f095af..2b2ec31a8b154344994cc28c9bfb9a3647624368 100644
--- a/chrome/browser/devtools/devtools_target_impl.cc
+++ b/chrome/browser/devtools/devtools_target_impl.cc
@@ -187,6 +187,64 @@ void WorkerTarget::Inspect(Profile* profile) const {
DevToolsWindow::OpenDevToolsWindowForWorker(profile, GetAgentHost());
}
+// Enumeration ----------------------------------------------------------------
+
+DevToolsTargetImpl::List EnumerateWebContentsTargets() {
+ std::set<WebContents*> tab_web_contents;
+ for (TabContentsIterator it; !it.done(); it.Next())
+ tab_web_contents.insert(*it);
+
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DevToolsTargetImpl::List result;
+ DevToolsAgentHost::List agents = DevToolsAgentHost::GetOrCreateAll();
+ for (DevToolsAgentHost::List::iterator it = agents.begin();
+ it != agents.end(); ++it) {
+ if (WebContents* web_contents = (*it)->GetWebContents()) {
+ bool is_tab =
+ tab_web_contents.find(web_contents) != tab_web_contents.end();
+ result.push_back(new WebContentsTarget(web_contents, is_tab));
+ }
+ }
+ return result;
+}
+
+void CreateWorkerTargets(
+ const std::vector<WorkerService::WorkerInfo>& worker_info,
+ DevToolsTargetImpl::Callback callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DevToolsTargetImpl::List result;
+ for (size_t i = 0; i < worker_info.size(); ++i) {
+ result.push_back(new WorkerTarget(worker_info[i]));
+ }
+ callback.Run(result);
+}
+
+void EnumerateWorkerTargets(DevToolsTargetImpl::Callback callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ content::BrowserThread::PostTask(
+ content::BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&CreateWorkerTargets,
+ WorkerService::GetInstance()->GetWorkers(),
+ callback));
+}
+
+void CollectAllTargets(
+ DevToolsTargetImpl::Callback callback,
+ const DevToolsTargetImpl::List& worker_targets) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DevToolsTargetImpl::List result = EnumerateWebContentsTargets();
+ result.insert(result.end(), worker_targets.begin(), worker_targets.end());
+
+ DevToolsAgentHost::List agents = DevToolsAgentHost::GetOrCreateAll();
+ for (DevToolsAgentHost::List::iterator it = agents.begin();
+ it != agents.end(); ++it) {
+ if ((*it)->GetType() == DevToolsAgentHost::TYPE_SERVICE_WORKER)
+ result.push_back(new WorkerTarget(*it));
+ }
+ callback.Run(result);
+}
+
} // namespace
// DevToolsTargetImpl ----------------------------------------------------------
@@ -277,70 +335,11 @@ scoped_ptr<DevToolsTargetImpl> DevToolsTargetImpl::CreateForWebContents(
}
// static
-DevToolsTargetImpl::List DevToolsTargetImpl::EnumerateWebContentsTargets() {
- std::set<WebContents*> tab_web_contents;
- for (TabContentsIterator it; !it.done(); it.Next())
- tab_web_contents.insert(*it);
-
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- DevToolsTargetImpl::List result;
- DevToolsAgentHost::List agents = DevToolsAgentHost::GetOrCreateAll();
- for (DevToolsAgentHost::List::iterator it = agents.begin();
- it != agents.end(); ++it) {
- if (WebContents* web_contents = (*it)->GetWebContents()) {
- bool is_tab =
- tab_web_contents.find(web_contents) != tab_web_contents.end();
- result.push_back(new WebContentsTarget(web_contents, is_tab));
- }
- }
- return result;
-}
-
-static void CreateWorkerTargets(
- const std::vector<WorkerService::WorkerInfo>& worker_info,
- DevToolsTargetImpl::Callback callback) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- DevToolsTargetImpl::List result;
- for (size_t i = 0; i < worker_info.size(); ++i) {
- result.push_back(new WorkerTarget(worker_info[i]));
- }
- callback.Run(result);
-}
-
-// static
-void DevToolsTargetImpl::EnumerateWorkerTargets(Callback callback) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- content::BrowserThread::PostTask(
- content::BrowserThread::UI,
- FROM_HERE,
- base::Bind(&CreateWorkerTargets,
- WorkerService::GetInstance()->GetWorkers(),
- callback));
-}
-
-static void CollectAllTargets(
- DevToolsTargetImpl::Callback callback,
- const DevToolsTargetImpl::List& worker_targets) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- DevToolsTargetImpl::List result =
- DevToolsTargetImpl::EnumerateWebContentsTargets();
- result.insert(result.end(), worker_targets.begin(), worker_targets.end());
-
- DevToolsAgentHost::List agents = DevToolsAgentHost::GetOrCreateAll();
- for (DevToolsAgentHost::List::iterator it = agents.begin();
- it != agents.end(); ++it) {
- if ((*it)->GetType() == DevToolsAgentHost::TYPE_SERVICE_WORKER)
- result.push_back(new WorkerTarget(*it));
- }
- callback.Run(result);
-}
-
-// static
void DevToolsTargetImpl::EnumerateAllTargets(Callback callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
content::BrowserThread::PostTask(
content::BrowserThread::IO,
FROM_HERE,
- base::Bind(&DevToolsTargetImpl::EnumerateWorkerTargets,
+ base::Bind(&EnumerateWorkerTargets,
base::Bind(&CollectAllTargets, callback)));
}
« 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