 Chromium Code Reviews
 Chromium Code Reviews Issue 62203007:
  Implement memory-persistent registration  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 62203007:
  Implement memory-persistent registration  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| Index: content/browser/service_worker/service_worker_context.h | 
| diff --git a/content/browser/service_worker/service_worker_context.h b/content/browser/service_worker/service_worker_context.h | 
| index f69599ca4c12a7f7cfddab0cc14c5d4c494afede..7e1a1489dcca7888dec133bb97d0c00b46361d07 100644 | 
| --- a/content/browser/service_worker/service_worker_context.h | 
| +++ b/content/browser/service_worker/service_worker_context.h | 
| @@ -5,9 +5,17 @@ | 
| #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_H_ | 
| #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_H_ | 
| +#include <map> | 
| +#include <string> | 
| + | 
| +#include "base/bind.h" | 
| +#include "base/containers/hash_tables.h" | 
| +#include "base/containers/scoped_ptr_hash_map.h" | 
| #include "base/files/file_path.h" | 
| #include "base/memory/ref_counted.h" | 
| +#include "content/browser/service_worker/service_worker_registration.h" | 
| #include "content/common/content_export.h" | 
| +#include "url/gurl.h" | 
| namespace base { | 
| class FilePath; | 
| @@ -19,13 +27,16 @@ class QuotaManagerProxy; | 
| namespace content { | 
| +class ServiceWorkerRegistration; | 
| + | 
| // This class manages metadata associated with all service workers, | 
| // including: | 
| // - persistent storage of pattern -> service worker scripts | 
| // - initialization and initial installation of service workers | 
| // - dispatching of non-fetch events to service workers | 
| class CONTENT_EXPORT ServiceWorkerContext | 
| - : public base::RefCountedThreadSafe<ServiceWorkerContext> { | 
| + : NON_EXPORTED_BASE( | 
| + public base::RefCountedThreadSafe<ServiceWorkerContext>) { | 
| public: | 
| // This is owned by the StoragePartition, which will supply it with | 
| // the local path on disk. | 
| @@ -33,6 +44,31 @@ class CONTENT_EXPORT ServiceWorkerContext | 
| quota::QuotaManagerProxy* quota_manager_proxy); | 
| bool IsEnabled(); | 
| + typedef base::Callback<void(int64)> ResponseCallback; | 
| 
kinuko
2013/11/08 09:08:21
nit: please move this typedef before all other met
 
alecflett
2013/11/08 22:50:54
Done.
 | 
| + | 
| + // The callback will be called on the IO thread. | 
| + void RegisterServiceWorker(const GURL& pattern, | 
| + const GURL& script_url, | 
| + const ResponseCallback& callback); | 
| + | 
| + // The callback will be called on the IO thread. | 
| + void UnregisterServiceWorker(const GURL& pattern, | 
| + const base::Closure& callback); | 
| + | 
| + // TODO(alecflett): These exist primarily for testing. As this class | 
| + // evolves to have persistent storage, they will need to become | 
| + // asynchronous. | 
| + scoped_refptr<ServiceWorkerRegistration> RegistrationForDocument( | 
| + const GURL& document_url); | 
| + scoped_refptr<ServiceWorkerRegistration> RegistrationForPattern( | 
| + const GURL& pattern); | 
| + | 
| + static bool PatternMatches(const GURL& pattern, const GURL& script_url); | 
| + | 
| + // TODO(alecflett): Propagate errors. Are there any? | 
| + ServiceWorkerRegistration* Register(const GURL& pattern, | 
| + const GURL& script_url); | 
| + void Unregister(const GURL& pattern); | 
| 
kinuko
2013/11/08 09:08:21
We do seem to have lots of register/registration m
 
alecflett
2013/11/08 22:50:54
Done.
They were there for testing, I found a bette
 | 
| private: | 
| friend class base::RefCountedThreadSafe<ServiceWorkerContext>; | 
| @@ -41,6 +77,13 @@ class CONTENT_EXPORT ServiceWorkerContext | 
| scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; | 
| base::FilePath path_; | 
| + // Mapping of url pattern -> script instance | 
| + // eventually the registration should be stored in leveldb, not in memory. | 
| + typedef std::map<GURL, scoped_refptr<ServiceWorkerRegistration> > | 
| 
kinuko
2013/11/08 09:08:21
I think this has been discussed once, but do we co
 
alecflett
2013/11/08 22:50:54
I'm fine changing it. Can I do that in a separate
 | 
| + PatternToRegistrationMap; | 
| + | 
| + PatternToRegistrationMap registration_by_pattern_; | 
| + | 
| DISALLOW_COPY_AND_ASSIGN(ServiceWorkerContext); | 
| }; |