Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Side by Side Diff: content/browser/service_worker/service_worker_context_wrapper.cc

Issue 2166523003: Add ref count to service workers for extension API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sync@tott Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_status.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 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 573 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
573 base::Bind(callback, false)); 574 base::Bind(callback, false));
574 return; 575 return;
575 } 576 }
576 context()->CheckHasServiceWorker( 577 context()->CheckHasServiceWorker(
577 net::SimplifyUrlForRequest(url), net::SimplifyUrlForRequest(other_url), 578 net::SimplifyUrlForRequest(url), net::SimplifyUrlForRequest(other_url),
578 base::Bind(&ServiceWorkerContextWrapper::DidCheckHasServiceWorker, this, 579 base::Bind(&ServiceWorkerContextWrapper::DidCheckHasServiceWorker, this,
579 callback)); 580 callback));
580 } 581 }
581 582
583 void ServiceWorkerContextWrapper::CountExternalRequestsForTest(
584 const GURL& origin,
585 const CountExternalRequestsCallback& callback) {
586 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
587 BrowserThread::PostTask(
588 BrowserThread::IO, FROM_HERE,
589 base::Bind(&ServiceWorkerContextWrapper::CountExternalRequestsForTest,
590 this, origin, callback));
591 return;
592 }
593
594 std::vector<ServiceWorkerVersionInfo> live_version_info =
595 GetAllLiveVersionInfo();
596 size_t pending_external_request_count = 0;
597 for (const ServiceWorkerVersionInfo& info : live_version_info) {
598 ServiceWorkerVersion* version = GetLiveVersion(info.version_id);
599 if (version && version->scope().GetOrigin() == origin) {
600 pending_external_request_count =
601 version->GetExternalRequestCountForTest();
602 break;
603 }
604 }
605 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
606 base::Bind(callback, pending_external_request_count));
607 }
608
582 void ServiceWorkerContextWrapper::ClearAllServiceWorkersForTest( 609 void ServiceWorkerContextWrapper::ClearAllServiceWorkersForTest(
583 const base::Closure& callback) { 610 const base::Closure& callback) {
584 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { 611 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
585 BrowserThread::PostTask( 612 BrowserThread::PostTask(
586 BrowserThread::IO, FROM_HERE, 613 BrowserThread::IO, FROM_HERE,
587 base::Bind(&ServiceWorkerContextWrapper::ClearAllServiceWorkersForTest, 614 base::Bind(&ServiceWorkerContextWrapper::ClearAllServiceWorkersForTest,
588 this, callback)); 615 this, callback));
589 return; 616 return;
590 } 617 }
591 if (!context_core_) { 618 if (!context_core_) {
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 user_data_directory, std::move(database_task_manager), disk_cache_thread, 852 user_data_directory, std::move(database_task_manager), disk_cache_thread,
826 quota_manager_proxy, special_storage_policy, observer_list_.get(), this)); 853 quota_manager_proxy, special_storage_policy, observer_list_.get(), this));
827 } 854 }
828 855
829 void ServiceWorkerContextWrapper::ShutdownOnIO() { 856 void ServiceWorkerContextWrapper::ShutdownOnIO() {
830 DCHECK_CURRENTLY_ON(BrowserThread::IO); 857 DCHECK_CURRENTLY_ON(BrowserThread::IO);
831 resource_context_ = nullptr; 858 resource_context_ = nullptr;
832 context_core_.reset(); 859 context_core_.reset();
833 } 860 }
834 861
862 bool ServiceWorkerContextWrapper::StartingExternalRequest(
863 int64_t service_worker_version_id,
864 const std::string& request_uuid) {
865 DCHECK_CURRENTLY_ON(BrowserThread::IO);
866 ServiceWorkerVersion* version =
867 context()->GetLiveVersion(service_worker_version_id);
868 if (!version)
869 return false;
870 return version->StartExternalRequest(request_uuid);
871 }
872
873 bool ServiceWorkerContextWrapper::FinishedExternalRequest(
874 int64_t service_worker_version_id,
875 const std::string& request_uuid) {
876 DCHECK_CURRENTLY_ON(BrowserThread::IO);
877 ServiceWorkerVersion* version =
878 context()->GetLiveVersion(service_worker_version_id);
879 if (!version)
880 return false;
881 return version->FinishExternalRequest(request_uuid);
882 }
883
835 void ServiceWorkerContextWrapper::DidDeleteAndStartOver( 884 void ServiceWorkerContextWrapper::DidDeleteAndStartOver(
836 ServiceWorkerStatusCode status) { 885 ServiceWorkerStatusCode status) {
837 DCHECK_CURRENTLY_ON(BrowserThread::IO); 886 DCHECK_CURRENTLY_ON(BrowserThread::IO);
838 if (status != SERVICE_WORKER_OK) { 887 if (status != SERVICE_WORKER_OK) {
839 context_core_.reset(); 888 context_core_.reset();
840 return; 889 return;
841 } 890 }
842 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); 891 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this));
843 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; 892 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully.";
844 893
845 observer_list_->Notify(FROM_HERE, 894 observer_list_->Notify(FROM_HERE,
846 &ServiceWorkerContextObserver::OnStorageWiped); 895 &ServiceWorkerContextObserver::OnStorageWiped);
847 } 896 }
848 897
849 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { 898 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() {
850 DCHECK_CURRENTLY_ON(BrowserThread::IO); 899 DCHECK_CURRENTLY_ON(BrowserThread::IO);
851 return context_core_.get(); 900 return context_core_.get();
852 } 901 }
853 902
854 } // namespace content 903 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698