[Ozone-Gbm] Explicitly crash if trying software rendering on GBM
[chromium-blink-merge.git] / content / browser / devtools / service_worker_devtools_agent_host.cc
blob777b438ad988e65558b86fb085ec480dd267a0dc
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.
5 #include "content/browser/devtools/service_worker_devtools_agent_host.h"
7 #include "base/strings/stringprintf.h"
8 #include "content/browser/devtools/service_worker_devtools_manager.h"
9 #include "content/browser/service_worker/service_worker_context_core.h"
10 #include "content/browser/service_worker/service_worker_version.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/render_process_host.h"
14 namespace content {
16 namespace {
18 void StatusNoOp(ServiceWorkerStatusCode status) {}
20 void TerminateServiceWorkerOnIO(
21 base::WeakPtr<ServiceWorkerContextCore> context_weak,
22 int64 version_id) {
23 if (ServiceWorkerContextCore* context = context_weak.get()) {
24 if (ServiceWorkerVersion* version = context->GetLiveVersion(version_id))
25 version->StopWorker(base::Bind(&StatusNoOp));
29 void SetDevToolsAttachedOnIO(
30 base::WeakPtr<ServiceWorkerContextCore> context_weak,
31 int64 version_id,
32 bool attached) {
33 if (ServiceWorkerContextCore* context = context_weak.get()) {
34 if (ServiceWorkerVersion* version = context->GetLiveVersion(version_id))
35 version->SetDevToolsAttached(attached);
39 } // namespace
41 ServiceWorkerDevToolsAgentHost::ServiceWorkerDevToolsAgentHost(
42 WorkerId worker_id,
43 const ServiceWorkerIdentifier& service_worker,
44 bool debug_service_worker_on_start)
45 : WorkerDevToolsAgentHost(worker_id),
46 service_worker_(new ServiceWorkerIdentifier(service_worker)) {
47 if (debug_service_worker_on_start)
48 set_state(WORKER_PAUSED_FOR_DEBUG_ON_START);
51 DevToolsAgentHost::Type ServiceWorkerDevToolsAgentHost::GetType() {
52 return TYPE_SERVICE_WORKER;
55 std::string ServiceWorkerDevToolsAgentHost::GetTitle() {
56 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id().first)) {
57 return base::StringPrintf("Worker pid:%d",
58 base::GetProcId(host->GetHandle()));
60 return "";
63 GURL ServiceWorkerDevToolsAgentHost::GetURL() {
64 return service_worker_->url();
67 bool ServiceWorkerDevToolsAgentHost::Activate() {
68 return false;
71 bool ServiceWorkerDevToolsAgentHost::Close() {
72 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
73 base::Bind(&TerminateServiceWorkerOnIO,
74 service_worker_->context_weak(),
75 service_worker_->version_id()));
76 return true;
79 void ServiceWorkerDevToolsAgentHost::OnClientAttached() {
80 WorkerDevToolsAgentHost::OnClientAttached();
81 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
82 base::Bind(&SetDevToolsAttachedOnIO,
83 service_worker_->context_weak(),
84 service_worker_->version_id(),
85 true));
88 void ServiceWorkerDevToolsAgentHost::OnClientDetached() {
89 WorkerDevToolsAgentHost::OnClientDetached();
90 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
91 base::Bind(&SetDevToolsAttachedOnIO,
92 service_worker_->context_weak(),
93 service_worker_->version_id(),
94 false));
97 bool ServiceWorkerDevToolsAgentHost::Matches(
98 const ServiceWorkerIdentifier& other) {
99 return service_worker_->Matches(other);
102 ServiceWorkerDevToolsAgentHost::~ServiceWorkerDevToolsAgentHost() {
103 ServiceWorkerDevToolsManager::GetInstance()->RemoveInspectedWorkerData(
104 worker_id());
107 } // namespace content