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

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

Issue 633873002: Service Worker: Respect the "clear on exit" content setting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@contentsettings
Patch Set: self review Created 6 years, 2 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 #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_database_task_manager.h"
19 #include "content/browser/service_worker/service_worker_version.h" 20 #include "content/browser/service_worker/service_worker_version.h"
20 #include "content/common/content_export.h" 21 #include "content/common/content_export.h"
21 #include "content/common/service_worker/service_worker_status_code.h" 22 #include "content/common/service_worker/service_worker_status_code.h"
22 #include "url/gurl.h" 23 #include "url/gurl.h"
23 24
24 namespace base { 25 namespace base {
25 class SequencedTaskRunner; 26 class SequencedTaskRunner;
26 class SingleThreadTaskRunner; 27 class SingleThreadTaskRunner;
27 } 28 }
28 29
29 namespace storage { 30 namespace storage {
30 class QuotaManagerProxy; 31 class QuotaManagerProxy;
32 class SpecialStoragePolicy;
31 } 33 }
32 34
33 namespace content { 35 namespace content {
34 36
35 class ServiceWorkerContextCore; 37 class ServiceWorkerContextCore;
36 class ServiceWorkerDiskCache; 38 class ServiceWorkerDiskCache;
37 class ServiceWorkerRegistration; 39 class ServiceWorkerRegistration;
38 class ServiceWorkerRegistrationInfo; 40 class ServiceWorkerRegistrationInfo;
39 class ServiceWorkerResponseReader; 41 class ServiceWorkerResponseReader;
40 class ServiceWorkerResponseWriter; 42 class ServiceWorkerResponseWriter;
(...skipping 13 matching lines...) Expand all
54 GetAllRegistrationInfosCallback; 56 GetAllRegistrationInfosCallback;
55 typedef base::Callback< 57 typedef base::Callback<
56 void(ServiceWorkerStatusCode status, bool are_equal)> 58 void(ServiceWorkerStatusCode status, bool are_equal)>
57 CompareCallback; 59 CompareCallback;
58 60
59 virtual ~ServiceWorkerStorage(); 61 virtual ~ServiceWorkerStorage();
60 62
61 static scoped_ptr<ServiceWorkerStorage> Create( 63 static scoped_ptr<ServiceWorkerStorage> Create(
62 const base::FilePath& path, 64 const base::FilePath& path,
63 base::WeakPtr<ServiceWorkerContextCore> context, 65 base::WeakPtr<ServiceWorkerContextCore> context,
64 const scoped_refptr<base::SequencedTaskRunner>& database_task_runner, 66 scoped_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager,
65 const scoped_refptr<base::SingleThreadTaskRunner>& disk_cache_thread, 67 const scoped_refptr<base::SingleThreadTaskRunner>& disk_cache_thread,
66 storage::QuotaManagerProxy* quota_manager_proxy); 68 storage::QuotaManagerProxy* quota_manager_proxy,
69 storage::SpecialStoragePolicy* special_storage_policy);
67 70
68 // Used for DeleteAndStartOver. Creates new storage based on |old_storage|. 71 // Used for DeleteAndStartOver. Creates new storage based on |old_storage|.
69 static scoped_ptr<ServiceWorkerStorage> Create( 72 static scoped_ptr<ServiceWorkerStorage> Create(
70 base::WeakPtr<ServiceWorkerContextCore> context, 73 base::WeakPtr<ServiceWorkerContextCore> context,
71 ServiceWorkerStorage* old_storage); 74 ServiceWorkerStorage* old_storage);
72 75
73 // Finds registration for |document_url| or |pattern| or |registration_id|. 76 // Finds registration for |document_url| or |pattern| or |registration_id|.
74 // The Find methods will find stored and initially installing registrations. 77 // The Find methods will find stored and initially installing registrations.
75 // Returns SERVICE_WORKER_OK with non-null registration if registration 78 // Returns SERVICE_WORKER_OK with non-null registration if registration
76 // 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
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest, 171 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest,
169 DeleteRegistration_NoLiveVersion); 172 DeleteRegistration_NoLiveVersion);
170 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest, 173 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest,
171 DeleteRegistration_WaitingVersion); 174 DeleteRegistration_WaitingVersion);
172 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest, 175 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest,
173 DeleteRegistration_ActiveVersion); 176 DeleteRegistration_ActiveVersion);
174 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest, 177 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest,
175 UpdateRegistration); 178 UpdateRegistration);
176 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageDiskTest, 179 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageDiskTest,
177 CleanupOnRestart); 180 CleanupOnRestart);
181 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageDiskTest,
182 ClearOnExit);
178 183
179 struct InitialData { 184 struct InitialData {
180 int64 next_registration_id; 185 int64 next_registration_id;
181 int64 next_version_id; 186 int64 next_version_id;
182 int64 next_resource_id; 187 int64 next_resource_id;
183 std::set<GURL> origins; 188 std::set<GURL> origins;
184 189
185 InitialData(); 190 InitialData();
186 ~InitialData(); 191 ~InitialData();
187 }; 192 };
(...skipping 28 matching lines...) Expand all
216 const ServiceWorkerDatabase::RegistrationData& data, 221 const ServiceWorkerDatabase::RegistrationData& data,
217 const ResourceList& resources, 222 const ResourceList& resources,
218 ServiceWorkerDatabase::Status status)> FindInDBCallback; 223 ServiceWorkerDatabase::Status status)> FindInDBCallback;
219 typedef base::Callback<void(const std::vector<int64>& resource_ids, 224 typedef base::Callback<void(const std::vector<int64>& resource_ids,
220 ServiceWorkerDatabase::Status status)> 225 ServiceWorkerDatabase::Status status)>
221 GetResourcesCallback; 226 GetResourcesCallback;
222 227
223 ServiceWorkerStorage( 228 ServiceWorkerStorage(
224 const base::FilePath& path, 229 const base::FilePath& path,
225 base::WeakPtr<ServiceWorkerContextCore> context, 230 base::WeakPtr<ServiceWorkerContextCore> context,
226 const scoped_refptr<base::SequencedTaskRunner>& database_task_runner, 231 scoped_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager,
227 const scoped_refptr<base::SingleThreadTaskRunner>& disk_cache_thread, 232 const scoped_refptr<base::SingleThreadTaskRunner>& disk_cache_thread,
228 storage::QuotaManagerProxy* quota_manager_proxy); 233 storage::QuotaManagerProxy* quota_manager_proxy,
234 storage::SpecialStoragePolicy* special_storage_policy);
229 235
230 base::FilePath GetDatabasePath(); 236 base::FilePath GetDatabasePath();
231 base::FilePath GetDiskCachePath(); 237 base::FilePath GetDiskCachePath();
232 238
233 bool LazyInitialize( 239 bool LazyInitialize(
234 const base::Closure& callback); 240 const base::Closure& callback);
235 void DidReadInitialData( 241 void DidReadInitialData(
236 InitialData* data, 242 InitialData* data,
237 ServiceWorkerDatabase::Status status); 243 ServiceWorkerDatabase::Status status);
238 void DidFindRegistrationForDocument( 244 void DidFindRegistrationForDocument(
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 void PurgeResource(int64 id); 301 void PurgeResource(int64 id);
296 void OnResourcePurged(int64 id, int rv); 302 void OnResourcePurged(int64 id, int rv);
297 303
298 // Deletes purgeable and uncommitted resources left over from the previous 304 // Deletes purgeable and uncommitted resources left over from the previous
299 // browser session. This must be called once per session before any database 305 // browser session. This must be called once per session before any database
300 // operation that may mutate the purgeable or uncommitted resource lists. 306 // operation that may mutate the purgeable or uncommitted resource lists.
301 void DeleteStaleResources(); 307 void DeleteStaleResources();
302 void DidCollectStaleResources(const std::vector<int64>& stale_resource_ids, 308 void DidCollectStaleResources(const std::vector<int64>& stale_resource_ids,
303 ServiceWorkerDatabase::Status status); 309 ServiceWorkerDatabase::Status status);
304 310
311 void ClearSessionOnlyOrigins();
312
305 // Static cross-thread helpers. 313 // Static cross-thread helpers.
306 static void CollectStaleResourcesFromDB( 314 static void CollectStaleResourcesFromDB(
307 ServiceWorkerDatabase* database, 315 ServiceWorkerDatabase* database,
308 scoped_refptr<base::SequencedTaskRunner> original_task_runner, 316 scoped_refptr<base::SequencedTaskRunner> original_task_runner,
309 const GetResourcesCallback& callback); 317 const GetResourcesCallback& callback);
310 static void ReadInitialDataFromDB( 318 static void ReadInitialDataFromDB(
311 ServiceWorkerDatabase* database, 319 ServiceWorkerDatabase* database,
312 scoped_refptr<base::SequencedTaskRunner> original_task_runner, 320 scoped_refptr<base::SequencedTaskRunner> original_task_runner,
313 const InitializeCallback& callback); 321 const InitializeCallback& callback);
314 static void DeleteRegistrationFromDB( 322 static void DeleteRegistrationFromDB(
(...skipping 17 matching lines...) Expand all
332 ServiceWorkerDatabase* database, 340 ServiceWorkerDatabase* database,
333 scoped_refptr<base::SequencedTaskRunner> original_task_runner, 341 scoped_refptr<base::SequencedTaskRunner> original_task_runner,
334 const GURL& scope, 342 const GURL& scope,
335 const FindInDBCallback& callback); 343 const FindInDBCallback& callback);
336 static void FindForIdInDB( 344 static void FindForIdInDB(
337 ServiceWorkerDatabase* database, 345 ServiceWorkerDatabase* database,
338 scoped_refptr<base::SequencedTaskRunner> original_task_runner, 346 scoped_refptr<base::SequencedTaskRunner> original_task_runner,
339 int64 registration_id, 347 int64 registration_id,
340 const GURL& origin, 348 const GURL& origin,
341 const FindInDBCallback& callback); 349 const FindInDBCallback& callback);
350 static void DeleteAllDataForOriginsFromDB(
351 ServiceWorkerDatabase* database,
352 const std::set<GURL>& origins);
342 353
343 void ScheduleDeleteAndStartOver(); 354 void ScheduleDeleteAndStartOver();
344 void DidDeleteDatabase( 355 void DidDeleteDatabase(
345 const StatusCallback& callback, 356 const StatusCallback& callback,
346 ServiceWorkerDatabase::Status status); 357 ServiceWorkerDatabase::Status status);
347 void DidDeleteDiskCache( 358 void DidDeleteDiskCache(
348 const StatusCallback& callback, 359 const StatusCallback& callback,
349 bool result); 360 bool result);
350 361
351 // For finding registrations being installed or uninstalled. 362 // For finding registrations being installed or uninstalled.
(...skipping 14 matching lines...) Expand all
366 UNINITIALIZED, 377 UNINITIALIZED,
367 INITIALIZING, 378 INITIALIZING,
368 INITIALIZED, 379 INITIALIZED,
369 DISABLED, 380 DISABLED,
370 }; 381 };
371 State state_; 382 State state_;
372 383
373 base::FilePath path_; 384 base::FilePath path_;
374 base::WeakPtr<ServiceWorkerContextCore> context_; 385 base::WeakPtr<ServiceWorkerContextCore> context_;
375 386
376 // Only accessed on |database_task_runner_|. 387 // Only accessed using |database_task_manager_|.
377 scoped_ptr<ServiceWorkerDatabase> database_; 388 scoped_ptr<ServiceWorkerDatabase> database_;
378 389
379 scoped_refptr<base::SequencedTaskRunner> database_task_runner_; 390 scoped_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager_;
380 scoped_refptr<base::SingleThreadTaskRunner> disk_cache_thread_; 391 scoped_refptr<base::SingleThreadTaskRunner> disk_cache_thread_;
381 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_; 392 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_;
393 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy_;
382 scoped_ptr<ServiceWorkerDiskCache> disk_cache_; 394 scoped_ptr<ServiceWorkerDiskCache> disk_cache_;
383 std::deque<int64> purgeable_resource_ids_; 395 std::deque<int64> purgeable_resource_ids_;
384 bool is_purge_pending_; 396 bool is_purge_pending_;
385 bool has_checked_for_stale_resources_; 397 bool has_checked_for_stale_resources_;
386 std::set<int64> pending_deletions_; 398 std::set<int64> pending_deletions_;
387 399
388 base::WeakPtrFactory<ServiceWorkerStorage> weak_factory_; 400 base::WeakPtrFactory<ServiceWorkerStorage> weak_factory_;
389 401
390 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerStorage); 402 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerStorage);
391 }; 403 };
392 404
393 } // namespace content 405 } // namespace content
394 406
395 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_ 407 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698