| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/devtools/service_worker_devtools_agent_host.h" | 5 #include "content/browser/devtools/service_worker_devtools_agent_host.h" |
| 6 | 6 |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "content/browser/devtools/service_worker_devtools_manager.h" | 8 #include "content/browser/devtools/service_worker_devtools_manager.h" |
| 9 #include "content/browser/service_worker/service_worker_context_core.h" | 9 #include "content/browser/service_worker/service_worker_context_core.h" |
| 10 #include "content/browser/service_worker/service_worker_version.h" | 10 #include "content/browser/service_worker/service_worker_version.h" |
| 11 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 12 #include "content/public/browser/render_process_host.h" | 12 #include "content/public/browser/render_process_host.h" |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 void StatusNoOp(ServiceWorkerStatusCode status) {} | 18 void StatusNoOp(ServiceWorkerStatusCode status) {} |
| 19 | 19 |
| 20 void TerminateServiceWorkerOnIO( | 20 void TerminateServiceWorkerOnIO( |
| 21 base::WeakPtr<ServiceWorkerContextCore> context_weak, | 21 base::WeakPtr<ServiceWorkerContextCore> context_weak, |
| 22 int64 version_id) { | 22 std::string version_uuid) { |
| 23 if (ServiceWorkerContextCore* context = context_weak.get()) { | 23 if (ServiceWorkerContextCore* context = context_weak.get()) { |
| 24 if (ServiceWorkerVersion* version = context->GetLiveVersion(version_id)) | 24 if (ServiceWorkerVersion* version = context->GetLiveVersion(version_uuid)) |
| 25 version->StopWorker(base::Bind(&StatusNoOp)); | 25 version->StopWorker(base::Bind(&StatusNoOp)); |
| 26 } | 26 } |
| 27 } | 27 } |
| 28 | 28 |
| 29 void UnregisterServiceWorkerOnIO( | 29 void UnregisterServiceWorkerOnIO( |
| 30 base::WeakPtr<ServiceWorkerContextCore> context_weak, | 30 base::WeakPtr<ServiceWorkerContextCore> context_weak, |
| 31 int64 version_id) { | 31 std::string version_uuid) { |
| 32 if (ServiceWorkerContextCore* context = context_weak.get()) { | 32 if (ServiceWorkerContextCore* context = context_weak.get()) { |
| 33 if (ServiceWorkerVersion* version = context->GetLiveVersion(version_id)) { | 33 if (ServiceWorkerVersion* version = context->GetLiveVersion(version_uuid)) { |
| 34 version->StopWorker(base::Bind(&StatusNoOp)); | 34 version->StopWorker(base::Bind(&StatusNoOp)); |
| 35 context->UnregisterServiceWorker( | 35 context->UnregisterServiceWorker( |
| 36 version->scope(), base::Bind(&StatusNoOp)); | 36 version->scope(), base::Bind(&StatusNoOp)); |
| 37 } | 37 } |
| 38 } | 38 } |
| 39 } | 39 } |
| 40 | 40 |
| 41 void SetDevToolsAttachedOnIO( | 41 void SetDevToolsAttachedOnIO( |
| 42 base::WeakPtr<ServiceWorkerContextCore> context_weak, | 42 base::WeakPtr<ServiceWorkerContextCore> context_weak, |
| 43 int64 version_id, | 43 std::string version_uuid, |
| 44 bool attached) { | 44 bool attached) { |
| 45 if (ServiceWorkerContextCore* context = context_weak.get()) { | 45 if (ServiceWorkerContextCore* context = context_weak.get()) { |
| 46 if (ServiceWorkerVersion* version = context->GetLiveVersion(version_id)) | 46 if (ServiceWorkerVersion* version = context->GetLiveVersion(version_uuid)) |
| 47 version->SetDevToolsAttached(attached); | 47 version->SetDevToolsAttached(attached); |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 | 50 |
| 51 } // namespace | 51 } // namespace |
| 52 | 52 |
| 53 ServiceWorkerDevToolsAgentHost::ServiceWorkerDevToolsAgentHost( | 53 ServiceWorkerDevToolsAgentHost::ServiceWorkerDevToolsAgentHost( |
| 54 WorkerId worker_id, | 54 WorkerId worker_id, |
| 55 const ServiceWorkerIdentifier& service_worker) | 55 const ServiceWorkerIdentifier& service_worker) |
| 56 : WorkerDevToolsAgentHost(worker_id), | 56 : WorkerDevToolsAgentHost(worker_id), |
| (...skipping 17 matching lines...) Expand all Loading... |
| 74 } | 74 } |
| 75 | 75 |
| 76 bool ServiceWorkerDevToolsAgentHost::Activate() { | 76 bool ServiceWorkerDevToolsAgentHost::Activate() { |
| 77 return false; | 77 return false; |
| 78 } | 78 } |
| 79 | 79 |
| 80 bool ServiceWorkerDevToolsAgentHost::Close() { | 80 bool ServiceWorkerDevToolsAgentHost::Close() { |
| 81 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 81 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 82 base::Bind(&TerminateServiceWorkerOnIO, | 82 base::Bind(&TerminateServiceWorkerOnIO, |
| 83 service_worker_->context_weak(), | 83 service_worker_->context_weak(), |
| 84 service_worker_->version_id())); | 84 service_worker_->version_uuid())); |
| 85 return true; | 85 return true; |
| 86 } | 86 } |
| 87 | 87 |
| 88 void ServiceWorkerDevToolsAgentHost::UnregisterWorker() { | 88 void ServiceWorkerDevToolsAgentHost::UnregisterWorker() { |
| 89 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 89 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 90 base::Bind(&UnregisterServiceWorkerOnIO, | 90 base::Bind(&UnregisterServiceWorkerOnIO, |
| 91 service_worker_->context_weak(), | 91 service_worker_->context_weak(), |
| 92 service_worker_->version_id())); | 92 service_worker_->version_uuid())); |
| 93 } | 93 } |
| 94 | 94 |
| 95 void ServiceWorkerDevToolsAgentHost::OnAttachedStateChanged(bool attached) { | 95 void ServiceWorkerDevToolsAgentHost::OnAttachedStateChanged(bool attached) { |
| 96 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 96 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 97 base::Bind(&SetDevToolsAttachedOnIO, | 97 base::Bind(&SetDevToolsAttachedOnIO, |
| 98 service_worker_->context_weak(), | 98 service_worker_->context_weak(), |
| 99 service_worker_->version_id(), | 99 service_worker_->version_uuid(), |
| 100 attached)); | 100 attached)); |
| 101 } | 101 } |
| 102 | 102 |
| 103 bool ServiceWorkerDevToolsAgentHost::Matches( | 103 bool ServiceWorkerDevToolsAgentHost::Matches( |
| 104 const ServiceWorkerIdentifier& other) { | 104 const ServiceWorkerIdentifier& other) { |
| 105 return service_worker_->Matches(other); | 105 return service_worker_->Matches(other); |
| 106 } | 106 } |
| 107 | 107 |
| 108 ServiceWorkerDevToolsAgentHost::~ServiceWorkerDevToolsAgentHost() { | 108 ServiceWorkerDevToolsAgentHost::~ServiceWorkerDevToolsAgentHost() { |
| 109 ServiceWorkerDevToolsManager::GetInstance()->RemoveInspectedWorkerData( | 109 ServiceWorkerDevToolsManager::GetInstance()->RemoveInspectedWorkerData( |
| 110 worker_id()); | 110 worker_id()); |
| 111 } | 111 } |
| 112 | 112 |
| 113 } // namespace content | 113 } // namespace content |
| OLD | NEW |