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

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

Issue 113133013: Refactor job coordination into a separate class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove WeakPtr usage from Storage Created 6 years, 11 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 <map> 8 #include <map>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/memory/scoped_vector.h" 13 #include "base/memory/scoped_vector.h"
14 #include "content/browser/service_worker/service_worker_registration_status.h" 14 #include "content/browser/service_worker/service_worker_registration_status.h"
15 #include "content/common/content_export.h" 15 #include "content/common/content_export.h"
16 #include "url/gurl.h" 16 #include "url/gurl.h"
17 17
18 namespace quota { 18 namespace quota {
19 class QuotaManagerProxy; 19 class QuotaManagerProxy;
20 } 20 }
21 21
22 namespace content { 22 namespace content {
23 23
24 class ServiceWorkerRegistration; 24 class ServiceWorkerRegistration;
25 class ServiceWorkerRegisterJob;
26 25
27 // This class provides an interface to load registration data and 26 // This class provides an interface to load registration data and
28 // instantiate ServiceWorkerRegistration objects. Any asynchronous 27 // instantiate ServiceWorkerRegistration objects.
29 // operations are run through instances of ServiceWorkerRegisterJob.
30 class CONTENT_EXPORT ServiceWorkerStorage { 28 class CONTENT_EXPORT ServiceWorkerStorage {
31 public: 29 public:
32 ServiceWorkerStorage(const base::FilePath& path, 30 ServiceWorkerStorage(const base::FilePath& path,
33 quota::QuotaManagerProxy* quota_manager_proxy); 31 quota::QuotaManagerProxy* quota_manager_proxy);
34 ~ServiceWorkerStorage(); 32 ~ServiceWorkerStorage();
35 33
36 typedef base::Callback<void(ServiceWorkerRegistrationStatus status,
37 const scoped_refptr<ServiceWorkerRegistration>&
38 registration)> RegistrationCallback;
39 typedef base::Callback<
40 void(ServiceWorkerRegistrationStatus status)> UnregistrationCallback;
41
42 // `found` is only valid if status == REGISTRATION_OK. 34 // `found` is only valid if status == REGISTRATION_OK.
43 typedef base::Callback<void(bool found, 35 typedef base::Callback<void(bool found,
44 ServiceWorkerRegistrationStatus status, 36 ServiceWorkerRegistrationStatus status,
45 const scoped_refptr<ServiceWorkerRegistration>& 37 const scoped_refptr<ServiceWorkerRegistration>&
46 registration)> FindRegistrationCallback; 38 registration)> FindRegistrationCallback;
47 39
48 void FindRegistrationForDocument(const GURL& document_url, 40 void FindRegistrationForDocument(const GURL& document_url,
49 const FindRegistrationCallback& callback); 41 const FindRegistrationCallback& callback);
50 void FindRegistrationForPattern(const GURL& pattern, 42 void FindRegistrationForPattern(const GURL& pattern,
51 const FindRegistrationCallback& callback); 43 const FindRegistrationCallback& callback);
52 44
53 void Register(const GURL& pattern,
54 const GURL& script_url,
55 const RegistrationCallback& callback);
56
57 void Unregister(const GURL& pattern, const UnregistrationCallback& callback);
58
59 private:
60 friend class ServiceWorkerRegisterJob;
61 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerStorageTest, PatternMatches);
62
63 typedef std::map<GURL, scoped_refptr<ServiceWorkerRegistration> >
64 PatternToRegistrationMap;
65 typedef ScopedVector<ServiceWorkerRegisterJob> RegistrationJobList;
66
67 // TODO(alecflett): These are temporary internal methods providing 45 // TODO(alecflett): These are temporary internal methods providing
68 // synchronous in-memory registration. Eventually these will be 46 // synchronous in-memory registration. Eventually these will be
69 // replaced by asynchronous methods that persist registration to disk. 47 // replaced by asynchronous methods that persist registration to disk.
70 scoped_refptr<ServiceWorkerRegistration> RegisterInternal( 48 scoped_refptr<ServiceWorkerRegistration> RegisterInternal(
71 const GURL& pattern, 49 const GURL& pattern,
72 const GURL& script_url); 50 const GURL& script_url);
73 void UnregisterInternal(const GURL& pattern); 51 void UnregisterInternal(const GURL& pattern);
52
53 private:
54 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerStorageTest, PatternMatches);
55
56 typedef std::map<GURL, scoped_refptr<ServiceWorkerRegistration> >
57 PatternToRegistrationMap;
58
74 static bool PatternMatches(const GURL& pattern, const GURL& script_url); 59 static bool PatternMatches(const GURL& pattern, const GURL& script_url);
75 60
76 // Jobs are removed whenever they are finished or canceled.
77 void EraseJob(ServiceWorkerRegisterJob* job);
78
79 // Called at ServiceWorkerRegisterJob completion.
80 void RegisterComplete(const RegistrationCallback& callback,
81 ServiceWorkerRegisterJob* job,
82 ServiceWorkerRegistrationStatus status,
83 ServiceWorkerRegistration* registration);
84
85 // Called at ServiceWorkerRegisterJob completion.
86 void UnregisterComplete(const UnregistrationCallback& callback,
87 ServiceWorkerRegisterJob* job,
88 ServiceWorkerRegistrationStatus status,
89 ServiceWorkerRegistration* registration);
90
91 // This is the in-memory registration. Eventually the registration will be 61 // This is the in-memory registration. Eventually the registration will be
92 // persisted to disk. 62 // persisted to disk.
93 // A list of currently running jobs. This is a temporary structure until we 63 PatternToRegistrationMap registration_by_pattern_;
94 // start managing overlapping registrations explicitly.
95 RegistrationJobList registration_jobs_;
96 64
97 // in-memory map, to eventually be replaced with persistence
98 PatternToRegistrationMap registration_by_pattern_;
99 scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; 65 scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_;
100 base::FilePath path_; 66 base::FilePath path_;
101 base::WeakPtrFactory<ServiceWorkerStorage> weak_factory_;
102 67
103 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerStorage); 68 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerStorage);
104 }; 69 };
105 70
106 } // namespace content 71 } // namespace content
107 72
108 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_ 73 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698