 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| 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_CONTEXT_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_H_ | 
| 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_H_ | 
| 7 | 7 | 
| 8 #include <map> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/bind.h" | |
| 12 #include "base/containers/hash_tables.h" | |
| 13 #include "base/containers/scoped_ptr_hash_map.h" | |
| 8 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" | 
| 9 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" | 
| 16 #include "content/browser/service_worker/service_worker_registration.h" | |
| 10 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" | 
| 18 #include "url/gurl.h" | |
| 11 | 19 | 
| 12 namespace base { | 20 namespace base { | 
| 13 class FilePath; | 21 class FilePath; | 
| 14 } | 22 } | 
| 15 | 23 | 
| 16 namespace quota { | 24 namespace quota { | 
| 17 class QuotaManagerProxy; | 25 class QuotaManagerProxy; | 
| 18 } | 26 } | 
| 19 | 27 | 
| 20 namespace content { | 28 namespace content { | 
| 21 | 29 | 
| 30 class ServiceWorkerRegistration; | |
| 31 | |
| 22 // This class manages metadata associated with all service workers, | 32 // This class manages metadata associated with all service workers, | 
| 23 // including: | 33 // including: | 
| 24 // - persistent storage of pattern -> service worker scripts | 34 // - persistent storage of pattern -> service worker scripts | 
| 25 // - initialization and initial installation of service workers | 35 // - initialization and initial installation of service workers | 
| 26 // - dispatching of non-fetch events to service workers | 36 // - dispatching of non-fetch events to service workers | 
| 27 class CONTENT_EXPORT ServiceWorkerContext | 37 class CONTENT_EXPORT ServiceWorkerContext | 
| 28 : public base::RefCountedThreadSafe<ServiceWorkerContext> { | 38 : NON_EXPORTED_BASE( | 
| 39 public base::RefCountedThreadSafe<ServiceWorkerContext>) { | |
| 29 public: | 40 public: | 
| 30 // This is owned by the StoragePartition, which will supply it with | 41 // This is owned by the StoragePartition, which will supply it with | 
| 31 // the local path on disk. | 42 // the local path on disk. | 
| 32 ServiceWorkerContext(const base::FilePath& path, | 43 ServiceWorkerContext(const base::FilePath& path, | 
| 33 quota::QuotaManagerProxy* quota_manager_proxy); | 44 quota::QuotaManagerProxy* quota_manager_proxy); | 
| 34 | 45 | 
| 35 bool IsEnabled(); | 46 bool IsEnabled(); | 
| 47 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.
 | |
| 48 | |
| 49 // The callback will be called on the IO thread. | |
| 50 void RegisterServiceWorker(const GURL& pattern, | |
| 51 const GURL& script_url, | |
| 52 const ResponseCallback& callback); | |
| 53 | |
| 54 // The callback will be called on the IO thread. | |
| 55 void UnregisterServiceWorker(const GURL& pattern, | |
| 56 const base::Closure& callback); | |
| 57 | |
| 58 // TODO(alecflett): These exist primarily for testing. As this class | |
| 59 // evolves to have persistent storage, they will need to become | |
| 60 // asynchronous. | |
| 61 scoped_refptr<ServiceWorkerRegistration> RegistrationForDocument( | |
| 62 const GURL& document_url); | |
| 63 scoped_refptr<ServiceWorkerRegistration> RegistrationForPattern( | |
| 64 const GURL& pattern); | |
| 65 | |
| 66 static bool PatternMatches(const GURL& pattern, const GURL& script_url); | |
| 67 | |
| 68 // TODO(alecflett): Propagate errors. Are there any? | |
| 69 ServiceWorkerRegistration* Register(const GURL& pattern, | |
| 70 const GURL& script_url); | |
| 71 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
 | |
| 36 | 72 | 
| 37 private: | 73 private: | 
| 38 friend class base::RefCountedThreadSafe<ServiceWorkerContext>; | 74 friend class base::RefCountedThreadSafe<ServiceWorkerContext>; | 
| 39 ~ServiceWorkerContext(); | 75 ~ServiceWorkerContext(); | 
| 40 | 76 | 
| 41 scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; | 77 scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; | 
| 42 base::FilePath path_; | 78 base::FilePath path_; | 
| 43 | 79 | 
| 80 // Mapping of url pattern -> script instance | |
| 81 // eventually the registration should be stored in leveldb, not in memory. | |
| 82 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
 | |
| 83 PatternToRegistrationMap; | |
| 84 | |
| 85 PatternToRegistrationMap registration_by_pattern_; | |
| 86 | |
| 44 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerContext); | 87 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerContext); | 
| 45 }; | 88 }; | 
| 46 | 89 | 
| 47 } // namespace content | 90 } // namespace content | 
| 48 | 91 | 
| 49 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_H_ | 92 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_H_ | 
| OLD | NEW |