| Index: content/browser/devtools/service_worker_devtools_agent_host.cc
|
| diff --git a/content/browser/devtools/service_worker_devtools_agent_host.cc b/content/browser/devtools/service_worker_devtools_agent_host.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..26ed56c3abfe1cfa386116de6fbdaed9eb1d5328
|
| --- /dev/null
|
| +++ b/content/browser/devtools/service_worker_devtools_agent_host.cc
|
| @@ -0,0 +1,104 @@
|
| +// Copyright 2014 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/devtools/service_worker_devtools_agent_host.h"
|
| +
|
| +#include "base/strings/stringprintf.h"
|
| +#include "content/browser/service_worker/service_worker_context_core.h"
|
| +#include "content/browser/service_worker/service_worker_version.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| +#include "content/public/browser/render_process_host.h"
|
| +
|
| +namespace content {
|
| +
|
| +namespace {
|
| +
|
| +void StatusNoOp(ServiceWorkerStatusCode status) {}
|
| +
|
| +void TerminateServiceWorkerOnIO(
|
| + base::WeakPtr<ServiceWorkerContextCore> context_weak,
|
| + int64 version_id) {
|
| + if (ServiceWorkerContextCore* context = context_weak.get()) {
|
| + if (ServiceWorkerVersion* version = context->GetLiveVersion(version_id))
|
| + version->StopWorker(base::Bind(&StatusNoOp));
|
| + }
|
| +}
|
| +
|
| +void SetDevToolsAttachedOnIO(
|
| + base::WeakPtr<ServiceWorkerContextCore> context_weak,
|
| + int64 version_id,
|
| + bool attached) {
|
| + if (ServiceWorkerContextCore* context = context_weak.get()) {
|
| + if (ServiceWorkerVersion* version = context->GetLiveVersion(version_id))
|
| + version->SetDevToolsAttached(attached);
|
| + }
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +ServiceWorkerDevToolsAgentHost::ServiceWorkerDevToolsAgentHost(
|
| + WorkerId worker_id,
|
| + const ServiceWorkerIdentifier& service_worker,
|
| + bool debug_service_worker_on_start)
|
| + : EmbeddedWorkerDevToolsAgentHost(worker_id),
|
| + service_worker_(new ServiceWorkerIdentifier(service_worker)) {
|
| + if (debug_service_worker_on_start)
|
| + set_state(WORKER_PAUSED_FOR_DEBUG_ON_START);
|
| +}
|
| +
|
| +DevToolsAgentHost::Type ServiceWorkerDevToolsAgentHost::GetType() {
|
| + return TYPE_SERVICE_WORKER;
|
| +}
|
| +
|
| +std::string ServiceWorkerDevToolsAgentHost::GetTitle() {
|
| + if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id().first)) {
|
| + return base::StringPrintf("Worker pid:%d",
|
| + base::GetProcId(host->GetHandle()));
|
| + }
|
| + return "";
|
| +}
|
| +
|
| +GURL ServiceWorkerDevToolsAgentHost::GetURL() {
|
| + return service_worker_->url();
|
| +}
|
| +
|
| +bool ServiceWorkerDevToolsAgentHost::Activate() {
|
| + return false;
|
| +}
|
| +
|
| +bool ServiceWorkerDevToolsAgentHost::Close() {
|
| + BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
| + base::Bind(&TerminateServiceWorkerOnIO,
|
| + service_worker_->context_weak(),
|
| + service_worker_->version_id()));
|
| + return true;
|
| +}
|
| +
|
| +void ServiceWorkerDevToolsAgentHost::OnClientAttached() {
|
| + EmbeddedWorkerDevToolsAgentHost::OnClientAttached();
|
| + BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
| + base::Bind(&SetDevToolsAttachedOnIO,
|
| + service_worker_->context_weak(),
|
| + service_worker_->version_id(),
|
| + true));
|
| +}
|
| +
|
| +void ServiceWorkerDevToolsAgentHost::OnClientDetached() {
|
| + EmbeddedWorkerDevToolsAgentHost::OnClientDetached();
|
| + BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
| + base::Bind(&SetDevToolsAttachedOnIO,
|
| + service_worker_->context_weak(),
|
| + service_worker_->version_id(),
|
| + false));
|
| +}
|
| +
|
| +bool ServiceWorkerDevToolsAgentHost::Matches(
|
| + const ServiceWorkerIdentifier& other) {
|
| + return service_worker_->Matches(other);
|
| +}
|
| +
|
| +ServiceWorkerDevToolsAgentHost::~ServiceWorkerDevToolsAgentHost() {
|
| +}
|
| +
|
| +} // namespace content
|
|
|