| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/service_worker/service_worker_context_wrapper.h" | 5 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/barrier_closure.h" | 13 #include "base/barrier_closure.h" |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/bind_helpers.h" |
| 15 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
| 16 #include "base/lazy_instance.h" | 17 #include "base/lazy_instance.h" |
| 17 #include "base/location.h" | 18 #include "base/location.h" |
| 18 #include "base/logging.h" | 19 #include "base/logging.h" |
| 19 #include "base/profiler/scoped_tracker.h" | 20 #include "base/profiler/scoped_tracker.h" |
| 20 #include "base/single_thread_task_runner.h" | 21 #include "base/single_thread_task_runner.h" |
| 21 #include "base/stl_util.h" | 22 #include "base/stl_util.h" |
| 22 #include "base/threading/sequenced_worker_pool.h" | 23 #include "base/threading/sequenced_worker_pool.h" |
| 23 #include "base/threading/thread_task_runner_handle.h" | 24 #include "base/threading/thread_task_runner_handle.h" |
| 24 #include "content/browser/renderer_host/render_process_host_impl.h" | 25 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 25 #include "content/browser/service_worker/embedded_worker_status.h" | 26 #include "content/browser/service_worker/embedded_worker_status.h" |
| 26 #include "content/browser/service_worker/service_worker_context_core.h" | 27 #include "content/browser/service_worker/service_worker_context_core.h" |
| 27 #include "content/browser/service_worker/service_worker_context_observer.h" | 28 #include "content/browser/service_worker/service_worker_context_observer.h" |
| 28 #include "content/browser/service_worker/service_worker_process_manager.h" | 29 #include "content/browser/service_worker/service_worker_process_manager.h" |
| 29 #include "content/browser/service_worker/service_worker_quota_client.h" | 30 #include "content/browser/service_worker/service_worker_quota_client.h" |
| 30 #include "content/browser/service_worker/service_worker_version.h" | 31 #include "content/browser/service_worker/service_worker_version.h" |
| 31 #include "content/browser/storage_partition_impl.h" | 32 #include "content/browser/storage_partition_impl.h" |
| 32 #include "content/common/service_worker/service_worker_utils.h" | 33 #include "content/common/service_worker/service_worker_utils.h" |
| 33 #include "content/public/browser/browser_context.h" | 34 #include "content/public/browser/browser_context.h" |
| 34 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
| 35 #include "content/public/browser/render_process_host.h" | 36 #include "content/public/browser/render_process_host.h" |
| 37 #include "content/public/common/result_codes.h" |
| 36 #include "net/base/url_util.h" | 38 #include "net/base/url_util.h" |
| 37 #include "storage/browser/quota/quota_manager_proxy.h" | 39 #include "storage/browser/quota/quota_manager_proxy.h" |
| 38 #include "storage/browser/quota/special_storage_policy.h" | 40 #include "storage/browser/quota/special_storage_policy.h" |
| 39 #include "third_party/WebKit/public/platform/WebNavigationHintType.h" | 41 #include "third_party/WebKit/public/platform/WebNavigationHintType.h" |
| 40 | 42 |
| 41 namespace content { | 43 namespace content { |
| 42 | 44 |
| 43 namespace { | 45 namespace { |
| 44 | 46 |
| 45 typedef std::set<std::string> HeaderNameSet; | 47 typedef std::set<std::string> HeaderNameSet; |
| (...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 return; | 503 return; |
| 502 } | 504 } |
| 503 std::vector<ServiceWorkerVersionInfo> live_versions = GetAllLiveVersionInfo(); | 505 std::vector<ServiceWorkerVersionInfo> live_versions = GetAllLiveVersionInfo(); |
| 504 for (const ServiceWorkerVersionInfo& info : live_versions) { | 506 for (const ServiceWorkerVersionInfo& info : live_versions) { |
| 505 ServiceWorkerVersion* version = GetLiveVersion(info.version_id); | 507 ServiceWorkerVersion* version = GetLiveVersion(info.version_id); |
| 506 if (version && version->scope().GetOrigin() == origin) | 508 if (version && version->scope().GetOrigin() == origin) |
| 507 version->StopWorker(base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 509 version->StopWorker(base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
| 508 } | 510 } |
| 509 } | 511 } |
| 510 | 512 |
| 513 void ServiceWorkerContextWrapper::KillAllServiceWorkersForOrigin( |
| 514 const GURL& origin) { |
| 515 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 516 BrowserThread::PostTask( |
| 517 BrowserThread::IO, FROM_HERE, |
| 518 base::Bind(&ServiceWorkerContextWrapper::KillAllServiceWorkersForOrigin, |
| 519 this, origin)); |
| 520 return; |
| 521 } |
| 522 if (!context_core_.get()) { |
| 523 return; |
| 524 } |
| 525 std::vector<ServiceWorkerVersionInfo> live_versions = GetAllLiveVersionInfo(); |
| 526 for (const ServiceWorkerVersionInfo& info : live_versions) { |
| 527 ServiceWorkerVersion* version = GetLiveVersion(info.version_id); |
| 528 if (version && version->scope().GetOrigin() == origin) { |
| 529 for (const auto& client_pair : info.clients) { |
| 530 RenderProcessHost* render_process_host = |
| 531 RenderProcessHost::FromID(client_pair.second.process_id); |
| 532 if (render_process_host) |
| 533 render_process_host->Shutdown(RESULT_CODE_KILLED, true /* wait */); |
| 534 } |
| 535 } |
| 536 } |
| 537 } |
| 538 |
| 511 void ServiceWorkerContextWrapper::DidFindRegistrationForUpdate( | 539 void ServiceWorkerContextWrapper::DidFindRegistrationForUpdate( |
| 512 ServiceWorkerStatusCode status, | 540 ServiceWorkerStatusCode status, |
| 513 scoped_refptr<ServiceWorkerRegistration> registration) { | 541 scoped_refptr<ServiceWorkerRegistration> registration) { |
| 514 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 542 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 515 | 543 |
| 516 if (status != SERVICE_WORKER_OK) | 544 if (status != SERVICE_WORKER_OK) |
| 517 return; | 545 return; |
| 518 if (!context_core_) | 546 if (!context_core_) |
| 519 return; | 547 return; |
| 520 DCHECK(registration); | 548 DCHECK(registration); |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 908 observer_list_->Notify(FROM_HERE, | 936 observer_list_->Notify(FROM_HERE, |
| 909 &ServiceWorkerContextObserver::OnStorageWiped); | 937 &ServiceWorkerContextObserver::OnStorageWiped); |
| 910 } | 938 } |
| 911 | 939 |
| 912 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { | 940 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { |
| 913 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 941 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 914 return context_core_.get(); | 942 return context_core_.get(); |
| 915 } | 943 } |
| 916 | 944 |
| 917 } // namespace content | 945 } // namespace content |
| OLD | NEW |