Chromium Code Reviews| 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/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/lazy_instance.h" | 16 #include "base/lazy_instance.h" |
| 17 #include "base/location.h" | 17 #include "base/location.h" |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "base/profiler/scoped_tracker.h" | 19 #include "base/profiler/scoped_tracker.h" |
| 20 #include "base/single_thread_task_runner.h" | 20 #include "base/single_thread_task_runner.h" |
| 21 #include "base/stl_util.h" | 21 #include "base/stl_util.h" |
| 22 #include "base/threading/sequenced_worker_pool.h" | 22 #include "base/threading/sequenced_worker_pool.h" |
| 23 #include "base/threading/thread_task_runner_handle.h" | 23 #include "base/threading/thread_task_runner_handle.h" |
| 24 #include "content/browser/renderer_host/render_process_host_impl.h" | 24 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 25 #include "content/browser/service_worker/embedded_worker_registry.h" | |
| 25 #include "content/browser/service_worker/service_worker_context_core.h" | 26 #include "content/browser/service_worker/service_worker_context_core.h" |
| 26 #include "content/browser/service_worker/service_worker_context_observer.h" | 27 #include "content/browser/service_worker/service_worker_context_observer.h" |
| 27 #include "content/browser/service_worker/service_worker_process_manager.h" | 28 #include "content/browser/service_worker/service_worker_process_manager.h" |
| 28 #include "content/browser/service_worker/service_worker_quota_client.h" | 29 #include "content/browser/service_worker/service_worker_quota_client.h" |
| 29 #include "content/browser/service_worker/service_worker_version.h" | 30 #include "content/browser/service_worker/service_worker_version.h" |
| 30 #include "content/browser/storage_partition_impl.h" | 31 #include "content/browser/storage_partition_impl.h" |
| 31 #include "content/common/service_worker/service_worker_utils.h" | 32 #include "content/common/service_worker/service_worker_utils.h" |
| 32 #include "content/public/browser/browser_context.h" | 33 #include "content/public/browser/browser_context.h" |
| 33 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
| 34 #include "content/public/browser/render_process_host.h" | 35 #include "content/public/browser/render_process_host.h" |
| (...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 818 user_data_directory, std::move(database_task_manager), disk_cache_thread, | 819 user_data_directory, std::move(database_task_manager), disk_cache_thread, |
| 819 quota_manager_proxy, special_storage_policy, observer_list_.get(), this)); | 820 quota_manager_proxy, special_storage_policy, observer_list_.get(), this)); |
| 820 } | 821 } |
| 821 | 822 |
| 822 void ServiceWorkerContextWrapper::ShutdownOnIO() { | 823 void ServiceWorkerContextWrapper::ShutdownOnIO() { |
| 823 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 824 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 824 resource_context_ = nullptr; | 825 resource_context_ = nullptr; |
| 825 context_core_.reset(); | 826 context_core_.reset(); |
| 826 } | 827 } |
| 827 | 828 |
| 829 bool ServiceWorkerContextWrapper::IncrementPendingActivity( | |
| 830 int64_t service_worker_version_id) { | |
| 831 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 832 ServiceWorkerVersion* version = | |
| 833 context()->GetLiveVersion(service_worker_version_id); | |
| 834 if (!version) { | |
| 835 DVLOG(1) << "ServiceWorkerVersion not found: " << service_worker_version_id; | |
| 836 return false; | |
| 837 } | |
| 838 if (version->running_status() != EmbeddedWorkerStatus::RUNNING) { | |
| 839 DVLOG(1) << "ServiceWorkerVersion is not running: " | |
| 840 << service_worker_version_id; | |
| 841 return false; | |
| 842 } | |
| 843 int request_id = version->StartRequest( | |
| 844 ServiceWorkerMetrics::EventType::EXTERNAL_REQUEST, | |
| 845 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | |
|
falken
2016/09/29 14:52:24
Are you sure you don't need to use the error callb
lazyboy
2016/09/29 18:07:19
(I was thinking that since the worker is running,
| |
| 846 pending_external_requests_[service_worker_version_id].insert(request_id); | |
| 847 return true; | |
| 848 } | |
| 849 | |
| 850 bool ServiceWorkerContextWrapper::DecrementPendingActivity( | |
| 851 int64_t service_worker_version_id) { | |
| 852 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 853 ServiceWorkerVersion* version = | |
| 854 context()->GetLiveVersion(service_worker_version_id); | |
| 855 | |
| 856 std::set<int>& pending_requests = | |
| 857 pending_external_requests_[service_worker_version_id]; | |
| 858 DCHECK(pending_requests.size() > 0); | |
| 859 int request_id = *pending_requests.begin(); | |
|
falken
2016/09/29 14:52:24
It seems like pending_requests should just be a qu
lazyboy
2016/09/29 18:07:19
Done.
It looks
| |
| 860 pending_requests.erase(request_id); | |
| 861 | |
| 862 // The service worker should be present and running. | |
| 863 if (!version || version->running_status() != EmbeddedWorkerStatus::RUNNING) { | |
| 864 NOTREACHED() | |
| 865 << "Failed to decrement pending activity of ServiceWorkerVersion: " | |
| 866 << service_worker_version_id; | |
| 867 return false; | |
| 868 } | |
| 869 return version->FinishRequest(request_id, true, base::Time::Now()); | |
| 870 } | |
| 871 | |
| 828 void ServiceWorkerContextWrapper::DidDeleteAndStartOver( | 872 void ServiceWorkerContextWrapper::DidDeleteAndStartOver( |
| 829 ServiceWorkerStatusCode status) { | 873 ServiceWorkerStatusCode status) { |
| 830 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 874 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 831 if (status != SERVICE_WORKER_OK) { | 875 if (status != SERVICE_WORKER_OK) { |
| 832 context_core_.reset(); | 876 context_core_.reset(); |
| 833 return; | 877 return; |
| 834 } | 878 } |
| 835 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); | 879 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); |
| 836 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; | 880 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; |
| 837 | 881 |
| 838 observer_list_->Notify(FROM_HERE, | 882 observer_list_->Notify(FROM_HERE, |
| 839 &ServiceWorkerContextObserver::OnStorageWiped); | 883 &ServiceWorkerContextObserver::OnStorageWiped); |
| 840 } | 884 } |
| 841 | 885 |
| 842 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { | 886 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { |
| 843 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 887 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 844 return context_core_.get(); | 888 return context_core_.get(); |
| 845 } | 889 } |
| 846 | 890 |
| 847 } // namespace content | 891 } // namespace content |
| OLD | NEW |