OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/devtools/service_worker_devtools_agent_host.h" |
| 6 |
| 7 #include "base/strings/stringprintf.h" |
| 8 #include "content/browser/service_worker/service_worker_context_core.h" |
| 9 #include "content/browser/service_worker/service_worker_version.h" |
| 10 #include "content/public/browser/browser_thread.h" |
| 11 #include "content/public/browser/render_process_host.h" |
| 12 |
| 13 namespace content { |
| 14 |
| 15 namespace { |
| 16 |
| 17 void StatusNoOp(ServiceWorkerStatusCode status) {} |
| 18 |
| 19 void TerminateServiceWorkerOnIO( |
| 20 base::WeakPtr<ServiceWorkerContextCore> context_weak, |
| 21 int64 version_id) { |
| 22 if (ServiceWorkerContextCore* context = context_weak.get()) { |
| 23 if (ServiceWorkerVersion* version = context->GetLiveVersion(version_id)) |
| 24 version->StopWorker(base::Bind(&StatusNoOp)); |
| 25 } |
| 26 } |
| 27 |
| 28 void SetDevToolsAttachedOnIO( |
| 29 base::WeakPtr<ServiceWorkerContextCore> context_weak, |
| 30 int64 version_id, |
| 31 bool attached) { |
| 32 if (ServiceWorkerContextCore* context = context_weak.get()) { |
| 33 if (ServiceWorkerVersion* version = context->GetLiveVersion(version_id)) |
| 34 version->SetDevToolsAttached(attached); |
| 35 } |
| 36 } |
| 37 |
| 38 } // namespace |
| 39 |
| 40 ServiceWorkerDevToolsAgentHost::ServiceWorkerDevToolsAgentHost( |
| 41 WorkerId worker_id, |
| 42 const ServiceWorkerIdentifier& service_worker, |
| 43 bool debug_service_worker_on_start) |
| 44 : EmbeddedWorkerDevToolsAgentHost(worker_id), |
| 45 service_worker_(new ServiceWorkerIdentifier(service_worker)) { |
| 46 if (debug_service_worker_on_start) |
| 47 set_state(WORKER_PAUSED_FOR_DEBUG_ON_START); |
| 48 } |
| 49 |
| 50 DevToolsAgentHost::Type ServiceWorkerDevToolsAgentHost::GetType() { |
| 51 return TYPE_SERVICE_WORKER; |
| 52 } |
| 53 |
| 54 std::string ServiceWorkerDevToolsAgentHost::GetTitle() { |
| 55 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id().first)) { |
| 56 return base::StringPrintf("Worker pid:%d", |
| 57 base::GetProcId(host->GetHandle())); |
| 58 } |
| 59 return ""; |
| 60 } |
| 61 |
| 62 GURL ServiceWorkerDevToolsAgentHost::GetURL() { |
| 63 return service_worker_->url(); |
| 64 } |
| 65 |
| 66 bool ServiceWorkerDevToolsAgentHost::Activate() { |
| 67 return false; |
| 68 } |
| 69 |
| 70 bool ServiceWorkerDevToolsAgentHost::Close() { |
| 71 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 72 base::Bind(&TerminateServiceWorkerOnIO, |
| 73 service_worker_->context_weak(), |
| 74 service_worker_->version_id())); |
| 75 return true; |
| 76 } |
| 77 |
| 78 void ServiceWorkerDevToolsAgentHost::OnClientAttached() { |
| 79 EmbeddedWorkerDevToolsAgentHost::OnClientAttached(); |
| 80 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 81 base::Bind(&SetDevToolsAttachedOnIO, |
| 82 service_worker_->context_weak(), |
| 83 service_worker_->version_id(), |
| 84 true)); |
| 85 } |
| 86 |
| 87 void ServiceWorkerDevToolsAgentHost::OnClientDetached() { |
| 88 EmbeddedWorkerDevToolsAgentHost::OnClientDetached(); |
| 89 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 90 base::Bind(&SetDevToolsAttachedOnIO, |
| 91 service_worker_->context_weak(), |
| 92 service_worker_->version_id(), |
| 93 false)); |
| 94 } |
| 95 |
| 96 bool ServiceWorkerDevToolsAgentHost::Matches( |
| 97 const ServiceWorkerIdentifier& other) { |
| 98 return service_worker_->Matches(other); |
| 99 } |
| 100 |
| 101 ServiceWorkerDevToolsAgentHost::~ServiceWorkerDevToolsAgentHost() { |
| 102 } |
| 103 |
| 104 } // namespace content |
OLD | NEW |