OLD | NEW |
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" |
(...skipping 18 matching lines...) Expand all Loading... |
29 public: | 29 public: |
30 typedef base::Callback<void(ServiceWorkerStatusCode status)> StatusCallback; | 30 typedef base::Callback<void(ServiceWorkerStatusCode status)> StatusCallback; |
31 typedef base::Callback<void(ServiceWorkerStatusCode status, | 31 typedef base::Callback<void(ServiceWorkerStatusCode status, |
32 const scoped_refptr<ServiceWorkerRegistration>& | 32 const scoped_refptr<ServiceWorkerRegistration>& |
33 registration)> FindRegistrationCallback; | 33 registration)> FindRegistrationCallback; |
34 | 34 |
35 ServiceWorkerStorage(const base::FilePath& path, | 35 ServiceWorkerStorage(const base::FilePath& path, |
36 quota::QuotaManagerProxy* quota_manager_proxy); | 36 quota::QuotaManagerProxy* quota_manager_proxy); |
37 ~ServiceWorkerStorage(); | 37 ~ServiceWorkerStorage(); |
38 | 38 |
39 // Finds registration for |document_url| or |pattern|. | 39 // Finds registration for |document_url| or |pattern| or |registraion_id|. |
40 // Returns SERVICE_WORKER_OK with non-null registration if registration | 40 // Returns SERVICE_WORKER_OK with non-null registration if registration |
41 // is found, or returns SERVICE_WORKER_ERROR_NOT_FOUND if no matching | 41 // is found, or returns SERVICE_WORKER_ERROR_NOT_FOUND if no matching |
42 // registration is found. | 42 // registration is found. |
43 void FindRegistrationForDocument(const GURL& document_url, | 43 void FindRegistrationForDocument(const GURL& document_url, |
44 const FindRegistrationCallback& callback); | 44 const FindRegistrationCallback& callback); |
45 void FindRegistrationForPattern(const GURL& pattern, | 45 void FindRegistrationForPattern(const GURL& pattern, |
46 const FindRegistrationCallback& callback); | 46 const FindRegistrationCallback& callback); |
| 47 void FindRegistrationForId(int64 registration_id, |
| 48 const FindRegistrationCallback& callback); |
47 | 49 |
48 // Stores |registration|. Returns SERVICE_WORKER_ERROR_EXISTS if | 50 // Stores |registration|. Returns SERVICE_WORKER_ERROR_EXISTS if |
49 // conflicting registration (which has different script_url) is | 51 // conflicting registration (which has different script_url) is |
50 // already registered for the |registration|->pattern(). | 52 // already registered for the |registration|->pattern(). |
51 void StoreRegistration(ServiceWorkerRegistration* registration, | 53 void StoreRegistration(ServiceWorkerRegistration* registration, |
52 const StatusCallback& callback); | 54 const StatusCallback& callback); |
53 | 55 |
54 // Deletes |registration|. This may return SERVICE_WORKER_ERROR_NOT_FOUND | 56 // Deletes |registration|. This may return SERVICE_WORKER_ERROR_NOT_FOUND |
55 // if no matching registration is found. | 57 // if no matching registration is found. |
56 void DeleteRegistration(const GURL& pattern, | 58 void DeleteRegistration(const GURL& pattern, |
57 const StatusCallback& callback); | 59 const StatusCallback& callback); |
58 | 60 |
59 // Returns new registration ID which is guaranteed to be unique in | 61 // Returns new registration ID which is guaranteed to be unique in |
60 // the storage. | 62 // the storage. |
61 int64 NewRegistrationId(); | 63 int64 NewRegistrationId(); |
62 | 64 |
63 private: | 65 private: |
64 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerStorageTest, PatternMatches); | 66 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerStorageTest, PatternMatches); |
65 | 67 |
66 typedef std::map<GURL, scoped_refptr<ServiceWorkerRegistration> > | 68 typedef std::map<GURL, scoped_refptr<ServiceWorkerRegistration> > |
67 PatternToRegistrationMap; | 69 PatternToRegistrationMap; |
| 70 typedef std::map<int64, scoped_refptr<ServiceWorkerRegistration> > |
| 71 RegistrationIdToRegistrationMap; |
68 | 72 |
69 static bool PatternMatches(const GURL& pattern, const GURL& script_url); | 73 static bool PatternMatches(const GURL& pattern, const GURL& script_url); |
70 | 74 |
71 // This is the in-memory registration. Eventually the registration will be | 75 // This is the in-memory registration. Eventually the registration will be |
72 // persisted to disk. | 76 // persisted to disk. |
73 PatternToRegistrationMap registration_by_pattern_; | 77 PatternToRegistrationMap registration_by_pattern_; |
74 | 78 |
75 int last_registration_id_; | 79 int last_registration_id_; |
76 | 80 |
77 scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; | 81 scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; |
78 base::FilePath path_; | 82 base::FilePath path_; |
79 | 83 |
80 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerStorage); | 84 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerStorage); |
81 }; | 85 }; |
82 | 86 |
83 } // namespace content | 87 } // namespace content |
84 | 88 |
85 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_ | 89 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_ |
OLD | NEW |