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

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: More 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/common/content_export.h"
15 #include "url/gurl.h"
16
17 namespace quota {
18 class QuotaManagerProxy;
19 }
20
21 namespace content {
22
23 class ServiceWorkerRegistration;
24 class ServiceWorkerRegisterJob;
25
26 // This class provides an interface to load registration data and
27 // instantiate ServiceWorkerRegistration objects. Any asynchronous
28 // operations are run through instances of ServiceWorkerRegisterJob.
29 class CONTENT_EXPORT ServiceWorkerStorage {
30 public:
31 ServiceWorkerStorage(const base::FilePath& path,
32 quota::QuotaManagerProxy* quota_manager_proxy);
33 ~ServiceWorkerStorage();
34
35 // This enum is used to describe the final result of a registration flow.
36 enum RegistrationStatus {
37 REGISTRATION_OK,
38 REGISTRATION_NOT_FOUND,
39 REGISTRATION_INSTALL_FAILED,
40 REGISTRATION_ACTIVATE_FAILED,
41 UNREGISTER_FAILED,
42 };
kinuko 2013/11/27 03:45:23 If this (or similar) enum is needed by multiple cl
alecflett 2013/12/02 16:11:35 Sure.
43
44 void Shutdown();
45
46 typedef base::Callback<
47 void(RegistrationStatus, const scoped_refptr<ServiceWorkerRegistration>&)>
48 RegistrationCallback;
49 typedef base::Callback<void(RegistrationStatus)> UnregistrationCallback;
50
51 void FindRegistrationForDocument(const GURL& document_url,
52 const RegistrationCallback& callback);
53 void FindRegistrationForPattern(const GURL& pattern,
54 const RegistrationCallback& callback);
55
56 void Register(const GURL& pattern,
57 const GURL& script_url,
58 const RegistrationCallback& callback);
59
60 void Unregister(const GURL& pattern, const UnregistrationCallback& callback);
61
62 private:
63 friend class ServiceWorkerRegisterJob;
64 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerStorageTest, RegisterMatch);
65
66 // TODO(alecflett): These are temporary internal methods providing
67 // synchronous in-memory registration. Eventually these will be
68 // replaced by asynchronous methods that persist registration to disk.
69 scoped_refptr<ServiceWorkerRegistration> RegisterInternal(
70 const GURL& pattern,
71 const GURL& script_url);
72 void UnregisterInternal(const GURL& pattern);
73 static bool PatternMatches(const GURL& pattern, const GURL& script_url);
74
75 // Jobs are removed whenever they are finished or canceled.
76 void EraseJob(ServiceWorkerRegisterJob* job);
77
78 // Called at ServiceWorkerRegisterJob completion.
79 void RegisterComplete(const RegistrationCallback& callback,
80 ServiceWorkerRegisterJob* job,
81 RegistrationStatus status,
82 ServiceWorkerRegistration* registration);
83
84 // Called at ServiceWorkerRegisterJob completion.
85 void UnregisterComplete(const UnregistrationCallback& callback,
86 ServiceWorkerRegisterJob* job,
87 RegistrationStatus status,
88 ServiceWorkerRegistration* registration);
89
90 // This is the in-memory registration. Eventually the registration will be per sisted to disk.
kinuko 2013/11/27 03:45:23 nit: over 80 cols
91 typedef std::map<GURL, scoped_refptr<ServiceWorkerRegistration> >
92 PatternToRegistrationMap;
93 typedef ScopedVector<ServiceWorkerRegisterJob> RegistrationJobList;
94
95 // A list of currently running jobs. This is a temporary structure until we
96 // start managing overlapping registrations explicitly.
97 RegistrationJobList registration_jobs_;
98
99 // in-memory map, to eventually be replaced with persistence
100 PatternToRegistrationMap registration_by_pattern_;
101 scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_;
102 base::FilePath path_;
103 base::WeakPtrFactory<ServiceWorkerStorage> weak_factory_;
104
105 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerStorage);
106 };
107
108 } // namespace content
109
110 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698