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 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_CORE_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_CORE_H_ |
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_CORE_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_CORE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "content/common/content_export.h" | 22 #include "content/common/content_export.h" |
23 | 23 |
24 class GURL; | 24 class GURL; |
25 | 25 |
26 namespace base { | 26 namespace base { |
27 class FilePath; | 27 class FilePath; |
28 class SequencedTaskRunner; | 28 class SequencedTaskRunner; |
29 class SingleThreadTaskRunner; | 29 class SingleThreadTaskRunner; |
30 } | 30 } |
31 | 31 |
32 namespace net { | |
33 class URLRequestContext; | |
34 } | |
35 | |
36 namespace storage { | 32 namespace storage { |
37 class QuotaManagerProxy; | 33 class QuotaManagerProxy; |
38 class SpecialStoragePolicy; | 34 class SpecialStoragePolicy; |
39 } | 35 } |
40 | 36 |
41 namespace content { | 37 namespace content { |
42 | 38 |
43 class EmbeddedWorkerRegistry; | 39 class EmbeddedWorkerRegistry; |
44 class ServiceWorkerCacheStorageManager; | |
45 class ServiceWorkerContextObserver; | 40 class ServiceWorkerContextObserver; |
46 class ServiceWorkerContextWrapper; | 41 class ServiceWorkerContextWrapper; |
47 class ServiceWorkerDatabaseTaskManager; | 42 class ServiceWorkerDatabaseTaskManager; |
48 class ServiceWorkerHandle; | 43 class ServiceWorkerHandle; |
49 class ServiceWorkerJobCoordinator; | 44 class ServiceWorkerJobCoordinator; |
50 class ServiceWorkerProviderHost; | 45 class ServiceWorkerProviderHost; |
51 class ServiceWorkerRegistration; | 46 class ServiceWorkerRegistration; |
52 class ServiceWorkerStorage; | 47 class ServiceWorkerStorage; |
53 | 48 |
54 // This class manages data associated with service workers. | 49 // This class manages data associated with service workers. |
55 // The class is single threaded and should only be used on the IO thread. | 50 // The class is single threaded and should only be used on the IO thread. |
56 // In chromium, there is one instance per storagepartition. This class | 51 // In chromium, there is one instance per storagepartition. This class |
57 // is the root of the containment hierarchy for service worker data | 52 // is the root of the containment hierarchy for service worker data |
58 // associated with a particular partition. | 53 // associated with a particular partition. |
59 class CONTENT_EXPORT ServiceWorkerContextCore | 54 class CONTENT_EXPORT ServiceWorkerContextCore |
60 : NON_EXPORTED_BASE(public ServiceWorkerVersion::Listener) { | 55 : NON_EXPORTED_BASE(public ServiceWorkerVersion::Listener) { |
61 public: | 56 public: |
62 typedef base::Callback<void(ServiceWorkerStatusCode status)> StatusCallback; | 57 typedef base::Callback<void(ServiceWorkerStatusCode status)> StatusCallback; |
63 typedef base::Callback<void(ServiceWorkerStatusCode status, | 58 typedef base::Callback<void(ServiceWorkerStatusCode status, |
64 const std::string& status_message, | 59 const std::string& status_message, |
65 int64 registration_id)> RegistrationCallback; | 60 int64 registration_id)> RegistrationCallback; |
66 typedef base::Callback< | 61 typedef base::Callback< |
67 void(ServiceWorkerStatusCode status)> UnregistrationCallback; | 62 void(ServiceWorkerStatusCode status)> UnregistrationCallback; |
68 typedef IDMap<ServiceWorkerProviderHost, IDMapOwnPointer> ProviderMap; | 63 typedef IDMap<ServiceWorkerProviderHost, IDMapOwnPointer> ProviderMap; |
69 typedef IDMap<ProviderMap, IDMapOwnPointer> ProcessToProviderMap; | 64 typedef IDMap<ProviderMap, IDMapOwnPointer> ProcessToProviderMap; |
70 | 65 |
71 // Directory for ServiceWorkerStorage and ServiceWorkerCacheManager. | 66 // Directory for ServiceWorkerStorage and ServiceWorkerCacheStorageManager. |
72 static const base::FilePath::CharType kServiceWorkerDirectory[]; | 67 static const base::FilePath::CharType kServiceWorkerDirectory[]; |
73 | 68 |
74 // Iterates over ServiceWorkerProviderHost objects in a ProcessToProviderMap. | 69 // Iterates over ServiceWorkerProviderHost objects in a ProcessToProviderMap. |
75 class ProviderHostIterator { | 70 class ProviderHostIterator { |
76 public: | 71 public: |
77 ~ProviderHostIterator(); | 72 ~ProviderHostIterator(); |
78 ServiceWorkerProviderHost* GetProviderHost(); | 73 ServiceWorkerProviderHost* GetProviderHost(); |
79 void Advance(); | 74 void Advance(); |
80 bool IsAtEnd(); | 75 bool IsAtEnd(); |
81 | 76 |
(...skipping 10 matching lines...) Expand all Loading... |
92 }; | 87 }; |
93 | 88 |
94 // This is owned by the StoragePartition, which will supply it with | 89 // This is owned by the StoragePartition, which will supply it with |
95 // the local path on disk. Given an empty |user_data_directory|, | 90 // the local path on disk. Given an empty |user_data_directory|, |
96 // nothing will be stored on disk. |observer_list| is created in | 91 // nothing will be stored on disk. |observer_list| is created in |
97 // ServiceWorkerContextWrapper. When Notify() of |observer_list| is called in | 92 // ServiceWorkerContextWrapper. When Notify() of |observer_list| is called in |
98 // ServiceWorkerContextCore, the methods of ServiceWorkerContextObserver will | 93 // ServiceWorkerContextCore, the methods of ServiceWorkerContextObserver will |
99 // be called on the thread which called AddObserver() of |observer_list|. | 94 // be called on the thread which called AddObserver() of |observer_list|. |
100 ServiceWorkerContextCore( | 95 ServiceWorkerContextCore( |
101 const base::FilePath& user_data_directory, | 96 const base::FilePath& user_data_directory, |
102 const scoped_refptr<base::SequencedTaskRunner>& cache_task_runner, | |
103 scoped_ptr<ServiceWorkerDatabaseTaskManager> database_task_runner_manager, | 97 scoped_ptr<ServiceWorkerDatabaseTaskManager> database_task_runner_manager, |
104 const scoped_refptr<base::SingleThreadTaskRunner>& disk_cache_thread, | 98 const scoped_refptr<base::SingleThreadTaskRunner>& disk_cache_thread, |
105 storage::QuotaManagerProxy* quota_manager_proxy, | 99 storage::QuotaManagerProxy* quota_manager_proxy, |
106 storage::SpecialStoragePolicy* special_storage_policy, | 100 storage::SpecialStoragePolicy* special_storage_policy, |
107 ObserverListThreadSafe<ServiceWorkerContextObserver>* observer_list, | 101 ObserverListThreadSafe<ServiceWorkerContextObserver>* observer_list, |
108 ServiceWorkerContextWrapper* wrapper); | 102 ServiceWorkerContextWrapper* wrapper); |
109 ServiceWorkerContextCore( | 103 ServiceWorkerContextCore( |
110 ServiceWorkerContextCore* old_context, | 104 ServiceWorkerContextCore* old_context, |
111 ServiceWorkerContextWrapper* wrapper); | 105 ServiceWorkerContextWrapper* wrapper); |
112 ~ServiceWorkerContextCore() override; | 106 ~ServiceWorkerContextCore() override; |
113 | 107 |
114 // ServiceWorkerVersion::Listener overrides. | 108 // ServiceWorkerVersion::Listener overrides. |
115 void OnRunningStateChanged(ServiceWorkerVersion* version) override; | 109 void OnRunningStateChanged(ServiceWorkerVersion* version) override; |
116 void OnVersionStateChanged(ServiceWorkerVersion* version) override; | 110 void OnVersionStateChanged(ServiceWorkerVersion* version) override; |
117 void OnErrorReported(ServiceWorkerVersion* version, | 111 void OnErrorReported(ServiceWorkerVersion* version, |
118 const base::string16& error_message, | 112 const base::string16& error_message, |
119 int line_number, | 113 int line_number, |
120 int column_number, | 114 int column_number, |
121 const GURL& source_url) override; | 115 const GURL& source_url) override; |
122 void OnReportConsoleMessage(ServiceWorkerVersion* version, | 116 void OnReportConsoleMessage(ServiceWorkerVersion* version, |
123 int source_identifier, | 117 int source_identifier, |
124 int message_level, | 118 int message_level, |
125 const base::string16& message, | 119 const base::string16& message, |
126 int line_number, | 120 int line_number, |
127 const GURL& source_url) override; | 121 const GURL& source_url) override; |
128 | 122 |
129 ServiceWorkerContextWrapper* wrapper() const { return wrapper_; } | 123 ServiceWorkerContextWrapper* wrapper() const { return wrapper_; } |
130 ServiceWorkerStorage* storage() { return storage_.get(); } | 124 ServiceWorkerStorage* storage() { return storage_.get(); } |
131 ServiceWorkerCacheStorageManager* cache_manager() { | |
132 return cache_manager_.get(); | |
133 } | |
134 ServiceWorkerProcessManager* process_manager(); | 125 ServiceWorkerProcessManager* process_manager(); |
135 EmbeddedWorkerRegistry* embedded_worker_registry() { | 126 EmbeddedWorkerRegistry* embedded_worker_registry() { |
136 return embedded_worker_registry_.get(); | 127 return embedded_worker_registry_.get(); |
137 } | 128 } |
138 ServiceWorkerJobCoordinator* job_coordinator() { | 129 ServiceWorkerJobCoordinator* job_coordinator() { |
139 return job_coordinator_.get(); | 130 return job_coordinator_.get(); |
140 } | 131 } |
141 | 132 |
142 // The context class owns the set of ProviderHosts. | 133 // The context class owns the set of ProviderHosts. |
143 ServiceWorkerProviderHost* GetProviderHost(int process_id, int provider_id); | 134 ServiceWorkerProviderHost* GetProviderHost(int process_id, int provider_id); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 // Returns new context-local unique ID. | 168 // Returns new context-local unique ID. |
178 int GetNewServiceWorkerHandleId(); | 169 int GetNewServiceWorkerHandleId(); |
179 int GetNewRegistrationHandleId(); | 170 int GetNewRegistrationHandleId(); |
180 | 171 |
181 void ScheduleDeleteAndStartOver() const; | 172 void ScheduleDeleteAndStartOver() const; |
182 | 173 |
183 // Deletes all files on disk and restarts the system. This leaves the system | 174 // Deletes all files on disk and restarts the system. This leaves the system |
184 // in a disabled state until it's done. | 175 // in a disabled state until it's done. |
185 void DeleteAndStartOver(const StatusCallback& callback); | 176 void DeleteAndStartOver(const StatusCallback& callback); |
186 | 177 |
187 void SetBlobParametersForCache( | |
188 net::URLRequestContext* request_context, | |
189 base::WeakPtr<storage::BlobStorageContext> blob_storage_context); | |
190 | |
191 // Methods to support cross site navigations. | 178 // Methods to support cross site navigations. |
192 scoped_ptr<ServiceWorkerProviderHost> TransferProviderHostOut( | 179 scoped_ptr<ServiceWorkerProviderHost> TransferProviderHostOut( |
193 int process_id, | 180 int process_id, |
194 int provider_id); | 181 int provider_id); |
195 void TransferProviderHostIn( | 182 void TransferProviderHostIn( |
196 int new_process_id, | 183 int new_process_id, |
197 int new_host_id, | 184 int new_host_id, |
198 scoped_ptr<ServiceWorkerProviderHost> provider_host); | 185 scoped_ptr<ServiceWorkerProviderHost> provider_host); |
199 | 186 |
200 base::WeakPtr<ServiceWorkerContextCore> AsWeakPtr() { | 187 base::WeakPtr<ServiceWorkerContextCore> AsWeakPtr() { |
(...skipping 24 matching lines...) Expand all Loading... |
225 const UnregistrationCallback& result, | 212 const UnregistrationCallback& result, |
226 const GURL& origin, | 213 const GURL& origin, |
227 const std::vector<ServiceWorkerRegistrationInfo>& registrations); | 214 const std::vector<ServiceWorkerRegistrationInfo>& registrations); |
228 | 215 |
229 // It's safe to store a raw pointer instead of a scoped_refptr to |wrapper_| | 216 // It's safe to store a raw pointer instead of a scoped_refptr to |wrapper_| |
230 // because the Wrapper::Shutdown call that hops threads to destroy |this| uses | 217 // because the Wrapper::Shutdown call that hops threads to destroy |this| uses |
231 // Bind() to hold a reference to |wrapper_| until |this| is fully destroyed. | 218 // Bind() to hold a reference to |wrapper_| until |this| is fully destroyed. |
232 ServiceWorkerContextWrapper* wrapper_; | 219 ServiceWorkerContextWrapper* wrapper_; |
233 scoped_ptr<ProcessToProviderMap> providers_; | 220 scoped_ptr<ProcessToProviderMap> providers_; |
234 scoped_ptr<ServiceWorkerStorage> storage_; | 221 scoped_ptr<ServiceWorkerStorage> storage_; |
235 scoped_ptr<ServiceWorkerCacheStorageManager> cache_manager_; | |
236 scoped_refptr<EmbeddedWorkerRegistry> embedded_worker_registry_; | 222 scoped_refptr<EmbeddedWorkerRegistry> embedded_worker_registry_; |
237 scoped_ptr<ServiceWorkerJobCoordinator> job_coordinator_; | 223 scoped_ptr<ServiceWorkerJobCoordinator> job_coordinator_; |
238 std::map<int64, ServiceWorkerRegistration*> live_registrations_; | 224 std::map<int64, ServiceWorkerRegistration*> live_registrations_; |
239 std::map<int64, ServiceWorkerVersion*> live_versions_; | 225 std::map<int64, ServiceWorkerVersion*> live_versions_; |
240 int next_handle_id_; | 226 int next_handle_id_; |
241 int next_registration_handle_id_; | 227 int next_registration_handle_id_; |
242 scoped_refptr<ObserverListThreadSafe<ServiceWorkerContextObserver> > | 228 scoped_refptr<ObserverListThreadSafe<ServiceWorkerContextObserver> > |
243 observer_list_; | 229 observer_list_; |
244 base::WeakPtrFactory<ServiceWorkerContextCore> weak_factory_; | 230 base::WeakPtrFactory<ServiceWorkerContextCore> weak_factory_; |
245 | 231 |
246 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerContextCore); | 232 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerContextCore); |
247 }; | 233 }; |
248 | 234 |
249 } // namespace content | 235 } // namespace content |
250 | 236 |
251 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_CORE_H_ | 237 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_CORE_H_ |
OLD | NEW |