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

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

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

Powered by Google App Engine
This is Rietveld 408576698