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

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

Issue 2934163003: Add a ServiceWorkerContextObserver to content's public API. (Closed)
Patch Set: Clarifying comment Created 3 years, 6 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_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
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 // Explicitly remove this object as an observer to avoid use-after-frees in
141 // tests where this object is not guaranteed to outlive the
142 // ServiceWorkerContextCore it wraps.
143 core_observer_list_->RemoveObserver(this);
117 DCHECK(!resource_context_); 144 DCHECK(!resource_context_);
118 } 145 }
119 146
120 void ServiceWorkerContextWrapper::Init( 147 void ServiceWorkerContextWrapper::Init(
121 const base::FilePath& user_data_directory, 148 const base::FilePath& user_data_directory,
122 storage::QuotaManagerProxy* quota_manager_proxy, 149 storage::QuotaManagerProxy* quota_manager_proxy,
123 storage::SpecialStoragePolicy* special_storage_policy) { 150 storage::SpecialStoragePolicy* special_storage_policy) {
124 DCHECK_CURRENTLY_ON(BrowserThread::UI); 151 DCHECK_CURRENTLY_ON(BrowserThread::UI);
125 152
126 is_incognito_ = user_data_directory.empty(); 153 is_incognito_ = user_data_directory.empty();
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 service_worker_provider_id, 861 service_worker_provider_id,
835 std::move(client_ptr_info)); 862 std::move(client_ptr_info));
836 } 863 }
837 864
838 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { 865 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() {
839 DCHECK_CURRENTLY_ON(BrowserThread::IO); 866 DCHECK_CURRENTLY_ON(BrowserThread::IO);
840 return context_core_.get(); 867 return context_core_.get();
841 } 868 }
842 869
843 } // namespace content 870 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_context_wrapper.h ('k') | content/public/browser/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698