| 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_REGISTER_JOB_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTER_JOB_H_ |
| 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTER_JOB_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTER_JOB_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "content/browser/service_worker/service_worker_registration_status.h" | 11 #include "content/browser/service_worker/service_worker_registration_status.h" |
| 12 #include "content/browser/service_worker/service_worker_storage.h" | 12 #include "content/browser/service_worker/service_worker_storage.h" |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 | 15 |
| 16 class ServiceWorkerJobCoordinator; | 16 class ServiceWorkerJobCoordinator; |
| 17 | 17 |
| 18 // A ServiceWorkerRegisterJob lives only for the lifetime of a single | 18 // A ServiceWorkerRegisterJob lives only for the lifetime of a single |
| 19 // registration or unregistration. | 19 // registration or unregistration. |
| 20 class ServiceWorkerRegisterJob { | 20 class ServiceWorkerRegisterJob { |
| 21 public: | 21 public: |
| 22 enum RegistrationType { | 22 enum RegistrationType { |
| 23 REGISTER, | 23 REGISTER, |
| 24 UNREGISTER, | 24 UNREGISTER, |
| 25 }; | 25 }; |
| 26 | 26 |
| 27 typedef base::Callback<void(ServiceWorkerRegistrationStatus status, | 27 typedef base::Callback<void(ServiceWorkerStatusCode status, |
| 28 const scoped_refptr<ServiceWorkerRegistration>& | 28 const scoped_refptr<ServiceWorkerRegistration>& |
| 29 registration)> RegistrationCallback; | 29 registration)> RegistrationCallback; |
| 30 typedef base::Callback<void(ServiceWorkerRegistrationStatus status)> | 30 typedef base::Callback<void(ServiceWorkerStatusCode status)> |
| 31 UnregistrationCallback; | 31 UnregistrationCallback; |
| 32 | 32 |
| 33 // All type of jobs (Register and Unregister) complete through a | 33 // All type of jobs (Register and Unregister) complete through a |
| 34 // single call to this callback on the IO thread. | 34 // single call to this callback on the IO thread. |
| 35 ServiceWorkerRegisterJob(ServiceWorkerStorage* storage, | 35 ServiceWorkerRegisterJob(ServiceWorkerStorage* storage, |
| 36 ServiceWorkerJobCoordinator* coordinator, | 36 ServiceWorkerJobCoordinator* coordinator, |
| 37 const GURL& pattern, | 37 const GURL& pattern, |
| 38 const GURL& script_url, | 38 const GURL& script_url, |
| 39 RegistrationType type); | 39 RegistrationType type); |
| 40 ~ServiceWorkerRegisterJob(); | 40 ~ServiceWorkerRegisterJob(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 62 | 62 |
| 63 // The Unregistration process is primarily cleanup, removing | 63 // The Unregistration process is primarily cleanup, removing |
| 64 // everything that was created during the Registration process, | 64 // everything that was created during the Registration process, |
| 65 // including the ServiceWorkerRegistration itself. | 65 // including the ServiceWorkerRegistration itself. |
| 66 // This method should be called once and only once per job. | 66 // This method should be called once and only once per job. |
| 67 void StartUnregister(); | 67 void StartUnregister(); |
| 68 | 68 |
| 69 // These are all steps in the registration and unregistration pipeline. | 69 // These are all steps in the registration and unregistration pipeline. |
| 70 void RegisterPatternAndContinue( | 70 void RegisterPatternAndContinue( |
| 71 const RegistrationCallback& callback, | 71 const RegistrationCallback& callback, |
| 72 ServiceWorkerRegistrationStatus previous_status); | 72 ServiceWorkerStatusCode previous_status); |
| 73 | 73 |
| 74 void UnregisterPatternAndContinue( | 74 void UnregisterPatternAndContinue( |
| 75 const UnregistrationCallback& callback, | 75 const UnregistrationCallback& callback, |
| 76 bool found, | 76 bool found, |
| 77 ServiceWorkerRegistrationStatus previous_status, | 77 ServiceWorkerStatusCode previous_status, |
| 78 const scoped_refptr<ServiceWorkerRegistration>& previous_registration); | 78 const scoped_refptr<ServiceWorkerRegistration>& previous_registration); |
| 79 | 79 |
| 80 // These methods are the last internal callback in the callback | 80 // These methods are the last internal callback in the callback |
| 81 // chain, and ultimately call callback_. | 81 // chain, and ultimately call callback_. |
| 82 void UnregisterComplete(ServiceWorkerRegistrationStatus status); | 82 void UnregisterComplete(ServiceWorkerStatusCode status); |
| 83 void RegisterComplete( | 83 void RegisterComplete( |
| 84 ServiceWorkerRegistrationStatus status, | 84 ServiceWorkerStatusCode status, |
| 85 const scoped_refptr<ServiceWorkerRegistration>& registration); | 85 const scoped_refptr<ServiceWorkerRegistration>& registration); |
| 86 | 86 |
| 87 void RunCallbacks( | 87 void RunCallbacks( |
| 88 ServiceWorkerRegistrationStatus status, | 88 ServiceWorkerStatusCode status, |
| 89 const scoped_refptr<ServiceWorkerRegistration>& registration); | 89 const scoped_refptr<ServiceWorkerRegistration>& registration); |
| 90 | 90 |
| 91 // The ServiceWorkerStorage object should always outlive | 91 // The ServiceWorkerStorage object should always outlive |
| 92 // this. | 92 // this. |
| 93 | 93 |
| 94 // TODO(alecflett) When we support job cancelling, if we are keeping | 94 // TODO(alecflett) When we support job cancelling, if we are keeping |
| 95 // this job alive for any reason, be sure to clear this variable, | 95 // this job alive for any reason, be sure to clear this variable, |
| 96 // because we may be cancelling while there are outstanding | 96 // because we may be cancelling while there are outstanding |
| 97 // callbacks that expect access to storage_. | 97 // callbacks that expect access to storage_. |
| 98 ServiceWorkerStorage* storage_; | 98 ServiceWorkerStorage* storage_; |
| 99 ServiceWorkerJobCoordinator* coordinator_; | 99 ServiceWorkerJobCoordinator* coordinator_; |
| 100 const GURL pattern_; | 100 const GURL pattern_; |
| 101 const GURL script_url_; | 101 const GURL script_url_; |
| 102 const RegistrationType type_; | 102 const RegistrationType type_; |
| 103 std::vector<RegistrationCallback> callbacks_; | 103 std::vector<RegistrationCallback> callbacks_; |
| 104 base::WeakPtrFactory<ServiceWorkerRegisterJob> weak_factory_; | 104 base::WeakPtrFactory<ServiceWorkerRegisterJob> weak_factory_; |
| 105 | 105 |
| 106 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegisterJob); | 106 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegisterJob); |
| 107 }; | 107 }; |
| 108 } // namespace content | 108 } // namespace content |
| 109 | 109 |
| 110 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTER_JOB_H_ | 110 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTER_JOB_H_ |
| OLD | NEW |