| 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_REGISTER_JOB_H_ | 
|  | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTER_JOB_H_ | 
|  | 7 | 
|  | 8 #include "base/memory/weak_ptr.h" | 
|  | 9 #include "content/browser/service_worker/service_worker_registration_status.h" | 
|  | 10 #include "content/browser/service_worker/service_worker_storage.h" | 
|  | 11 | 
|  | 12 namespace content { | 
|  | 13 | 
|  | 14 // A ServiceWorkerRegisterJob lives only for the lifetime of a single | 
|  | 15 // registration or unregistration. | 
|  | 16 class ServiceWorkerRegisterJob { | 
|  | 17  public: | 
|  | 18   typedef base::Callback<void( | 
|  | 19       ServiceWorkerRegisterJob* job, | 
|  | 20       ServiceWorkerRegistrationStatus status, | 
|  | 21       ServiceWorkerRegistration* registration)> RegistrationCompleteCallback; | 
|  | 22 | 
|  | 23   // All type of jobs (Register and Unregister) complete through a | 
|  | 24   // single call to this callback on the IO thread. | 
|  | 25   ServiceWorkerRegisterJob(const base::WeakPtr<ServiceWorkerStorage>& storage, | 
|  | 26                            const RegistrationCompleteCallback& callback); | 
|  | 27   ~ServiceWorkerRegisterJob(); | 
|  | 28 | 
|  | 29   // The Registration flow includes most or all of the following, | 
|  | 30   // depending on what is already registered: | 
|  | 31   //  - creating a ServiceWorkerRegistration instance if there isn't | 
|  | 32   //    already something registered | 
|  | 33   //  - creating a ServiceWorkerVersion for the new registration instance. | 
|  | 34   //  - starting a worker for the ServiceWorkerVersion | 
|  | 35   //  - telling the Version to evaluate the script | 
|  | 36   //  - firing the 'install' event at the ServiceWorkerVersion | 
|  | 37   //  - firing the 'activate' event at the ServiceWorkerVersion | 
|  | 38   //  - Waiting for older ServiceWorkerVersions to deactivate | 
|  | 39   //  - designating the new version to be the 'active' version | 
|  | 40   // This method should be called once and only once per job. | 
|  | 41   void StartRegister(const GURL& pattern, const GURL& script_url); | 
|  | 42 | 
|  | 43   // The Unregistration process is primarily cleanup, removing | 
|  | 44   // everything that was created during the Registration process, | 
|  | 45   // including the ServiceWorkerRegistration itself. | 
|  | 46   // This method should be called once and only once per job. | 
|  | 47   void StartUnregister(const GURL& pattern); | 
|  | 48 | 
|  | 49  private: | 
|  | 50   // These are all steps in the registration and unregistration pipeline. | 
|  | 51   void RegisterPatternAndContinue( | 
|  | 52       const GURL& pattern, | 
|  | 53       const GURL& script_url, | 
|  | 54       const ServiceWorkerStorage::RegistrationCallback& callback, | 
|  | 55       ServiceWorkerRegistrationStatus previous_status); | 
|  | 56 | 
|  | 57   void UnregisterPatternAndContinue( | 
|  | 58       const GURL& pattern, | 
|  | 59       const GURL& script_url, | 
|  | 60       const ServiceWorkerStorage::UnregistrationCallback& callback, | 
|  | 61       ServiceWorkerRegistrationStatus previous_status, | 
|  | 62       const scoped_refptr<ServiceWorkerRegistration>& previous_registration); | 
|  | 63 | 
|  | 64   // These methods are the last internal callback in the callback | 
|  | 65   // chain, and ultimately call callback_. | 
|  | 66   void UnregisterComplete(ServiceWorkerRegistrationStatus status); | 
|  | 67   void RegisterComplete( | 
|  | 68       ServiceWorkerRegistrationStatus status, | 
|  | 69       const scoped_refptr<ServiceWorkerRegistration>& registration); | 
|  | 70 | 
|  | 71   const base::WeakPtr<ServiceWorkerStorage> storage_; | 
|  | 72   const RegistrationCompleteCallback callback_; | 
|  | 73   base::WeakPtrFactory<ServiceWorkerRegisterJob> weak_factory_; | 
|  | 74 | 
|  | 75   DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegisterJob); | 
|  | 76 }; | 
|  | 77 }  // namespace content | 
|  | 78 | 
|  | 79 #endif  // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTER_JOB_H_ | 
| OLD | NEW | 
|---|