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" | |
|
falken
2016/09/30 01:48:55
Is this used? Can it just be embedded_worker_statu
lazyboy
2016/09/30 08:02:15
Thanks.
Done.
| |
| 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 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 370 void ServiceWorkerContextWrapper::DidFinishNavigationHintTaskOnUI( | 371 void ServiceWorkerContextWrapper::DidFinishNavigationHintTaskOnUI( |
| 371 int render_process_id, | 372 int render_process_id, |
| 372 const ResultCallback& callback, | 373 const ResultCallback& callback, |
| 373 bool result) { | 374 bool result) { |
| 374 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 375 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 375 if (!--navigation_hint_task_count_per_process_[render_process_id]) | 376 if (!--navigation_hint_task_count_per_process_[render_process_id]) |
| 376 navigation_hint_task_count_per_process_.erase(render_process_id); | 377 navigation_hint_task_count_per_process_.erase(render_process_id); |
| 377 callback.Run(result); | 378 callback.Run(result); |
| 378 } | 379 } |
| 379 | 380 |
| 381 void ServiceWorkerContextWrapper::ExternalRequestErrorCallback( | |
| 382 int64_t service_worker_version_id, | |
| 383 ServiceWorkerStatusCode status) { | |
| 384 if (status != SERVICE_WORKER_OK) | |
| 385 pending_external_requests_[service_worker_version_id].pop(); | |
|
falken
2016/09/30 01:48:55
Hmm... it might be slightly safer to bind the requ
lazyboy
2016/09/30 08:02:15
It won't be possible to do this without changing S
| |
| 386 } | |
| 387 | |
| 380 bool ServiceWorkerContextWrapper::IsRunningNavigationHintTask( | 388 bool ServiceWorkerContextWrapper::IsRunningNavigationHintTask( |
| 381 int render_process_id) const { | 389 int render_process_id) const { |
| 382 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 390 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 383 return base::ContainsKey(navigation_hint_task_count_per_process_, | 391 return base::ContainsKey(navigation_hint_task_count_per_process_, |
| 384 render_process_id); | 392 render_process_id); |
| 385 } | 393 } |
| 386 | 394 |
| 387 void ServiceWorkerContextWrapper::StartServiceWorker( | 395 void ServiceWorkerContextWrapper::StartServiceWorker( |
| 388 const GURL& pattern, | 396 const GURL& pattern, |
| 389 const StatusCallback& callback) { | 397 const StatusCallback& callback) { |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 818 user_data_directory, std::move(database_task_manager), disk_cache_thread, | 826 user_data_directory, std::move(database_task_manager), disk_cache_thread, |
| 819 quota_manager_proxy, special_storage_policy, observer_list_.get(), this)); | 827 quota_manager_proxy, special_storage_policy, observer_list_.get(), this)); |
| 820 } | 828 } |
| 821 | 829 |
| 822 void ServiceWorkerContextWrapper::ShutdownOnIO() { | 830 void ServiceWorkerContextWrapper::ShutdownOnIO() { |
| 823 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 831 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 824 resource_context_ = nullptr; | 832 resource_context_ = nullptr; |
| 825 context_core_.reset(); | 833 context_core_.reset(); |
| 826 } | 834 } |
| 827 | 835 |
| 836 bool ServiceWorkerContextWrapper::IncrementPendingActivity( | |
| 837 int64_t service_worker_version_id) { | |
| 838 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 839 ServiceWorkerVersion* version = | |
| 840 context()->GetLiveVersion(service_worker_version_id); | |
| 841 if (!version) { | |
| 842 DVLOG(1) << "ServiceWorkerVersion not found: " << service_worker_version_id; | |
| 843 return false; | |
|
falken
2016/09/30 01:48:55
Sorry I didn't suggest this sooner. Consider havin
lazyboy
2016/09/30 08:02:15
Done.
| |
| 844 } | |
| 845 if (version->running_status() != EmbeddedWorkerStatus::RUNNING) { | |
| 846 DVLOG(1) << "ServiceWorkerVersion is not running: " | |
| 847 << service_worker_version_id; | |
| 848 return false; | |
| 849 } | |
| 850 int request_id = version->StartRequest( | |
| 851 ServiceWorkerMetrics::EventType::EXTERNAL_REQUEST, | |
| 852 base::Bind(&ServiceWorkerContextWrapper::ExternalRequestErrorCallback, | |
| 853 this, service_worker_version_id)); | |
| 854 pending_external_requests_[service_worker_version_id].push(request_id); | |
| 855 return true; | |
| 856 } | |
| 857 | |
| 858 bool ServiceWorkerContextWrapper::DecrementPendingActivity( | |
| 859 int64_t service_worker_version_id) { | |
| 860 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 861 ServiceWorkerVersion* version = | |
| 862 context()->GetLiveVersion(service_worker_version_id); | |
| 863 | |
| 864 std::queue<int>& pending_requests = | |
| 865 pending_external_requests_[service_worker_version_id]; | |
| 866 DCHECK(pending_requests.size() > 0); | |
|
falken
2016/09/30 01:48:55
Now that requests can be removed by the error call
lazyboy
2016/09/30 08:02:15
Slightly modified code now, but done.
| |
| 867 int request_id = pending_requests.front(); | |
| 868 pending_requests.pop(); | |
| 869 | |
| 870 // The service worker should be present and running. | |
| 871 if (!version || version->running_status() != EmbeddedWorkerStatus::RUNNING) { | |
| 872 NOTREACHED() | |
| 873 << "Failed to decrement pending activity of ServiceWorkerVersion: " | |
| 874 << service_worker_version_id; | |
| 875 return false; | |
| 876 } | |
| 877 return version->FinishRequest(request_id, true, base::Time::Now()); | |
| 878 } | |
| 879 | |
| 828 void ServiceWorkerContextWrapper::DidDeleteAndStartOver( | 880 void ServiceWorkerContextWrapper::DidDeleteAndStartOver( |
| 829 ServiceWorkerStatusCode status) { | 881 ServiceWorkerStatusCode status) { |
| 830 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 882 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 831 if (status != SERVICE_WORKER_OK) { | 883 if (status != SERVICE_WORKER_OK) { |
| 832 context_core_.reset(); | 884 context_core_.reset(); |
| 833 return; | 885 return; |
| 834 } | 886 } |
| 835 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); | 887 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); |
| 836 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; | 888 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; |
| 837 | 889 |
| 838 observer_list_->Notify(FROM_HERE, | 890 observer_list_->Notify(FROM_HERE, |
| 839 &ServiceWorkerContextObserver::OnStorageWiped); | 891 &ServiceWorkerContextObserver::OnStorageWiped); |
| 840 } | 892 } |
| 841 | 893 |
| 842 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { | 894 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { |
| 843 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 895 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 844 return context_core_.get(); | 896 return context_core_.get(); |
| 845 } | 897 } |
| 846 | 898 |
| 847 } // namespace content | 899 } // namespace content |
| OLD | NEW |