summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryurys@chromium.org <yurys@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-08 06:23:46 +0000
committeryurys@chromium.org <yurys@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-08 06:23:46 +0000
commitb3762af2f645ce363f4bc5fd99fbda14260c11fe (patch)
tree9d7acef3359d4ea40fd2b4c2e7ce634863c1b72b
parentbfe9d6d536336f7a5a88279cf6686756e6b95ab2 (diff)
downloadchromium_src-b3762af2f645ce363f4bc5fd99fbda14260c11fe.zip
chromium_src-b3762af2f645ce363f4bc5fd99fbda14260c11fe.tar.gz
chromium_src-b3762af2f645ce363f4bc5fd99fbda14260c11fe.tar.bz2
DevTools: introduce WorkderDevToolsAgentHost
We already have RenderViewDevToolsAgent host for inspected pages. This patch introduces WorkderDevToolsAgentHost which implements DevToolsAgentHost interface for inspected shared workers. Also this patch moves part of devtools message routing for workers to DevToolsManager. BUG=None TEST=Existing DevTools tests Review URL: http://codereview.chromium.org/7737026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@100112 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/debugger/devtools_sanity_unittest.cc14
-rw-r--r--chrome/browser/debugger/devtools_window.cc11
-rw-r--r--chrome/browser/debugger/devtools_window.h1
-rw-r--r--chrome/browser/ui/webui/workers_ui.cc18
-rw-r--r--content/browser/debugger/devtools_client_host.cc5
-rw-r--r--content/browser/debugger/devtools_client_host.h2
-rw-r--r--content/browser/debugger/devtools_manager.cc9
-rw-r--r--content/browser/debugger/devtools_manager.h2
-rw-r--r--content/browser/debugger/worker_devtools_manager.cc337
-rw-r--r--content/browser/debugger/worker_devtools_manager.h62
-rw-r--r--content/browser/debugger/worker_devtools_manager_io.cc321
-rw-r--r--content/browser/debugger/worker_devtools_manager_io.h66
-rw-r--r--content/browser/debugger/worker_devtools_message_filter.cc6
-rw-r--r--content/common/devtools_messages.h3
-rw-r--r--content/content_browser.gypi4
-rw-r--r--content/renderer/worker_devtools_agent_proxy.cc4
-rw-r--r--content/worker/worker_devtools_agent.cc6
17 files changed, 444 insertions, 427 deletions
diff --git a/chrome/browser/debugger/devtools_sanity_unittest.cc b/chrome/browser/debugger/devtools_sanity_unittest.cc
index 5e8ad78..f8280ff 100644
--- a/chrome/browser/debugger/devtools_sanity_unittest.cc
+++ b/chrome/browser/debugger/devtools_sanity_unittest.cc
@@ -20,7 +20,7 @@
#include "content/browser/content_browser_client.h"
#include "content/browser/debugger/devtools_client_host.h"
#include "content/browser/debugger/devtools_manager.h"
-#include "content/browser/debugger/worker_devtools_manager_io.h"
+#include "content/browser/debugger/worker_devtools_manager.h"
#include "content/browser/renderer_host/render_view_host.h"
#include "content/browser/tab_contents/tab_contents.h"
#include "content/browser/worker_host/worker_process_host.h"
@@ -322,11 +322,13 @@ class WorkerDevToolsSanityTest : public InProcessBrowserTest {
Profile* profile = browser()->profile();
window_ = DevToolsWindow::CreateDevToolsWindowForWorker(profile);
window_->Show(DEVTOOLS_TOGGLE_ACTION_NONE);
- WorkerDevToolsManagerIO::RegisterDevToolsClientForWorkerOnUIThread(
- window_,
- worker_data->worker_process_id,
- worker_data->worker_route_id);
-
+ DevToolsAgentHost* agent_host =
+ WorkerDevToolsManager::GetDevToolsAgentHostForWorker(
+ worker_data->worker_process_id,
+ worker_data->worker_route_id);
+ DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(
+ agent_host,
+ window_);
RenderViewHost* client_rvh = window_->GetRenderViewHost();
TabContents* client_contents = client_rvh->delegate()->GetAsTabContents();
if (client_contents->IsLoading()) {
diff --git a/chrome/browser/debugger/devtools_window.cc b/chrome/browser/debugger/devtools_window.cc
index 5ae3c46..7218f40 100644
--- a/chrome/browser/debugger/devtools_window.cc
+++ b/chrome/browser/debugger/devtools_window.cc
@@ -32,7 +32,6 @@
#include "content/browser/browsing_instance.h"
#include "content/browser/content_browser_client.h"
#include "content/browser/debugger/devtools_manager.h"
-#include "content/browser/debugger/worker_devtools_manager_io.h"
#include "content/browser/in_process_webkit/session_storage_namespace.h"
#include "content/browser/load_notification_details.h"
#include "content/browser/renderer_host/render_view_host.h"
@@ -621,7 +620,7 @@ void DevToolsWindow::RenderViewHostDestroyed() {
bool DevToolsWindow::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(DevToolsWindow, message)
- IPC_MESSAGE_HANDLER(DevToolsHostMsg_ForwardToAgent, OnForwardToAgent)
+ IPC_MESSAGE_HANDLER(DevToolsHostMsg_ForwardToAgent, ForwardToDevToolsAgent)
IPC_MESSAGE_HANDLER(DevToolsHostMsg_ActivateWindow, OnActivateWindow)
IPC_MESSAGE_HANDLER(DevToolsHostMsg_CloseWindow, OnCloseWindow)
IPC_MESSAGE_HANDLER(DevToolsHostMsg_RequestDockWindow, OnRequestDockWindow)
@@ -634,14 +633,6 @@ bool DevToolsWindow::OnMessageReceived(const IPC::Message& message) {
return handled;
}
-void DevToolsWindow::OnForwardToAgent(const IPC::Message& message) {
- if (DevToolsManager::GetInstance()->
- ForwardToDevToolsAgent(this, message))
- return;
- WorkerDevToolsManagerIO::ForwardToWorkerDevToolsAgentOnUIThread(
- this, message);
-}
-
void DevToolsWindow::OnRequestDockWindow() {
RequestSetDocked(true);
}
diff --git a/chrome/browser/debugger/devtools_window.h b/chrome/browser/debugger/devtools_window.h
index 4b02e96..63c68f1 100644
--- a/chrome/browser/debugger/devtools_window.h
+++ b/chrome/browser/debugger/devtools_window.h
@@ -124,7 +124,6 @@ class DevToolsWindow
virtual void RenderViewHostDestroyed() OVERRIDE;
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
- void OnForwardToAgent(const IPC::Message& message);
void OnActivateWindow();
void OnCloseWindow();
void OnRequestDockWindow();
diff --git a/chrome/browser/ui/webui/workers_ui.cc b/chrome/browser/ui/webui/workers_ui.cc
index 167dec4..3fddfdd 100644
--- a/chrome/browser/ui/webui/workers_ui.cc
+++ b/chrome/browser/ui/webui/workers_ui.cc
@@ -14,7 +14,8 @@
#include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h"
#include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
#include "chrome/common/url_constants.h"
-#include "content/browser/debugger/worker_devtools_manager_io.h"
+#include "content/browser/debugger/devtools_manager.h"
+#include "content/browser/debugger/worker_devtools_manager.h"
#include "content/browser/tab_contents/tab_contents.h"
#include "content/browser/worker_host/worker_process_host.h"
#include "content/common/devtools_messages.h"
@@ -121,19 +122,20 @@ void WorkersDOMHandler::HandleOpenDevTools(const ListValue* args) {
&worker_process_host_id));
CHECK(base::StringToInt(worker_route_id_str, &worker_route_id));
- if (WorkerDevToolsManagerIO::HasDevToolsClient(worker_process_host_id,
- worker_route_id))
- return;
Profile* profile = Profile::FromWebUI(web_ui_);
if (!profile)
return;
+ DevToolsAgentHost* agent_host =
+ WorkerDevToolsManager::GetDevToolsAgentHostForWorker(
+ worker_process_host_id,
+ worker_route_id);
+ if (DevToolsManager::GetInstance()->GetDevToolsClientHostFor(agent_host))
+ return;
DevToolsWindow* window = DevToolsWindow::CreateDevToolsWindowForWorker(
profile);
window->Show(DEVTOOLS_TOGGLE_ACTION_NONE);
- WorkerDevToolsManagerIO::RegisterDevToolsClientForWorkerOnUIThread(
- window,
- worker_process_host_id,
- worker_route_id);
+ DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(agent_host,
+ window);
}
} // namespace
diff --git a/content/browser/debugger/devtools_client_host.cc b/content/browser/debugger/devtools_client_host.cc
index 86f7009..5e79723 100644
--- a/content/browser/debugger/devtools_client_host.cc
+++ b/content/browser/debugger/devtools_client_host.cc
@@ -6,6 +6,7 @@
#include "base/logging.h"
#include "content/browser/debugger/devtools_client_host.h"
+#include "content/browser/debugger/devtools_manager.h"
DevToolsClientHost::DevToolsClientHostList DevToolsClientHost::instances_;
@@ -36,6 +37,10 @@ DevToolsClientHost::DevToolsClientHost() : close_listener_(NULL) {
instances_.push_back(this);
}
+void DevToolsClientHost::ForwardToDevToolsAgent(const IPC::Message& message) {
+ DevToolsManager::GetInstance()->ForwardToDevToolsAgent(this, message);
+}
+
void DevToolsClientHost::NotifyCloseListener() {
if (close_listener_) {
close_listener_->ClientHostClosing(this);
diff --git a/content/browser/debugger/devtools_client_host.h b/content/browser/debugger/devtools_client_host.h
index f629967..796d7fe 100644
--- a/content/browser/debugger/devtools_client_host.h
+++ b/content/browser/debugger/devtools_client_host.h
@@ -62,6 +62,8 @@ class DevToolsClientHost {
protected:
DevToolsClientHost();
+ void ForwardToDevToolsAgent(const IPC::Message& message);
+
// Should be called when the devtools client is going to die and this
// DevToolsClientHost should not be used anymore.
void NotifyCloseListener();
diff --git a/content/browser/debugger/devtools_manager.cc b/content/browser/debugger/devtools_manager.cc
index 0eb2e6e..4bceaf62 100644
--- a/content/browser/debugger/devtools_manager.cc
+++ b/content/browser/debugger/devtools_manager.cc
@@ -56,10 +56,15 @@ void DevToolsManager::RegisterDevToolsClientHostFor(
RenderViewHost* inspected_rvh,
DevToolsClientHost* client_host) {
DCHECK(!GetDevToolsClientHostFor(inspected_rvh));
-
- DevToolsRuntimeProperties initial_properties;
DevToolsAgentHost* agent_host = RenderViewDevToolsAgentHost::FindFor(
inspected_rvh);
+ RegisterDevToolsClientHostFor(agent_host, client_host);
+}
+
+void DevToolsManager::RegisterDevToolsClientHostFor(
+ DevToolsAgentHost* agent_host,
+ DevToolsClientHost* client_host) {
+ DevToolsRuntimeProperties initial_properties;
BindClientHost(agent_host, client_host, initial_properties);
client_host->set_close_listener(this);
SendAttachToAgent(agent_host);
diff --git a/content/browser/debugger/devtools_manager.h b/content/browser/debugger/devtools_manager.h
index 3965308..6aa43f9 100644
--- a/content/browser/debugger/devtools_manager.h
+++ b/content/browser/debugger/devtools_manager.h
@@ -84,6 +84,8 @@ class DevToolsManager : public DevToolsClientHost::CloseListener,
void CloseAllClientHosts();
DevToolsClientHost* GetDevToolsClientHostFor(DevToolsAgentHost* agent_host);
+ void RegisterDevToolsClientHostFor(DevToolsAgentHost* agent_host,
+ DevToolsClientHost* client_host);
void UnregisterDevToolsClientHostFor(DevToolsAgentHost* agent_host);
private:
diff --git a/content/browser/debugger/worker_devtools_manager.cc b/content/browser/debugger/worker_devtools_manager.cc
new file mode 100644
index 0000000..573ef3f
--- /dev/null
+++ b/content/browser/debugger/worker_devtools_manager.cc
@@ -0,0 +1,337 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/debugger/worker_devtools_manager.h"
+
+#include <list>
+#include <map>
+
+#include "base/tuple.h"
+#include "content/browser/browser_thread.h"
+#include "content/browser/debugger/devtools_agent_host.h"
+#include "content/browser/debugger/devtools_manager.h"
+#include "content/browser/debugger/worker_devtools_message_filter.h"
+#include "content/browser/worker_host/worker_process_host.h"
+#include "content/common/content_notification_types.h"
+#include "content/common/devtools_messages.h"
+#include "content/common/notification_observer.h"
+#include "content/common/notification_registrar.h"
+#include "content/common/notification_service.h"
+
+namespace {
+typedef std::pair<int, int> WorkerId;
+}
+
+class WorkerDevToolsManager::AgentHosts : private NotificationObserver {
+public:
+ static void Add(WorkerId id, WorkerDevToolsAgentHost* host) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ if (!instance_)
+ instance_ = new AgentHosts();
+ instance_->map_[id] = host;
+ }
+ static void Remove(WorkerId id) {
+ DCHECK(instance_);
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ Instances& map = instance_->map_;
+ map.erase(id);
+ if (map.empty()) {
+ delete instance_;
+ instance_ = NULL;
+ }
+ }
+
+ static WorkerDevToolsAgentHost* GetAgentHost(WorkerId id) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ if (!instance_)
+ return NULL;
+ Instances& map = instance_->map_;
+ Instances::iterator it = map.find(id);
+ if (it == map.end())
+ return NULL;
+ return it->second;
+ }
+
+private:
+ AgentHosts() {
+ registrar_.Add(this, content::NOTIFICATION_APP_TERMINATING,
+ NotificationService::AllSources());
+ }
+ ~AgentHosts() {}
+
+ // NotificationObserver implementation.
+ virtual void Observe(int type,
+ const NotificationSource&,
+ const NotificationDetails&) OVERRIDE;
+
+ static AgentHosts* instance_;
+ typedef std::map<WorkerId, WorkerDevToolsAgentHost*> Instances;
+ Instances map_;
+ NotificationRegistrar registrar_;
+};
+
+WorkerDevToolsManager::AgentHosts*
+ WorkerDevToolsManager::AgentHosts::instance_ = NULL;
+
+
+class WorkerDevToolsManager::WorkerDevToolsAgentHost
+ : public DevToolsAgentHost {
+ public:
+ explicit WorkerDevToolsAgentHost(WorkerId worker_id)
+ : worker_id_(worker_id) {
+ AgentHosts::Add(worker_id, this);
+ BrowserThread::PostTask(
+ BrowserThread::IO,
+ FROM_HERE,
+ NewRunnableFunction(
+ &RegisterAgent,
+ worker_id.first,
+ worker_id.second));
+ }
+
+ void WorkerDestroyed() {
+ NotifyCloseListener();
+ delete this;
+ }
+
+ private:
+ virtual ~WorkerDevToolsAgentHost() {
+ AgentHosts::Remove(worker_id_);
+ }
+
+ static void RegisterAgent(
+ int worker_process_id,
+ int worker_route_id) {
+ WorkerDevToolsManager::GetInstance()->RegisterDevToolsAgentHostForWorker(
+ worker_process_id, worker_route_id);
+ }
+
+ static void ForwardToWorkerDevToolsAgent(
+ int worker_process_id,
+ int worker_route_id,
+ const IPC::Message& message) {
+ WorkerDevToolsManager::GetInstance()->ForwardToWorkerDevToolsAgent(
+ worker_process_id, worker_route_id, message);
+ }
+
+ // DevToolsAgentHost implementation.
+ virtual void SendMessageToAgent(IPC::Message* message) OVERRIDE {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ NewRunnableFunction(
+ &WorkerDevToolsAgentHost::ForwardToWorkerDevToolsAgent,
+ worker_id_.first,
+ worker_id_.second,
+ *message));
+ }
+ virtual void NotifyClientClosing() OVERRIDE {}
+ virtual int GetRenderProcessId() OVERRIDE { return -1; }
+
+ WorkerId worker_id_;
+
+ DISALLOW_COPY_AND_ASSIGN(WorkerDevToolsAgentHost);
+};
+
+void WorkerDevToolsManager::AgentHosts::Observe(int type,
+ const NotificationSource&,
+ const NotificationDetails&) {
+ DCHECK(type == content::NOTIFICATION_APP_TERMINATING);
+ Instances copy(map_);
+ for (Instances::iterator it = copy.begin(); it != copy.end(); ++it)
+ it->second->WorkerDestroyed();
+ DCHECK(!instance_);
+}
+
+class WorkerDevToolsManager::InspectedWorkersList {
+ public:
+ InspectedWorkersList() {}
+
+ void AddInstance(WorkerProcessHost* host, int route_id) {
+ DCHECK(!Contains(host->id(), route_id));
+ map_.push_back(Entry(host, route_id));
+ }
+
+ bool Contains(int host_id, int route_id) {
+ return FindHost(host_id, route_id) != NULL;
+ }
+
+ WorkerProcessHost* FindHost(int host_id, int route_id) {
+ Entries::iterator it = FindEntry(host_id, route_id);
+ if (it == map_.end())
+ return NULL;
+ return it->host;
+ }
+
+ WorkerProcessHost* RemoveInstance(int host_id, int route_id) {
+ Entries::iterator it = FindEntry(host_id, route_id);
+ if (it == map_.end())
+ return NULL;
+ WorkerProcessHost* host = it->host;
+ map_.erase(it);
+ return host;
+ }
+
+ void WorkerDevToolsMessageFilterClosing(int worker_process_id) {
+ Entries::iterator it = map_.begin();
+ while (it != map_.end()) {
+ if (it->host->id() == worker_process_id) {
+ NotifyWorkerDestroyedOnIOThread(
+ it->host->id(),
+ it->route_id);
+ it = map_.erase(it);
+ } else
+ ++it;
+ }
+ }
+
+ private:
+ struct Entry {
+ Entry(WorkerProcessHost* host, int route_id)
+ : host(host),
+ route_id(route_id) {}
+ WorkerProcessHost* const host;
+ int const route_id;
+ };
+ typedef std::list<Entry> Entries;
+
+ Entries::iterator FindEntry(int host_id, int route_id) {
+ Entries::iterator it = map_.begin();
+ while (it != map_.end()) {
+ if (it->host->id() == host_id && it->route_id == route_id)
+ break;
+ ++it;
+ }
+ return it;
+ }
+
+ Entries map_;
+ DISALLOW_COPY_AND_ASSIGN(InspectedWorkersList);
+};
+
+// static
+WorkerDevToolsManager* WorkerDevToolsManager::GetInstance() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ return Singleton<WorkerDevToolsManager>::get();
+}
+
+// static
+DevToolsAgentHost* WorkerDevToolsManager::GetDevToolsAgentHostForWorker(
+ int worker_process_id,
+ int worker_route_id) {
+ WorkerId id(worker_process_id, worker_route_id);
+ WorkerDevToolsAgentHost* result = AgentHosts::GetAgentHost(id);
+ if (!result)
+ result = new WorkerDevToolsAgentHost(id);
+ return result;
+}
+
+WorkerDevToolsManager::WorkerDevToolsManager()
+ : inspected_workers_(new InspectedWorkersList()) {
+}
+
+WorkerDevToolsManager::~WorkerDevToolsManager() {
+}
+
+static WorkerProcessHost* FindWorkerProcessHostForWorker(
+ int worker_process_id,
+ int worker_route_id) {
+ BrowserChildProcessHost::Iterator iter(ChildProcessInfo::WORKER_PROCESS);
+ for (; !iter.Done(); ++iter) {
+ if (iter->id() != worker_process_id)
+ continue;
+ WorkerProcessHost* worker = static_cast<WorkerProcessHost*>(*iter);
+ const WorkerProcessHost::Instances& instances = worker->instances();
+ for (WorkerProcessHost::Instances::const_iterator i = instances.begin();
+ i != instances.end(); ++i) {
+ if (i->shared() && i->worker_route_id() == worker_route_id)
+ return worker;
+ }
+ return NULL;
+ }
+ return NULL;
+}
+
+void WorkerDevToolsManager::RegisterDevToolsAgentHostForWorker(
+ int worker_process_id,
+ int worker_route_id) {
+ WorkerProcessHost* host = FindWorkerProcessHostForWorker(
+ worker_process_id,
+ worker_route_id);
+ if (host)
+ inspected_workers_->AddInstance(host, worker_route_id);
+ else
+ NotifyWorkerDestroyedOnIOThread(worker_process_id, worker_route_id);
+}
+
+void WorkerDevToolsManager::ForwardToDevToolsClient(
+ int worker_process_id,
+ int worker_route_id,
+ const IPC::Message& message) {
+ if (!inspected_workers_->Contains(worker_process_id, worker_route_id)) {
+ NOTREACHED();
+ return;
+ }
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ NewRunnableFunction(
+ ForwardToDevToolsClientOnUIThread,
+ worker_process_id,
+ worker_route_id,
+ message));
+}
+
+void WorkerDevToolsManager::WorkerProcessDestroying(
+ int worker_process_id) {
+ inspected_workers_->WorkerDevToolsMessageFilterClosing(
+ worker_process_id);
+}
+
+void WorkerDevToolsManager::ForwardToWorkerDevToolsAgent(
+ int worker_process_id,
+ int worker_route_id,
+ const IPC::Message& message) {
+ WorkerProcessHost* host = inspected_workers_->FindHost(
+ worker_process_id,
+ worker_route_id);
+ if (!host)
+ return;
+ IPC::Message* msg = new IPC::Message(message);
+ msg->set_routing_id(worker_route_id);
+ host->Send(msg);
+}
+
+// static
+void WorkerDevToolsManager::ForwardToDevToolsClientOnUIThread(
+ int worker_process_id,
+ int worker_route_id,
+ const IPC::Message& message) {
+ WorkerDevToolsAgentHost* agent_host = AgentHosts::GetAgentHost(WorkerId(
+ worker_process_id,
+ worker_route_id));
+ if (!agent_host)
+ return;
+ DevToolsManager::GetInstance()->ForwardToDevToolsClient(agent_host, message);
+}
+
+// static
+void WorkerDevToolsManager::NotifyWorkerDestroyedOnIOThread(
+ int worker_process_id,
+ int worker_route_id) {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ NewRunnableFunction(
+ &WorkerDevToolsManager::NotifyWorkerDestroyedOnUIThread,
+ worker_process_id,
+ worker_route_id));
+}
+
+// static
+void WorkerDevToolsManager::NotifyWorkerDestroyedOnUIThread(
+ int worker_process_id,
+ int worker_route_id) {
+ WorkerDevToolsAgentHost* host =
+ AgentHosts::GetAgentHost(WorkerId(worker_process_id, worker_route_id));
+ if (host)
+ host->WorkerDestroyed();
+}
diff --git a/content/browser/debugger/worker_devtools_manager.h b/content/browser/debugger/worker_devtools_manager.h
new file mode 100644
index 0000000..25f68f6
--- /dev/null
+++ b/content/browser/debugger/worker_devtools_manager.h
@@ -0,0 +1,62 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_BROWSER_DEBUGGER_WORKER_DEVTOOLS_MANAGER_H_
+#define CONTENT_BROWSER_DEBUGGER_WORKER_DEVTOOLS_MANAGER_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/singleton.h"
+
+namespace IPC {
+class Message;
+}
+class DevToolsAgentHost;
+class WorkerDevToolsMessageFilter;
+
+// All methods are supposed to be called on the IO thread.
+class WorkerDevToolsManager {
+ public:
+ // Returns the WorkerDevToolsManager singleton.
+ static WorkerDevToolsManager* GetInstance();
+
+ // Called on the UI thread.
+ static DevToolsAgentHost* GetDevToolsAgentHostForWorker(
+ int worker_process_id,
+ int worker_route_id);
+
+ void WorkerProcessDestroying(int worker_process_host_id);
+ void ForwardToDevToolsClient(int worker_process_id,
+ int worker_route_id,
+ const IPC::Message& message);
+ private:
+ friend struct DefaultSingletonTraits<WorkerDevToolsManager>;
+ class AgentHosts;
+ class WorkerDevToolsAgentHost;
+
+ WorkerDevToolsManager();
+ ~WorkerDevToolsManager();
+
+ void RegisterDevToolsAgentHostForWorker(int worker_process_id,
+ int worker_route_id);
+ void ForwardToWorkerDevToolsAgent(int worker_process_host_id,
+ int worker_route_id,
+ const IPC::Message& message);
+ static void ForwardToDevToolsClientOnUIThread(
+ int worker_process_id,
+ int worker_route_id,
+ const IPC::Message& message);
+ static void NotifyWorkerDestroyedOnIOThread(int worker_process_id,
+ int worker_route_id);
+ static void NotifyWorkerDestroyedOnUIThread(int worker_process_id,
+ int worker_route_id);
+
+ class InspectedWorkersList;
+ scoped_ptr<InspectedWorkersList> inspected_workers_;
+
+ DISALLOW_COPY_AND_ASSIGN(WorkerDevToolsManager);
+};
+
+#endif // CONTENT_BROWSER_DEBUGGER_WORKER_DEVTOOLS_MANAGER_H_
diff --git a/content/browser/debugger/worker_devtools_manager_io.cc b/content/browser/debugger/worker_devtools_manager_io.cc
deleted file mode 100644
index 1f4ae86..0000000
--- a/content/browser/debugger/worker_devtools_manager_io.cc
+++ /dev/null
@@ -1,321 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "content/browser/debugger/worker_devtools_manager_io.h"
-
-#include <list>
-
-#include "base/tuple.h"
-#include "content/browser/browser_thread.h"
-#include "content/browser/debugger/devtools_manager.h"
-#include "content/browser/debugger/worker_devtools_message_filter.h"
-#include "content/browser/worker_host/worker_process_host.h"
-#include "content/common/devtools_messages.h"
-
-namespace {
-
-void NotifyWorkerDevToolsClientClosingOnIOThread(int worker_process_host_id,
- int worker_route_id) {
- WorkerDevToolsManagerIO::GetInstance()->WorkerDevToolsClientClosing(
- worker_process_host_id,
- worker_route_id);
-}
-
-class ClientsUI : public DevToolsClientHost::CloseListener {
- public:
- static ClientsUI* GetInstance() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- static ClientsUI* instance = new ClientsUI();
- return instance;
- }
-
- DevToolsClientHost* FindDevToolsClient(int worker_process_host_id,
- int worker_route_id) {
- WorkerIdToClientHostMap::iterator it =
- worker_id_to_client_host_.find(WorkerId(worker_process_host_id,
- worker_route_id));
- if (it == worker_id_to_client_host_.end())
- return NULL;
- return it->second;
- }
-
- bool FindWorkerInfo(DevToolsClientHost* client_host,
- int* host_id,
- int* route_id) {
- for (WorkerIdToClientHostMap::const_iterator it =
- worker_id_to_client_host_.begin();
- it != worker_id_to_client_host_.end(); ++it) {
- if (it->second == client_host) {
- WorkerId id = it->first;
- *host_id = id.first;
- *route_id = id.second;
- return true;
- }
- }
- return false;
- }
-
- void RegisterDevToolsClientForWorker(int worker_process_host_id,
- int worker_route_id,
- DevToolsClientHost* client) {
- client->set_close_listener(this);
- WorkerId worker_id(worker_process_host_id, worker_route_id);
- worker_id_to_client_host_[worker_id] = client;
- }
-
- private:
- ClientsUI() {}
- virtual ~ClientsUI() {}
-
- virtual void ClientHostClosing(DevToolsClientHost* host) {
- WorkerIdToClientHostMap::iterator it = worker_id_to_client_host_.begin();
- for (; it != worker_id_to_client_host_.end(); ++it) {
- if (it->second == host) {
- WorkerId id = it->first;
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- NewRunnableFunction(NotifyWorkerDevToolsClientClosingOnIOThread,
- id.first, id.second));
- worker_id_to_client_host_.erase(it);
- return;
- }
- }
- }
-
- typedef std::pair<int, int> WorkerId;
- typedef std::map<WorkerId, DevToolsClientHost*> WorkerIdToClientHostMap;
- WorkerIdToClientHostMap worker_id_to_client_host_;
-
- DISALLOW_COPY_AND_ASSIGN(ClientsUI);
-};
-
-} // namespace
-
-class WorkerDevToolsManagerIO::InspectedWorkersList {
- public:
- InspectedWorkersList() {}
-
- void AddInstance(WorkerProcessHost* host, int route_id) {
- DCHECK(!Contains(host->id(), route_id));
- map_.push_back(Entry(host, route_id));
- }
-
- bool Contains(int host_id, int route_id) {
- return FindHost(host_id, route_id) != NULL;
- }
-
- WorkerProcessHost* FindHost(int host_id, int route_id) {
- Entries::iterator it = FindEntry(host_id, route_id);
- if (it == map_.end())
- return NULL;
- return it->host;
- }
-
- WorkerProcessHost* RemoveInstance(int host_id, int route_id) {
- Entries::iterator it = FindEntry(host_id, route_id);
- if (it == map_.end())
- return NULL;
- WorkerProcessHost* host = it->host;
- map_.erase(it);
- return host;
- }
-
- void WorkerDevToolsMessageFilterClosing(int worker_process_host_id) {
- Entries::iterator it = map_.begin();
- while (it != map_.end()) {
- if (it->host->id() == worker_process_host_id)
- it = map_.erase(it);
- else
- ++it;
- }
- }
-
- private:
- struct Entry {
- Entry(WorkerProcessHost* host, int route_id)
- : host(host),
- route_id(route_id) {}
- WorkerProcessHost* const host;
- int const route_id;
- };
- typedef std::list<Entry> Entries;
-
- Entries::iterator FindEntry(int host_id, int route_id) {
- Entries::iterator it = map_.begin();
- while (it != map_.end()) {
- if (it->host->id() == host_id && it->route_id == route_id)
- break;
- ++it;
- }
- return it;
- }
-
- Entries map_;
- DISALLOW_COPY_AND_ASSIGN(InspectedWorkersList);
-};
-
-// static
-WorkerDevToolsManagerIO* WorkerDevToolsManagerIO::GetInstance() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- return Singleton<WorkerDevToolsManagerIO>::get();
-}
-
-WorkerDevToolsManagerIO::WorkerDevToolsManagerIO()
- : inspected_workers_(new InspectedWorkersList()) {
-}
-
-WorkerDevToolsManagerIO::~WorkerDevToolsManagerIO() {
-}
-
-bool WorkerDevToolsManagerIO::ForwardToWorkerDevToolsAgentOnUIThread(
- DevToolsClientHost* from,
- const IPC::Message& message) {
- int worker_process_host_id;
- int worker_route_id;
- if (!ClientsUI::GetInstance()->FindWorkerInfo(
- from, &worker_process_host_id, &worker_route_id))
- return false;
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- NewRunnableFunction(
- ForwardToWorkerDevToolsAgentOnIOThread,
- worker_process_host_id,
- worker_route_id,
- IPC::Message(message)));
- return true;
-}
-
-static WorkerProcessHost* FindWorkerProcessHostForWorker(
- int worker_process_host_id,
- int worker_route_id) {
- BrowserChildProcessHost::Iterator iter(ChildProcessInfo::WORKER_PROCESS);
- for (; !iter.Done(); ++iter) {
- if (iter->id() != worker_process_host_id)
- continue;
- WorkerProcessHost* worker = static_cast<WorkerProcessHost*>(*iter);
- const WorkerProcessHost::Instances& instances = worker->instances();
- for (WorkerProcessHost::Instances::const_iterator i = instances.begin();
- i != instances.end(); ++i) {
- if (i->shared() && i->worker_route_id() == worker_route_id)
- return worker;
- }
- return NULL;
- }
- return NULL;
-}
-
-// static
-bool WorkerDevToolsManagerIO::HasDevToolsClient(
- int worker_process_id,
- int worker_route_id) {
- return NULL != ClientsUI::GetInstance()->
- FindDevToolsClient(worker_process_id, worker_route_id);
-}
-
-// static
-void WorkerDevToolsManagerIO::RegisterDevToolsClientForWorkerOnUIThread(
- DevToolsClientHost* client,
- int worker_process_id,
- int worker_route_id) {
- DCHECK(!HasDevToolsClient(worker_process_id, worker_route_id));
- ClientsUI::GetInstance()->RegisterDevToolsClientForWorker(
- worker_process_id, worker_route_id, client);
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- NewRunnableFunction(
- WorkerDevToolsManagerIO::RegisterDevToolsClientForWorker,
- worker_process_id,
- worker_route_id));
-}
-
-// static
-void WorkerDevToolsManagerIO::RegisterDevToolsClientForWorker(
- int worker_process_id,
- int worker_route_id) {
- WorkerDevToolsManagerIO::GetInstance()->AddInspectedInstance(
- worker_process_id,
- worker_route_id);
-}
-
-void WorkerDevToolsManagerIO::AddInspectedInstance(
- int worker_process_host_id,
- int worker_route_id) {
- WorkerProcessHost* host = FindWorkerProcessHostForWorker(
- worker_process_host_id,
- worker_route_id);
- if (!host)
- return;
-
- // DevTools client is already attached.
- if (inspected_workers_->Contains(worker_process_host_id, worker_route_id))
- return;
-
- host->Send(new WorkerDevToolsAgentMsg_Attach(worker_route_id));
-
- inspected_workers_->AddInstance(host, worker_route_id);
-}
-
-void WorkerDevToolsManagerIO::WorkerDevToolsClientClosing(
- int worker_process_host_id,
- int worker_route_id) {
- WorkerProcessHost* host = inspected_workers_->RemoveInstance(
- worker_process_host_id, worker_route_id);
- if (host)
- host->Send(new WorkerDevToolsAgentMsg_Detach(worker_route_id));
-}
-
-static void ForwardToDevToolsClientOnUIThread(
- int worker_process_host_id,
- int worker_route_id,
- const IPC::Message& message) {
- DevToolsClientHost* client = ClientsUI::GetInstance()->
- FindDevToolsClient(worker_process_host_id, worker_route_id);
- if (client)
- client->SendMessageToClient(message);
-}
-
-void WorkerDevToolsManagerIO::ForwardToDevToolsClient(
- int worker_process_host_id,
- int worker_route_id,
- const IPC::Message& message) {
- if (!inspected_workers_->Contains(worker_process_host_id, worker_route_id)) {
- NOTREACHED();
- return;
- }
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- NewRunnableFunction(
- ForwardToDevToolsClientOnUIThread,
- worker_process_host_id,
- worker_route_id,
- IPC::Message(message)));
-}
-
-void WorkerDevToolsManagerIO::WorkerProcessDestroying(
- int worker_process_host_id) {
- inspected_workers_->WorkerDevToolsMessageFilterClosing(
- worker_process_host_id);
-}
-
-void WorkerDevToolsManagerIO::ForwardToWorkerDevToolsAgentOnIOThread(
- int worker_process_host_id,
- int worker_route_id,
- const IPC::Message& message) {
- WorkerDevToolsManagerIO::GetInstance()->ForwardToWorkerDevToolsAgent(
- worker_process_host_id, worker_route_id, message);
-}
-
-void WorkerDevToolsManagerIO::ForwardToWorkerDevToolsAgent(
- int worker_process_host_id,
- int worker_route_id,
- const IPC::Message& message) {
- WorkerProcessHost* host = inspected_workers_->FindHost(
- worker_process_host_id,
- worker_route_id);
- if (!host)
- return;
- IPC::Message* msg = new IPC::Message(message);
- msg->set_routing_id(worker_route_id);
- host->Send(msg);
-}
diff --git a/content/browser/debugger/worker_devtools_manager_io.h b/content/browser/debugger/worker_devtools_manager_io.h
deleted file mode 100644
index 19b4388..0000000
--- a/content/browser/debugger/worker_devtools_manager_io.h
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CONTENT_BROWSER_DEBUGGER_WORKER_DEVTOOLS_MANAGER_IO_H_
-#define CONTENT_BROWSER_DEBUGGER_WORKER_DEVTOOLS_MANAGER_IO_H_
-#pragma once
-
-#include "base/basictypes.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/memory/singleton.h"
-
-namespace IPC {
-class Message;
-}
-class DevToolsClientHost;
-class WorkerDevToolsMessageFilter;
-
-// All methods are supposed to be called on the IO thread.
-class WorkerDevToolsManagerIO {
- public:
- // Returns the WorkerDevToolsManagerIO singleton.
- static WorkerDevToolsManagerIO* GetInstance();
-
- // This method is called on the UI thread by the devtools handler.
- static bool ForwardToWorkerDevToolsAgentOnUIThread(
- DevToolsClientHost* from,
- const IPC::Message& message);
-
- static bool HasDevToolsClient(int worker_process_id, int worker_route_id);
- static void RegisterDevToolsClientForWorkerOnUIThread(
- DevToolsClientHost* client,
- int worker_process_id,
- int worker_route_id);
-
- void WorkerDevToolsClientClosing(int worker_process_host_id,
- int worker_route_id);
-
- void ForwardToDevToolsClient(int worker_process_id,
- int worker_route_id,
- const IPC::Message& message);
- void WorkerProcessDestroying(int worker_process_host_id);
-
- private:
- friend struct DefaultSingletonTraits<WorkerDevToolsManagerIO>;
-
- WorkerDevToolsManagerIO();
- ~WorkerDevToolsManagerIO();
- static void RegisterDevToolsClientForWorker(int worker_process_id,
- int worker_route_id);
- void AddInspectedInstance(int worker_process_host_id,
- int worker_route_id);
- static void ForwardToWorkerDevToolsAgentOnIOThread(
- int worker_process_host_id,
- int worker_route_id,
- const IPC::Message& message);
- void ForwardToWorkerDevToolsAgent(int worker_process_host_id,
- int worker_route_id,
- const IPC::Message& message);
- class InspectedWorkersList;
- scoped_ptr<InspectedWorkersList> inspected_workers_;
-
- DISALLOW_COPY_AND_ASSIGN(WorkerDevToolsManagerIO);
-};
-
-#endif // CONTENT_BROWSER_DEBUGGER_WORKER_DEVTOOLS_MANAGER_IO_H_
diff --git a/content/browser/debugger/worker_devtools_message_filter.cc b/content/browser/debugger/worker_devtools_message_filter.cc
index a086c9b..4f074ea 100644
--- a/content/browser/debugger/worker_devtools_message_filter.cc
+++ b/content/browser/debugger/worker_devtools_message_filter.cc
@@ -4,7 +4,7 @@
#include "content/browser/debugger/worker_devtools_message_filter.h"
-#include "content/browser/debugger/worker_devtools_manager_io.h"
+#include "content/browser/debugger/worker_devtools_manager.h"
#include "content/browser/worker_host/worker_service.h"
#include "content/common/devtools_messages.h"
#include "content/common/worker_messages.h"
@@ -19,7 +19,7 @@ WorkerDevToolsMessageFilter::~WorkerDevToolsMessageFilter() {
void WorkerDevToolsMessageFilter::OnChannelClosing() {
BrowserMessageFilter::OnChannelClosing();
- WorkerDevToolsManagerIO::GetInstance()->WorkerProcessDestroying(
+ WorkerDevToolsManager::GetInstance()->WorkerProcessDestroying(
worker_process_host_id_);
}
@@ -37,6 +37,6 @@ bool WorkerDevToolsMessageFilter::OnMessageReceived(
void WorkerDevToolsMessageFilter::OnForwardToClient(
const IPC::Message& message) {
- WorkerDevToolsManagerIO::GetInstance()->ForwardToDevToolsClient(
+ WorkerDevToolsManager::GetInstance()->ForwardToDevToolsClient(
worker_process_host_id_, message.routing_id(), message);
}
diff --git a/content/common/devtools_messages.h b/content/common/devtools_messages.h
index 6adb62c..6536f40 100644
--- a/content/common/devtools_messages.h
+++ b/content/common/devtools_messages.h
@@ -156,6 +156,3 @@ IPC_MESSAGE_ROUTED0(DevToolsHostMsg_ClearBrowserCookies)
//-----------------------------------------------------------------------------
// These are messages sent from the inspected page renderer to the worker
// renderer.
-
-IPC_MESSAGE_ROUTED0(WorkerDevToolsAgentMsg_Attach)
-IPC_MESSAGE_ROUTED0(WorkerDevToolsAgentMsg_Detach)
diff --git a/content/content_browser.gypi b/content/content_browser.gypi
index 44e8364..2ecde32 100644
--- a/content/content_browser.gypi
+++ b/content/content_browser.gypi
@@ -95,8 +95,8 @@
'browser/debugger/devtools_netlog_observer.h',
'browser/debugger/render_view_devtools_agent_host.cc',
'browser/debugger/render_view_devtools_agent_host.h',
- 'browser/debugger/worker_devtools_manager_io.cc',
- 'browser/debugger/worker_devtools_manager_io.h',
+ 'browser/debugger/worker_devtools_manager.cc',
+ 'browser/debugger/worker_devtools_manager.h',
'browser/debugger/worker_devtools_message_filter.cc',
'browser/debugger/worker_devtools_message_filter.h',
'browser/device_orientation/accelerometer_mac.cc',
diff --git a/content/renderer/worker_devtools_agent_proxy.cc b/content/renderer/worker_devtools_agent_proxy.cc
index db09e0d..6a1907b 100644
--- a/content/renderer/worker_devtools_agent_proxy.cc
+++ b/content/renderer/worker_devtools_agent_proxy.cc
@@ -44,11 +44,11 @@ bool WorkerDevToolsAgentProxy::OnMessageReceived(const IPC::Message& message) {
}
void WorkerDevToolsAgentProxy::AttachDevTools() {
- Send(new WorkerDevToolsAgentMsg_Attach(route_id_));
+ Send(new DevToolsAgentMsg_Attach(route_id_, DevToolsRuntimeProperties()));
}
void WorkerDevToolsAgentProxy::DetachDevTools() {
- Send(new WorkerDevToolsAgentMsg_Detach(route_id_));
+ Send(new DevToolsAgentMsg_Detach(route_id_));
}
void WorkerDevToolsAgentProxy::SendDevToolsMessage(
diff --git a/content/worker/worker_devtools_agent.cc b/content/worker/worker_devtools_agent.cc
index 2ff069a..1ef2f03 100644
--- a/content/worker/worker_devtools_agent.cc
+++ b/content/worker/worker_devtools_agent.cc
@@ -31,8 +31,8 @@ class WorkerDevToolsAgentImpl : public WorkerDevToolsAgent {
virtual bool OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(WorkerDevToolsAgentImpl, message)
- IPC_MESSAGE_HANDLER(WorkerDevToolsAgentMsg_Attach, OnAttach)
- IPC_MESSAGE_HANDLER(WorkerDevToolsAgentMsg_Detach, OnDetach)
+ IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Attach, OnAttach)
+ IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Detach, OnDetach)
IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DispatchOnInspectorBackend,
OnDispatchOnInspectorBackend)
IPC_MESSAGE_UNHANDLED(handled = false)
@@ -42,7 +42,7 @@ class WorkerDevToolsAgentImpl : public WorkerDevToolsAgent {
virtual void SendDevToolsMessage(const WebKit::WebString& message);
- void OnAttach() {
+ void OnAttach(const DevToolsRuntimeProperties&) {
webworker_->attachDevTools();
}