| Index: content/browser/devtools/embedded_worker_devtools_manager.cc
|
| diff --git a/content/browser/devtools/embedded_worker_devtools_manager.cc b/content/browser/devtools/embedded_worker_devtools_manager.cc
|
| index 3ba61aafeea20e9b12ec8973ef32aa1e3f5cd7cb..36d1c84eb2bd16f12955cda20e86ca425801b847 100644
|
| --- a/content/browser/devtools/embedded_worker_devtools_manager.cc
|
| +++ b/content/browser/devtools/embedded_worker_devtools_manager.cc
|
| @@ -8,6 +8,8 @@
|
| #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/service_worker/service_worker_context_core.h"
|
| +#include "content/browser/service_worker/service_worker_version.h"
|
| #include "content/browser/shared_worker/shared_worker_instance.h"
|
| #include "content/common/devtools_messages.h"
|
| #include "content/public/browser/browser_thread.h"
|
| @@ -35,18 +37,25 @@ bool SendMessageToWorker(
|
| } // namespace
|
|
|
| EmbeddedWorkerDevToolsManager::ServiceWorkerIdentifier::ServiceWorkerIdentifier(
|
| - const ServiceWorkerContextCore* const service_worker_context,
|
| + const ServiceWorkerContextCore* service_worker_context,
|
| + base::WeakPtr<ServiceWorkerContextCore> service_worker_context_weak,
|
| int64 service_worker_version_id)
|
| : service_worker_context_(service_worker_context),
|
| + service_worker_context_weak_(service_worker_context_weak),
|
| service_worker_version_id_(service_worker_version_id) {
|
| }
|
|
|
| EmbeddedWorkerDevToolsManager::ServiceWorkerIdentifier::ServiceWorkerIdentifier(
|
| const ServiceWorkerIdentifier& other)
|
| : service_worker_context_(other.service_worker_context_),
|
| + service_worker_context_weak_(other.service_worker_context_weak_),
|
| service_worker_version_id_(other.service_worker_version_id_) {
|
| }
|
|
|
| +EmbeddedWorkerDevToolsManager::
|
| +ServiceWorkerIdentifier::~ServiceWorkerIdentifier() {
|
| +}
|
| +
|
| bool EmbeddedWorkerDevToolsManager::ServiceWorkerIdentifier::Matches(
|
| const ServiceWorkerIdentifier& other) const {
|
| return service_worker_context_ == other.service_worker_context_ &&
|
| @@ -88,13 +97,14 @@ class EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsAgentHost
|
| : public IPCDevToolsAgentHost,
|
| public IPC::Listener {
|
| public:
|
| - explicit EmbeddedWorkerDevToolsAgentHost(WorkerId worker_id)
|
| - : worker_id_(worker_id), worker_attached_(false) {
|
| - AttachToWorker();
|
| + EmbeddedWorkerDevToolsAgentHost(WorkerId worker_id, const GURL& url)
|
| + : worker_id_(worker_id), worker_attached_(false), url_(url) {
|
| + WorkerCreated();
|
| }
|
|
|
| // DevToolsAgentHost override.
|
| virtual bool IsWorker() const OVERRIDE { return true; }
|
| + virtual GURL GetURL() OVERRIDE { return url_; }
|
|
|
| // IPCDevToolsAgentHost implementation.
|
| virtual void SendMessageToAgent(IPC::Message* message) OVERRIDE {
|
| @@ -139,9 +149,16 @@ class EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsAgentHost
|
| worker_attached_ = false;
|
| if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first))
|
| host->RemoveRoute(worker_id_.second);
|
| + }
|
| +
|
| + void WorkerDestroyed() {
|
| Release();
|
| }
|
|
|
| + void WorkerCreated() {
|
| + AddRef();
|
| + }
|
| +
|
| WorkerId worker_id() const { return worker_id_; }
|
|
|
| private:
|
| @@ -162,13 +179,13 @@ class EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsAgentHost
|
| if (worker_attached_)
|
| return;
|
| worker_attached_ = true;
|
| - AddRef();
|
| if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first))
|
| host->AddRoute(worker_id_.second, this);
|
| }
|
|
|
| WorkerId worker_id_;
|
| bool worker_attached_;
|
| + GURL url_;
|
| std::string state_;
|
| DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerDevToolsAgentHost);
|
| };
|
| @@ -179,9 +196,17 @@ EmbeddedWorkerDevToolsManager* EmbeddedWorkerDevToolsManager::GetInstance() {
|
| return Singleton<EmbeddedWorkerDevToolsManager>::get();
|
| }
|
|
|
| -DevToolsAgentHost* EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForWorker(
|
| +DevToolsAgentHost*
|
| +EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForWorker(
|
| int worker_process_id,
|
| int worker_route_id) {
|
| + return GetOrCreateAgentHost(worker_process_id, worker_route_id, GURL());
|
| +}
|
| +
|
| +DevToolsAgentHost* EmbeddedWorkerDevToolsManager::GetOrCreateAgentHost(
|
| + int worker_process_id,
|
| + int worker_route_id,
|
| + const GURL& url) {
|
| WorkerId id(worker_process_id, worker_route_id);
|
|
|
| WorkerInfoMap::iterator it = workers_.find(id);
|
| @@ -195,7 +220,7 @@ DevToolsAgentHost* EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForWorker(
|
| }
|
|
|
| EmbeddedWorkerDevToolsAgentHost* agent_host =
|
| - new EmbeddedWorkerDevToolsAgentHost(id);
|
| + new EmbeddedWorkerDevToolsAgentHost(id, url);
|
| info->set_agent_host(agent_host);
|
| info->set_state(WORKER_INSPECTED);
|
| return agent_host;
|
| @@ -210,6 +235,63 @@ EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForServiceWorker(
|
| return GetDevToolsAgentHostForWorker(it->first.first, it->first.second);
|
| }
|
|
|
| +void EmbeddedWorkerDevToolsManager::GetOrCreateAllHosts(
|
| + const DevToolsAgentHost::ListCallback& callback) {
|
| + std::map<WorkerId, ServiceWorkerIdentifier> ids;
|
| + for (WorkerInfoMap::iterator it = workers_.begin();
|
| + it != workers_.end(); ++it) {
|
| + if (const ServiceWorkerIdentifier* worker_id =
|
| + it->second->service_worker_id()) {
|
| + ids.insert(std::make_pair(it->first, *worker_id));
|
| + }
|
| + }
|
| + BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
| + base::Bind(&EmbeddedWorkerDevToolsManager::GetServiceWorkerUrlsOnIO,
|
| + ids, callback));
|
| +}
|
| +
|
| +// static
|
| +void EmbeddedWorkerDevToolsManager::GetServiceWorkerUrlsOnIO(
|
| + const std::map<WorkerId, ServiceWorkerIdentifier>& ids,
|
| + const DevToolsAgentHost::ListCallback& callback) {
|
| + std::map<WorkerId, GURL> url_map;
|
| + for (std::map<WorkerId, ServiceWorkerIdentifier>::const_iterator it =
|
| + ids.begin(); it != ids.end(); ++it) {
|
| + if (ServiceWorkerContextCore* context =
|
| + it->second.service_worker_context_weak_.get()) {
|
| + if (ServiceWorkerVersion* version =
|
| + context->GetLiveVersion(it->second.service_worker_version_id_)) {
|
| + url_map[it->first] = version->script_url();
|
| + }
|
| + }
|
| + }
|
| + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
| + base::Bind(&EmbeddedWorkerDevToolsManager::CreateAgentHosts,
|
| + url_map, callback));
|
| +}
|
| +
|
| +// static
|
| +void EmbeddedWorkerDevToolsManager::CreateAgentHosts(
|
| + const std::map<WorkerId, GURL> url_map,
|
| + const DevToolsAgentHost::ListCallback& callback) {
|
| + DevToolsAgentHost::List agent_hosts;
|
| + EmbeddedWorkerDevToolsManager* instance = GetInstance();
|
| + for (WorkerInfoMap::iterator it = instance->workers_.begin();
|
| + it != instance->workers_.end(); ++it) {
|
| + if (it->second->service_worker_id()) {
|
| + std::map<WorkerId, GURL>::const_iterator url_it = url_map.find(it->first);
|
| + if (url_it != url_map.end()) {
|
| + agent_hosts.push_back(instance->GetOrCreateAgentHost(
|
| + it->first.first, it->first.second, url_it->second));
|
| + }
|
| + } else {
|
| + agent_hosts.push_back(instance->GetOrCreateAgentHost(
|
| + it->first.first, it->first.second, GURL()));
|
| + }
|
| + }
|
| + callback.Run(agent_hosts);
|
| +}
|
| +
|
| EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsManager()
|
| : debug_service_worker_on_start_(false) {
|
| }
|
| @@ -258,26 +340,24 @@ void EmbeddedWorkerDevToolsManager::WorkerDestroyed(int worker_process_id,
|
| WorkerInfoMap::iterator it = workers_.find(id);
|
| DCHECK(it != workers_.end());
|
| WorkerInfo* info = it->second;
|
| + EmbeddedWorkerDevToolsAgentHost* agent_host = info->agent_host();
|
| switch (info->state()) {
|
| case WORKER_UNINSPECTED:
|
| case WORKER_PAUSED_FOR_DEBUG_ON_START:
|
| workers_.erase(it);
|
| break;
|
| case WORKER_INSPECTED: {
|
| - EmbeddedWorkerDevToolsAgentHost* agent_host = info->agent_host();
|
| info->set_state(WORKER_TERMINATED);
|
| - if (!agent_host->IsAttached()) {
|
| + if (agent_host->IsAttached()) {
|
| + // Client host is debugging this worker agent host.
|
| + std::string notification =
|
| + DevToolsProtocol::CreateNotification(
|
| + devtools::Worker::disconnectedFromWorker::kName, NULL)
|
| + ->Serialize();
|
| + DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend(
|
| + agent_host, notification);
|
| agent_host->DetachFromWorker();
|
| - 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, notification);
|
| - agent_host->DetachFromWorker();
|
| break;
|
| }
|
| case WORKER_TERMINATED:
|
| @@ -291,6 +371,8 @@ void EmbeddedWorkerDevToolsManager::WorkerDestroyed(int worker_process_id,
|
| break;
|
| }
|
| }
|
| + if (agent_host)
|
| + agent_host->WorkerDestroyed();
|
| }
|
|
|
| void EmbeddedWorkerDevToolsManager::WorkerContextStarted(int worker_process_id,
|
| @@ -369,6 +451,8 @@ void EmbeddedWorkerDevToolsManager::MoveToPausedState(
|
| DCHECK_EQ(WORKER_TERMINATED, it->second->state());
|
| scoped_ptr<WorkerInfo> info = workers_.take_and_erase(it);
|
| info->set_state(WORKER_PAUSED_FOR_REATTACH);
|
| + if (EmbeddedWorkerDevToolsAgentHost* agent_host = info->agent_host())
|
| + agent_host->WorkerCreated();
|
| workers_.set(id, info.Pass());
|
| }
|
|
|
|
|