 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 | 
|---|---|
| (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. | |
| 28 class CONTENT_EXPORT ServiceWorkerStorage { | |
| 29 public: | |
| 30 ServiceWorkerStorage(const base::FilePath& path, | |
| 31 quota::QuotaManagerProxy* quota_manager_proxy); | |
| 32 ~ServiceWorkerStorage(); | |
| 33 | |
| 34 void Shutdown(); | |
| 35 | |
| 36 typedef base::Callback<void(const scoped_refptr<ServiceWorkerRegistration>&)> | |
| 37 ResponseCallback; | |
| 38 | |
| 39 void FindRegistrationForDocument(const GURL& document_url, | |
| 40 const ResponseCallback& callback); | |
| 41 void FindRegistrationForPattern(const GURL& pattern, | |
| 42 const ResponseCallback& callback); | |
| 43 | |
| 44 void Register(const GURL& pattern, | |
| 45 const GURL& script_url, | |
| 46 const ResponseCallback& callback); | |
| 47 | |
| 48 void Unregister(const GURL& pattern, const base::Closure& callback); | |
| 49 | |
| 50 private: | |
| 51 friend class ServiceWorkerRegisterJob; | |
| 52 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerStorageTest, RegisterMatch); | |
| 53 | |
| 54 void EraseJob(ServiceWorkerRegisterJob* job); | |
| 55 | |
| 56 void RegisterComplete(const ResponseCallback& callback, | |
| 57 ServiceWorkerRegisterJob* job, | |
| 58 ServiceWorkerRegistration* registration); | |
| 59 void UnregisterComplete(const base::Closure& callback, | |
| 60 ServiceWorkerRegisterJob* job, | |
| 61 ServiceWorkerRegistration* registration); | |
| 62 | |
| 63 // TODO(alecflett): These are temporary internal methods mainly for | |
| 64 // exposure to tests. These should eventually call through to some | |
| 65 // sort of ServiceWorkerStorage interface which will be | |
| 66 // asynchronous. | |
| 
kinuko
2013/11/25 08:17:10
Not seem to be really used by tests? (Instead Job
 | |
| 67 scoped_refptr<ServiceWorkerRegistration> RegisterInternal( | |
| 68 const GURL& pattern, | |
| 69 const GURL& script_url); | |
| 70 void UnregisterInternal(const GURL& pattern); | |
| 71 static bool PatternMatches(const GURL& pattern, const GURL& script_url); | |
| 72 | |
| 73 // Eventually the registration should be stored in leveldb, not in | |
| 74 // memory. | |
| 75 typedef std::map<GURL, scoped_refptr<ServiceWorkerRegistration> > | |
| 76 PatternToRegistrationMap; | |
| 77 typedef ScopedVector<ServiceWorkerRegisterJob> RegistrationJobList; | |
| 78 | |
| 79 // currently running jobs. This is a temporary structure until we | |
| 80 // start managing overlapping registrations explicitly. | |
| 81 RegistrationJobList registration_jobs_; | |
| 82 | |
| 83 // in-memory map, to eventually be replaced with persistence | |
| 84 PatternToRegistrationMap registration_by_pattern_; | |
| 85 scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; | |
| 86 base::FilePath path_; | |
| 87 base::WeakPtrFactory<ServiceWorkerStorage> weak_factory_; | |
| 88 | |
| 89 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerStorage); | |
| 90 }; | |
| 91 | |
| 92 } // namespace content | |
| 93 | |
| 94 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_ | |
| OLD | NEW |