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/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_status.h" | 23 #include "content/browser/service_worker/embedded_worker_status.h" |
24 #include "content/browser/service_worker/service_worker_context_core.h" | |
25 #include "content/browser/service_worker/service_worker_context_core_observer.h" | |
26 #include "content/browser/service_worker/service_worker_process_manager.h" | 24 #include "content/browser/service_worker/service_worker_process_manager.h" |
27 #include "content/browser/service_worker/service_worker_quota_client.h" | 25 #include "content/browser/service_worker/service_worker_quota_client.h" |
28 #include "content/browser/service_worker/service_worker_version.h" | 26 #include "content/browser/service_worker/service_worker_version.h" |
29 #include "content/browser/storage_partition_impl.h" | 27 #include "content/browser/storage_partition_impl.h" |
30 #include "content/common/service_worker/service_worker_utils.h" | 28 #include "content/common/service_worker/service_worker_utils.h" |
31 #include "content/public/browser/browser_context.h" | 29 #include "content/public/browser/browser_context.h" |
32 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
31 #include "content/public/browser/service_worker_context_observer.h" | |
33 #include "net/base/url_util.h" | 32 #include "net/base/url_util.h" |
34 #include "storage/browser/quota/quota_manager_proxy.h" | 33 #include "storage/browser/quota/quota_manager_proxy.h" |
35 #include "storage/browser/quota/special_storage_policy.h" | 34 #include "storage/browser/quota/special_storage_policy.h" |
36 | 35 |
37 namespace content { | 36 namespace content { |
38 | 37 |
39 namespace { | 38 namespace { |
40 | 39 |
41 typedef std::set<std::string> HeaderNameSet; | 40 typedef std::set<std::string> HeaderNameSet; |
42 base::LazyInstance<HeaderNameSet>::DestructorAtExit g_excluded_header_name_set = | 41 base::LazyInstance<HeaderNameSet>::DestructorAtExit g_excluded_header_name_set = |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 header_names.end()); | 94 header_names.end()); |
96 } | 95 } |
97 | 96 |
98 bool ServiceWorkerContext::IsExcludedHeaderNameForFetchEvent( | 97 bool ServiceWorkerContext::IsExcludedHeaderNameForFetchEvent( |
99 const std::string& header_name) { | 98 const std::string& header_name) { |
100 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 99 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
101 return g_excluded_header_name_set.Get().find(header_name) != | 100 return g_excluded_header_name_set.Get().find(header_name) != |
102 g_excluded_header_name_set.Get().end(); | 101 g_excluded_header_name_set.Get().end(); |
103 } | 102 } |
104 | 103 |
104 bool ServiceWorkerContext::ScopeMatches(const GURL& scope, const GURL& url) { | |
105 return ServiceWorkerUtils::ScopeMatches(scope, url); | |
106 } | |
107 | |
108 void ServiceWorkerContextWrapper::OnRegistrationStored(int64_t registration_id, | |
109 const GURL& pattern) { | |
110 for (auto& observer : observer_list_) | |
111 observer.OnRegistrationStored(pattern); | |
112 } | |
113 | |
114 void ServiceWorkerContextWrapper::AddObserver( | |
115 ServiceWorkerContextObserver* observer) { | |
116 observer_list_.AddObserver(observer); | |
117 } | |
118 | |
119 void ServiceWorkerContextWrapper::RemoveObserver( | |
120 ServiceWorkerContextObserver* observer) { | |
121 observer_list_.RemoveObserver(observer); | |
122 } | |
123 | |
105 ServiceWorkerContextWrapper::ServiceWorkerContextWrapper( | 124 ServiceWorkerContextWrapper::ServiceWorkerContextWrapper( |
106 BrowserContext* browser_context) | 125 BrowserContext* browser_context) |
107 : core_observer_list_( | 126 : core_observer_list_( |
108 new base::ObserverListThreadSafe<ServiceWorkerContextCoreObserver>()), | 127 new base::ObserverListThreadSafe<ServiceWorkerContextCoreObserver>()), |
109 process_manager_(new ServiceWorkerProcessManager(browser_context)), | 128 process_manager_(new ServiceWorkerProcessManager(browser_context)), |
110 is_incognito_(false), | 129 is_incognito_(false), |
111 storage_partition_(nullptr), | 130 storage_partition_(nullptr), |
112 resource_context_(nullptr) { | 131 resource_context_(nullptr) { |
113 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 132 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
133 | |
134 // Add this object as an observer of the wrapped |context_core_|. This lets us | |
135 // forward observer methods to observers outside of content. | |
136 core_observer_list_->AddObserver(this); | |
114 } | 137 } |
115 | 138 |
116 ServiceWorkerContextWrapper::~ServiceWorkerContextWrapper() { | 139 ServiceWorkerContextWrapper::~ServiceWorkerContextWrapper() { |
140 core_observer_list_->RemoveObserver(this); | |
kinuko
2017/06/14 07:33:45
I think this wrapper almost always live longer tha
dominickn
2017/06/14 09:10:58
You can see in #ps1 that a bunch of test failures
| |
117 DCHECK(!resource_context_); | 141 DCHECK(!resource_context_); |
118 } | 142 } |
119 | 143 |
120 void ServiceWorkerContextWrapper::Init( | 144 void ServiceWorkerContextWrapper::Init( |
121 const base::FilePath& user_data_directory, | 145 const base::FilePath& user_data_directory, |
122 storage::QuotaManagerProxy* quota_manager_proxy, | 146 storage::QuotaManagerProxy* quota_manager_proxy, |
123 storage::SpecialStoragePolicy* special_storage_policy) { | 147 storage::SpecialStoragePolicy* special_storage_policy) { |
124 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 148 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
125 | 149 |
126 is_incognito_ = user_data_directory.empty(); | 150 is_incognito_ = user_data_directory.empty(); |
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
834 service_worker_provider_id, | 858 service_worker_provider_id, |
835 std::move(client_ptr_info)); | 859 std::move(client_ptr_info)); |
836 } | 860 } |
837 | 861 |
838 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { | 862 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { |
839 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 863 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
840 return context_core_.get(); | 864 return context_core_.get(); |
841 } | 865 } |
842 | 866 |
843 } // namespace content | 867 } // namespace content |
OLD | NEW |