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

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: Created 4 years, 5 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/threading/sequenced_worker_pool.h" 21 #include "base/threading/sequenced_worker_pool.h"
22 #include "base/threading/thread_task_runner_handle.h" 22 #include "base/threading/thread_task_runner_handle.h"
23 #include "content/browser/service_worker/embedded_worker_registry.h"
23 #include "content/browser/service_worker/service_worker_context_core.h" 24 #include "content/browser/service_worker/service_worker_context_core.h"
24 #include "content/browser/service_worker/service_worker_context_observer.h" 25 #include "content/browser/service_worker/service_worker_context_observer.h"
25 #include "content/browser/service_worker/service_worker_process_manager.h" 26 #include "content/browser/service_worker/service_worker_process_manager.h"
26 #include "content/browser/service_worker/service_worker_quota_client.h" 27 #include "content/browser/service_worker/service_worker_quota_client.h"
27 #include "content/browser/service_worker/service_worker_version.h" 28 #include "content/browser/service_worker/service_worker_version.h"
28 #include "content/browser/storage_partition_impl.h" 29 #include "content/browser/storage_partition_impl.h"
29 #include "content/common/service_worker/service_worker_utils.h" 30 #include "content/common/service_worker/service_worker_utils.h"
30 #include "content/public/browser/browser_context.h" 31 #include "content/public/browser/browser_context.h"
31 #include "content/public/browser/browser_thread.h" 32 #include "content/public/browser/browser_thread.h"
32 #include "net/base/url_util.h" 33 #include "net/base/url_util.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 header_names.end()); 95 header_names.end());
95 } 96 }
96 97
97 bool ServiceWorkerContext::IsExcludedHeaderNameForFetchEvent( 98 bool ServiceWorkerContext::IsExcludedHeaderNameForFetchEvent(
98 const std::string& header_name) { 99 const std::string& header_name) {
99 DCHECK_CURRENTLY_ON(BrowserThread::IO); 100 DCHECK_CURRENTLY_ON(BrowserThread::IO);
100 return g_excluded_header_name_set.Get().find(header_name) != 101 return g_excluded_header_name_set.Get().find(header_name) !=
101 g_excluded_header_name_set.Get().end(); 102 g_excluded_header_name_set.Get().end();
102 } 103 }
103 104
105 // static.
106 void ServiceWorkerContext::IncrementEmbeddedWorkerRefCount(
107 StoragePartition* storage_partition,
108 int embedded_worker_id) {
109 ServiceWorkerContextWrapper::IncrementEmbeddedWorkerRefCount(
110 storage_partition, embedded_worker_id);
111 }
112
113 // static.
114 void ServiceWorkerContext::DecrementEmbeddedWorkerRefCount(
115 StoragePartition* storage_partition,
116 int embedded_worker_id) {
117 ServiceWorkerContextWrapper::DecrementEmbeddedWorkerRefCount(
118 storage_partition, embedded_worker_id);
119 }
120
104 ServiceWorkerContextWrapper::ServiceWorkerContextWrapper( 121 ServiceWorkerContextWrapper::ServiceWorkerContextWrapper(
105 BrowserContext* browser_context) 122 BrowserContext* browser_context)
106 : observer_list_( 123 : observer_list_(
107 new base::ObserverListThreadSafe<ServiceWorkerContextObserver>()), 124 new base::ObserverListThreadSafe<ServiceWorkerContextObserver>()),
108 process_manager_(new ServiceWorkerProcessManager(browser_context)), 125 process_manager_(new ServiceWorkerProcessManager(browser_context)),
109 is_incognito_(false), 126 is_incognito_(false),
110 storage_partition_(nullptr), 127 storage_partition_(nullptr),
111 resource_context_(nullptr) { 128 resource_context_(nullptr) {
112 DCHECK_CURRENTLY_ON(BrowserThread::UI); 129 DCHECK_CURRENTLY_ON(BrowserThread::UI);
113 } 130 }
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 void ServiceWorkerContextWrapper::ShutdownOnIO() { 737 void ServiceWorkerContextWrapper::ShutdownOnIO() {
721 DCHECK_CURRENTLY_ON(BrowserThread::IO); 738 DCHECK_CURRENTLY_ON(BrowserThread::IO);
722 // Can be null in tests. 739 // Can be null in tests.
723 if (request_context_getter_) 740 if (request_context_getter_)
724 request_context_getter_->RemoveObserver(this); 741 request_context_getter_->RemoveObserver(this);
725 request_context_getter_ = nullptr; 742 request_context_getter_ = nullptr;
726 resource_context_ = nullptr; 743 resource_context_ = nullptr;
727 context_core_.reset(); 744 context_core_.reset();
728 } 745 }
729 746
747 // static.
748 void ServiceWorkerContextWrapper::IncrementEmbeddedWorkerRefCount(
749 StoragePartition* storage_partition,
750 int embedded_worker_id) {
751 ServiceWorkerContextWrapper* context_wrapper =
752 static_cast<ServiceWorkerContextWrapper*>(
753 storage_partition->GetServiceWorkerContext());
754 BrowserThread::PostTask(
755 BrowserThread::IO, FROM_HERE,
756 base::Bind(
757 &ServiceWorkerContextWrapper::IncrementEmbeddedWorkerRefCountOnIO,
758 context_wrapper, embedded_worker_id));
759 }
760
761 // static.
762 void ServiceWorkerContextWrapper::DecrementEmbeddedWorkerRefCount(
763 StoragePartition* storage_partition,
764 int embedded_worker_id) {
765 ServiceWorkerContextWrapper* context_wrapper =
766 static_cast<ServiceWorkerContextWrapper*>(
767 storage_partition->GetServiceWorkerContext());
768 BrowserThread::PostTask(
769 BrowserThread::IO, FROM_HERE,
770 base::Bind(
771 &ServiceWorkerContextWrapper::DecrementEmbeddedWorkerRefCountOnIO,
772 context_wrapper, embedded_worker_id));
773 }
774
775 void ServiceWorkerContextWrapper::IncrementEmbeddedWorkerRefCountOnIO(
776 int embedded_worker_id) {
777 context()
778 ->embedded_worker_registry()
779 ->GetWorker(embedded_worker_id)
780 ->IncrementRefCount();
781 }
782 void ServiceWorkerContextWrapper::DecrementEmbeddedWorkerRefCountOnIO(
783 int embedded_worker_id) {
784 context()
785 ->embedded_worker_registry()
786 ->GetWorker(embedded_worker_id)
787 ->DecrementRefCount();
788 }
789
730 void ServiceWorkerContextWrapper::DidDeleteAndStartOver( 790 void ServiceWorkerContextWrapper::DidDeleteAndStartOver(
731 ServiceWorkerStatusCode status) { 791 ServiceWorkerStatusCode status) {
732 DCHECK_CURRENTLY_ON(BrowserThread::IO); 792 DCHECK_CURRENTLY_ON(BrowserThread::IO);
733 if (status != SERVICE_WORKER_OK) { 793 if (status != SERVICE_WORKER_OK) {
734 context_core_.reset(); 794 context_core_.reset();
735 return; 795 return;
736 } 796 }
737 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); 797 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this));
738 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; 798 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully.";
739 799
740 observer_list_->Notify(FROM_HERE, 800 observer_list_->Notify(FROM_HERE,
741 &ServiceWorkerContextObserver::OnStorageWiped); 801 &ServiceWorkerContextObserver::OnStorageWiped);
742 } 802 }
743 803
744 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { 804 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() {
745 DCHECK_CURRENTLY_ON(BrowserThread::IO); 805 DCHECK_CURRENTLY_ON(BrowserThread::IO);
746 return context_core_.get(); 806 return context_core_.get();
747 } 807 }
748 808
749 } // namespace content 809 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698