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

Side by Side Diff: content/browser/service_worker/service_worker_storage.h

Issue 355163003: Don't prematurely delete script resources when registration is deleted (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: redesign Created 6 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 | Annotate | Revision Log
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 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_ 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_ 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/gtest_prod_util.h" 15 #include "base/gtest_prod_util.h"
16 #include "base/memory/scoped_vector.h" 16 #include "base/memory/scoped_vector.h"
17 #include "base/memory/weak_ptr.h" 17 #include "base/memory/weak_ptr.h"
18 #include "content/browser/service_worker/service_worker_database.h" 18 #include "content/browser/service_worker/service_worker_database.h"
19 #include "content/browser/service_worker/service_worker_version.h"
19 #include "content/common/content_export.h" 20 #include "content/common/content_export.h"
20 #include "content/common/service_worker/service_worker_status_code.h" 21 #include "content/common/service_worker/service_worker_status_code.h"
21 #include "url/gurl.h" 22 #include "url/gurl.h"
22 23
23 namespace base { 24 namespace base {
24 class MessageLoopProxy; 25 class MessageLoopProxy;
25 class SequencedTaskRunner; 26 class SequencedTaskRunner;
26 } 27 }
27 28
28 namespace quota { 29 namespace quota {
29 class QuotaManagerProxy; 30 class QuotaManagerProxy;
30 } 31 }
31 32
32 namespace content { 33 namespace content {
33 34
34 class ServiceWorkerContextCore; 35 class ServiceWorkerContextCore;
35 class ServiceWorkerDiskCache; 36 class ServiceWorkerDiskCache;
36 class ServiceWorkerRegistration; 37 class ServiceWorkerRegistration;
37 class ServiceWorkerRegistrationInfo; 38 class ServiceWorkerRegistrationInfo;
38 class ServiceWorkerResponseReader; 39 class ServiceWorkerResponseReader;
39 class ServiceWorkerResponseWriter; 40 class ServiceWorkerResponseWriter;
40 class ServiceWorkerVersion;
41 41
42 // This class provides an interface to store and retrieve ServiceWorker 42 // This class provides an interface to store and retrieve ServiceWorker
43 // registration data. 43 // registration data.
44 class CONTENT_EXPORT ServiceWorkerStorage { 44 class CONTENT_EXPORT ServiceWorkerStorage
45 : public ServiceWorkerVersion::Listener {
45 public: 46 public:
46 typedef std::vector<ServiceWorkerDatabase::ResourceRecord> ResourceList; 47 typedef std::vector<ServiceWorkerDatabase::ResourceRecord> ResourceList;
47 typedef base::Callback<void(ServiceWorkerStatusCode status)> StatusCallback; 48 typedef base::Callback<void(ServiceWorkerStatusCode status)> StatusCallback;
48 typedef base::Callback<void(ServiceWorkerStatusCode status, 49 typedef base::Callback<void(ServiceWorkerStatusCode status,
49 const scoped_refptr<ServiceWorkerRegistration>& 50 const scoped_refptr<ServiceWorkerRegistration>&
50 registration)> FindRegistrationCallback; 51 registration)> FindRegistrationCallback;
51 typedef base::Callback< 52 typedef base::Callback<
52 void(const std::vector<ServiceWorkerRegistrationInfo>& registrations)> 53 void(const std::vector<ServiceWorkerRegistrationInfo>& registrations)>
53 GetAllRegistrationInfosCallback; 54 GetAllRegistrationInfosCallback;
54 typedef base::Callback< 55 typedef base::Callback<
55 void(ServiceWorkerStatusCode status, int result)> 56 void(ServiceWorkerStatusCode status, int result)>
56 CompareCallback; 57 CompareCallback;
57 58
58 ~ServiceWorkerStorage(); 59 virtual ~ServiceWorkerStorage();
59 60
60 static scoped_ptr<ServiceWorkerStorage> Create( 61 static scoped_ptr<ServiceWorkerStorage> Create(
61 const base::FilePath& path, 62 const base::FilePath& path,
62 base::WeakPtr<ServiceWorkerContextCore> context, 63 base::WeakPtr<ServiceWorkerContextCore> context,
63 base::SequencedTaskRunner* database_task_runner, 64 base::SequencedTaskRunner* database_task_runner,
64 base::MessageLoopProxy* disk_cache_thread, 65 base::MessageLoopProxy* disk_cache_thread,
65 quota::QuotaManagerProxy* quota_manager_proxy); 66 quota::QuotaManagerProxy* quota_manager_proxy);
66 67
67 // Used for DeleteAndStartOver. Creates new storage based on |old_storage|. 68 // Used for DeleteAndStartOver. Creates new storage based on |old_storage|.
68 static scoped_ptr<ServiceWorkerStorage> Create( 69 static scoped_ptr<ServiceWorkerStorage> Create(
69 base::WeakPtr<ServiceWorkerContextCore> context, 70 base::WeakPtr<ServiceWorkerContextCore> context,
70 ServiceWorkerStorage* old_storage); 71 ServiceWorkerStorage* old_storage);
71 72
73 // ServiceWorkerVersion::Listener override
74 virtual void OnNoControllees(ServiceWorkerVersion* version) OVERRIDE;
michaeln 2014/06/30 22:31:54 please put this method in the private section, its
falken 2014/07/01 06:17:39 Done.
75
72 // Finds registration for |document_url| or |pattern| or |registration_id|. 76 // Finds registration for |document_url| or |pattern| or |registration_id|.
73 // The Find methods will find stored and initially installing registrations. 77 // The Find methods will find stored and initially installing registrations.
74 // Returns SERVICE_WORKER_OK with non-null registration if registration 78 // Returns SERVICE_WORKER_OK with non-null registration if registration
75 // is found, or returns SERVICE_WORKER_ERROR_NOT_FOUND if no matching 79 // is found, or returns SERVICE_WORKER_ERROR_NOT_FOUND if no matching
76 // registration is found. The FindRegistrationForPattern method is 80 // registration is found. The FindRegistrationForPattern method is
77 // guaranteed to return asynchronously. However, the methods to find 81 // guaranteed to return asynchronously. However, the methods to find
78 // for |document_url| or |registration_id| may complete immediately 82 // for |document_url| or |registration_id| may complete immediately
79 // (the callback may be called prior to the method returning) or 83 // (the callback may be called prior to the method returning) or
80 // asynchronously. 84 // asynchronously.
81 void FindRegistrationForDocument(const GURL& document_url, 85 void FindRegistrationForDocument(const GURL& document_url,
(...skipping 14 matching lines...) Expand all
96 void StoreRegistration( 100 void StoreRegistration(
97 ServiceWorkerRegistration* registration, 101 ServiceWorkerRegistration* registration,
98 ServiceWorkerVersion* version, 102 ServiceWorkerVersion* version,
99 const StatusCallback& callback); 103 const StatusCallback& callback);
100 104
101 // Updates the state of the registration's stored version to active. 105 // Updates the state of the registration's stored version to active.
102 void UpdateToActiveState( 106 void UpdateToActiveState(
103 ServiceWorkerRegistration* registration, 107 ServiceWorkerRegistration* registration,
104 const StatusCallback& callback); 108 const StatusCallback& callback);
105 109
106 // Deletes the registration data for |registration_id|, the 110 // Deletes the registration data for |registration_id|. The script resources
107 // script resources for the registration's stored version 111 // for the registration's stored version will remain available until that
108 // will remain available until either a browser restart or 112 // version no longer controls a page.
109 // DeleteVersionResources is called.
110 void DeleteRegistration(int64 registration_id, 113 void DeleteRegistration(int64 registration_id,
111 const GURL& origin, 114 const GURL& origin,
112 const StatusCallback& callback); 115 const StatusCallback& callback);
113 116
114 scoped_ptr<ServiceWorkerResponseReader> CreateResponseReader( 117 scoped_ptr<ServiceWorkerResponseReader> CreateResponseReader(
115 int64 response_id); 118 int64 response_id);
116 scoped_ptr<ServiceWorkerResponseWriter> CreateResponseWriter( 119 scoped_ptr<ServiceWorkerResponseWriter> CreateResponseWriter(
117 int64 response_id); 120 int64 response_id);
118 121
119 // Adds |id| to the set of resources ids that are in the disk 122 // Adds |id| to the set of resources ids that are in the disk
(...skipping 17 matching lines...) Expand all
137 ServiceWorkerRegistration* registration); 140 ServiceWorkerRegistration* registration);
138 void NotifyDoneInstallingRegistration( 141 void NotifyDoneInstallingRegistration(
139 ServiceWorkerRegistration* registration, 142 ServiceWorkerRegistration* registration,
140 ServiceWorkerVersion* version, 143 ServiceWorkerVersion* version,
141 ServiceWorkerStatusCode status); 144 ServiceWorkerStatusCode status);
142 145
143 void Disable(); 146 void Disable();
144 bool IsDisabled() const; 147 bool IsDisabled() const;
145 148
146 private: 149 private:
147 friend class ServiceWorkerStorageTest; 150 friend class ServiceWorkerResourceStorageTest;
148 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerStorageTest, 151 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest,
149 ResourceIdsAreStoredAndPurged); 152 ResourceIdsAreStoredAndPurged);
153 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest,
154 ResourceIdsAreStoredAndPurged2);
150 155
151 struct InitialData { 156 struct InitialData {
152 int64 next_registration_id; 157 int64 next_registration_id;
153 int64 next_version_id; 158 int64 next_version_id;
154 int64 next_resource_id; 159 int64 next_resource_id;
155 std::set<GURL> origins; 160 std::set<GURL> origins;
156 161
157 InitialData(); 162 InitialData();
158 ~InitialData(); 163 ~InitialData();
159 }; 164 };
160 165
161 typedef std::vector<ServiceWorkerDatabase::RegistrationData> RegistrationList; 166 typedef std::vector<ServiceWorkerDatabase::RegistrationData> RegistrationList;
162 typedef std::map<int64, scoped_refptr<ServiceWorkerRegistration> > 167 typedef std::map<int64, scoped_refptr<ServiceWorkerRegistration> >
163 RegistrationRefsById; 168 RegistrationRefsById;
164 typedef base::Callback<void( 169 typedef base::Callback<void(
165 InitialData* data, 170 InitialData* data,
166 ServiceWorkerDatabase::Status status)> InitializeCallback; 171 ServiceWorkerDatabase::Status status)> InitializeCallback;
167 typedef base::Callback<void( 172 typedef base::Callback<void(
168 const GURL& origin, 173 const GURL& origin,
169 const std::vector<int64>& newly_purgeable_resources, 174 const std::vector<int64>& newly_purgeable_resources,
170 ServiceWorkerDatabase::Status status)> WriteRegistrationCallback; 175 ServiceWorkerDatabase::Status status)> WriteRegistrationCallback;
171 typedef base::Callback<void( 176 typedef base::Callback<
172 bool origin_is_deletable, 177 void(bool origin_is_deletable,
173 const std::vector<int64>& newly_purgeable_resources, 178 int64 version_id,
174 ServiceWorkerDatabase::Status status)> DeleteRegistrationCallback; 179 const std::vector<int64>& newly_purgeable_resources,
180 ServiceWorkerDatabase::Status status)> DeleteRegistrationCallback;
175 typedef base::Callback<void( 181 typedef base::Callback<void(
176 const ServiceWorkerDatabase::RegistrationData& data, 182 const ServiceWorkerDatabase::RegistrationData& data,
177 const ResourceList& resources, 183 const ResourceList& resources,
178 ServiceWorkerDatabase::Status status)> FindInDBCallback; 184 ServiceWorkerDatabase::Status status)> FindInDBCallback;
179 185
180 ServiceWorkerStorage(const base::FilePath& path, 186 ServiceWorkerStorage(const base::FilePath& path,
181 base::WeakPtr<ServiceWorkerContextCore> context, 187 base::WeakPtr<ServiceWorkerContextCore> context,
182 base::SequencedTaskRunner* database_task_runner, 188 base::SequencedTaskRunner* database_task_runner,
183 base::MessageLoopProxy* disk_cache_thread, 189 base::MessageLoopProxy* disk_cache_thread,
184 quota::QuotaManagerProxy* quota_manager_proxy); 190 quota::QuotaManagerProxy* quota_manager_proxy);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 const GURL& origin, 223 const GURL& origin,
218 const std::vector<int64>& newly_purgeable_resources, 224 const std::vector<int64>& newly_purgeable_resources,
219 ServiceWorkerDatabase::Status status); 225 ServiceWorkerDatabase::Status status);
220 void DidUpdateToActiveState( 226 void DidUpdateToActiveState(
221 const StatusCallback& callback, 227 const StatusCallback& callback,
222 ServiceWorkerDatabase::Status status); 228 ServiceWorkerDatabase::Status status);
223 void DidDeleteRegistration( 229 void DidDeleteRegistration(
224 const GURL& origin, 230 const GURL& origin,
225 const StatusCallback& callback, 231 const StatusCallback& callback,
226 bool origin_is_deletable, 232 bool origin_is_deletable,
233 int64 version_id,
227 const std::vector<int64>& newly_purgeable_resources, 234 const std::vector<int64>& newly_purgeable_resources,
228 ServiceWorkerDatabase::Status status); 235 ServiceWorkerDatabase::Status status);
229 236
230 scoped_refptr<ServiceWorkerRegistration> GetOrCreateRegistration( 237 scoped_refptr<ServiceWorkerRegistration> GetOrCreateRegistration(
231 const ServiceWorkerDatabase::RegistrationData& data, 238 const ServiceWorkerDatabase::RegistrationData& data,
232 const ResourceList& resources); 239 const ResourceList& resources);
233 ServiceWorkerRegistration* FindInstallingRegistrationForDocument( 240 ServiceWorkerRegistration* FindInstallingRegistrationForDocument(
234 const GURL& document_url); 241 const GURL& document_url);
235 ServiceWorkerRegistration* FindInstallingRegistrationForPattern( 242 ServiceWorkerRegistration* FindInstallingRegistrationForPattern(
236 const GURL& scope); 243 const GURL& scope);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 base::FilePath path_; 320 base::FilePath path_;
314 base::WeakPtr<ServiceWorkerContextCore> context_; 321 base::WeakPtr<ServiceWorkerContextCore> context_;
315 322
316 // Only accessed on |database_task_runner_|. 323 // Only accessed on |database_task_runner_|.
317 scoped_ptr<ServiceWorkerDatabase> database_; 324 scoped_ptr<ServiceWorkerDatabase> database_;
318 325
319 scoped_refptr<base::SequencedTaskRunner> database_task_runner_; 326 scoped_refptr<base::SequencedTaskRunner> database_task_runner_;
320 scoped_refptr<base::MessageLoopProxy> disk_cache_thread_; 327 scoped_refptr<base::MessageLoopProxy> disk_cache_thread_;
321 scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; 328 scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_;
322 scoped_ptr<ServiceWorkerDiskCache> disk_cache_; 329 scoped_ptr<ServiceWorkerDiskCache> disk_cache_;
323 std::deque<int64> purgeable_reource_ids_; 330 std::deque<int64> purgeable_resource_ids_;
324 bool is_purge_pending_; 331 bool is_purge_pending_;
332 std::map<int64, std::vector<int64> > deleted_version_resource_ids_;
325 333
326 base::WeakPtrFactory<ServiceWorkerStorage> weak_factory_; 334 base::WeakPtrFactory<ServiceWorkerStorage> weak_factory_;
327 335
328 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerStorage); 336 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerStorage);
329 }; 337 };
330 338
331 } // namespace content 339 } // namespace content
332 340
333 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_ 341 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698