Chromium Code Reviews| Index: content/browser/devtools/shared_worker_devtools_manager.cc |
| diff --git a/content/browser/devtools/worker_devtools_manager.cc b/content/browser/devtools/shared_worker_devtools_manager.cc |
| similarity index 18% |
| copy from content/browser/devtools/worker_devtools_manager.cc |
| copy to content/browser/devtools/shared_worker_devtools_manager.cc |
| index 00735f34c2ebfe69744a2fb44fb261bd4b230872..f3a97cda6b9736916a0b5ebc22df7b0fddf6fc38 100644 |
| --- a/content/browser/devtools/worker_devtools_manager.cc |
| +++ b/content/browser/devtools/shared_worker_devtools_manager.cc |
| @@ -2,446 +2,289 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "content/browser/devtools/worker_devtools_manager.h" |
| +#include "content/browser/devtools/shared_worker_devtools_manager.h" |
| -#include <list> |
| -#include <map> |
| - |
| -#include "base/bind.h" |
| #include "base/lazy_instance.h" |
| +#include "base/logging.h" |
| +#include "base/memory/singleton.h" |
|
kinuko
2014/03/24 12:24:02
nit: we already have this in .h
horo
2014/03/25 06:28:17
Done.
|
| #include "content/browser/devtools/devtools_manager_impl.h" |
| #include "content/browser/devtools/devtools_protocol.h" |
| #include "content/browser/devtools/devtools_protocol_constants.h" |
| #include "content/browser/devtools/ipc_devtools_agent_host.h" |
| -#include "content/browser/devtools/worker_devtools_message_filter.h" |
| -#include "content/browser/worker_host/worker_service_impl.h" |
| +#include "content/browser/shared_worker/shared_worker_instance.h" |
| #include "content/common/devtools_messages.h" |
| #include "content/public/browser/browser_thread.h" |
| -#include "content/public/browser/child_process_data.h" |
| -#include "content/public/common/process_type.h" |
| +#include "content/public/browser/render_process_host.h" |
| +#include "content/public/browser/worker_service.h" |
| +#include "ipc/ipc_listener.h" |
| namespace content { |
| -// Called on the UI thread. |
| -// static |
| -scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::GetForWorker( |
| - int worker_process_id, |
| - int worker_route_id) { |
| - return WorkerDevToolsManager::GetDevToolsAgentHostForWorker( |
| - worker_process_id, |
| - worker_route_id); |
| -} |
| - |
| namespace { |
| -typedef std::map<WorkerDevToolsManager::WorkerId, |
| - WorkerDevToolsManager::WorkerDevToolsAgentHost*> AgentHosts; |
| +typedef std::map<SharedWorkerDevToolsManager::WorkerId, |
| + SharedWorkerDevToolsManager::SharedWorkerDevToolsAgentHost*> |
| + AgentHosts; |
| base::LazyInstance<AgentHosts>::Leaky g_agent_map = LAZY_INSTANCE_INITIALIZER; |
| base::LazyInstance<AgentHosts>::Leaky g_orphan_map = LAZY_INSTANCE_INITIALIZER; |
| -} // namespace |
| - |
| -struct WorkerDevToolsManager::TerminatedInspectedWorker { |
| - TerminatedInspectedWorker(WorkerId id, |
| - const GURL& url, |
| - const base::string16& name) |
| - : old_worker_id(id), |
| - worker_url(url), |
| - worker_name(name) {} |
| - WorkerId old_worker_id; |
| - GURL worker_url; |
| - base::string16 worker_name; |
| -}; |
| +bool SendMessageToWorker(const SharedWorkerDevToolsManager::WorkerId& worker_id, |
| + IPC::Message* message) { |
| + RenderProcessHost* host = RenderProcessHost::FromID(worker_id.first); |
| + if (!host) { |
| + delete message; |
| + return false; |
| + } |
| + message->set_routing_id(worker_id.second); |
| + host->Send(message); |
| + return true; |
| +} |
| +} // namespace |
| -class WorkerDevToolsManager::WorkerDevToolsAgentHost |
| - : public IPCDevToolsAgentHost { |
| +class SharedWorkerDevToolsManager::SharedWorkerDevToolsAgentHost |
| + : public IPCDevToolsAgentHost, |
| + public IPC::Listener { |
| public: |
| - explicit WorkerDevToolsAgentHost(WorkerId worker_id) |
| + SharedWorkerDevToolsAgentHost(WorkerId worker_id) |
| : has_worker_id_(false) { |
| SetWorkerId(worker_id, false); |
|
kinuko
2014/03/24 12:24:02
nit: can you add '/* reattach */' comment after 'f
horo
2014/03/25 06:28:17
Done.
|
| } |
| + // IPCDevToolsAgentHost implementation. |
| + virtual void SendMessageToAgent(IPC::Message* message) OVERRIDE { |
| + SendMessageToWorker(worker_id_, message); |
| + } |
| + virtual void OnClientAttached() OVERRIDE {} |
| + virtual void OnClientDetached() OVERRIDE {} |
| + |
| + // IPC::Listener implementation. |
| + virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + bool handled = true; |
| + IPC_BEGIN_MESSAGE_MAP(SharedWorkerDevToolsAgentHost, msg) |
| + IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend, |
| + OnDispatchOnInspectorFrontend) |
| + IPC_MESSAGE_HANDLER(DevToolsHostMsg_SaveAgentRuntimeState, |
| + OnSaveAgentRumtimeState) |
|
kinuko
2014/03/24 12:24:02
typo: Rumtime -> Runtime
horo
2014/03/25 06:28:17
Done.
|
| + IPC_MESSAGE_UNHANDLED(handled = false) |
| + IPC_END_MESSAGE_MAP() |
| + return handled; |
| + } |
| + |
| + void OnDispatchOnInspectorFrontend(const std::string& message) { |
| + DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend(this, |
| + message); |
|
kinuko
2014/03/24 12:24:02
indent is off
horo
2014/03/25 06:28:17
Done.
|
| + } |
|
kinuko
2014/03/24 12:24:02
nit: please have an empty line between methods unl
horo
2014/03/25 06:28:17
Done.
Moved to private.
|
| + void OnSaveAgentRumtimeState(const std::string& state) { |
| + SaveAgentRuntimeState(state); |
|
kinuko
2014/03/24 12:24:02
nit: as far as this is the only place we call it,
horo
2014/03/25 06:28:17
Done.
|
| + } |
| void SetWorkerId(WorkerId worker_id, bool reattach) { |
| + if (!SharedWorkerDevToolsManager::GetInstance() |
| + ->ConnectDevToolsAgentHostToWorker(worker_id)) { |
| + NotifyCloseListener(); |
| + return; |
| + } |
| worker_id_ = worker_id; |
| - if (!has_worker_id_) |
| + if (!has_worker_id_) { |
| AddRef(); // Balanced in ResetWorkerId. |
| + } |
|
kinuko
2014/03/24 12:24:02
nit: no need of { } for single-line body
horo
2014/03/25 06:28:17
Done.
|
| has_worker_id_ = true; |
| g_agent_map.Get()[worker_id_] = this; |
| - BrowserThread::PostTask( |
| - BrowserThread::IO, |
| - FROM_HERE, |
| - base::Bind( |
| - &ConnectToWorker, |
| - worker_id.first, |
| - worker_id.second)); |
| + if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) |
| + host->AddRoute(worker_id_.second, this); |
| if (reattach) |
| Reattach(state_); |
| } |
| void ResetWorkerId() { |
| + CHECK(has_worker_id_); |
| g_agent_map.Get().erase(worker_id_); |
| has_worker_id_ = false; |
| + if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) |
| + host->RemoveRoute(worker_id_.second); |
| Release(); // Balanced in SetWorkerId. |
| } |
| - void SaveAgentRuntimeState(const std::string& state) { |
| - state_ = state; |
| - } |
| - |
| - void ConnectionFailed() { |
| - NotifyCloseListener(); |
| - // Object can be deleted here. |
| - } |
| + void SaveAgentRuntimeState(const std::string& state) { state_ = state; } |
| private: |
| - virtual ~WorkerDevToolsAgentHost(); |
| - |
| - static void ConnectToWorker( |
| - int worker_process_id, |
| - int worker_route_id) { |
| - WorkerDevToolsManager::GetInstance()->ConnectDevToolsAgentHostToWorker( |
| - worker_process_id, worker_route_id); |
| - } |
| - |
| - static void ForwardToWorkerDevToolsAgent( |
| - int worker_process_id, |
| - int worker_route_id, |
| - IPC::Message* message) { |
| - WorkerDevToolsManager::GetInstance()->ForwardToWorkerDevToolsAgent( |
| - worker_process_id, worker_route_id, *message); |
| - } |
| - |
| - // IPCDevToolsAgentHost implementation. |
| - virtual void SendMessageToAgent(IPC::Message* message) OVERRIDE { |
| - if (!has_worker_id_) { |
| - delete message; |
| - return; |
| + virtual ~SharedWorkerDevToolsAgentHost() { |
| + if (has_worker_id_) { |
|
kinuko
2014/03/24 12:24:02
Could we reach here other without going through Re
horo
2014/03/25 06:28:17
Done.
We should call RemoveInspectedWorkerData and
|
| + SharedWorkerDevToolsManager::GetInstance()->RemoveInspectedWorkerData( |
| + worker_id_); |
| + g_agent_map.Get().erase(worker_id_); |
| + g_orphan_map.Get().erase(worker_id_); |
| + if (RenderProcessHost* host = |
| + RenderProcessHost::FromID(worker_id_.first)) { |
| + host->RemoveRoute(worker_id_.second); |
| + } |
| } |
| - BrowserThread::PostTask( |
| - BrowserThread::IO, FROM_HERE, |
| - base::Bind( |
| - &WorkerDevToolsAgentHost::ForwardToWorkerDevToolsAgent, |
| - worker_id_.first, |
| - worker_id_.second, |
| - base::Owned(message))); |
| } |
|
kinuko
2014/03/24 12:24:02
nit: can we have one empty line here?
horo
2014/03/25 06:28:17
Done.
|
| - |
| - virtual void OnClientAttached() OVERRIDE {} |
| - virtual void OnClientDetached() OVERRIDE {} |
| - |
| bool has_worker_id_; |
| WorkerId worker_id_; |
| std::string state_; |
| - |
| - DISALLOW_COPY_AND_ASSIGN(WorkerDevToolsAgentHost); |
| -}; |
| - |
| - |
| -class WorkerDevToolsManager::DetachedClientHosts { |
| - public: |
| - static void WorkerReloaded(WorkerId old_id, WorkerId new_id) { |
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| - AgentHosts::iterator it = g_orphan_map.Get().find(old_id); |
| - if (it != g_orphan_map.Get().end()) { |
| - it->second->SetWorkerId(new_id, true); |
| - g_orphan_map.Get().erase(old_id); |
| - return; |
| - } |
| - RemovePendingWorkerData(old_id); |
| - } |
| - |
| - static void WorkerDestroyed(WorkerId id) { |
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| - AgentHosts::iterator it = g_agent_map.Get().find(id); |
| - if (it == g_agent_map.Get().end()) { |
| - RemovePendingWorkerData(id); |
| - return; |
| - } |
| - |
| - WorkerDevToolsAgentHost* agent = it->second; |
| - DevToolsManagerImpl* devtools_manager = DevToolsManagerImpl::GetInstance(); |
| - if (!agent->IsAttached()) { |
| - // Agent has no client hosts -> delete it. |
| - RemovePendingWorkerData(id); |
| - return; |
| - } |
| - |
| - // Client host is debugging this worker agent host. |
| - std::string notification = DevToolsProtocol::CreateNotification( |
| - devtools::Worker::disconnectedFromWorker::kName, NULL)->Serialize(); |
| - devtools_manager->DispatchOnInspectorFrontend(agent, notification); |
| - g_orphan_map.Get()[id] = agent; |
| - agent->ResetWorkerId(); |
| - } |
| - |
| - static void RemovePendingWorkerData(WorkerId id) { |
| - BrowserThread::PostTask( |
| - BrowserThread::IO, FROM_HERE, |
| - base::Bind(&RemoveInspectedWorkerDataOnIOThread, id)); |
| - } |
| - |
| - private: |
| - DetachedClientHosts() {} |
| - ~DetachedClientHosts() {} |
| - |
| - static void RemoveInspectedWorkerDataOnIOThread(WorkerId id) { |
| - WorkerDevToolsManager::GetInstance()->RemoveInspectedWorkerData(id); |
| - } |
| + DISALLOW_COPY_AND_ASSIGN(SharedWorkerDevToolsAgentHost); |
| }; |
| -struct WorkerDevToolsManager::InspectedWorker { |
| - InspectedWorker(WorkerProcessHost* host, int route_id, const GURL& url, |
| - const base::string16& name) |
| - : host(host), |
| - route_id(route_id), |
| - worker_url(url), |
| - worker_name(name) {} |
| - WorkerProcessHost* const host; |
| - int const route_id; |
| +struct SharedWorkerDevToolsManager::WorkerInfo { |
| + WorkerInfo(WorkerId id, const GURL& url, const base::string16& name) |
| + : worker_id(id), worker_url(url), worker_name(name) {} |
| + WorkerId worker_id; |
| GURL worker_url; |
| base::string16 worker_name; |
| }; |
| // static |
| -WorkerDevToolsManager* WorkerDevToolsManager::GetInstance() { |
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| - return Singleton<WorkerDevToolsManager>::get(); |
| +SharedWorkerDevToolsManager* SharedWorkerDevToolsManager::GetInstance() { |
| + DCHECK(WorkerService::EmbeddedSharedWorkerEnabled()); |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + return Singleton<SharedWorkerDevToolsManager>::get(); |
| } |
| // static |
| -DevToolsAgentHost* WorkerDevToolsManager::GetDevToolsAgentHostForWorker( |
| +DevToolsAgentHost* SharedWorkerDevToolsManager::GetDevToolsAgentHostForWorker( |
| int worker_process_id, |
| int worker_route_id) { |
| + DCHECK(WorkerService::EmbeddedSharedWorkerEnabled()); |
| WorkerId id(worker_process_id, worker_route_id); |
| AgentHosts::iterator it = g_agent_map.Get().find(id); |
| if (it == g_agent_map.Get().end()) |
| - return new WorkerDevToolsAgentHost(id); |
| + return new SharedWorkerDevToolsAgentHost(id); |
|
kinuko
2014/03/24 12:24:02
It looks we could return a new refptr without stor
horo
2014/03/25 06:28:17
It is OK.
When ConnectDevToolsAgentHostToWorker fa
|
| return it->second; |
| } |
| -WorkerDevToolsManager::WorkerDevToolsManager() { |
| -} |
| - |
| -WorkerDevToolsManager::~WorkerDevToolsManager() { |
| +// static |
| +bool SharedWorkerDevToolsManager::HasDevToolsAgentHostForWorker( |
| + int worker_process_id, |
| + int worker_route_id) { |
| + DCHECK(WorkerService::EmbeddedSharedWorkerEnabled()); |
| + WorkerId id(worker_process_id, worker_route_id); |
| + return g_agent_map.Get().find(id) != g_agent_map.Get().end(); |
| } |
| -void WorkerDevToolsManager::WorkerCreated( |
| - WorkerProcessHost* worker, |
| - const WorkerProcessHost::WorkerInstance& instance) { |
| - for (TerminatedInspectedWorkers::iterator it = terminated_workers_.begin(); |
| - it != terminated_workers_.end(); ++it) { |
| - if (instance.Matches(it->worker_url, it->worker_name, |
| - instance.partition(), |
| - instance.resource_context())) { |
| - worker->Send(new DevToolsAgentMsg_PauseWorkerContextOnStart( |
| - instance.worker_route_id())); |
| - WorkerId new_worker_id(worker->GetData().id, instance.worker_route_id()); |
| - paused_workers_[new_worker_id] = it->old_worker_id; |
| - terminated_workers_.erase(it); |
| - return; |
| +SharedWorkerDevToolsManager::SharedWorkerDevToolsManager() {} |
| + |
| +SharedWorkerDevToolsManager::~SharedWorkerDevToolsManager() {} |
| + |
| +void SharedWorkerDevToolsManager::WorkerCreated(int worker_process_id, |
| + int worker_route_id, |
| + const GURL& url, |
| + const base::string16& name) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + const WorkerId id(worker_process_id, worker_route_id); |
| + WorkerInfoMap::iterator it = FindTerminatedWorker(url, name); |
| + if (it != terminated_workers_.end()) { |
| + scoped_ptr<WorkerInfo> info = terminated_workers_.take_and_erase(it); |
| + WorkerId old_id = info->worker_id; |
| + AgentHosts::iterator orphan_agent_host_it = g_orphan_map.Get().find(old_id); |
| + if (orphan_agent_host_it != g_orphan_map.Get().end()) { |
| + g_agent_map.Get()[id] = orphan_agent_host_it->second; |
| } |
| + paused_workers_.set(id, info.Pass()); |
| + SendMessageToWorker( |
| + id, new DevToolsAgentMsg_PauseWorkerContextOnStart(worker_route_id)); |
| + } else { |
| + scoped_ptr<WorkerInfo> info(new WorkerInfo(id, url, name)); |
| + uninspected_workers_.set(id, info.Pass()); |
| } |
| } |
| -void WorkerDevToolsManager::WorkerDestroyed( |
| - WorkerProcessHost* worker, |
| - int worker_route_id) { |
| - InspectedWorkersList::iterator it = FindInspectedWorker( |
| - worker->GetData().id, |
| - worker_route_id); |
| +void SharedWorkerDevToolsManager::WorkerDestroyed(int worker_process_id, |
| + int worker_route_id) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + const WorkerId id(worker_process_id, worker_route_id); |
| + if (uninspected_workers_.erase(id)) |
| + return; |
| + WorkerInfoMap::iterator it = inspected_workers_.find(id); |
| if (it == inspected_workers_.end()) |
| return; |
| + scoped_ptr<WorkerInfo> info = inspected_workers_.take_and_erase(it); |
| + |
| + AgentHosts::iterator agent_host_it = g_agent_map.Get().find(id); |
| + if (agent_host_it == g_agent_map.Get().end()) |
| + return; |
| - WorkerId worker_id(worker->GetData().id, worker_route_id); |
| - terminated_workers_.push_back(TerminatedInspectedWorker( |
| - worker_id, |
| - it->worker_url, |
| - it->worker_name)); |
| - inspected_workers_.erase(it); |
| - BrowserThread::PostTask( |
| - BrowserThread::UI, FROM_HERE, |
| - base::Bind(&DetachedClientHosts::WorkerDestroyed, worker_id)); |
| + if (!agent_host_it->second->IsAttached()) { |
| + RemoveInspectedWorkerData(id); |
| + agent_host_it->second->ResetWorkerId(); |
| + return; |
| + } |
| + |
| + // Client host is debugging this worker agent host. |
| + std::string notification = |
| + DevToolsProtocol::CreateNotification( |
| + devtools::Worker::disconnectedFromWorker::kName, NULL)->Serialize(); |
| + DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend( |
| + agent_host_it->second, notification); |
| + terminated_workers_.set(id, info.Pass()); |
| + g_orphan_map.Get()[id] = agent_host_it->second; |
| + agent_host_it->second->ResetWorkerId(); |
| } |
| -void WorkerDevToolsManager::WorkerContextStarted(WorkerProcessHost* process, |
| - int worker_route_id) { |
| - WorkerId new_worker_id(process->GetData().id, worker_route_id); |
| - PausedWorkers::iterator it = paused_workers_.find(new_worker_id); |
| +void SharedWorkerDevToolsManager::WorkerContextStarted(int worker_process_id, |
| + int worker_route_id) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + const WorkerId id(worker_process_id, worker_route_id); |
| + WorkerInfoMap::iterator it = paused_workers_.find(id); |
| if (it == paused_workers_.end()) |
| return; |
| + scoped_ptr<WorkerInfo> info = paused_workers_.take_and_erase(it); |
| + const WorkerId old_id(info->worker_id); |
| + info->worker_id = id; |
| + uninspected_workers_.set(id, info.Pass()); |
| - BrowserThread::PostTask( |
| - BrowserThread::UI, FROM_HERE, |
| - base::Bind( |
| - &DetachedClientHosts::WorkerReloaded, |
| - it->second, |
| - new_worker_id)); |
| - paused_workers_.erase(it); |
| + AgentHosts::iterator orphan_agent_host_it = g_orphan_map.Get().find(old_id); |
| + if (orphan_agent_host_it == g_orphan_map.Get().end()) |
| + return; |
| + orphan_agent_host_it->second->SetWorkerId(id, true); |
| + g_orphan_map.Get().erase(old_id); |
| + g_agent_map.Get().erase(old_id); |
| } |
| -void WorkerDevToolsManager::RemoveInspectedWorkerData( |
| - const WorkerId& id) { |
| - for (TerminatedInspectedWorkers::iterator it = terminated_workers_.begin(); |
| - it != terminated_workers_.end(); ++it) { |
| - if (it->old_worker_id == id) { |
| - terminated_workers_.erase(it); |
| - return; |
| - } |
| - } |
| +bool SharedWorkerDevToolsManager::ConnectDevToolsAgentHostToWorker( |
| + const WorkerId& worker_id) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + WorkerInfoMap::iterator it = uninspected_workers_.find(worker_id); |
| + if (it == uninspected_workers_.end()) |
| + return false; |
| + inspected_workers_.set(worker_id, uninspected_workers_.take_and_erase(it)); |
| + return true; |
| +} |
| - for (PausedWorkers::iterator it = paused_workers_.begin(); |
| - it != paused_workers_.end(); ++it) { |
| - if (it->second == id) { |
| - SendResumeToWorker(it->first); |
| +void SharedWorkerDevToolsManager::RemoveInspectedWorkerData( |
| + const WorkerId& worker_id) { |
| + if (terminated_workers_.erase(worker_id)) |
| + return; |
| + |
| + for (WorkerInfoMap::iterator it = paused_workers_.begin(); |
| + it != paused_workers_.end(); |
| + ++it) { |
| + if (it->second->worker_id == worker_id) { |
| + SendMessageToWorker( |
| + it->first, |
| + new DevToolsAgentMsg_ResumeWorkerContext(it->first.second)); |
| paused_workers_.erase(it); |
| return; |
| } |
| } |
| } |
| -WorkerDevToolsManager::InspectedWorkersList::iterator |
| -WorkerDevToolsManager::FindInspectedWorker( |
| - int host_id, int route_id) { |
| - InspectedWorkersList::iterator it = inspected_workers_.begin(); |
| - while (it != inspected_workers_.end()) { |
| - if (it->host->GetData().id == host_id && it->route_id == route_id) |
| +SharedWorkerDevToolsManager::WorkerInfoMap::iterator |
| +SharedWorkerDevToolsManager::FindTerminatedWorker(const GURL& url, |
| + const base::string16& name) { |
| + WorkerInfoMap::iterator it = terminated_workers_.begin(); |
| + for (; it != terminated_workers_.end(); ++it) { |
| + if (SharedWorkerInstance::UrlNameMatches(it->second->worker_url, |
| + it->second->worker_name, |
| + url, |
| + name)) { |
| break; |
| - ++it; |
| - } |
| - return it; |
| -} |
| - |
| -static WorkerProcessHost* FindWorkerProcess(int worker_process_id) { |
| - for (WorkerProcessHostIterator iter; !iter.Done(); ++iter) { |
| - if (iter.GetData().id == worker_process_id) |
| - return *iter; |
| - } |
| - return NULL; |
| -} |
| - |
| -void WorkerDevToolsManager::ConnectDevToolsAgentHostToWorker( |
| - int worker_process_id, |
| - int worker_route_id) { |
| - if (WorkerProcessHost* process = FindWorkerProcess(worker_process_id)) { |
| - const WorkerProcessHost::Instances& instances = process->instances(); |
| - for (WorkerProcessHost::Instances::const_iterator i = instances.begin(); |
| - i != instances.end(); ++i) { |
| - if (i->worker_route_id() == worker_route_id) { |
| - DCHECK(FindInspectedWorker(worker_process_id, worker_route_id) == |
| - inspected_workers_.end()); |
| - inspected_workers_.push_back( |
| - InspectedWorker(process, worker_route_id, i->url(), i->name())); |
| - return; |
| - } |
| } |
| } |
| - NotifyConnectionFailedOnIOThread(worker_process_id, worker_route_id); |
| -} |
| - |
| -void WorkerDevToolsManager::ForwardToDevToolsClient( |
| - int worker_process_id, |
| - int worker_route_id, |
| - const std::string& message) { |
| - if (FindInspectedWorker(worker_process_id, worker_route_id) == |
| - inspected_workers_.end()) { |
| - NOTREACHED(); |
| - return; |
| - } |
| - BrowserThread::PostTask( |
| - BrowserThread::UI, FROM_HERE, |
| - base::Bind( |
| - &ForwardToDevToolsClientOnUIThread, |
| - worker_process_id, |
| - worker_route_id, |
| - message)); |
| -} |
| - |
| -void WorkerDevToolsManager::SaveAgentRuntimeState(int worker_process_id, |
| - int worker_route_id, |
| - const std::string& state) { |
| - BrowserThread::PostTask( |
| - BrowserThread::UI, FROM_HERE, |
| - base::Bind( |
| - &SaveAgentRuntimeStateOnUIThread, |
| - worker_process_id, |
| - worker_route_id, |
| - state)); |
| -} |
| - |
| -void WorkerDevToolsManager::ForwardToWorkerDevToolsAgent( |
| - int worker_process_id, |
| - int worker_route_id, |
| - const IPC::Message& message) { |
| - InspectedWorkersList::iterator it = FindInspectedWorker( |
| - worker_process_id, |
| - worker_route_id); |
| - if (it == inspected_workers_.end()) |
| - return; |
| - IPC::Message* msg = new IPC::Message(message); |
| - msg->set_routing_id(worker_route_id); |
| - it->host->Send(msg); |
| -} |
| - |
| -// static |
| -void WorkerDevToolsManager::ForwardToDevToolsClientOnUIThread( |
| - int worker_process_id, |
| - int worker_route_id, |
| - const std::string& message) { |
| - AgentHosts::iterator it = g_agent_map.Get().find(WorkerId(worker_process_id, |
| - worker_route_id)); |
| - if (it == g_agent_map.Get().end()) |
| - return; |
| - DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend(it->second, |
| - message); |
| -} |
| - |
| -// static |
| -void WorkerDevToolsManager::SaveAgentRuntimeStateOnUIThread( |
| - int worker_process_id, |
| - int worker_route_id, |
| - const std::string& state) { |
| - AgentHosts::iterator it = g_agent_map.Get().find(WorkerId(worker_process_id, |
| - worker_route_id)); |
| - if (it == g_agent_map.Get().end()) |
| - return; |
| - it->second->SaveAgentRuntimeState(state); |
| -} |
| - |
| -// static |
| -void WorkerDevToolsManager::NotifyConnectionFailedOnIOThread( |
| - int worker_process_id, |
| - int worker_route_id) { |
| - BrowserThread::PostTask( |
| - BrowserThread::UI, FROM_HERE, |
| - base::Bind( |
| - &WorkerDevToolsManager::NotifyConnectionFailedOnUIThread, |
| - worker_process_id, |
| - worker_route_id)); |
| -} |
| - |
| -// static |
| -void WorkerDevToolsManager::NotifyConnectionFailedOnUIThread( |
| - int worker_process_id, |
| - int worker_route_id) { |
| - AgentHosts::iterator it = g_agent_map.Get().find(WorkerId(worker_process_id, |
| - worker_route_id)); |
| - if (it != g_agent_map.Get().end()) |
| - it->second->ConnectionFailed(); |
| -} |
| - |
| -// static |
| -void WorkerDevToolsManager::SendResumeToWorker(const WorkerId& id) { |
| - if (WorkerProcessHost* process = FindWorkerProcess(id.first)) |
| - process->Send(new DevToolsAgentMsg_ResumeWorkerContext(id.second)); |
| -} |
| - |
| -WorkerDevToolsManager::WorkerDevToolsAgentHost::~WorkerDevToolsAgentHost() { |
| - DetachedClientHosts::RemovePendingWorkerData(worker_id_); |
| - g_agent_map.Get().erase(worker_id_); |
| - g_orphan_map.Get().erase(worker_id_); |
| + return it; |
| } |
| } // namespace content |