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